Commit b83c44fe1f06fd34fc21a5bf3621c35ac422a876

Authored by 喻鹏
1 parent 137d6c3ecf
Exists in master

购物车和用户推荐传参

src/components/CommodityCard/CommodityCard.vue
1 1 <template>
2 2 <view
3 3 class="card"
4   - @tap="toGoods(goods.id?goods.id:goods.sk_id)"
  4 + @tap="toGoods(goods.id?goods.id:goods.pid)"
5 5 >
6 6 <image
7 7 mode="widthFix"
... ...
src/pages/cart/cart.vue
... ... @@ -28,7 +28,7 @@
28 28 <image :src="item.img_index_url" mode="aspectFit" style="width: 188rpx;height: 168rpx;"></image>
29 29 </view> -->
30 30 <view class="infoRight">
31   - <view class="goodName" @tap="toGoods(item.pid,item.p_root_index)">{{item.p_name}}</view>
  31 + <view class="goodName" @tap="toGoods(item.pid)">{{item.p_name}}</view>
32 32 <!-- <view class="describ"> -->
33 33 <uni-collapse accordion="true" >
34 34 <uni-collapse-item showAnimation='true'
... ... @@ -52,10 +52,10 @@
52 52 <text class="maxCount">(限购{{maxCount}}副)</text>
53 53 <view class="counter">
54 54 <view class="btn" disabled="this.addDisabled" type="default"
55   - @tap="counter(index,false,item.mp_id,item.sk_id,item.num,item.cart_id)">-</view>
  55 + @tap="counter(index,false,item)">-</view>
56 56 <text>{{item.num}}</text>
57 57 <view class="btn" disabled="this.desDisabled" type="default"
58   - @tap="counter(index,true,item.mp_id,item.sk_id,item.num,item.cart_id)">+</view>
  58 + @tap="counter(index,true,item)">+</view>
