order-list.js 1.61 KB
export default function() {
  return {
    namespaced: true,
    state: {
      page: 1,
      pageSize: 10,
      pagetotal: 0,
      orderList: [], // 订单列表
      // scroll 组件参数,是否触发上拉事件
      pullUpLoad: true,
      currentStatus: 1,
    },
    mutations: {
      setOrderList(state, { fetchData, isStatusChange }) {
        let { page, pagetotal, data = [] } = fetchData;

        state.page = ++page;
        state.pagetotal = pagetotal;
        state.orderList = isStatusChange ? data : state.orderList.concat(data);

        // 分页结束
        if (page > pagetotal) {
          state.pullUpLoad = false;
        }
      },
      setOrderStatus(state, currentStatus) {
        state.currentStatus = +currentStatus;
      },
    },
    actions: {
      /**
       *  获取订单列表
       * @param {*}  param0 vue store context
       * @param {
       *  owner: 订单来源
       *  status: 订单状态 默认全部
       * }
       * r
       */
      async fetchOrderList(
        {
          commit,
          state: { page, currentStatus },
        },
        { owner, status = 1 } = {},
      ) {
        const isStatusChange = currentStatus !== +status;
        const res = await this.$api.get('/api/order/list', {
          tabType: owner,
          type: status,
          page: isStatusChange ? 1 : page,
          limit: 5,

          // Todo 删除
          uid: 600043484,
        });

        if (res.code === 200) {
          commit('setOrderList', { fetchData: res.data, isStatusChange });
          commit('setOrderStatus', status);
        }
      },
    },
    getters: {},
  };
}