xuxueyang
2024-07-31 d18a571aa4dacab6928dbc8c6c45d5aa3f291afb
sub_pages/customer/trade/detail.vue
@@ -39,9 +39,19 @@
               <image src="../../../static/common/icon-kf.png" class="icon-kf m-l-15 img100"></image>
            </view>
            <view class="m-r-0 gwc" @click="submitShopping(dto)">
            <view class="m-r-0 gwc" @click="submitShopping(dto)" v-if="!dto.shopnum">
               + 购物车
            </view>
            <view class="m-r-0 button-icons flex" v-if="dto.shopnum">
               <uni-icons v-if="dto.shopnum&&dto.shopnum>=1" type="minus" size="32"
                  @click.stop="addnum(dto,-1)"></uni-icons>
               <view class="curnums" @click.stop="updateItemNum(dto)" v-if="dto.shopnum&&dto.shopnum>=1">
                  {{ dto.shopnum }}
               </view>
               <uni-icons v-if="!dto.shopnum||dto.shopnum<=99" type="plus-filled" size="32"
                  @click.stop="addnum(dto,1)"></uni-icons>
            </view>
         </view>
      </view>
      <view class="line">
@@ -138,6 +148,9 @@
            shopnum: 0,
         }
      },
      onShow() {
         this.refreshShopNum()
      },
      onLoad(options) {
         this.id = options.id || ''
         if (this.id) {
@@ -146,8 +159,73 @@
         this.refreshShopNum()
      },
      methods: {
         async updateItemNum(item) {
            const res = await this.$message.confirm('', {
               editable: true,
               title: '请输入想要购买的数量'
            })
            if (res.content && res.confirm) {
               // 发送请求
               var t = parseInt(res.content)
               if (isNaN(t) || t < 0) {
                  this.$message.showToast('数目需要大于等于0')
               } else {
                  if (!item.stock || t > item.stock) {
                     this.$message.showToast('库存不足无法修改')
                     return
                  }
                  this.addnum(item, (t - item.shopnum))
               }
            } else {
            }
         },
         async addnum(item, addnum) {
            if (!this.currentInfo.id) {
               await this.$message.confirm('请前往登录')
               uni.navigateTo({
                  url: '/pages/user/supplier-user'
               })
               return
            }
            if (!item.shopnum) {
               item.shopnum = 0
            }
            if (!item.stock) {
               item.stock = 0
            }
            if (addnum > 0 & item.shopnum + addnum > item.stock) {
               this.$message.showToast('库存不足,无法修改')
               return
            }
            if (item.shopnum + addnum >= 0) {
            } else {
               return
            }
            this.$message.showLoading()
            const {
               code
            } = await this.$http.request('post', '/api/customer/flower/cart/change-num', {
               data: {
                  id: item.id,
                  num: addnum
               }
            })
            this.$message.hideLoading()
            if (code === 0) {
               item.shopnum += addnum
               this.refreshShopNum()
               this.$forceUpdate()
            }
         },
         async refreshShopNum() {
            this.shopnum = await this.$store.dispatch('countShopping');
            this.shopnum = await this.$store.dispatch('countShopping');
            this.$store.dispatch('sign_add','shopnum')
         },
         async collectItem(dto) {
            if (!this.currentInfo.id) {
@@ -180,11 +258,14 @@
            //提交到购物车中
            // this.$message.showLoading()
            const {
               code
               code,
               data
            } = await this.$store.dispatch('submitShopping', dto);
            // this.$message.hideLoading()
            if (code == 0) {
               dto.shopnum = data || 0
               this.refreshShopNum()
               this.$forceUpdate()
            }
         },
@@ -255,6 +336,15 @@
            }
         }
         .button-icons {
            line-height: 40rpx;
            .curnums {
               padding-left: 20rpx;
               padding-right: 20rpx;
            }
         }
         .desc {
            font-weight: 400;
            font-size: 28rpx;