order-confirm.js 3.11 KB
import { get, find } from 'lodash';

export const Types = {
  FETCH_ORDER_ADDRESS: 'FETCH_ORDER_ADDRESS',
  FETCH_ORDER_USER_STATUS: 'FETCH_ORDER_USER_STATUS',
  FETCH_ORDER_FEE: 'FETCH_ORDER_FEE',
  CHANGE_PRICE: 'CHANGE_PRICE',
  CHANGE_AGREE: 'CHANGE_AGREE',
  FETCH_ORDER_BUY_ORDER: 'FETCH_ODER_BUY_ORDER',
  FETCH_ORDER_COUPON_LIST: 'FETCH_ORDER_COUPON_LIST'
};

export const UserType = {
  sell: 'sell',
  buy: 'buy'
};

export default function() {
  return {
    namespaced: true,
    state: {
      address: {},
      fee: {
        income: '',
        bankTransferFee: '',
        platformFee: {
          amount: '',
          appraiseFee: '',
          goodsPaymentRatePercent: '',
          packageFee: '',
          payChannelPercentage: '',
          serviceFee: ''
        }
      },
      alipayStatus: false,
      userStatus: false,
      price: '',
      agree: false,

      orderDetail: {},
      couponList: []
    },
    mutations: {
      [Types.FETCH_ORDER_ADDRESS](state, data) {
        state.address = data;
      },
      [Types.FETCH_ORDER_FEE](state, data) {
        state.fee = data;
      },
      [Types.CHANGE_PRICE](state, data) {
        state.price = data;
      },
      [Types.CHANGE_AGREE](state, data) {
        state.agree = data;
      },
      [Types.FETCH_ORDER_BUY_ORDER](state, data) {
        state.orderDetail = data;
      },
      [Types.FETCH_ORDER_COUPON_LIST](state, data) {
        state.couponList = data;
      }
    },
    actions: {
      async fetchOrderAddress({ commit }, payload) {
        const orderCount = await this.$api.get('/api/order/confirm/count', payload);

        if (get(orderCount, 'data.cnt', 0)) {
          const addressInfo = await this.$api.get('/api/order/confirm/address');

          const address = find(get(addressInfo, 'data', []), { is_default: 'Y' });

          commit(Types.FETCH_ORDER_ADDRESS, address);
        }
      },

      async fetchOrderPrice({ commit }, payload) {
        const order = await this.$api.post('/api/order/confirm/compute', payload);

        if (order.code !== 200) {
          return {
            error: order.message
          };
        }

        commit(Types.FETCH_ORDER_FEE, order.data);
        return order.data;
      },

      async fetchUserStatus() {
        const alipayStatus = await this.$api.get('/api/order/alipay/status');
        const userStatus = await this.$api.get('/api/order/user/status');
      },

      async submitOrder({ commit }, payload) {
        return this.$api.post('/api/order/presubmit', payload);
      },

      async fetchPayList({ commit }, payload) {
        return this.$api.post('/api/order/paytype', payload);
      },

      async fetchPayment({ commit }, { skup }) {
        const orderInfo = await this.$api.post('/api/order/confirm/buypayment', { skup, api_version: 1 });
        const couponList = await this.$api.get('/api/order/confirm/coupon', { skup, depositRequirement: 'N' });

        if (orderInfo.code !== 200) {
          return;
        }

        commit(Types.FETCH_ORDER_BUY_ORDER, orderInfo.data);
        commit(Types.FETCH_ORDER_COUPON_LIST, couponList.data);
      },
    },
    getters: {},
  };
}