Authored by huangyCode

商品列表

  1 +<template>
  2 + <div>
  3 + <div class="item" v-if="list.length" v-for="(product,index) in list"
  4 + :class="((index === 0 || index === 1) ? 'top-line':'') +' '+((index) % 2 === 0 ? 'right-line' :'')"
  5 + :key="index">
  6 + <div class="item-price">{{product.price ? '¥' + product.price : ' '}}</div>
  7 + <ImgSize class="item-imge" :src="product.default_images" :width="300" :height="300"/>
  8 + <div class="item-name">{{product.product_name}}</div>
  9 + </div>
  10 + </div>
  11 +</template>
  12 +
  13 +<script>
  14 +import {Scroll} from 'cube-ui';
  15 +import ImgSize from '../../../components/img-size';
  16 +
  17 +export default {
  18 + props: {
  19 + list: Array,
  20 + },
  21 + methods: {},
  22 + components: {
  23 + ImgSize,
  24 + Scroll,
  25 + }
  26 +};
  27 +</script>
  28 +
  29 +<style lang="scss" scoped>
  30 + .top-line {
  31 + border-top: 1px #ddd solid;
  32 + }
  33 +
  34 + .right-line {
  35 + border-right: 1px #ddd solid;
  36 + }
  37 +
  38 + .item {
  39 + width: 9.37rem;
  40 + border-bottom: 1px #ddd solid;
  41 + padding: 28px 38px 0 38px;
  42 + float: left;
  43 + overflow: hidden;
  44 + height: 560px;
  45 + }
  46 +
  47 + .item-price {
  48 + margin-bottom: 38px;
  49 + font-size: 28px;
  50 + color: #000;
  51 + letter-spacing: 0;
  52 + }
  53 +
  54 + .item-imge {
  55 + width: 300px;
  56 + height: 300px;
  57 + }
  58 +
  59 + .item-name {
  60 + font-size: 28px;
  61 + color: #000;
  62 + letter-spacing: 0;
  63 + text-align: center;
  64 + line-height: 40px;
  65 + margin-top: 38px;
  66 + margin-bottom: 44px;
  67 + }
  68 +</style>
1 export default [{ 1 export default [{
  2 + name: 'list',
2 path: '/xianyu/list', 3 path: '/xianyu/list',
3 - component: () => null 4 + component: () => import(/* webpackChunkName: "list" */ './list')
  5 +},
  6 +{
  7 + name: 'filter',
  8 + path: '/xianyu/list/filter',
  9 + component: () => import(/* webpackChunkName: "filter" */ './filter')
  10 +},
  11 +{
  12 + name: 'search',
  13 + path: '/xianyu/list/search',
  14 + component: () => import(/* webpackChunkName: "search" */ './search')
4 }]; 15 }];
  1 +<template>
  2 + <LayoutApp :show-back="true">
  3 + <Scroll :scrollEvents="['scroll']" :options="scrollOptions" @scroll="scroll"
  4 + @pulling-up="onPullingUp">
  5 + <ProductList :list="productList.list"></ProductList>
  6 + </Scroll>
  7 + </LayoutApp>
  8 +</template>
  9 +<script>
  10 +import ProductList from './components/productList';
  11 +import {Scroll} from 'cube-ui';
  12 +import {createNamespacedHelpers} from 'vuex';
  13 +
  14 +const {mapState, mapActions} = createNamespacedHelpers('list');
  15 +
  16 +export default {
  17 + name: 'list',
  18 + components: {
  19 + ProductList,
  20 + Scroll
  21 + },
  22 + data() {
  23 + return {
  24 + scrollOptions: {
  25 + bounce: {
  26 + top: false
  27 + },
  28 + pullUpLoad: true
  29 + },
  30 + fixed: false
  31 + };
  32 + },
  33 + mounted() {
  34 + this.fetchProductList();
  35 + },
  36 + methods: {
  37 + ...mapActions(['fetchProductList']),
  38 +
  39 + async onPullingUp() {
  40 + await this.fetchProductList();
  41 + },
  42 + scroll({ y }) {
  43 + const height = this.$refs.banner.$el.offsetHeight + this.$refs.header.offsetHeight;
  44 +
  45 + if (-y >= height) {
  46 + this.fixed = true;
  47 + } else {
  48 + this.fixed = false;
  49 + }
  50 + }
  51 + },
  52 + computed: {
  53 + ...mapState(['productList']),
  54 + },
  55 +};
  56 +</script>
  57 +
  58 +<style scoped>
  59 +</style>
