import PersistedState from '../PersistedState' import { getGoodsInfo } from '../../api/homegoodsdetail' const initState = { storeInfo:PersistedState.getStorage('goodsdetail','storeInfo', {}), detailInfo:PersistedState.getStorage('goodsdetail','detailInfo', {}), // 商品详情 mansongInfo:PersistedState.getStorage('goodsdetail','mansongInfo', {}), // 满减 voucher:PersistedState.getStorage('goodsdetail','voucher', {}), // 代金券 commendList:PersistedState.getStorage('goodsdetail','commendList', []), // 推荐商品 specList:PersistedState.getStorage('goodsdetail','specList', {}), // 规格列表 consultType:PersistedState.getStorage('goodsdetail','consultType', {}), // 商品咨询 mbBody:PersistedState.getStorage('goodsdetail','mbBody', []), isFavorate:PersistedState.getStorage('goodsdetail','isFavorate', false), // 是否收藏 isShowcartInfo:PersistedState.getStorage('goodsdetail','isShowcartInfo', false), // 是否显示购物车 isShowtranslateInfo:PersistedState.getStorage('goodsdetail','isShowtranslateInfo', false), // 是否显示保障列表 number:PersistedState.getStorage('goodsdetail','number', 0), // 选择商品的数量 // ispromotion: false, //点击促销, 根据该值来判断弹出框距离底部的距离 type:PersistedState.getStorage('goodsdetail','type', '确定'), // 点击购买和加入购物车, 购买浮层的按钮显示 chooseinfo: PersistedState.getStorage('goodsdetail','chooseinfo', { specification: [], ids: [] }), // 选择该商品的ids和属性名称 properties:PersistedState.getStorage('goodsdetail','properties', []), // 多属性商品的属性名称值 index:PersistedState.getStorage('goodsdetail','index', 0), // 当前点击的type值 currentProductId:PersistedState.getStorage('goodsdetail','currentProductId', ''), // 当前商品的id isPreviewPicture:PersistedState.getStorage('goodsdetail','isPreviewPicture', false), // 当前是否是预览大图 swipeId:PersistedState.getStorage('goodsdetail','swipeId', 0), // 当前滑动的swiperid值 promoPopstatus: PersistedState.getStorage('goodsdetail','promoPopstatus', false) } // initial state const state = { ...initState, initState () { return initState } } // mutations const mutations = { saveStoreInfo (state, value) { state.storeInfo = value PersistedState.setStorage('goodsdetail',state) }, // 保存商品详情, 各个组件数据共享 saveDetailInfo (state, value) { state.detailInfo = value PersistedState.setStorage('goodsdetail',state) }, saveConsultType (state, value) { state.consultType = value PersistedState.setStorage('goodsdetail',state) }, saveMansongInfo (state, value) { state.mansongInfo = value PersistedState.setStorage('goodsdetail',state) }, saveVoucher (state, value) { state.voucher = value PersistedState.setStorage('goodsdetail',state) }, // 商品详情 saveMbBody (state, value) { state.mbBody = value PersistedState.setStorage('goodsdetail',state) }, saveIsFavorate (state, value) { state.isFavorate = value PersistedState.setStorage('goodsdetail',state) }, // 商品评论 saveCommendList (state, value) { state.commendList = value PersistedState.setStorage('goodsdetail',state) }, // 商品规格 saveSpecList (state, value) { state.specList = value PersistedState.setStorage('goodsdetail',state) }, // 根据点击时是否显示购物车浮层 saveCartState (state, value) { state.isShowcartInfo = value PersistedState.setStorage('goodsdetail',state) }, // 根据点击时是否显示店铺保障浮层 saveTranslateState (state, value) { state.isShowtranslateInfo = value PersistedState.setStorage('goodsdetail',state) }, // 保存选择的商品的数量 saveNumber (state, number) { state.number = number PersistedState.setStorage('goodsdetail',state) }, // 加入购物车,还是确定的文案设置 changeType (state, value) { state.type = value PersistedState.setStorage('goodsdetail',state) }, // 保存当钱切换的tab值 changeIndex (state, value) { state.index = value PersistedState.setStorage('goodsdetail',state) }, // 设置当前商品的id值 setCurrentProductId (state, value) { state.currentProductId = value PersistedState.setStorage('goodsdetail',state) }, // 设置当前商品的属性值 saveChooseInfo (state, info) { state.chooseinfo = info PersistedState.setStorage('goodsdetail',state) }, // 点击促销信息, 弹出框的位置 changePromotion (state, data) { state.ispromotion = data PersistedState.setStorage('goodsdetail',state) }, saveProperties (state, value) { state.properties = value PersistedState.setStorage('goodsdetail',state) }, // 改变当前是否是预览大图的值 setisPreviewPicture (state, value) { state.isPreviewPicture = value PersistedState.setStorage('goodsdetail',state) }, setSwiperId (state, value) { state.swipeId = value PersistedState.setStorage('goodsdetail',state) }, changePopstatus (state, value) { state.promoPopstatus = value PersistedState.setStorage('goodsdetail',state) } } // actions const actions = { // 获取商品详情 getGoodsDetail ({ commit, state }, params) { return new Promise((resolve, reject) => { commit('setCurrentProductId', params.goods_id) getGoodsInfo(params.goods_id, params.token, params.extra).then(res => { if (res.result.goods_image) { res.result.goods_info.photos = res.result.goods_image } var goods_info=res.result.goods_info var goods_spec=goods_info.goods_spec var spec_detail=res.result.spec_detail var spec_disable=[] for(var i in spec_detail){ if(spec_detail[i].stock<=0 && spec_detail[i].sign){ var spec4=spec_detail[i].sign.split('|') var temp=[] for(var j in spec4){ if(!goods_spec[spec4[j]]){ temp.push(spec4[j]) } } if(temp.length==1){ spec_disable.push(temp[0]) } } } goods_info.spec_disable=spec_disable commit('saveDetailInfo', goods_info) commit('saveStoreInfo', res.result.store_info) commit('saveConsultType', res.result.consult_type) commit('saveVoucher', res.result.voucher) commit('saveMansongInfo', res.result.mansong_info) commit('saveCommendList', res.result.goods_commend_list) commit('saveSpecList', res.result.spec_list) commit('saveIsFavorate', res.result.is_favorate) commit('saveMbBody', res.result.mb_body) resolve(res) }, (error) => { reject(error) }) }) } } export default { state, mutations, actions }