Ver código fonte

Merge branch 'iteration_1.3.4' into dev

lex 2 anos atrás
pai
commit
17f0ee3453

+ 20 - 6
src/student/trade/tradeOrder.ts

@@ -11,7 +11,11 @@ const apiSuffix =
 // VIDEO: '视频课',
 // VIP: '开通会员',
 // MUSIC: '单曲点播'
-export const formatOrderDetail = async (item: any, couponAmount?: number) => {
+interface IAmount {
+  couponAmount: number
+  discountPrice: number
+}
+export const formatOrderDetail = async (item: any, amount?: IAmount) => {
   const type = item.goodType
   let tempList: any = {}
 
@@ -89,8 +93,14 @@ export const formatOrderDetail = async (item: any, couponAmount?: number) => {
             id: item.id,
             title: memberType[res.period] || '',
             // 判断是否有优惠金额
-            price: couponAmount
-              ? Number((res.salePrice - couponAmount).toFixed(2))
+            price: amount?.couponAmount
+              ? Number(
+                  (
+                    res.salePrice -
+                    amount.couponAmount +
+                    amount.discountPrice
+                  ).toFixed(2)
+                )
               : res.salePrice || item.actualPrice,
             startTime: dayjs(res.startTime).format('YYYY-MM-DD'),
             endTime: dayjs(res.endTime).format('YYYY-MM-DD')
@@ -208,18 +218,22 @@ export const tradeOrder = (result: any, callBack?: any) => {
     orderName,
     orderType,
     orderDetailList,
-    couponAmount // 优惠金额
+    couponAmount, // 优惠金额
+    discountPrice
   } = result
   orderStatus.orderObject.orderType = orderType
   orderStatus.orderObject.orderName = orderName
   orderStatus.orderObject.orderDesc = orderDesc
   orderStatus.orderObject.actualPrice = actualPrice
   orderStatus.orderObject.orderNo = orderNo
-  // orderStatus.orderObject.actualPrice = actualPrice
+  orderStatus.orderObject.discountPrice = discountPrice
   orderStatus.orderObject.orderList = []
   try {
     orderDetailList.forEach(async (item: any) => {
-      await formatOrderDetail(item, couponAmount)
+      await formatOrderDetail(item, {
+        couponAmount,
+        discountPrice
+      })
     })
     callBack && callBack()
   } catch {

+ 1 - 0
src/views/order-detail/index.tsx

@@ -224,6 +224,7 @@ export default defineComponent({
 
             {/* 优惠券使用 */}
             <UseCoupon
+              discountPrice={orderStatus.orderObject.discountPrice}
               orderType={this.orderType}
               orderAmount={this.orderAmount}
               onCouponSelect={this.onCouponSelect}

+ 2 - 1
src/views/order-detail/orderStatus.ts

@@ -33,7 +33,8 @@ const original = () => {
       recomUserId: null as any, // 推荐人编号
       orderList: [] as Array<any>, // 商品信息
       activityId: '' as any, // 活动编号
-      couponId: '' as string // 优惠券编号
+      couponId: '' as string, // 优惠券编号
+      discountPrice: 0 as number // 优惠
     }
     // orderObject: {
     //   orderNo: '',

+ 63 - 46
src/views/order-detail/use-coupons/choice-coupon.tsx

@@ -20,13 +20,17 @@ export default defineComponent({
     couponCategory: {
       type: String,
       default: 'UNIVERSAL'
+    },
+    couponList: {
+      type: Array,
+      default: () => []
     }
   },
   emits: ['close', 'submit'],
   data() {
     return {
-      list: [],
-      consumeAmount: 0, // 消耗金额
+      list: [] as any,
+      // consumeAmount: 0 // 消耗金额
       dataLoading: false
     }
   },
@@ -37,55 +41,68 @@ export default defineComponent({
     }
   },
   async mounted() {
-    this.getList()
+    // this.getList()
+    // 处理显示已选择的优惠券
+    // 处理可用优惠券是否支付使用
+    this.couponList.forEach((item: any) => {
+      this.useCoupon.forEach((coupon: any) => {
+        if (item.couponIssueId === coupon.couponIssueId) {
+          item.checked = true
+        }
+      })
+    })
+    const canUsable = this.couponList.filter((list: any) => !list.disabled)
+    const canUsed = this.couponList.filter((list: any) => list.disabled)
+    this.list = [...canUsable, ...canUsed]
+    this.calcCoupon()
   },
   methods: {
-    async getList() {
-      if (this.dataLoading) return
-      this.dataLoading = true
-      try {
-        const res = await request.post(`${state.platformApi}/couponInfo/page`, {
-          data: {
-            couponCategory: this.couponCategory,
-            couponType: 'FULL_DISCOUNT',
-            useState: 'USABLE',
-            page: 1,
-            rows: 100
-          }
-        })
-        this.dataLoading = false
-        const result = res.data || {}
-        // 处理重复请求数据
-        if (this.list.length > 0 && result.pageNo === 1) return
-        this.list = result.rows || []
+    // async getList() {
+    //   if (this.dataLoading) return
+    //   this.dataLoading = true
+    //   try {
+    //     const res = await request.post(`${state.platformApi}/couponInfo/page`, {
+    //       data: {
+    //         couponCategory: this.couponCategory,
+    //         couponType: 'FULL_DISCOUNT',
+    //         useState: 'USABLE',
+    //         page: 1,
+    //         rows: 100
+    //       }
+    //     })
+    //     this.dataLoading = false
+    //     const result = res.data || {}
+    //     // 处理重复请求数据
+    //     if (this.list.length > 0 && result.pageNo === 1) return
+    //     this.list = result.rows || []
 
-        // 处理可用优惠券是否支付使用
-        this.list.forEach((item: any) => {
-          item.checked = false
-          // 如果使用金额大于订单金额则优惠券不可用
-          if (item.useLimit > this.orderAmount) {
-            item.disabled = true
-          } else {
-            item.disabled = false
-          }
+    //     // 处理可用优惠券是否支付使用
+    //     this.list.forEach((item: any) => {
+    //       item.checked = false
+    //       // 如果使用金额大于订单金额则优惠券不可用
+    //       if (item.useLimit > this.orderAmount) {
+    //         item.disabled = true
+    //       } else {
+    //         item.disabled = false
+    //       }
 
-          // 处理显示已选择的优惠券
-          this.useCoupon.forEach((coupon: any) => {
-            if (item.couponIssueId === coupon.couponIssueId) {
-              item.checked = true
-            }
-          })
-        })
-        // 初始化排序
-        const canUsable = this.list.filter((list: any) => !list.disabled)
-        const canUsed = this.list.filter((list: any) => list.disabled)
-        this.list = [...canUsable, ...canUsed]
+    //       // 处理显示已选择的优惠券
+    //       this.useCoupon.forEach((coupon: any) => {
+    //         if (item.couponIssueId === coupon.couponIssueId) {
+    //           item.checked = true
+    //         }
+    //       })
+    //     })
+    //     // 初始化排序
+    //     const canUsable = this.list.filter((list: any) => !list.disabled)
+    //     const canUsed = this.list.filter((list: any) => list.disabled)
+    //     this.list = [...canUsable, ...canUsed]
 
-        this.calcCoupon()
-      } catch {
-        //
-      }
-    },
+    //     this.calcCoupon()
+    //   } catch {
+    //     //
+    //   }
+    // },
     onSubmit() {
       // 返回选中的优惠券
       this.$emit(

+ 76 - 19
src/views/order-detail/use-coupons/index.tsx

@@ -33,6 +33,11 @@ export default defineComponent({
     orderType: {
       type: String,
       default: ''
+    },
+    discountPrice: {
+      // 优惠券使用金额
+      type: Number,
+      default: 0
     }
   },
   emits: ['couponSelect'],
@@ -42,7 +47,9 @@ export default defineComponent({
       popupLoading: false,
       useCouponList: [] as any,
       useCouponLoading: false,
-      useCouponCount: 0
+      useCouponCount: 0,
+      dataLoading: false,
+      list: [] as any
     }
   },
   computed: {
@@ -50,11 +57,18 @@ export default defineComponent({
       const limitCount = this.useCouponList.map((list: any) => {
         return Number(list.discountPrice || 0)
       })
-      return limitCount.length > 0
-        ? limitCount.reduce((sum: any, list: any) => {
-            return sum + list
-          })
-        : 0
+      let count = 0
+      if (this.disabled) {
+        count = this.discountPrice
+      } else {
+        count =
+          limitCount.length > 0
+            ? limitCount.reduce((sum: any, list: any) => {
+                return sum + list
+              })
+            : 0
+      }
+      return count
     },
     couponCategory() {
       // 如果订单类型不在优惠券类型里面,则默认查询通用券
@@ -62,25 +76,67 @@ export default defineComponent({
     }
   },
   mounted() {
-    this.getUseableCoupon()
+    // this.getUseableCoupon()
+    this.getList()
   },
   methods: {
-    async getUseableCoupon() {
+    async getList() {
+      if (this.dataLoading) return
+      this.dataLoading = true
       try {
-        this.useCouponLoading = true
-        // 判断是哪个端
-        const url =
-          state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
-        const res = await request.get(`${url}/couponInfo/statInfo`)
-        this.useCouponLoading = false
-        const result = (res.data || []).find(
-          result => result.useState === 'USABLE'
-        )
-        this.useCouponCount = result.total || 0
+        const res = await request.post(`${state.platformApi}/couponInfo/page`, {
+          data: {
+            couponCategory: this.couponCategory,
+            couponType: 'FULL_DISCOUNT',
+            useState: 'USABLE',
+            page: 1,
+            rows: 100
+          }
+        })
+        this.dataLoading = false
+        const result = res.data || {}
+        // 处理重复请求数据
+        if (this.list.length > 0 && result.pageNo === 1) return
+        this.list = result.rows || []
+
+        // 处理可用优惠券是否支付使用
+        this.list.forEach((item: any) => {
+          item.checked = false
+          // 如果使用金额大于订单金额则优惠券不可用
+          if (item.useLimit > this.orderAmount) {
+            item.disabled = true
+          } else {
+            item.disabled = false
+          }
+        })
+
+        let count = 0
+        this.list.forEach((item: any) => {
+          if (!item.disabled) {
+            count++
+          }
+        })
+        this.useCouponCount = count
       } catch {
-        // TODO: handle
+        //
       }
     },
+    // async getUseableCoupon() {
+    //   try {
+    //     this.useCouponLoading = true
+    //     // 判断是哪个端
+    //     const url =
+    //       state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
+    //     const res = await request.get(`${url}/couponInfo/statInfo`)
+    //     this.useCouponLoading = false
+    //     const result = (res.data || []).find(
+    //       result => result.useState === 'USABLE'
+    //     )
+    //     this.useCouponCount = result.total || 0
+    //   } catch {
+    //     // TODO: handle
+    //   }
+    // },
     onSubmit(item: any) {
       // useCouponList
       this.useCouponList = item
@@ -142,6 +198,7 @@ export default defineComponent({
               couponCategory={this.couponCategory}
               useCoupon={this.useCouponList}
               orderAmount={this.orderAmount}
+              couponList={this.list}
               onClose={() => (this.popupStatus = false)}
               onSubmit={(item: any) => this.onSubmit(item)}
             />