xuxueyang
2024-08-04 8b0c13b27b2ea6d98f5769bb4658327bf17afa8e
sub_pages/customer/trade/detail.vue
@@ -3,18 +3,24 @@
      <view class="top-img-container">
         <image :src="dto.cover" class="top-img" mode="aspectFill"></image>
         <view class="icon-container">
            <image src="../../../static/common/icon-sc.png" @click="collectItem(dto)" class="icon-sc"></image>
            <image v-if="!dto.collection" src="../../../static/common/icon-sc.png" @click="collectItem(dto)"
               class="icon-sc"></image>
            <image v-if="dto.collection" src="../../../static/common/icon-sc-fill.png" @click="collectItem(dto)"
               class="icon-sc"></image>
            <!--        <view class="num">12</view>-->
         </view>
         <view class="icon-container">
            <image src="../../../static/common/icon-shop.png" @click="submitShopping(dto)" class="icon-shop">
            <image src="../../../static/common/icon-shop.png" @click="toShopping(dto)" class="icon-shop">
               <view class="image-shop-number" v-if="shopnum">{{shopnum||''}}</view>
            </image>
         </view>
      </view>
      <view class="trade-info-container">
         <view class="title flex">
            <view class="level m-r-15">{{ dto.levelStr || '-' }}级</view>
            <view class="level m-r-15">{{ dto.levelStr || '-' }}</view>
            <view class="">
               {{ dto.name || '-' }}
            </view>
@@ -33,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">
@@ -47,7 +63,12 @@
            <view class="label">{{ param.name}}:</view>
            <view class="value">{{ param.value || '-'}}</view>
         </view>
         <!--      <view class="flex m-t-8">-->
         <view v-if="!dto.params">
            <view class="flex m-t-8">
               <view class="label">暂无</view>
            </view>
         </view>
         <!--      <view class="flex m-t-8">
         <!--        <view class="label">枝粗:</view>-->
         <!--        <view class="value">中等粗细</view>-->
         <!--      </view>-->
