Authored by 陈峰

commit

... ... @@ -17,7 +17,7 @@ const errHandle = (error) => {
const request = (options, store) => {
return axios(options).then((res) => {
if (res.data.code === 401) {
store && store.commit('needLogin', {needLogin: true});
store && store.commit('SET_NEED_LOGIN', {needLogin: true});
return Promise.reject(res.data);
}
return res.data;
... ...
... ... @@ -41,7 +41,7 @@ export default context => {
}).catch(e => {
reportError(e);
if (e.code === 401) {
store.commit('needLogin', {needLogin: true});
store.commit('SET_NEED_LOGIN', {needLogin: true});
}
context.state = store.state;
return resolve(app);
... ...
<template>
<Layout>
<LayoutHeader slot='header' title="推荐" :share="shareData"></LayoutHeader>
ArticlePage
<div class="article-content">
page-content
</div>
</Layout>
</template>
... ...
import storeList from './list';
export default function() {
return {
namespaced: true,
modules: {
yoho: storeList()
}
};
}
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 = true;
// 线下店不可使用
if (!item.is_online_avail) {
item.useNowLink = '';
}
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, 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
};
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.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', {});
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);
}
},
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);
}
return result || {};
}
};
import actions from './actions';
import mutations from './mutations';
function handleNum(n) {
return n > 99 ? '99+' : n;
}
export default function() {
return {
namespaced: true,
state: {
fetching: false,
yohoList: {
notuse: {
couponList: [],
pageNum: 0,
pageSize: 10,
total: 0,
page: 0,
filterId: 0
},
use: {
couponList: [],
pageNum: 0,
pageSize: 10,
total: 0,
page: 0,
filterId: 0
},
overtime: {
couponList: [],
pageNum: 0,
pageSize: 10,
total: 0,
page: 0,
filterId: 0
}
},
num: {
notuse: 0,
use: 0,
overtime: 0
},
ufoList: [],
filterList: [],
},
actions,
mutations,
getters: {
getNum(state) {
return [handleNum(state.num.notuse), handleNum(state.num.use), handleNum(state.num.overtime)];
},
getNotUseList(state) {
return state.yohoList.notuse.couponList;
},
getUseList(state) {
return state.yohoList.use.couponList;
},
getOvertimeList(state) {
return state.yohoList.overtime.couponList;
},
}
};
}
import * as Types from './types';
export default {
[Types.FETCH_YOHO_COUPON_REQUEST](state) {
state.fetching = true;
},
[Types.FETCH_YOHO_COUPON_SUCCESS](state, {couponList, filter, type, pageNum, pageSize, total, filterId, page, refresh}) {
state.fetching = false;
const typeData = state.yohoList[type];
const list = typeData.couponList;
const newCouponList = refresh ? couponList : list.concat(couponList);
typeData.couponList = newCouponList;
typeData.pageNum = pageNum;
typeData.pageSize = pageSize;
typeData.total = total;
typeData.filterId = filterId;
typeData.page = page;
if (filter) {
state.filterList = filter;
}
},
[Types.FETCH_YOHO_COUPON_FAILED](state) {
state.fetching = false;
},
[Types.FETCH_YOHO_COUPON_NUM_SUCCESS](state, data) {
state.num = data;
},
[Types.FETCH_UFO_COUPON_SUCCESS](state, {list = []}) {
state.fetching = false;
state.ufoList = list;
}
};
export const FETCH_YOHO_COUPON_REQUEST = 'FETCH_YOHO_COUPON_REQUEST';
export const FETCH_YOHO_COUPON_FAILED = 'FETCH_YOHO_COUPON_FAILED';
export const FETCH_YOHO_COUPON_SUCCESS = 'FETCH_YOHO_COUPON_SUCCESS';
export const FETCH_YOHO_COUPON_NUM_SUCCESS = 'FETCH_YOHO_COUPON_NUM_SUCCESS';
export const FETCH_YOHO_COUPON_CODE_SUCCESS = 'FETCH_YOHO_COUPON_CODE_SUCCESS';
export const FETCH_UFO_COUPON_SUCCESS = 'FETCH_UFO_COUPON_SUCCESS';
... ... @@ -2,8 +2,7 @@ import Vue from 'vue';
import Vuex from 'vuex';
import {createApi} from 'create-api';
import storeYoho from './yoho';
import storeUfo from './order';
import storeLicense from './license';
import plugin from './plugin';
Vue.use(Vuex);
... ... @@ -12,10 +11,9 @@ export function createStore(context) {
namespaced: true,
modules: {
yoho: storeYoho(),
ufo: storeUfo(),
license: storeLicense()
},
strict: process.env.NODE_ENV !== 'production'
strict: process.env.NODE_ENV !== 'production',
plugins: [plugin]
});
const api = createApi(context, store);
... ...
import * as Types from './types';
function _url({ name }) {
return `//cdn.yoho.cn/${name}`;
}
function _handleData(data) {
const result = {
business_type: data.businessType,
business_name: data.businessName,
social_credit_code: data.socialCreditCode,
cert_name: data.certName,
cert_no: data.certNo,
start_time: data.time.start_time,
expire_time: data.time.noLimit ? '0' : data.time.expire_time,
license_original_image: data.licenseOriginalImage.map(_url).join(''),
license_copy_image: data.licenseCopyImage.map(_url).join(''),
cert_face_image: data.certFaceImage.map(_url).join(''),
cert_reverse_image: data.certReverseImage.map(_url).join('')
};
return result;
}
export default {
async fetchToken({ commit }) {
const result = await this.$api.get('/getToken?type=yohocdn');
commit(Types.FETCH_UFO_UPLOAD_TOKEN_SUCCESS, { token: result.uptoken });
},
async saveLicense({ commit }, data) {
const result = await this.$api.post(
'/api/ufo/license/save',
_handleData(data)
);
return result;
},
async licenseStatus({ commit }) {
let result = await this.$api.get('/api/ufo/license/status');
if (result.code === 200) {
commit(Types.FETCH_UFO_STATUS_SUCCESS, { status: result.data, message: result.message });
} else {
commit(Types.FETCH_UFO_STATUS_SUCCESS, { status: -1 });
}
},
async getStoreStatus({ commit }) {
let result = {};
try {
result = await this.$api.get('/api/ufo/store/status');
} catch (e) {
return result;
}
return result;
}
};
import actions from './actions';
import mutations from './mutations';
export default function() {
return {
namespaced: true,
state: {
fetching: false,
token: false,
status: -1,
message: ''
},
actions,
mutations
};
}
import * as Types from './types';
export default {
[Types.FETCH_UFO_UPLOAD_TOKEN_SUCCESS](state, {token}) {
state.token = token;
},
[Types.FETCH_UFO_STATUS_SUCCESS](state, {status, message}) {
state.status = status;
state.message = message;
},
[Types.FETCH_UFO_NEED_LOGIN](state, data) {
state.needLogin = data;
}
};
export const FETCH_UFO_UPLOAD_TOKEN_SUCCESS = 'FETCH_UFO_UPLOAD_TOKEN_SUCCESS';
export const FETCH_UFO_SAVE_REQUEST = 'FETCH_UFO_SAVE_REQUEST';
export const FETCH_UFO_SAVE_SUCCESS = 'FETCH_UFO_SAVE_SUCCESS';
export const FETCH_UFO_SAVE_ERROR = 'FETCH_UFO_SAVE_ERROR';
export const FETCH_UFO_STATUS_REQUEST = 'FETCH_UFO_STATUS_REQUEST';
export const FETCH_UFO_STATUS_SUCCESS = 'FETCH_UFO_STATUS_SUCCESS';
export const FETCH_UFO_STATUS_ERROR = 'FETCH_UFO_STATUS_ERROR';
export const FETCH_UFO_NEED_LOGIN = 'FETCH_UFO_NEED_LOGIN';
import storeList from './form';
export default function() {
return {
namespaced: true,
modules: {
form: storeList()
}
};
}
import storeChannel from './channel';
import storeUser from './user';
import storePush from './push';
export default function() {
return {
namespaced: true,
modules: {
channel: storeChannel(),
user: storeUser(),
push: storePush(),
}
};
}
import storeOrder from './ufo';
export default function() {
return {
namespaced: true,
modules: {
order: storeOrder()
}
};
}
import * as Types from './types';
import {first, get, flatten} from 'lodash';
export default {
async fetchProduct({commit}, {productId, page = 1, refresh = false}) {
commit(Types.FETCH_ORDER_PRODUCT_REQUEST);
let result;
if (refresh) {
const results = await Promise.all(Array.from(new Array(page)).map((v, i) => {
return this.$api.get('/api/ufo/seller/entryGoodsSizeList', {
productId,
page: i + 1
});
}));
result = {
code: 200,
data: {
productInfo: get(first(results), 'data.productInfo'),
data: flatten(results.map(r => get(r, 'data.data', [])))
}
};
} else {
result = await this.$api.get('/api/ufo/seller/entryGoodsSizeList', {
productId,
page
});
}
if (result && result.code === 200) {
commit(Types.FETCH_ORDER_PRODUCT_SUCCESS, {
order: result.data,
refresh,
});
} else {
commit(Types.FETCH_ORDER_PRODUCT_FAILD);
}
return result;
},
async postNoSale({commit}, payload) {
commit(Types.POST_NOSALE_REQUEST);
const result = await this.$api.get('/api/ufo/sellerOrder/batchDownShelf', payload);
if (result && result.code === 200) {
commit(Types.POST_NOSALE_SUCCESS, {
order: result.data
});
} else {
commit(Types.POST_NOSALE_FAILD);
}
return result || {};
},
async postCalcPrice({commit}, payload) {
commit(Types.POST_CALCPRICE_REQUEST);
const result = await this.$api.get('/api/ufo/sellerOrder/computeAdjustPrice', payload);
if (result && result.code === 200) {
commit(Types.POST_CALCPRICE_SUCCESS, {
order: result.data
});
} else {
commit(Types.POST_CALCPRICE_FAILD);
}
return result || {};
},
async postChangePrice({commit}, payload) {
commit(Types.POST_CHANGEPRICE_REQUEST);
const result = await this.$api.get('/api/ufo/sellerOrder/batchAdjustPrice', payload);
if (result && result.code === 200) {
commit(Types.POST_CHANGEPRICE_SUCCESS, {
order: result.data
});
} else {
commit(Types.POST_CHANGEPRICE_FAILD);
}
return result || {};
}
};
import actions from './actions';
import mutations from './mutations';
export default function() {
return {
namespaced: true,
state: {
fetchingPro: false,
fetchingNoSale: false,
fetchingChangePrice: false,
fetchingCalcPrice: false,
productInfo: {},
skcs: []
},
actions,
mutations
};
}
import * as Types from './types';
export default {
[Types.FETCH_ORDER_PRODUCT_REQUEST](state) {
state.orderInfo = {};
state.fetchingPro = true;
},
[Types.FETCH_ORDER_PRODUCT_FAILD](state) {
state.fetchingPro = false;
},
[Types.FETCH_ORDER_PRODUCT_SUCCESS](state, {order, refresh}) {
state.fetchingPro = false;
if (order.productInfo && state.productInfo.productId !== order.productInfo.productId || refresh) {
state.productInfo = order.productInfo || state.productInfo;
}
if (refresh) {
state.skcs = order.data;
} else if (order.data) {
state.skcs = state.skcs.concat(order.data);
}
},
[Types.MERGE_CHANGEPRICE_DATA](state, {skc, mergeData}) {
Object.assign(skc, mergeData);
},
[Types.POST_NOSALE_REQUEST](state) {
state.fetchingNoSale = true;
},
[Types.POST_NOSALE_FAILD](state) {
state.fetchingNoSale = false;
},
[Types.POST_NOSALE_SUCCESS](state) {
state.fetchingNoSale = false;
},
[Types.POST_CHANGEPRICE_REQUEST](state) {
state.fetchingChangePrice = true;
},
[Types.POST_CHANGEPRICE_FAILD](state) {
state.fetchingChangePrice = false;
},
[Types.POST_CHANGEPRICE_SUCCESS](state) {
state.fetchingChangePrice = false;
},
[Types.POST_CALCPRICE_REQUEST](state) {
state.fetchingCalcPrice = true;
},
[Types.POST_CALCPRICE_FAILD](state) {
state.fetchingCalcPrice = false;
},
[Types.POST_CALCPRICE_SUCCESS](state) {
state.fetchingCalcPrice = false;
},
};
export const FETCH_ORDER_PRODUCT_REQUEST = 'FETCH_ORDER_PRODUCT_REQUEST';
export const FETCH_ORDER_PRODUCT_FAILD = 'FETCH_ORDER_PRODUCT_FAILD';
export const FETCH_ORDER_PRODUCT_SUCCESS = 'FETCH_ORDER_PRODUCT_SUCCESS';
export const POST_NOSALE_REQUEST = 'POST_NOSALE_REQUEST';
export const POST_NOSALE_FAILD = 'POST_NOSALE_FAILD';
export const POST_NOSALE_SUCCESS = 'POST_NOSALE_SUCCESS';
export const POST_CHANGEPRICE_REQUEST = 'POST_CHANGEPRICE_REQUEST';
export const POST_CHANGEPRICE_FAILD = 'POST_CHANGEPRICE_FAILD';
export const POST_CHANGEPRICE_SUCCESS = 'POST_CHANGEPRICE_SUCCESS';
export const MERGE_CHANGEPRICE_DATA = 'MERGE_CHANGEPRICE_DATA';
export const POST_CALCPRICE_REQUEST = 'POST_CALCPRICE_REQUEST';
export const POST_CALCPRICE_FAILD = 'POST_CALCPRICE_FAILD';
export const POST_CALCPRICE_SUCCESS = 'POST_CALCPRICE_SUCCESS';
export default (store) => {
if (process.env.VUE_ENV !== 'server') {
window.onresize = () => {
const {clientWidth, clientHeight} = document.body;
store.commit('SET_WINDOW_SIZE', {clientWidth, clientHeight});
};
setTimeout(() => {
const {clientWidth, clientHeight} = document.body;
store.commit('SET_WINDOW_SIZE', {clientWidth, clientHeight});
}, 0);
}
};
... ...
... ... @@ -18,9 +18,11 @@ export default function() {
path: '',
needLogin: false
},
window: {
clientHeight: 0,
clientWidth: 0
},
historys: [],
visible: true,
pageVisible: false,
direction: 'forword',
},
mutations: {
... ... @@ -53,8 +55,11 @@ export default function() {
state.direction = 'forword';
}
},
[Types.NEED_LOGIN](state, {needLogin}) {
[Types.SET_NEED_LOGIN](state, {needLogin}) {
state.context.needLogin = needLogin;
},
[Types.SET_WINDOW_SIZE](state, data) {
state.window = Object.assign(state.window, data);
}
},
actions: {
... ...
export const SET_ENV = 'SET_ENV';
export const SET_TITLE = 'SET_TITLE';
export const ROUTE_CHANGE = 'ROUTE_CHANGE';
export const PAGE_INIT_VISIBLE = 'PAGE_INIT_VISIBLE';
export const YOHO_PAGE_VISIBLE = 'YOHO_PAGE_VISIBLE';
export const REPORT_YAS = 'REPORT_YAS';
export const NEED_LOGIN = 'needLogin';
export const SET_NEED_LOGIN = 'SET_NEED_LOGIN';
export const SET_WINDOW_SIZE = 'SET_WINDOW_SIZE';
... ...