Commit 678d6b48aaed6062bd4e9d050ebcaf689484f806
1 parent
a196efbcb1
Exists in
master
async函数修改
Showing
2 changed files
with
173 additions
and
166 deletions
Show diff stats
src/pages/cart/cart.vue
| ... | ... | @@ -130,7 +130,7 @@ export default { |
| 130 | 130 | isCart: Number, |
| 131 | 131 | sk_id: String, |
| 132 | 132 | mp_id: String, |
| 133 | - isShowBottom: false, // 底部弹窗开关 | |
| 133 | + isShowBottom: false, // 底部弹窗开关 | |
| 134 | 134 | cart_id: Number, |
| 135 | 135 | maxCount: 20, |
| 136 | 136 | cartIndex: Number, |
| ... | ... | @@ -145,88 +145,88 @@ export default { |
| 145 | 145 | return false |
| 146 | 146 | }, |
| 147 | 147 | goodInfo () { |
| 148 | - return this.$store.state.read.goodInfo | |
| 148 | + return this.$store.state.read.goodInfo | |
| 149 | 149 | }, |
| 150 | 150 | totalPrice() { |
| 151 | 151 | let totalPrice = 0 |
| 152 | 152 | this.cartList.forEach((item) => { |
| 153 | - if (item.isChecked) { | |
| 153 | + if (item.isChecked) { | |
| 154 | 154 | totalPrice += item.nowPrice * item.num |
| 155 | - } | |
| 155 | + } | |
| 156 | 156 | }) |
| 157 | 157 | return totalPrice |
| 158 | 158 | }, |
| 159 | 159 | }, |
| 160 | - onShow() { | |
| 160 | + onShow: async function() { | |
| 161 | 161 | await this.$store.dispatch('cart/getCartList', { |
| 162 | 162 | uid: this.$store.state.user.userInfo.uid, // 用户id |
| 163 | 163 | }) |
| 164 | 164 | |
| 165 | 165 | this.cartList = this.$store.state.cart.cartList |
| 166 | 166 | this.cartList.forEach((item) => { |
| 167 | - item.isChecked = false | |
| 167 | + item.isChecked = false | |
| 168 | 168 | }) |
| 169 | 169 | }, |
| 170 | 170 | onLoad: async function() { |
| 171 | 171 | }, |
| 172 | 172 | methods: { |
| 173 | - // 全选按钮 | |
| 174 | - pClick() { | |
| 175 | - const pStatus = !this.cartList.find(item => !item.isChecked) | |
| 176 | - const oldList = this.cartList | |
| 177 | - oldList.forEach((item, index) => { | |
| 178 | - item.isChecked = !pStatus | |
| 179 | - this.cartList.splice(index, 1, item) | |
| 180 | - }) | |
| 181 | - }, | |
| 182 | - // 单选按钮 | |
| 183 | - childClick(type, index) { | |
| 184 | - this.cartList[index].isChecked = !this.cartList[index].isChecked | |
| 185 | - // vue没有办法监听数组内部值的变化,所以需要通过这个方法去触发 | |
| 186 | - this.cartList.splice(index, 1, this.cartList[index]) | |
| 187 | - }, | |
| 188 | - // 修改购物车 | |
| 189 | - chooseCartModi(mp_id, sk_id, price, pid, num, cart_id, index) { | |
| 190 | - // console.log('modi',mp_id,sk_id,price,pid,num,cart_id) | |
| 191 | - store.dispatch('cart/modiCart', { | |
| 192 | - uid: this.$store.state.user.userInfo.uid, | |
| 193 | - openid: this.$store.state.user.userInfo.openid, | |
| 194 | - mp_id: mp_id, | |
| 195 | - sk_id: sk_id, | |
| 196 | - price: price, | |
| 197 | - pid: pid, | |
| 198 | - num: num, | |
| 199 | - cart_id: cart_id, | |
| 173 | + // 全选按钮 | |
| 174 | + pClick() { | |
| 175 | + const pStatus = !this.cartList.find(item => !item.isChecked) | |
| 176 | + const oldList = this.cartList | |
| 177 | + oldList.forEach((item, index) => { | |
| 178 | + item.isChecked = !pStatus | |
| 179 | + this.cartList.splice(index, 1, item) | |
| 180 | + }) | |
| 181 | + }, | |
| 182 | + // 单选按钮 | |
| 183 | + childClick(type, index) { | |
| 184 | + this.cartList[index].isChecked = !this.cartList[index].isChecked | |
| 185 | + // vue没有办法监听数组内部值的变化,所以需要通过这个方法去触发 | |
| 186 | + this.cartList.splice(index, 1, this.cartList[index]) | |
| 187 | + }, | |
| 188 | + // 修改购物车 | |
| 189 | + chooseCartModi(mp_id, sk_id, price, pid, num, cart_id, index) { | |
| 190 | + // console.log('modi',mp_id,sk_id,price,pid,num,cart_id) | |
| 191 | + store.dispatch('cart/modiCart', { | |
| 192 | + uid: this.$store.state.user.userInfo.uid, | |
| 193 | + openid: this.$store.state.user.userInfo.openid, | |
| 194 | + mp_id: mp_id, | |
| 195 | + sk_id: sk_id, | |
| 196 | + price: price, | |
| 197 | + pid: pid, | |
| 198 | + num: num, | |
| 199 | + cart_id: cart_id, | |
| 200 | 200 | args: { |
| 201 | - index: index, | |
| 201 | + index: index, | |
| 202 | 202 | }, |
| 203 | - }) | |
| 204 | - this.$nextTick(function() { | |
| 205 | - store.dispatch('cart/getCartList', { | |
| 206 | - uid: this.$store.state.user.userInfo.uid, // 用户id | |
| 207 | - }).then(() => { | |
| 203 | + }) | |
| 204 | + this.$nextTick(function() { | |
| 205 | + store.dispatch('cart/getCartList', { | |
| 206 | + uid: this.$store.state.user.userInfo.uid, // 用户id | |
| 207 | + }).then(() => { | |
| 208 | 208 | this.cartList = this.$store.state.cart.cartList |
| 209 | 209 | }) |
| 210 | - }) | |
| 211 | - }, | |
| 212 | - // 底部弹窗开关 | |
| 213 | - showBottom(isCart, pid, skId, mp_id, cart_id, index) { | |
| 214 | - store.dispatch('read/fetch', { | |
| 210 | + }) | |
| 211 | + }, | |
| 212 | + // 底部弹窗开关 | |
| 213 | + showBottom(isCart, pid, skId, mp_id, cart_id, index) { | |
| 214 | + store.dispatch('read/fetch', { | |
| 215 | 215 | pid, |
| 216 | 216 | sk_id: skId, |
| 217 | - }).then(() => { | |
| 218 | - this.cartIndex = index | |
| 219 | - this.sk_id = skId | |
| 220 | - this.pid = pid | |
| 221 | - this.mp_id = mp_id | |
| 222 | - this.isCart = isCart | |
| 223 | - this.cart_id = cart_id | |
| 224 | - this.isShowBottom = true | |
| 225 | - }) | |
| 226 | - }, | |
| 227 | - closeBottom() { | |
| 228 | - this.isShowBottom = false | |
| 229 | - }, | |
| 217 | + }).then(() => { | |
| 218 | + this.cartIndex = index | |
| 219 | + this.sk_id = skId | |
| 220 | + this.pid = pid | |
| 221 | + this.mp_id = mp_id | |
| 222 | + this.isCart = isCart | |
| 223 | + this.cart_id = cart_id | |
| 224 | + this.isShowBottom = true | |
| 225 | + }) | |
| 226 | + }, | |
| 227 | + closeBottom() { | |
| 228 | + this.isShowBottom = false | |
| 229 | + }, | |
| 230 | 230 | toGoods(id, skId) { |
| 231 | 231 | uni.navigateTo({ |
| 232 | 232 | url: '../details/details?pid=' + id + '&sk_id=' + skId, |
| ... | ... | @@ -300,20 +300,20 @@ export default { |
| 300 | 300 | }, |
| 301 | 301 | delCart(cart_id, index) { |
| 302 | 302 | cart_id = parseInt(cart_id) |
| 303 | - uni.showModal({ | |
| 304 | - title: '是否删除该商品', | |
| 305 | - success: function (res) { | |
| 306 | - if (res.confirm) { | |
| 307 | - store.dispatch('cart/delCart', { | |
| 308 | - uid: this.$store.state.user.userInfo.uid, | |
| 309 | - openid: this.$store.state.user.userInfo.openid, | |
| 310 | - cart_id: cart_id, // 要修改的购物车id | |
| 311 | - arg: index, // 由于action 传参是能接收两参数,因此将index放入对象 | |
| 312 | - }) | |
| 313 | - } | |
| 314 | - }.bind(this), | |
| 315 | - }) | |
| 316 | - // this.cartList.splice(index,1) | |
| 303 | + uni.showModal({ | |
| 304 | + title: '是否删除该商品', | |
| 305 | + success: function (res) { | |
| 306 | + if (res.confirm) { | |
| 307 | + store.dispatch('cart/delCart', { | |
| 308 | + uid: this.$store.state.user.userInfo.uid, | |
| 309 | + openid: this.$store.state.user.userInfo.openid, | |
| 310 | + cart_id: cart_id, // 要修改的购物车id | |
| 311 | + arg: index, // 由于action 传参是能接收两参数,因此将index放入对象 | |
| 312 | + }) | |
| 313 | + } | |
| 314 | + }.bind(this), | |
| 315 | + }) | |
| 316 | + // this.cartList.splice(index,1) | |
| 317 | 317 | }, |
| 318 | 318 | }, |
| 319 | 319 | } | ... | ... |
src/pages/confirmOrder/confirmOrder.vue
| ... | ... | @@ -52,58 +52,66 @@ |
| 52 | 52 | ></image> |
| 53 | 53 | <text>非常戴镜</text> |
| 54 | 54 | </view> |
| 55 | - | |
| 56 | - <view class="infoBox" v-if="isCart == 'true'" v-for="(item, index) in checkedCartLst" :key="index"> | |
| 57 | - <view class="infoTop"> | |
| 58 | - <image | |
| 59 | - :src="item.img_index_url" | |
| 60 | - mode="aspectFill" | |
| 61 | - ></image> | |
| 62 | - <view class="infoRight"> | |
| 63 | - <text class="goodName">{{item.p_name}}</text> | |
| 64 | - <text class="remarks">支持7天无理由退货 顺丰发货</text> | |
| 65 | - <view class="priceBox"> | |
| 66 | - <view class="price">¥{{Number(item.nowPrice) * item.num}}<text class="originCost"> | |
| 67 | - ¥{{item.oldPrice*item.num}} | |
| 68 | - </text></view> | |
| 69 | - <view class="counter"> | |
| 70 | - <view | |
| 71 | - class="btn" | |
| 72 | - disabled="this.disabled" | |
| 73 | - type="default" | |
| 74 | - @click="counter(false,index)" | |
| 75 | - >-</view> | |
| 76 | - <text>{{checkedCartLst[index].num}}</text> | |
| 77 | - <view | |
| 78 | - class="btn" | |
| 79 | - type="default" | |
| 80 | - @click="counter(true,index)" | |
| 81 | - >+</view> | |
| 82 | - </view> | |
| 83 | - </view> | |
| 84 | - </view> | |
| 85 | - </view> | |
| 86 | - <view class="infoBottom"> | |
| 87 | - <view class="norm">规格 <text> | |
| 88 | - <!-- 长度超出变省略号未做 --> | |
| 89 | - <block >{{item.sku_name}}<block v-if="index !== current.length -1">/</block> | |
| 90 | - </block> | |
| 91 | - </text></view> | |
| 92 | - <view class="shippingMethod">使用人 <text> | |
| 93 | - {{item.peopleName}} | |
| 94 | - </text></view> | |
| 95 | - <view class="shippingMethod">配送方式 <text>快递</text></view> | |
| 96 | - <view class="message">买家留言 | |
| 97 | - <input | |
| 98 | - type="text" | |
| 99 | - :value="note" | |
| 100 | - placeholder="建议提前协商(50字以内)" | |
| 101 | - /> | |
| 102 | - </view> | |
| 103 | - </view> | |
| 104 | - </view> | |
| 105 | - | |
| 106 | - <view class="infoBox" v-if="isCart !== 'true'"> | |
| 55 | + | |
| 56 | + <view | |
| 57 | + class="infoBox" | |
| 58 | + v-if="isCart == 'true'" | |
| 59 | + v-for="(item, index) in checkedCartLst" | |
| 60 | + :key="index" | |
| 61 | + > | |
| 62 | + <view class="infoTop"> | |
| 63 | + <image | |
| 64 | + :src="item.img_index_url" | |
| 65 | + mode="aspectFill" | |
| 66 | + ></image> | |
| 67 | + <view class="infoRight"> | |
| 68 | + <text class="goodName">{{item.p_name}}</text> | |
| 69 | + <text class="remarks">支持7天无理由退货 顺丰发货</text> | |
| 70 | + <view class="priceBox"> | |
| 71 | + <view class="price">¥{{Number(item.nowPrice) * item.num}}<text class="originCost"> | |
| 72 | + ¥{{item.oldPrice*item.num}} | |
| 73 | + </text></view> | |
| 74 | + <view class="counter"> | |
| 75 | + <view | |
| 76 | + class="btn" | |
| 77 | + disabled="this.disabled" | |
| 78 | + type="default" | |
| 79 | + @click="counter(false,index)" | |
| 80 | + >-</view> | |
| 81 | + <text>{{checkedCartLst[index].num}}</text> | |
| 82 | + <view | |
| 83 | + class="btn" | |
| 84 | + type="default" | |
| 85 | + @click="counter(true,index)" | |
| 86 | + >+</view> | |
| 87 | + </view> | |
| 88 | + </view> | |
| 89 | + </view> | |
| 90 | + </view> | |
| 91 | + <view class="infoBottom"> | |
| 92 | + <view class="norm">规格 <text> | |
| 93 | + <!-- 长度超出变省略号未做 --> | |
| 94 | + <block>{{item.sku_name}}<block v-if="index !== current.length -1">/</block> | |
| 95 | + </block> | |
| 96 | + </text></view> | |
| 97 | + <view class="shippingMethod">使用人 <text> | |
| 98 | + {{item.peopleName}} | |
| 99 | + </text></view> | |
| 100 | + <view class="shippingMethod">配送方式 <text>快递</text></view> | |
| 101 | + <view class="message">买家留言 | |
| 102 | + <input | |
| 103 | + type="text" | |
| 104 | + :value="note" | |
| 105 | + placeholder="建议提前协商(50字以内)" | |
| 106 | + /> | |
| 107 | + </view> | |
| 108 | + </view> | |
| 109 | + </view> | |
| 110 | + | |
| 111 | + <view | |
| 112 | + class="infoBox" | |
| 113 | + v-if="isCart !== 'true'" | |
| 114 | + > | |
| 107 | 115 | <view class="infoTop"> |
| 108 | 116 | <image |
| 109 | 117 | :src="buyItem.pic" |
| ... | ... | @@ -217,9 +225,9 @@ |
| 217 | 225 | <view class="last_zhanwei"></view> |
| 218 | 226 | <view class="footer"> |
| 219 | 227 | <view class="footerLeft">实付金额: |
| 220 | - <text >¥{{totalPrice}}</text> | |
| 221 | - <!-- <text v-else>¥{{Number(skuInfo.real_price) * count}}</text> --> | |
| 222 | - </view> | |
| 228 | + <text>¥{{totalPrice}}</text> | |
| 229 | + <!-- <text v-else>¥{{Number(skuInfo.real_price) * count}}</text> --> | |
| 230 | + </view> | |
| 223 | 231 | <view class="footerRight"> |
| 224 | 232 | <view |
| 225 | 233 | class="paybtn" |
| ... | ... | @@ -237,7 +245,7 @@ import MD5Util from '../../utils/md5' |
| 237 | 245 | export default { |
| 238 | 246 | data() { |
| 239 | 247 | return { |
| 240 | - name:String, | |
| 248 | + name: String, | |
| 241 | 249 | addAddress: '添加收货地址', |
| 242 | 250 | count: 1, |
| 243 | 251 | pid: 0, |
| ... | ... | @@ -248,14 +256,14 @@ export default { |
| 248 | 256 | addressInfo: { |
| 249 | 257 | address: '', |
| 250 | 258 | }, |
| 251 | - isCart:Boolean, | |
| 259 | + isCart: Boolean, | |
| 252 | 260 | // isAnonymous: |
| 253 | - checkedCartLst:[] | |
| 261 | + checkedCartLst: [], | |
| 254 | 262 | } |
| 255 | 263 | }, |
| 256 | 264 | onShow(addressId) { |
| 257 | 265 | // console.log('+-+-*-*-+-+',addressId) |
| 258 | - if (addressId) { | |
| 266 | + if (addressId) { | |
| 259 | 267 | store |
| 260 | 268 | .dispatch('address/details', { |
| 261 | 269 | add_id: addressId, |
| ... | ... | @@ -267,23 +275,22 @@ export default { |
| 267 | 275 | this.addressInfo = data |
| 268 | 276 | } |
| 269 | 277 | }) |
| 270 | - } | |
| 278 | + } | |
| 271 | 279 | }, |
| 272 | - onLoad({ pid, addressId,isCart ,count,name}) { | |
| 273 | - if(isCart == 'false'){ | |
| 274 | - | |
| 275 | - this.pid = pid; | |
| 276 | - store.dispatch('read/fetch', { | |
| 280 | + onLoad({ pid, addressId, isCart, count, name }) { | |
| 281 | + if (isCart == 'false') { | |
| 282 | + this.pid = pid | |
| 283 | + store.dispatch('read/fetch', { | |
| 277 | 284 | pid, |
| 278 | - }) | |
| 285 | + }) | |
| 279 | 286 | } |
| 280 | - this.count = count; | |
| 281 | - this.name = name; | |
| 282 | - this.isCart = isCart; | |
| 283 | - | |
| 284 | - console.log('++++++++++++'+pid,addressId,isCart) | |
| 285 | - this.checkedCartLst = this.$store.state.cart.checkedCartLst | |
| 286 | - // console.log('++++++++++6666666666++',this.$store.state.cart.checkedCartLst) | |
| 287 | + this.count = count | |
| 288 | + this.name = name | |
| 289 | + this.isCart = isCart | |
| 290 | + | |
| 291 | + console.log('++++++++++++' + pid, addressId, isCart) | |
| 292 | + this.checkedCartLst = this.$store.state.cart.checkedCartLst | |
| 293 | + // console.log('++++++++++6666666666++',this.$store.state.cart.checkedCartLst) | |
| 287 | 294 | // 若已经选择地址 |
| 288 | 295 | if (addressId) { |
| 289 | 296 | store |
| ... | ... | @@ -308,18 +315,18 @@ export default { |
| 308 | 315 | } |
| 309 | 316 | }, |
| 310 | 317 | computed: { |
| 311 | - totalPrice(){ | |
| 312 | - if(this.isCart == 'true'){ | |
| 318 | + totalPrice() { | |
| 319 | + if (this.isCart == 'true') { | |
| 313 | 320 | let total = 0 |
| 314 | - this.$store.state.cart.checkedCartLst.map(item =>{ | |
| 315 | - total += item.nowPrice*item.num | |
| 321 | + this.$store.state.cart.checkedCartLst.map(item => { | |
| 322 | + total += item.nowPrice * item.num | |
| 316 | 323 | }) |
| 317 | - return total | |
| 318 | - }else{ | |
| 319 | - return this.buyItem.real_price* this.count | |
| 324 | + return total | |
| 325 | + } else { | |
| 326 | + return this.buyItem.real_price * this.count | |
| 320 | 327 | } |
| 321 | 328 | }, |
| 322 | - buyItem(){ | |
| 329 | + buyItem() { | |
| 323 | 330 | return this.$store.state.cart.buyItem |
| 324 | 331 | }, |
| 325 | 332 | // checkedCartLst(){ |
| ... | ... | @@ -341,17 +348,17 @@ export default { |
| 341 | 348 | }, |
| 342 | 349 | }, |
| 343 | 350 | methods: { |
| 344 | - counter(isadd,index) { | |
| 351 | + counter(isadd, index) { | |
| 345 | 352 | if (isadd) { |
| 346 | - if(this.isCart =='true'){ | |
| 353 | + if (this.isCart == 'true') { | |
| 347 | 354 | this.checkedCartLst[index].num++ |
| 348 | - }else{ | |
| 349 | - this.count++ | |
| 355 | + } else { | |
| 356 | + this.count++ | |
| 350 | 357 | } |
| 351 | 358 | } else { |
| 352 | - if(this.isCart =='true'){ | |
| 353 | - this.checkedCartLst[index].num<= 1 ? (this.disabled = true) : this.checkedCartLst[index].num-- | |
| 354 | - }else{ | |
| 359 | + if (this.isCart == 'true') { | |
| 360 | + this.checkedCartLst[index].num <= 1 ? (this.disabled = true) : this.checkedCartLst[index].num-- | |
| 361 | + } else { | |
| 355 | 362 | this.count <= 1 ? (this.disabled = true) : this.count-- |
| 356 | 363 | } |
| 357 | 364 | } |
| ... | ... | @@ -372,24 +379,24 @@ export default { |
| 372 | 379 | uni.showLoading({ |
| 373 | 380 | title: '支付中', |
| 374 | 381 | }) |
| 375 | - if(this.isCart == 'true'){ | |
| 382 | + if (this.isCart == 'true') { | |
| 376 | 383 | const checkedGoods = [] |
| 377 | 384 | const sk_id_arr = [] |
| 378 | - this.checkedCartLst.map(item=>{ | |
| 385 | + this.checkedCartLst.map(item => { | |
| 379 | 386 | checkedGoods.push(item.pid) |
| 380 | 387 | sk_id_arr.push(item.sk_id) |
| 381 | 388 | }) |
| 382 | 389 | store.dispatch('order/build', { |
| 383 | - uid: this.$store.state.user.userInfo.uid, | |
| 390 | + uid: this.$store.state.user.userInfo.uid, | |
| 384 | 391 | address: JSON.stringify(this.addressInfo), |
| 385 | - checkedGoods:checkedGoods, | |
| 392 | + checkedGoods: checkedGoods, | |
| 386 | 393 | sk_id_arr: sk_id_arr, |
| 387 | 394 | totalPrice: this.totalPrice, |
| 388 | 395 | }).then((res) => { |
| 389 | 396 | this.pay(res.data) |
| 390 | 397 | }) |
| 391 | 398 | } |
| 392 | - if(this.isCart == 'false'){ | |
| 399 | + if (this.isCart == 'false') { | |
| 393 | 400 | const { sk_id_arr: skId, mp_id: mpId } = this.$store.state.order.param |
| 394 | 401 | store.dispatch('order/buyNow', { |
| 395 | 402 | pid: skId.pid, |
| ... | ... | @@ -762,7 +769,7 @@ export default { |
| 762 | 769 | width: 100%; |
| 763 | 770 | align-items: center; |
| 764 | 771 | padding-left: 126rpx; |
| 765 | - box-sizing: border-box; | |
| 772 | + box-sizing: border-box; | |
| 766 | 773 | .name { |
| 767 | 774 | display: flex; |
| 768 | 775 | justify-content: space-between; |
| ... | ... | @@ -817,7 +824,7 @@ export default { |
| 817 | 824 | bottom: 104rpx; |
| 818 | 825 | } |
| 819 | 826 | } |
| 820 | -.last_zhanwei{ | |
| 827 | +.last_zhanwei { | |
| 821 | 828 | background: #f2f2f2; |
| 822 | 829 | height: 60px; |
| 823 | 830 | } | ... | ... |