goodsdetail.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import PersistedState from '../PersistedState'
  2. import { getGoodsInfo } from '../../api/homegoodsdetail'
  3. const initState = {
  4. storeInfo:PersistedState.getStorage('goodsdetail','storeInfo', {}),
  5. detailInfo:PersistedState.getStorage('goodsdetail','detailInfo', {}), // 商品详情
  6. mansongInfo:PersistedState.getStorage('goodsdetail','mansongInfo', {}), // 满减
  7. voucher:PersistedState.getStorage('goodsdetail','voucher', {}), // 代金券
  8. commendList:PersistedState.getStorage('goodsdetail','commendList', []), // 推荐商品
  9. specList:PersistedState.getStorage('goodsdetail','specList', {}), // 规格列表
  10. consultType:PersistedState.getStorage('goodsdetail','consultType', {}), // 商品咨询
  11. mbBody:PersistedState.getStorage('goodsdetail','mbBody', []),
  12. isFavorate:PersistedState.getStorage('goodsdetail','isFavorate', false), // 是否收藏
  13. isShowcartInfo:PersistedState.getStorage('goodsdetail','isShowcartInfo', false), // 是否显示购物车
  14. isShowtranslateInfo:PersistedState.getStorage('goodsdetail','isShowtranslateInfo', false), // 是否显示保障列表
  15. number:PersistedState.getStorage('goodsdetail','number', 0), // 选择商品的数量
  16. // ispromotion: false, //点击促销, 根据该值来判断弹出框距离底部的距离
  17. type:PersistedState.getStorage('goodsdetail','type', '确定'), // 点击购买和加入购物车, 购买浮层的按钮显示
  18. chooseinfo: PersistedState.getStorage('goodsdetail','chooseinfo', {
  19. specification: [],
  20. ids: []
  21. }), // 选择该商品的ids和属性名称
  22. properties:PersistedState.getStorage('goodsdetail','properties', []), // 多属性商品的属性名称值
  23. index:PersistedState.getStorage('goodsdetail','index', 0), // 当前点击的type值
  24. currentProductId:PersistedState.getStorage('goodsdetail','currentProductId', ''), // 当前商品的id
  25. isPreviewPicture:PersistedState.getStorage('goodsdetail','isPreviewPicture', false), // 当前是否是预览大图
  26. swipeId:PersistedState.getStorage('goodsdetail','swipeId', 0), // 当前滑动的swiperid值
  27. promoPopstatus: PersistedState.getStorage('goodsdetail','promoPopstatus', false)
  28. }
  29. // initial state
  30. const state = {
  31. ...initState,
  32. initState () {
  33. return initState
  34. }
  35. }
  36. // mutations
  37. const mutations = {
  38. saveStoreInfo (state, value) {
  39. state.storeInfo = value
  40. PersistedState.setStorage('goodsdetail',state)
  41. },
  42. // 保存商品详情, 各个组件数据共享
  43. saveDetailInfo (state, value) {
  44. state.detailInfo = value
  45. PersistedState.setStorage('goodsdetail',state)
  46. },
  47. saveConsultType (state, value) {
  48. state.consultType = value
  49. PersistedState.setStorage('goodsdetail',state)
  50. },
  51. saveMansongInfo (state, value) {
  52. state.mansongInfo = value
  53. PersistedState.setStorage('goodsdetail',state)
  54. },
  55. saveVoucher (state, value) {
  56. state.voucher = value
  57. PersistedState.setStorage('goodsdetail',state)
  58. },
  59. // 商品详情
  60. saveMbBody (state, value) {
  61. state.mbBody = value
  62. PersistedState.setStorage('goodsdetail',state)
  63. },
  64. saveIsFavorate (state, value) {
  65. state.isFavorate = value
  66. PersistedState.setStorage('goodsdetail',state)
  67. },
  68. // 商品评论
  69. saveCommendList (state, value) {
  70. state.commendList = value
  71. PersistedState.setStorage('goodsdetail',state)
  72. },
  73. // 商品规格
  74. saveSpecList (state, value) {
  75. state.specList = value
  76. PersistedState.setStorage('goodsdetail',state)
  77. },
  78. // 根据点击时是否显示购物车浮层
  79. saveCartState (state, value) {
  80. state.isShowcartInfo = value
  81. PersistedState.setStorage('goodsdetail',state)
  82. },
  83. // 根据点击时是否显示店铺保障浮层
  84. saveTranslateState (state, value) {
  85. state.isShowtranslateInfo = value
  86. PersistedState.setStorage('goodsdetail',state)
  87. },
  88. // 保存选择的商品的数量
  89. saveNumber (state, number) {
  90. state.number = number
  91. PersistedState.setStorage('goodsdetail',state)
  92. },
  93. // 加入购物车,还是确定的文案设置
  94. changeType (state, value) {
  95. state.type = value
  96. PersistedState.setStorage('goodsdetail',state)
  97. },
  98. // 保存当钱切换的tab值
  99. changeIndex (state, value) {
  100. state.index = value
  101. PersistedState.setStorage('goodsdetail',state)
  102. },
  103. // 设置当前商品的id值
  104. setCurrentProductId (state, value) {
  105. state.currentProductId = value
  106. PersistedState.setStorage('goodsdetail',state)
  107. },
  108. // 设置当前商品的属性值
  109. saveChooseInfo (state, info) {
  110. state.chooseinfo = info
  111. PersistedState.setStorage('goodsdetail',state)
  112. },
  113. // 点击促销信息, 弹出框的位置
  114. changePromotion (state, data) {
  115. state.ispromotion = data
  116. PersistedState.setStorage('goodsdetail',state)
  117. },
  118. saveProperties (state, value) {
  119. state.properties = value
  120. PersistedState.setStorage('goodsdetail',state)
  121. },
  122. // 改变当前是否是预览大图的值
  123. setisPreviewPicture (state, value) {
  124. state.isPreviewPicture = value
  125. PersistedState.setStorage('goodsdetail',state)
  126. },
  127. setSwiperId (state, value) {
  128. state.swipeId = value
  129. PersistedState.setStorage('goodsdetail',state)
  130. },
  131. changePopstatus (state, value) {
  132. state.promoPopstatus = value
  133. PersistedState.setStorage('goodsdetail',state)
  134. }
  135. }
  136. // actions
  137. const actions = {
  138. // 获取商品详情
  139. getGoodsDetail ({ commit, state }, params) {
  140. return new Promise((resolve, reject) => {
  141. commit('setCurrentProductId', params.goods_id)
  142. getGoodsInfo(params.goods_id, params.token, params.extra).then(res => {
  143. if (res.result.goods_image) {
  144. res.result.goods_info.photos = res.result.goods_image
  145. }
  146. var goods_info=res.result.goods_info
  147. var goods_spec=goods_info.goods_spec
  148. var spec_detail=res.result.spec_detail
  149. var spec_disable=[]
  150. for(var i in spec_detail){
  151. if(spec_detail[i].stock<=0 && spec_detail[i].sign){
  152. var spec4=spec_detail[i].sign.split('|')
  153. var temp=[]
  154. for(var j in spec4){
  155. if(!goods_spec[spec4[j]]){
  156. temp.push(spec4[j])
  157. }
  158. }
  159. if(temp.length==1){
  160. spec_disable.push(temp[0])
  161. }
  162. }
  163. }
  164. goods_info.spec_disable=spec_disable
  165. commit('saveDetailInfo', goods_info)
  166. commit('saveStoreInfo', res.result.store_info)
  167. commit('saveConsultType', res.result.consult_type)
  168. commit('saveVoucher', res.result.voucher)
  169. commit('saveMansongInfo', res.result.mansong_info)
  170. commit('saveCommendList', res.result.goods_commend_list)
  171. commit('saveSpecList', res.result.spec_list)
  172. commit('saveIsFavorate', res.result.is_favorate)
  173. commit('saveMbBody', res.result.mb_body)
  174. resolve(res)
  175. }, (error) => {
  176. reject(error)
  177. })
  178. })
  179. }
  180. }
  181. export default {
  182. state,
  183. mutations,
  184. actions
  185. }