Ver código fonte

fix:pc超级订阅活动逻辑

yangfeng 3 anos atrás
pai
commit
0ca88c5595

+ 4 - 0
src/components/coupon/CouponGiftList.vue

@@ -59,6 +59,7 @@ export default {
       if (!info.useProduct) {
         return this.giftListLoaded(0)
       }
+      this.giftList = []
       const { data } = await getGiftList(info)
       if (Array.isArray(data)) {
         this.giftList = data.map(item => {
@@ -66,6 +67,9 @@ export default {
           item.startTime = item.beginDate && item.beginDate.toString().length === 10 ? item.beginDate * 1000 : item.beginDate
           item.endTime = item.endDate && item.endDate.toString().length === 10 ? item.endDate * 1000 : item.endDate
           item.isReceive = item.IsReceive
+          if (!item.stockNumber) {
+            item.stockNumber = 0
+          }
           const giftInfo = this.sortGiftInfo(item)
           return {
             ...item,

+ 5 - 4
src/components/limited-banner/index.vue

@@ -54,11 +54,11 @@ export default {
       default: 0
     },
     stockNumber: {
-      type: Number,
+      type: [Number, String],
       default: -1
     },
     status: {
-      type: Number,
+      type: [Number, String],
       default: -1
     }
   },
@@ -90,7 +90,8 @@ export default {
       return !this.isStart && this.status === 0 && this.stockNumber > 0
     },
     alreadyStatus () {
-      return this.isStart && !this.isEnd && this.status === 1 && this.stockNumber > 0
+      // 活动没有开始 且已预约且有库存
+      return !this.isStart && this.status === 1 && this.stockNumber > 0
     },
     emptyStatus () {
       return this.stockNumber === 0
@@ -112,9 +113,9 @@ export default {
           this.isEnd = true
         }
       }
-      // console.log(this.isStart, '111')
     }
   },
+  mounted () {},
   methods: {
     getCurTime (data) {
       const beginDate = this.startTime.toString().length === 10 ? this.startTime * 1000 : this.startTime

+ 70 - 38
src/views/vipsubscribe/Buy.vue

@@ -1,6 +1,6 @@
 <template>
   <div>
-    <LimitedBanner v-if="isActivity" v-bind="activity" @sub="onSubscribe" @curTime="getCurTime"></LimitedBanner>
+    <LimitedBanner v-if="isActivity" v-bind="activity" :status="activity.status" @sub="onSubscribe" @curTime="getCurTime"></LimitedBanner>
     <Layout class="vip-subscribe-buy" contentWithState="full" :needAd="false">
       <div class="vip-subscribe-title">{{ buyTypeText }}超级订阅</div>
       <div class="vip-subscribe-content">
@@ -109,7 +109,8 @@ import {
   createCommonOrder,
   getGiftList,
   appointmentAdd,
-  getIsAppointment
+  getIsAppointment,
+  getServerInitTime
 } from '@/api/modules/'
 
 export default {
@@ -202,7 +203,8 @@ export default {
       activity: {},
       appointmentStatus: -1, // 预约状态
       curTime: 0,
-      goodsBadge: false
+      serverInitTime: 0,
+      allActivityData: [] // 所有活动信息
     }
   },
   computed: {
@@ -283,19 +285,19 @@ export default {
       } else {
         return false
       }
-    }
+    },
     // 商品规格上是否展示优惠信息、价格是否计算优惠(活动未开始前、库存为0不展示不计算优惠)
-    // isDiscounts () {
-    //   console.log(this.goodsBadge, JSON.stringify(this.activity))
-    //   return this.goodsBadge && this.activity && this.activity.stockNumber && this.activity.stockNumber > 0
-    // }
+    isDiscounts () {
+      console.log(JSON.stringify(this.activity))
+      return this.activity && this.activity.stockNumber && this.activity.stockNumber > 0
+    }
   },
-  created () {
+  async created () {
     this.getType()
+    await this.getAllGiftList()
     this.getGoodsPrice()
     this.getUserPower() // 获取最新的power
     this.getUserAccountInfo()
-    this.getAllGiftList()
   },
   beforeRouteEnter (to, from, next) {
     const title = document.title
@@ -402,15 +404,15 @@ export default {
       this.updatePrice()
     },
     specChange (spec) {
-      if (Object.keys(this.activity).length > 0) {
-        this.activity.reduce = 0
-        this.activity.promotionalPrice = 0
-        this.activity.discount = 0
-        this.activity.stockNumber = 0
-        this.activity.status = this.appointmentStatus
-      } else {
-        this.activity.stockNumber = 0
-      }
+      // if (Object.keys(this.activity).length > 0) {
+      //   this.activity.reduce = 0
+      //   this.activity.promotionalPrice = 0
+      //   this.activity.discount = 0
+      //   this.activity.activityName = ''
+      //   this.activity.stockNumber = ''
+      //   this.activity.status = ''
+      // }
+      this.activity.status = this.appointmentStatus
       if (this.buyType === 'upgrade') {
         spec.productionId = 1015
       }
@@ -443,6 +445,7 @@ export default {
         for (const key in activity) {
           this.activity[key] = activity[key]
         }
+        // this.changGoodsBadge()
         this.updatePrice()
         const gift = list[0]
         // this.specActiveItem.tipText = gift.giftInfo ? `加赠${gift.giftInfo}` : ''
@@ -507,9 +510,13 @@ export default {
     async updatePrice () {
       const params = this.getSubmitParam()
       const { data, success } = await getSelectPrice(params)
+      await this.initAdjustTime()
       if (success) {
-        const { reduce, promotionalPrice, discount, stockNumber } = this.activity
-        if (stockNumber > 0) {
+        const { reduce, promotionalPrice, discount, stockNumber, beginDate, endDate } = this.activity
+        const beginTime = beginDate && beginDate.toString().length === 10 ? beginDate * 1000 : beginDate
+        const endTime = endDate && endDate.toString().length === 10 ? endDate * 1000 : endDate
+        const nowTime = this.serverInitTime
+        if (stockNumber > 0 && nowTime > beginTime && nowTime < endTime) {
           if (reduce) {
             data.order_price = data.order_price - reduce
           } else if (promotionalPrice) {
@@ -619,6 +626,7 @@ export default {
         } else {
           this.$toast(msg)
         }
+        this.appointmentStatus = data.status
         this.activity.status = data.status
         this.$forceUpdate()
       }
@@ -631,21 +639,10 @@ export default {
       }
       const { data } = await getGiftList(info)
       if (data && data.length > 0) {
-        this.getActivityStatus(data[0].activityId)
-        this.specList.forEach(v => {
-          data.forEach(s => {
-            if (v.productionId === s.productCode) {
-              if (s.time) {
-                // 赠周期
-                v.tipText = this.sortGiftInfo(s)
-              } else {
-                // 折扣、满减、特惠
-                v.tipText = this.sortActivityInfo(s)
-              }
-            }
-          })
-        })
+        await this.getActivityStatus(data[0].activityId)
+        this.allActivityData = data
       } else {
+        this.allActivityData = []
         this.specList.forEach(v => {
           v.tipText = ''
         })
@@ -695,8 +692,12 @@ export default {
         this.activity.promotionalPrice = 0
         this.activity.discount = 0
         this.$refs.buySubmitRef.changeBtnText(false)
+      } else if (data === this.activity.startTime) {
+        this.changGoodsBadge(true)
+        this.updatePrice()
       } else if (data > this.activity.startTime && data < this.activity.endTime) {
         // 活动进行中
+        this.changGoodsBadge(true)
         const { stockNumber } = this.activity
         this.$nextTick(() => {
           if (stockNumber > 0) {
@@ -704,7 +705,6 @@ export default {
           } else {
             this.$refs.buySubmitRef.changeBtnText(false)
           }
-          this.goodsBadge = true
         })
       } else if (data >= this.activity.endTime) {
         // 活动结束
@@ -716,10 +716,42 @@ export default {
           this.updatePrice()
           this.$refs.buySubmitRef.changeBtnText(false)
         }, 300)
-        this.goodsBadge = false
         this.$forceUpdate()
+      }
+    },
+    async initAdjustTime () {
+      // 接口响应时服务端的本地时间
+      const { data } = await getServerInitTime()
+      if (data) {
+        this.serverInitTime = data?.time.toString().length === 10 ? data?.time * 1000 : data?.time
       } else {
-        this.goodsBadge = false
+        this.serverInitTime = Date.now()
+      }
+    },
+    changGoodsBadge (isShow) {
+      if (isShow) {
+        const data = this.allActivityData
+        this.specList.forEach(v => {
+          data.forEach(s => {
+            if (!s.stockNumber) {
+              s.stockNumber = 0
+            }
+            if (v.productionId === s.productCode) {
+              if (s.time) {
+                // 赠周期
+                v.tipText = '加赠' + this.sortGiftInfo(s)
+              } else {
+                // 折扣、满减、特惠
+                // 库存大于0限时活动标签
+                v.tipText = s.stockNumber > 0 ? this.sortActivityInfo(s) : ''
+              }
+            }
+          })
+        })
+      } else {
+        this.specList.forEach(v => {
+          v.tipText = ''
+        })
       }
     }
   }

+ 1 - 1
vue.config.js

@@ -74,7 +74,7 @@ module.exports = {
       },
       '^/jyCoupon': {
         // target: 'https://jybx2-webtest.jydev.jianyu360.com',
-        target: 'http://192.168.3.240:826',
+        target: 'http://192.168.3.240:827',
         changeOrigin: true,
         logLevel: 'debug'
       },