deming/common/store/index.js
2020-09-04 17:29:45 +08:00

104 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Vue from 'vue'
import Vuex from 'vuex'
import {
mapMutations
} from 'vuex';
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
orderType: '', // 订单类型 1 普通订单 2 拼团订单 3 秒杀订单 4 优惠券 5 购物车订单 和 goodsDetails 的 type 相同
orderInfo: {}, // 订单数据 订单步骤1展示结算数据
orderAddress: {}, // 下单时选择的地址
goodsDetails: {}, // 商品详情 1普通 2拼团 3秒杀 4优惠券
goods_id: '', // 拼团商品 id
pintuangroup_headid: '', // 拼团团长id 有为开团 无为参团
groupbuyInfo: {}, // 秒杀详情
loadmore: {}, // 下拉加载返回的数据
hasLogin: false, // 登录状态
token: "", // 储存token
showLoginModel: false, // 登录框
question: {}, // 帮助与反馈
showCoupons: true, // 是否显示新人领取优惠券
invoiceInfo: { // 是否选择发票
invoice_type: '',
invoice_id: 0,
}
},
getters: {
getOrderAddress(state) {
return state.orderAddress || {};
},
getGoodsType(state) {
return state.goodsDetails.type;
},
getGoodsInfo(state) {
return state.goodsDetails.goods;
},
hasInvoice(state) {
const type = state.invoiceInfo.invoice_type;
return type ? type : 0;
},
getInvoiceId(state) {
return state.invoiceInfo.invoice_id || 0;
}
},
mutations: {
// 登录
loginIn(state, token) {
state.hasLogin = true;
state.token = token;
uni.setStorage({
key: "token",
data: token
})
},
// 退出登录
logout(state) {
state.hasLogin = false;
state.token = "";
uni.removeStorage({
key: "token"
})
uni.removeStorage({
key: "user_info"
})
},
setOrderType(state, type) {
state.orderType = type;
},
updateOrderInfo(state, info) {
state.orderInfo = info;
},
updateAddress(state, address) {
state.orderAddress = address;
},
setGoodsDetails(state, goods) {
state.goodsDetails = goods;
},
setGoodsId(state, id) {
state.goods_id = id;
},
setGroupbuyInfo(state, info) {
state.groupbuyInfo = info;
},
setGroupHeadId(state, id) {
state.pintuangroup_headid = id;
},
setLoadMore(state, info) {
state.loadmore = info;
},
setQuestion(state, question) {
state.question = question;
},
updateShowCoupons(state, status) {
state.showCoupons = status;
},
setInvoiceInfo(state, invoice = {}) {
state.invoiceInfo = invoice;
}
}
})
export default store;