order-deliver.js 1.88 KB
export default function () {
  return {
    namespaced: true,
    state: {
      appraiseAddress: {},
      appraiseAddressCodes: []
    },
    mutations: {
      SET_APPRAISE_ADDRESS(state, { orderCode, data }) {
        let addr = {
          [orderCode]: data
        };

        state.appraiseAddressCodes.push(orderCode);

        if (state.appraiseAddressCodes.length > 5) {
          state.appraiseAddressCodes.shift()
        }

        state.appraiseAddressCodes.forEach(code => {
          if (state.appraiseAddress[code]) {
            addr[code] = state.appraiseAddress[code];
          }
        });

        state.appraiseAddress = addr;
      }
    },
    actions: {
      /**
       * @param {
       *  skup skup
       *  orderCode 订单编码
       * }
       */
      async fetchAppraiseAddress({ commit }, { skup, orderCode } = {}) {
        const res = await this.$api.get('/api/order/appraiseAddress', {
          skup,
          orderCode: orderCode + '',
        });

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

        return res;
      },
      /**
       * @param {
       *  orderCode 订单编码
       * }
       */
      async fetchAppraiseAddressChangeNotice({ commit }, { orderCode } = {}) {
        return await this.$api.get('/api/order/noticeAppraiseAddressChanged', {
          orderCode: orderCode + '',
        });
      },
      /**
       * @param {
       *  orderCode 订单编码
       *  wayBillCode 物流快递号
       *  depotNum 鉴定中心id
       * }
       */
      async deliverOrderToDepot({ commit }, { orderCode, wayBillCode, depotNum } = {}) {
        return await this.$api.post('/api/order/deliverToDepot', {
          expressCompanyId: 23,
          orderCode: orderCode + '',
          wayBillCode,
          depotNum
        });
      }
    },
  };
}