123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- import {
- SET_TOKEN,
- LOGOUT,
- SET_ISLOGIN,
- SET_USERINFO,
- SET_REFERRERID,
- SET_ISNOTICE,
- SET_TABBARINDEX,
- SET_STARTTIME,
- SET_ENDTIME,
- SET_ISPLAY,
- SET_ADDRESS,
- SET_REMARK,
- SET_GOODS,
- SET_SEARCHHISTORY,
- SET_CARTGOODS,
- ADD_CARTGOODS,
- EMPTY_SEARCHHISTORY,
- DELETE_SEARCHHISTORY,
- SET_SEARCHHISTORY2,
- EMPTY_SEARCHHISTORY2,
- DELETE_SEARCHHISTORY2,
- SET_YES_NUM,
- SET_ORDER_INFO,
- SET_BANK_CARD,
- SET_SELF_PICKUP_POINT
- } from '@/common/store/types';
- const module = {
- namespaced: true,
- state() {
- return {
- token: uni.getStorageSync('token'),
- // token: '',
- isLogin: uni.getStorageSync('isLogin') || false,
- userInfo: uni.getStorageSync('userInfo') || {},
- referrerId: uni.getStorageSync('referrerId'),
- isPlay: uni.getStorageSync('isPlay'),
- goods: uni.getStorageSync('goods') || [],
- searchHistory: uni.getStorageSync('searchHistory')||[],
- searchHistory2: uni.getStorageSync('searchHistory2')||[],
- cartGoods: uni.getStorageSync('cartGoods') || [],
- address: null,
- remark: '',
- isNotice: false,
- tabBarIndex: 0,
- startTime: '',
- endTime:'',
- yesNum: 0,
- bankCard: {},
- selfPickupPoint: {},
- orderInfo: {
- sumCount: 0,
- sumPrice: 0,
- data: []
- }
- }
- },
- getters: {
- _token:(state:any)=> state.token,
- _isLogin: (state:any) => state.isLogin,
- _referrerId: (state:any) => state.referrerId,
- _userInfo:(state:any)=> JSON.parse(JSON.stringify(state.userInfo)) || {},
- _isNotice: (state:any) => state.isNotice,
- _tabBarIndex: (state:any) => state.tabBarIndex,
- _startTime: (state:any) => state.startTime,
- _endTime: (state:any) => state.endTime,
- _isPlay: (state:any) => state.isPlay,
- _address: (state:any) => state.address,
- _remark: (state:any) => state.remark,
- _goods: (state:any) => state.goods,
- _searchHistory: (state: any) => JSON.parse(JSON.stringify(state.searchHistory)),
- _searchHistory2: (state: any) => JSON.parse(JSON.stringify(state.searchHistory2)),
- _cartGoods:(state: any) => JSON.parse(JSON.stringify(state.cartGoods)),
- _yesNum:(state:any) => state.yesNum || 0,
- _orderInfo:(state:any) => state.orderInfo,
- _bankCard:(state:any) => state.bankCard,
- _selfPickupPoint:(state:any) => state.selfPickupPoint,
- },
- mutations: {
- // 登录成功将, token保存在localStorage中
- [SET_TOKEN]: (state:any, data:any) => {
- uni.setStorageSync('token', data);
- state.token = data;
- },
- // 退出登录将, token清空
- [LOGOUT]: (state:any) => {
- uni.removeStorageSync('token');
- uni.removeStorageSync('userInfo');
- uni.removeStorageSync('isLogin');
- state.token = '';
- state.userInfo = null;
- state.isLogin = false;
- },
- // 登录状态
- [SET_ISLOGIN]: (state:any, data:any) => {
- uni.setStorageSync('isLogin', data);
- state.isLogin = data;
- },
- // 用户信息
- [SET_USERINFO]: (state:any, data:any) => {
- uni.setStorageSync('userInfo', data);
- state.userInfo = data;
- },
- // 保存推荐人
- [SET_REFERRERID]: (state:any, data:any) => {
- uni.setStorageSync('referrerId', data);
- state.referrerId = data;
- },
- // tabbar
- [SET_TABBARINDEX]: (state:any, data:any) => {
- state.tabBarIndex = data;
- },
- [SET_STARTTIME]: (state:any, data:any) => {
- state.startTime = data;
- },
- [SET_ENDTIME]: (state:any, data:any) => {
- state.endTime = data;
- },
- [SET_ADDRESS]: (state:any, data:any) => {
- state.address = data;
- },
- [SET_GOODS]: (state:any, data:any) => {
- uni.setStorageSync('goods', data);
- state.goods = data;
- },
- [SET_YES_NUM]: (state:any, data:any) => {
- state.yesNum = data;
- },
- // 购物车数据
- [SET_CARTGOODS]: (state: any, data: any) => {
- uni.setStorageSync('cartGoods', data);
- state.cartGoods = data;
- },
- // 搜索历史数据
- [SET_SEARCHHISTORY]: (state: any, data: any) => {
- if(!data) return;
- let val:Array<any> = state.searchHistory||[]
- let index = val.findIndex((item: any) => item === data);
- (index > -1) && val.splice(index,1);
- val.unshift(data);
- val = val.slice(0, 10);
- state.searchHistory = val;
- uni.setStorageSync('searchHistory', val);
- },
- // 清空搜索记录
- [EMPTY_SEARCHHISTORY]:(state: any, data: any) => {
- state.searchHistory = [];
- uni.setStorageSync('searchHistory', []);
- },
- [DELETE_SEARCHHISTORY]: (state: any, data: any) => {
- if(!data) return;
- let val:Array<any> = state.searchHistory||[]
- let index = val.findIndex((item: any) => item === data);
- (index > -1) && val.splice(index,1);
- uni.setStorageSync('searchHistory', val);
- },
- // 搜索历史数据
- [SET_SEARCHHISTORY2]: (state: any, data: any) => {
- if(!data) return;
- let val:Array<any> = state.searchHistory2||[]
- let index = val.findIndex((item: any) => item === data);
- (index > -1) && val.splice(index,1);
- val.unshift(data);
- uni.setStorageSync('searchHistory2', val);
- },
- // 清空搜索记录
- [EMPTY_SEARCHHISTORY2]:(state: any, data: any) => {
- state.searchHistory2 = [];
- uni.setStorageSync('searchHistory2', []);
- },
- [DELETE_SEARCHHISTORY2]: (state: any, data: any) => {
- if(!data) return;
- let val:Array<any> = state.searchHistory2||[]
- let index = val.findIndex((item: any) => item === data);
- (index > -1) && val.splice(index,1);
- uni.setStorageSync('searchHistory2', val);
- },
- [SET_ORDER_INFO]: (state:any, data:any) => {
- state.orderInfo = data;
- },
- [SET_BANK_CARD]: (state:any, data:any) => {
- state.bankCard = data;
- },
- [SET_SELF_PICKUP_POINT]: (state:any, data:any) => {
- state.selfPickupPoint = data;
- },
- },
- actions: {
- [ADD_CARTGOODS]:({state,commit}:any,goodsInfo: any) => {
- const cartFlag = state.cartGoods.find((res: any)=> res.sku_id == goodsInfo.sku_id)
-
- if(!cartFlag){
- goodsInfo.check = false;
- state.cartGoods.unshift(goodsInfo);
- }else{
- state.cartGoods.forEach((res: any)=>{
- if(res.sku_id == goodsInfo.sku_id){
- res.num += goodsInfo.num;
- }
- })
- console.log('数量加的有点问题呀',state.cartGoods,goodsInfo.num);
- }
- commit(SET_CARTGOODS,state.cartGoods);
- console.log('state.cartGoods------>',state.cartGoods)
- console.log('goodsInfo------>',goodsInfo)
- }
- }
- }
- export default module;
|