|
|
import * as Types from './types';
|
|
|
|
|
|
const TYPE = {notuse: 'notuse', use: 'use', overtime: 'overtime'};
|
|
|
|
|
|
export default {
|
|
|
async fetchYohoList({commit, state}, {type, filter = 0, refresh = false}) {
|
|
|
commit(Types.FETCH_YOHO_COUPON_REQUEST);
|
|
|
|
|
|
if (!refresh) {
|
|
|
if (state.yohoList[type].page > state.yohoList[type].pageNum) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const fetchPage = refresh ? 1 : state.yohoList[type].page + 1;
|
|
|
|
|
|
// 下一页的数据
|
|
|
const result = await this.$api.get('/api/coupon/yoho/list', {
|
|
|
type,
|
|
|
filter,
|
|
|
limit: 10,
|
|
|
page: fetchPage
|
|
|
});
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
const data = {
|
|
|
type,
|
|
|
couponList: result.data.couponList ? result.data.couponList.map((i) => _handleCoupon(i, type)) : [],
|
|
|
pageNum: result.data.pageNum,
|
|
|
pageSize: result.data.pageSize,
|
|
|
total: result.data.total,
|
|
|
filterId: filter,
|
|
|
page: fetchPage,
|
|
|
refresh
|
|
|
function _url({name}) {
|
|
|
return `//cdn.yoho.cn/${name}`;
|
|
|
}
|
|
|
|
|
|
function _handleData(data) {
|
|
|
const result = {
|
|
|
businessType: data.businessType,
|
|
|
businessName: data.businessName,
|
|
|
socialCreditCode: data.socialCreditCode,
|
|
|
certName: data.certName,
|
|
|
certNo: data.certNo,
|
|
|
start_time: data.time.start_time,
|
|
|
expire_time: data.time.noLimit ? '0' : data.time.expire_time,
|
|
|
licenseOriginalImage: data.licenseOriginalImage.map(_url).join(''),
|
|
|
licenseCopyImage: data.licenseCopyImage.map(_url).join(''),
|
|
|
certFaceImage: data.certFaceImage.map(_url).join(''),
|
|
|
certReverseImage: data.certReverseImage.map(_url).join('')
|
|
|
};
|
|
|
|
|
|
if (type === TYPE.notuse) {
|
|
|
data.filter = result.data.filters;
|
|
|
}
|
|
|
|
|
|
commit(Types.FETCH_YOHO_COUPON_SUCCESS, data);
|
|
|
} else {
|
|
|
commit(Types.FETCH_YOHO_COUPON_FAILED);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
return result.data.couponList ? result.data.couponList.length !== 0 : false;
|
|
|
},
|
|
|
|
|
|
async fetchYohoNum({commit}) {
|
|
|
commit(Types.FETCH_YOHO_COUPON_REQUEST);
|
|
|
|
|
|
const result = await this.$api.get('/api/coupon/yoho/num', {});
|
|
|
export default {
|
|
|
async fetchToken({ commit }) {
|
|
|
const result = await this.$api.get('/getToken?type=yohocdn');
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
commit(Types.FETCH_YOHO_COUPON_NUM_SUCCESS, result.data);
|
|
|
} else {
|
|
|
commit(Types.FETCH_YOHO_COUPON_FAILED);
|
|
|
}
|
|
|
commit(Types.FETCH_UFO_UPLOAD_TOKEN_SUCCESS, { token: result.uptoken });
|
|
|
},
|
|
|
|
|
|
async fetchUfoList({commit}) {
|
|
|
commit(Types.FETCH_YOHO_COUPON_REQUEST);
|
|
|
async saveAuth({ commit }, data) {
|
|
|
const result = await this.$api.post('/', _handleData(data));
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
return result;
|
|
|
},
|
|
|
|
|
|
async getCouponCode({commit}, {code}) {
|
|
|
commit(Types.FETCH_YOHO_COUPON_REQUEST);
|
|
|
|
|
|
const result = await this.$api.post('/api/coupon/yoho/getcoupon', {
|
|
|
coupon_code: code
|
|
|
});
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
commit(Types.FETCH_YOHO_COUPON_CODE_SUCCESS);
|
|
|
} else {
|
|
|
commit(Types.FETCH_YOHO_COUPON_FAILED);
|
|
|
}
|
|
|
async authSave({ commit }) {
|
|
|
const result = await this.$api.get('/state');
|
|
|
|
|
|
return result || {};
|
|
|
return result;
|
|
|
}
|
|
|
}; |
...
|
...
|
|