Repository navigation
Expand file tree
/
Copy pathmutations.js
More file actions
244 lines (238 loc) · 5.2 KB
/
Copy pathmutations.js
File metadata and controls
244 lines (238 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import {
RECORD_ADDRESS,
ADD_CART,
REDUCE_CART,
INIT_BUYCART,
CLEAR_CART,
RECORD_SHOPDETAIL,
RECORD_USERINFO,
GET_USERINFO,
CONFIRM_REMARK,
CONFIRM_INVOICE,
CHOOSE_SEARCH_ADDRESS,
SAVE_GEOHASH,
CONFIRM_ADDRESS,
CHOOSE_ADDRESS,
NEED_VALIDATION,
SAVE_CART_ID_SIG,
SAVE_ORDER_PARAM,
CHANGE_ORDER_PARAM,
ORDER_SUCCESS,
SAVE_SHOPID,
SAVE_ORDER,
OUT_LOGIN,
RETSET_NAME,
SAVE_AVANDER,
SAVE_ADDRESS,
SAVE_ADDDETAIL,
SAVE_QUESTION,
ADD_ADDRESS,
BUY_CART,
} from './mutation-types.js'
import {setStore, getStore} from '../config/mUtils'
import {localapi, proapi} from 'src/config/env'
export default {
// 记录当前经度纬度
[RECORD_ADDRESS](state, {
latitude,
longitude
}) {
state.latitude = latitude;
state.longitude = longitude;
},
[RECORD_SHOPDETAIL](state, detail) {
state.shopDetail = detail;
},
// 加入购物车
[ADD_CART](state, {
shopid,
category_id,
item_id,
food_id,
name,
price,
specs,
packing_fee,
sku_id,
stock
}) {
let cart = state.cartList;
let shop = cart[shopid] = (cart[shopid] || {});
let category = shop[category_id] = (shop[category_id] || {});
let item = category[item_id] = (category[item_id] || {});
if (item[food_id]) {
item[food_id]['num']++;
} else {
item[food_id] = {
"num" : 1,
"id" : food_id,
"name" : name,
"price" : price,
"specs" : specs,
"packing_fee" : packing_fee,
"sku_id" : sku_id,
"stock" : stock
};
}
state.cartList = {...cart};
//存入localStorage
setStore('buyCart', state.cartList);
},
// 移出购物车
[REDUCE_CART](state, {
shopid,
category_id,
item_id,
food_id,
name,
price,
specs,
}) {
let cart = state.cartList;
let shop = (cart[shopid] || {});
let category = (shop[category_id] || {});
let item = (category[item_id] || {});
if (item && item[food_id]) {
if (item[food_id]['num'] > 0) {
item[food_id]['num']--;
state.cartList = {...cart};
//存入localStorage
setStore('buyCart', state.cartList);
} else {
//商品数量为0,则清空当前商品的信息
item[food_id] = null;
}
}
},
//网页初始化时从本地缓存获取购物车数据
[INIT_BUYCART](state) {
let initCart = getStore('buyCart');
if (initCart) {
state.cartList = JSON.parse(initCart);
}
},
//清空当前商品的购物车信息
[CLEAR_CART](state, shopid) {
state.cartList[shopid] = null;
state.cartList = {...state.cartList};
setStore('buyCart', state.cartList);
},
// 记录用户信息
[RECORD_USERINFO](state, info) {
state.userInfo = info;
state.login = true;
setStore('user_id', info.user_id);
},
//获取用户信息存入vuex
[GET_USERINFO](state, info) {
if (state.userInfo && (state.userInfo.username !== info.username)) {
return;
};
if (!state.login) {
return
}
if (!info.message) {
state.userInfo = {...info};
} else {
state.userInfo = null;
}
},
//修改用户名
[RETSET_NAME](state,username) {
state.userInfo = Object.assign({}, state.userInfo,{username})
},
//保存商铺id
[SAVE_SHOPID](state, shopid) {
state.shopid = shopid;
},
//记录订单页面用户选择的备注, 传递给订单确认页面
[CONFIRM_REMARK](state, {
remarkText,
inputText
}) {
state.remarkText = remarkText;
state.inputText = inputText;
},
//是否开发票
[CONFIRM_INVOICE](state, invoice) {
state.invoice = invoice;
},
//选择搜索的地址
[CHOOSE_SEARCH_ADDRESS](state, place) {
state.searchAddress = place;
},
//保存geohash
[SAVE_GEOHASH](state, geohash) {
state.geohash = geohash;
},
//确认订单页添加新的的地址
[CONFIRM_ADDRESS](state, newAddress) {
state.newAddress.push(newAddress);
},
//选择的地址
[CHOOSE_ADDRESS](state, {
address,
index
}) {
state.choosedAddress = address;
state.addressIndex = index;
},
//保存下单需要验证的返回值
[NEED_VALIDATION](state, needValidation) {
state.needValidation = needValidation;
},
//保存下单后购物id 和 sig
[SAVE_CART_ID_SIG](state, {
cart_id,
sig
}) {
state.cart_id = cart_id;
state.sig = sig;
},
//保存下单参数,用户验证页面调用
[SAVE_ORDER_PARAM](state, orderParam) {
state.orderParam = orderParam;
},
//修改下单参数
[CHANGE_ORDER_PARAM](state, newParam) {
state.orderParam = Object.assign({}, state.orderParam, newParam);
},
//下单成功,保存订单返回信息
[ORDER_SUCCESS](state, order) {
state.cartPrice = null;
state.orderMessage = order;
},
//进入订单详情页前保存该订单信息
[SAVE_ORDER](state, orderDetail) {
state.orderDetail = orderDetail;
},
//退出登录
[OUT_LOGIN](state) {
state.userInfo = {};
state.login = false;
},
//保存图片
[SAVE_AVANDER](state, imgPath) {
state.imgPath = imgPath;
},
//删除地址列表
[SAVE_ADDRESS](state, newAdress) {
state.removeAddress = newAdress
},
//添加地址name
[SAVE_ADDDETAIL](state, addAddress){
state.addAddress=addAddress;
},
//保存所选问题标题和详情
[SAVE_QUESTION](state, question) {
state.question = {...question};
},
//增加地址
[ADD_ADDRESS](state, obj) {
state.removeAddress = [obj, ...state.removeAddress];
},
//会员卡价格纪录
[BUY_CART](state, price) {
state.cartPrice = price;
},
}