59 59 </view>
60 60 </view>
61 61 </view>
... ... @@ -93,7 +93,7 @@ export default {
93 93 computed: {
94 94  
95 95 cartList() {
96   - // console.log('cart-list', this.$store.state.cart.cartList);
  96 + console.log('cart-list', this.$store.state.cart.cartList);
97 97 return this.$store.state.cart.cartList
98 98 },
99 99 childIsOpen() {
... ... @@ -124,58 +124,67 @@ export default {
124 124  
125 125 methods: {
126 126  
127   - toGoods(id, type) {
128   - uni.navigateTo({
129   - url: '../frameDetail/frameDetail?oderId=' + id,
130   - success: res => {},
131   - fail: () => {},
132   - complete: () => {}
133   - })
134   - console.log('toGoods =====> id:' + id + '======>type:' + type)
135   - switch (type) {
136   - case 1:
137   - uni.navigateTo({
138   - url: '../frameDetail/frameDetail?oderId=' + id + '&goodType=' + type,
139   - success: res => {},
140   - fail: () => {},
141   - complete: () => {}
142   - })
143   - break
144   - case 2:
145   - uni.navigateTo({
146   - url: '../frameDetail/frameDetail?oderId=' + id + '&goodType=' + type,
147   - success: res => {},
148   - fail: () => {},
149   - complete: () => {}
150   - })
151   - break
152   - case 3:
153   - uni.navigateTo({
154   - url: '../frameDetail/frameDetail?oderId=' + id + '&goodType=' + type,
155   - success: res => {},
156   - fail: () => {},
157   - complete: () => {}
158   - })
159   - break
160   - case 4:
161   - uni.navigateTo({
162   - url: '../frameDetail/frameDetail?oderId=' + id + '&goodType=' + type,
163   - success: res => {},
164   - fail: () => {},
165   - complete: () => {}
166   - })
167   - break
168   - default :
169   - break
170   - }
  127 + toGoods(id) {
  128 + console.log('---', '../frameDetail/frameDetail?pid=' + id)
  129 + uni.navigateTo({
  130 + url: '../frameDetail/frameDetail?pid=' + id,
  131 + success: res => {},
  132 + fail: () => {},
  133 + complete: () => {}
  134 + })
  135 + // uni.navigateTo({
  136 + // url: '../frameDetail/frameDetail?oderId=' + id,
  137 + // success: res => {},
  138 + // fail: () => {},
  139 + // complete: () => {}
  140 + // })
  141 + // console.log('toGoods =====> id:' + id + '======>type:' + type)
  142 + // switch (type) {
  143 + // case 1:
  144 + // uni.navigateTo({
  145 + // url: '../frameDetail/frameDetail?oderId=' + id + '&goodType=' + type,
  146 + // success: res => {},
  147 + // fail: () => {},
  148 + // complete: () => {}
  149 + // })
  150 + // break
  151 + // case 2:
  152 + // uni.navigateTo({
  153 + // url: '../frameDetail/frameDetail?oderId=' + id + '&goodType=' + type,
  154 + // success: res => {},
  155 + // fail: () => {},
  156 + // complete: () => {}
  157 + // })
  158 + // break
  159 + // case 3:
  160 + // uni.navigateTo({
  161 + // url: '../frameDetail/frameDetail?oderId=' + id + '&goodType=' + type,
  162 + // success: res => {},
  163 + // fail: () => {},
  164 + // complete: () => {}
  165 + // })
  166 + // break
  167 + // case 4:
  168 + // uni.navigateTo({
  169 + // url: '../frameDetail/frameDetail?oderId=' + id + '&goodType=' + type,
  170 + // success: res => {},
  171 + // fail: () => {},
  172 + // complete: () => {}
  173 + // })
  174 + // break
  175 + // default :
  176 + // break
  177 + // }
171 178 },
172 179  
173   - counter(index, isadd, mp_id, sk_id, num, cart_id) {
  180 + counter(index, isadd, item) {
174 181 // console.log('===>>counter ===>num',num)
175 182 // console.log('===>>counter ===>isadd',isadd)
176   - num = parseInt(num)
  183 + console.log('item=====>',item)
  184 + console.log('num=====>',item.num)
  185 + let nums = parseInt(item.num)
177 186 if (isadd) {
178   - if (num >= this.maxCount) {
  187 + if (nums >= this.maxCount) {
179 188 this.addDisabled = true
180 189 } else {
181 190 this.addDisabled = true
... ... @@ -186,10 +195,12 @@ export default {
186 195 store.dispatch('cart/modiCart', {
187 196 uid: this.$store.state.user.userInfo.uid,
188 197 openid: this.$store.state.user.userInfo.openid,
189   - mp_id: mp_id,
190   - sk_id: sk_id,
191   - cart_id: cart_id,
192   - num: num + 1,
  198 + mp_id: item.mp_id,
  199 + sk_id: item.sk_id,
  200 + price: item.nowPrice,
  201 + pid: item.pid,
  202 + num: nums + 1,
  203 + cart_id: item.cart_id,
193 204 args: {
194 205 index: index,
195 206 isadd: isadd
... ... @@ -198,7 +209,7 @@ export default {
198 209 this.addDisabled = false
199 210 }
200 211 } else {
201   - if (num <= 1) {
  212 + if (nums <= 1) {
202 213 this.desDisabled = true
203 214 } else {
204 215 this.desDisabled = false
... ... @@ -209,10 +220,12 @@ export default {
209 220 store.dispatch('cart/modiCart', {
210 221 uid: this.$store.state.user.userInfo.uid,
211 222 openid: this.$store.state.user.userInfo.openid,
212   - mp_id: mp_id,
213   - sk_id: sk_id,
214   - cart_id: cart_id,
215   - num: num - 1,
  223 + mp_id: item.mp_id,
  224 + sk_id: item.sk_id,
  225 + price: item.nowPrice,
  226 + pid: item.pid,
  227 + num: nums - 1,
  228 + cart_id: item.cart_id,
216 229 args: {
217 230 index: index,
218 231 isadd: isadd
... ... @@ -268,6 +281,8 @@ export default {
268 281 // console.log('delcart------>cart_id',cart_id)
269 282 // console.log('cartlist====>delcart',this.$store.state.cart.cartList)
270 283 // console.log('delcart======>index',index)
  284 + const uid=this.$store.state.user.userInfo.uid
  285 + const openid=this.$store.state.user.userInfo.openid
271 286 uni.showModal({
272 287 title: '是否删除该商品',
273 288 // content: '是否删除该商品',
... ... @@ -275,8 +290,8 @@ export default {
275 290 if (res.confirm) {
276 291 // this.$store.state.cart.cartList.splice(index,1)
277 292 store.dispatch('cart/delCart', {
278   - uid: this.$store.state.user.userInfo.uid,
279   - openid: this.$store.state.user.userInfo.openid,
  293 + uid: uid,
  294 + openid: openid,
280 295 cart_id: cart_id, // 要修改的购物车id
281 296 arg: index // 由于action 传参是能接收两参数,因此将index放入对象
282 297 })
... ...
src/pages/user/user.vue
... ... @@ -268,6 +268,7 @@ export default {
268 268 return this.$store.state.user.userInfo.headerphoto
269 269 },
270 270 userRecommandList() {
  271 + console.log('userRecommandList=====>',this.$store.state.userRecommand.recommandList)
271 272 return this.$store.state.userRecommand.recommandList
272 273 }
273 274 },
... ...
src/store/modules/cart.js
... ... @@ -33,10 +33,6 @@ const actions = {
33 33 data: param,
34 34 success: (res) => {
35 35 console.log('cart===>接口数据', res.data.data)
36   - // const resData = {
37   - // ...res,
38   - // data,
39   - // }
40 36 commit('INIT', res.data.data)
41 37 },
42 38 fail: (res) => {
... ... @@ -77,8 +73,6 @@ const actions = {
77 73 success: (res) => {
78 74 console.log('del-parm', param)
79 75 console.log('del-myparms==>', arg)
80   - // console.log('deacart====>cartList',this.$store.state.cart.cartList)
81   -
82 76 commit('DEL', arg)
83 77 },
84 78 fail: (res) => {
... ...