1 -import { get } from 'lodash';  
2 -import { getImgUrl } from '../../common/utils'; 1 +import {get} from 'lodash';
  2 +import Vue from 'vue';
3 3
4 export default function() { 4 export default function() {
5 return { 5 return {
6 namespaced: true, 6 namespaced: true,
7 state: { 7 state: {
  8 + productList: {
  9 + showErrorPage: false,
  10 + isFetching: false,
  11 + error: null,
  12 + page: 0, // 当前页
  13 + page_size: 10, // 每页数量
  14 + page_total: 0, // 总共多少页
  15 + total: 0, // 总共多少条
  16 + endReached: false, // 到达底部
  17 + list: [], // 商品列表
  18 + isEmpty: false,
  19 + },
  20 + searchParams: {
  21 + type: 0, // type:0,推荐;1,热销;2,即将发售; 3,品类; 4,品牌;5,系列;6,搜索 7, 收藏
  22 + order: null, // 指定排序
  23 + productPool: null, // 商品池id
  24 + sort: null, // 品类id
  25 + brand: null, // 品牌id
  26 + series: null, // 系列id
  27 + gender: null, // 性别
  28 + size: null, // 尺码id
  29 + isSoonSale: null, // 是否是即将售卖
  30 + query: null, // 搜索词
  31 + limit: null, // 每页记录数
  32 + page: null, // 当前页号
  33 + coupon_token: null, // 优惠券token
  34 + },
  35 + filterParams: {
  36 + sort: [], // 品类id
  37 + brand: [], // 品牌id
  38 + gender: [], // 性别
  39 + size: [], // 尺码id
  40 + },
  41 + filterData: [],
  42 + filterVisible: false,
8 }, 43 },
9 mutations: { 44 mutations: {
  45 + addProductList(state, {data}) {
  46 + Vue.set(state.productList, 'list', state.productList.list.concat(data.product_list));
  47 + Vue.set(state.productList, 'page', data.page);
  48 + },
10 }, 49 },
11 actions: { 50 actions: {
  51 + async fetchProductList({commit, state}) {
  52 + let page = state.productList.page;
  53 + let size = state.productList.page_size;
  54 + const result = await this.$api.get('/api/ufo/list/productList', {
  55 + page: page + 1,
  56 + size: size
  57 + });
  58 +
  59 + if (result.code === 200) {
  60 + commit('addProductList', {data: result.data});
  61 + }
  62 +
  63 + return result.data ? result.data.length : 0;
  64 + },
12 }, 65 },
13 }; 66 };
14 } 67 }
1 module.exports = { 1 module.exports = {
  2 + '/api/ufo/list/productList': {
  3 + ufo: true,
  4 + api: 'ufo.product.search.list',
  5 + params: {
  6 + page: {type: Number},
  7 + size: {type: Number},
  8 + type: {type: Number}, // type:0,推荐;1,热销;2,即将发售; 3,品类; 4,品牌;5,系列;6,搜索 7, 收藏
  9 + order: {type: String}, // 指定排序
  10 + productPool: {type: Number}, // 商品池id
  11 + sort: {type: Number}, // 品类id
  12 + brand: {type: Number}, // 品牌id
  13 + series: {type: Number}, // 系列id
  14 + gender: {type: String}, // 性别
  15 + query: {type: String}, // 搜索词
  16 + limit: {type: Number}, // 每页记录数
  17 + coupon_token: {type: String}, // 优惠券token
  18 + },
  19 + },
2 }; 20 };