@@ -123,38 +144,194 @@
      data() {
         return {
            id: '',
            dto: {}
            dto: {},
            shopnum: 0,
            sharePartnerUserId: '',
         }
      },
      onShow() {
         if (this.id) {
            this.getDetail()
         }
         this.refreshShopNum()
      },
      onLoad(options) {
         console.log('trade detail options', options)
         this.id = options.id || ''
         if (this.id) {
            this.getDetail()
         }
         this.refreshShopNum()
         if (options.partnerUserId) {
            //合伙人绑定的,判断当前用户,是否有登录
            this.sharePartnerUserId = options.partnerUserId
            // let tmp = this
            // setTimeout(() => {
            //    if (!tmp.currentInfo.id) {
            //       //前往登录,,但是带上
            //    }
            // }, 500)
         }
      },
      // #ifdef PUB_CUSTOMER
      onShareAppMessage() {
         let that = this;
         var name = that.currentInfo.customerDTO && currentInfo.customerDTO.name || that.currentInfo.supplierDTO &&
            currentInfo.supplierDTO.name || that.currentInfo.partnerDTO && currentInfo.partnerDTO.name || ''
         //如果是合伙人的id,那么分享出去,需要附加id了
         console.log('onShareAppMessage', this.currentInfo)
         var partnerUserId = ''
         if (that.currentInfo.partnerDTO && currentInfo.partnerDTO.id) {
            partnerUserId = this.currentInfo.id
         }
         var url =
            `/sub_pages/customer/trade/detail?partnerUserId=${partnerUserId}&id=${this.id}&shareId=${this.currentInfo&&this.currentInfo.id||''}&shareName=${name||''}`; //你的转发页面路径拼接参数
         return {
            title: this.dto.id ? (this.dto.name + " " + (this.dto.price || '-') + '元/扎 ' + (this.dto.unit || '')) :
               "花满芫",
            path: url,
         }
      },
      onShareTimeline() {
         let that = this;
         var name = that.currentInfo.customerDTO && currentInfo.customerDTO.name || that.currentInfo.supplierDTO &&
            currentInfo.supplierDTO.name || that.currentInfo.partnerDTO && currentInfo.partnerDTO.name || ''
         //如果是合伙人的id,那么分享出去,需要附加id了
         var partnerUserId = ''
         if (that.currentInfo.partnerDTO && currentInfo.partnerDTO.id) {
            partnerUserId = this.currentInfo.id
         }
         var url =
            `/sub_pages/customer/trade/detail?partnerUserId=${partnerUserId}&id=${this.id}&shareId=${this.currentInfo&&this.currentInfo.id||''}&shareName=${name||''}`; //你的转发页面路径拼接参数
         return {
            title: this.dto.id ? (this.dto.name + " " + (this.dto.price || '-') + '元/扎 ' + (this.dto.unit || '')) :
               "花满芫",
            path: url,
         }
      },
      // #endif
      methods: {
         async collectItem(dto){
            await this.$message.confirm('是否添加到收藏')
         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/login/supplier-login?source=jump&sharePartnerUserId=${this.sharePartnerUserId}`
               })
               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.$store.dispatch('sign_add', 'shopnum')
         },
         async collectItem(dto) {
            if (!this.currentInfo.id) {
               // this.$message.showToast('请先登录')
               uni.navigateTo({
                  url: `/pages/login/supplier-login?source=jump&sharePartnerUserId=${this.sharePartnerUserId}`
               })
               return
            }
            await this.$message.confirm(`是否${dto.collection?'移除':'添加到'}收藏`)
            this.$message.showLoading()
            const {
               code,
               data
            } = await this.$http.request('post', '/api/collect/add', {
               data: {
                  flowerId: dto.id
               }
            })
            } = await this.$http.request(dto.collection ? "get" : 'post', dto.collection ? '/api/collect/delete' :
               '/api/collect/add', {
                  data: {
                     flowerId: dto.id
                  },
                  params: {
                     flowerId: dto.id
                  }
               })
            if (code === 0) {
               this.$message.showToast('收藏成功')
               this.$message.showToast('操作成功')
               dto.collection = !dto.collection
               this.$forceUpdate()
            }
            this.$message.hideLoading()
         },
         async submitShopping(dto) {
            //提交到购物车中
            this.$message.showLoading()
            await this.$store.dispatch('submitShopping', dto);
            this.$message.hideLoading()
            // this.$message.showLoading()
            if (!this.currentInfo.id) {
               // this.$message.showToast('请先登录')
               uni.navigateTo({
                  url: `/pages/login/supplier-login?source=jump&sharePartnerUserId=${this.sharePartnerUserId}`
               })
               return
            }
            const {
               code,
               data
            } = await this.$store.dispatch('submitShopping', dto);
            // this.$message.hideLoading()
            if (code == 0) {
               dto.shopnum = data || 0
               this.refreshShopNum()
               this.$forceUpdate()
            }
         },
         async getDetail() {
            this.$message.showLoading()
@@ -175,6 +352,18 @@
            this.$message.hideLoading()
         },
         toShopping() {
            if (!this.currentInfo.id) {
               // this.$message.showToast('请先登录')
               uni.navigateTo({
                  url: `/pages/login/supplier-login?source=jump&sharePartnerUserId=${this.sharePartnerUserId}`
               })
               return
            }
            uni.navigateTo({
               url: '/sub_pages/customer/shopping/shopping'
            })
         },
         openbrand() {
            uni.navigateTo({
               url: '/sub_pages/customer/shop/shop?id=' + (this.dto.id || '')
@@ -188,6 +377,21 @@
   .trade-detail {
      background-color: #FFFFFF;
      .image-shop-number {
         width: 30rpx;
         height: 30rpx;
         background: #F20000;
         line-height: 30rpx;
         text-align: center;
         position: absolute;
         right: 0rpx;
         top: -6rpx;
         color: #FFFFFF;
         border-radius: 50%;
         font-size: 24rpx;
      }
      .trade-info-container {
         padding: 46rpx 30rpx;
         border-radius: 40rpx 40rpx 0rpx 0rpx;
@@ -200,6 +404,15 @@
            .level {
               color: #20613D;
            }
         }
         .button-icons {
            line-height: 40rpx;
            .curnums {
               padding-left: 20rpx;
               padding-right: 20rpx;
            }
         }
@@ -353,9 +566,11 @@
            position: absolute;
            top: 20rpx;
            width: 80rpx;
            left: 40rpx;
            right: 140rpx;
            height: 80rpx;
            background: rgba(0, 0, 0, 0);
            background: rgba(0, 0, 0, 0.42);
            border-radius: 50%;
            display: flex;
            .icon-sc {
               width: 54rpx;
@@ -371,6 +586,8 @@
               margin: 0 auto;
               margin-top: 12rpx;
               display: inline-block;
               margin-left: 12rpx;
               position: relative;
            }
@@ -386,7 +603,7 @@
         }
         .icon-container:last-child {
            left: 100rpx;
            right: 20rpx;
         }
         // .icon-container:first-child {