actions.js 1.74 KB
import * as Types from './types';

const TYPE = {notuse: 'notuse', use: 'use', overtime: 'overtime'};

function _handleCoupon(item, type) {
  if (type === TYPE.use) {
    item.is_used = true;
  }

  if (type === TYPE.use || item.is_overtime === 'Y' || item.is_invalid === 'Y') {
    item.usedOvertimeOrInValid = true;
  }

  item.useNowLink = 'fdsafdsa';
  return item;
}

function _handleUfoCoupon(item) {
  item.coupon_value_str = item.coupon_value;
  item.catalog_name = 'UFO';
  item.catalog = 'UFO';
  return item;
}

export default {
  async fetchYohoList({commit}, {type, filter, limit, page}) {
    commit(Types.FETCH_YOHO_COUPON_REQUEST);

    const result = await this.$api.get('/api/coupon/yoho/list', {type, filter, limit, page});

    if (result && result.code === 200) {
      const data = {
        type,
        list: result.data.couponList.map(_handleCoupon),
      };

      if (type === TYPE.notuse) {
        data.filter = result.data.filters;
      }

      commit(Types.FETCH_YOHO_COUPON_SUCCESS, data);
    } else {
      commit(Types.FETCH_YOHO_COUPON_FAILED);
    }
  },

  async fetchYohoNum({commit}) {
    commit(Types.FETCH_YOHO_COUPON_REQUEST);

    const result = await this.$api.get('/api/coupon/yoho/num', {});

    if (result && result.code === 200) {
      commit(Types.FETCH_YOHO_COUPON_NUM_SUCCESS, result.data);
    } else {
      commit(Types.FETCH_YOHO_COUPON_FAILED);
    }
  },

  async fetchUfoList({commit}) {
    commit(Types.FETCH_YOHO_COUPON_REQUEST);

    const result = await this.$api.get('/api/coupon/ufo/list');

    if (result && result.code === 200) {
      commit(Types.FETCH_UFO_COUPON_SUCCESS, {
        list: result.data.map(_handleUfoCoupon)
      });
    } else {
      commit(Types.FETCH_YOHO_COUPON_FAILED);
    }
  },
};