mutations.js 1.46 KB
import * as Types from './types';
// import { find, set } from 'lodash';

export default {

  /*
   * @ description: 更新二手商品详情页
   * @ author: huzhiming
   * @ date: 2019-11-22 19:09:49
   * @ version: v1.0.0
  */
  [Types.UPDATE_PRODUCT_DETAIL](state, { info }) {
    state.info = { ...state.info, ...info };
  },

  /*
   * @ description: 更新相同尺寸 二手商品列表
   * @ author: huzhiming
   * @ date: 2019-11-22 19:09:02
   * @ version: v1.0.0
  */
  [Types.UPDATE_PRODUCT_LIST](state, { data: { product_list, page_total, page }, isReset, error }) {
    if (error) {
      state.isShowEmpty = true;
      return false;
    }

    if (product_list) {
      if (page_total > page) {
        state.isMore = true;
        state.pageTotal = page_total;
        state.page = page + 1;
      } else {
        state.isMore = false;
      }

      // 为了适配组件内数据,[apps/pages/second/components/second-list.vue]
      product_list = product_list.map(item=>({
        ...item,
        secondhand_image: item.image,
        skup_price: item.price,
        secondhandTypeName: item.sechondHandTypeName, // 修复字段单词拼写错误
        size_name: item.sizeName.replace('码', '')
      }));

      if (isReset) {
        state.productList = product_list;
      } else {
        state.productList = state.productList.push(...product_list);
      }
    }
  },

  [Types.UPDATE_PRODUCT_FILTER](state, { filter }) {
    state.filterData = filter;
  }
};