order-list.js 1.59 KB
export default function() {
  return {
    namespaced: true,
    state: {
      page: 1,
      pageSize: 10,
      pagetotal: 0,
      orderList: [], // 订单列表
      // scroll 组件参数,是否触发上拉事件
      pullUpLoad: true,

      // 当前查询订单状态
      currentStatus: 1,
      routerParam: {},
    },
    mutations: {
      setOrderList(state, res) {
        let { page, pagetotal, data = [] } = res;

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

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

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

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