Quellcode durchsuchen

添加优惠券阿乐

lex vor 2 Jahren
Ursprung
Commit
c8351f558a

BIN
public/favicon.ico


+ 16 - 0
src/constant/index.ts

@@ -68,3 +68,19 @@ export const difficulty = {
   ADVANCED: '进阶级',
   PERFORMER: '大师级'
 }
+
+// 优惠券类型
+export const coupontypeDetail = {
+  FULLCOUPON: '全类券',
+  OTHER: '其他',
+  MALLCOUPON: '商城',
+  MUSICAL: '乐器',
+  ACCESSORIES: '辅件',
+  MAINTENANCE: '乐保服务',
+  TEACHING: '教材',
+  PRACTICE: '网管课',
+  SINGLE: '声部课',
+  MIX: '合奏课',
+  VIP: 'VIP',
+  MEMBER: '云教练'
+}

+ 83 - 14
src/views/cart/cart-confirm/index.tsx

@@ -8,7 +8,16 @@ import {
   watch,
   onBeforeMount
 } from 'vue'
-import { Card, Cell, CellGroup, Popup, SubmitBar, Toast } from 'vant'
+import {
+  Card,
+  Cell,
+  CellGroup,
+  Checkbox,
+  Popup,
+  Radio,
+  SubmitBar,
+  Toast
+} from 'vant'
 import { addressType, cartConfirm, formateAttr } from '../cart'
 import styles from '../index.module.less'
 import Address from '../components/address'
@@ -36,8 +45,15 @@ export default defineComponent({
     const loading = ref(true)
     const route = useRoute()
     const address = ref<addressType>()
+    const cartUseAmount = ref<any>({
+      useBalance: false,
+      balance: 0,
+      couponId: ''
+    })
     onMounted(async () => {
       loading.value = true
+      // 获取用户余额
+      await getUserBalance()
       if (route.query.cartIds) {
         try {
           let { code, data } = await request.post(
@@ -70,6 +86,15 @@ export default defineComponent({
       }
     })
 
+    // 获取用户余额
+    const getUserBalance = async () => {
+      try {
+        // 获取用户余额
+        const { data } = await request.get('/api-student/userCashAccount/get')
+        cartUseAmount.value.balance = data.balance || 0
+      } catch {}
+    }
+
     const setAddress = (result: addressType) => {
       address.value = result
     }
@@ -123,8 +148,9 @@ export default defineComponent({
         orderAmount: (
           cartConfirm.calcAmount.payAmount -
           cartConfirm.calcAmount.promotionAmount
-        ).toFixed(2)
-        // couponId: orderInfo.couponId
+        ).toFixed(2),
+        couponId: cartUseAmount.value.couponId,
+        useBalance: cartUseAmount.value.useBalance // 是否使用余额
       }
       try {
         const { code, data } = await request.post(
@@ -156,6 +182,30 @@ export default defineComponent({
       console.log(state.user.data)
       onSubmit() // 实名成功后自动支付
     }
+
+    // {
+    //   moneyFormat(
+    //     cartConfirm.calcAmount.payAmount -
+    //       cartConfirm.calcAmount.promotionAmount
+    //   )
+    // }
+    const needPayPrice = () => {
+      let price = Number(
+        (
+          cartConfirm.calcAmount.payAmount -
+          cartConfirm.calcAmount.promotionAmount
+        ).toFixed(2)
+      )
+      console.log(price)
+      if (cartUseAmount.value.useBalance) {
+        price =
+          price - cartUseAmount.value.balance <= 0
+            ? 0
+            : Number((price - cartUseAmount.value.balance).toFixed(2))
+      }
+
+      return price
+    }
     return () => (
       <>
         <ColHeader />
@@ -187,22 +237,45 @@ export default defineComponent({
                     ))}
                   </div>
                   <CellGroup border={true}>
-                    {/* <UseCoupons
-                      orderType="GOODS"
+                    <UseCoupons
+                      useSystem="MALL"
+                      typeDetail="MALLCOUPON"
                       orderAmount={cartConfirm.calcAmount.totalAmount}
                       onCouponSelect={coupon => {
+                        console.log(coupon, 'coupon')
                         const discountPrice = coupon
-                          .map(n => n.discountPrice)
+                          .map(n => n.faceValue)
                           .reduce((total, n) => {
                             return total + n
                           }, 0)
                         const couponId = coupon
-                          .map(n => n.couponIssueId)
+                          .map(n => n.couponCodeId)
                           .join(',')
                         cartConfirm.calcAmount.promotionAmount = discountPrice
-                        orderInfo.couponId = couponId
+                        cartUseAmount.value.couponId = couponId
+
+                        console.log(cartUseAmount, 'coupon')
+                        // orderInfo.couponId = couponId
+                      }}
+                    />
+
+                    <Cell
+                      v-slots={{
+                        title: `余额支付(剩余:¥${moneyFormat(
+                          cartUseAmount.value.balance
+                        )})`,
+                        'right-icon': () => (
+                          <Checkbox
+                            modelValue={cartUseAmount.value.useBalance}
+                          />
+                        )
+                      }}
+                      onClick={() => {
+                        console.log(true, '111')
+                        cartUseAmount.value.useBalance =
+                          !cartUseAmount.value.useBalance
                       }}
-                    /> */}
+                    />
 
                     <Cell
                       border={false}
@@ -228,11 +301,7 @@ export default defineComponent({
                     <div class={styles.confirmBottom}>
                       合计{' '}
                       <span class={styles['price-des']}>
-                        ¥
-                        {moneyFormat(
-                          cartConfirm.calcAmount.payAmount -
-                            cartConfirm.calcAmount.promotionAmount
-                        )}
+                        ¥{moneyFormat(needPayPrice())}
                       </span>
                     </div>
                   </SubmitBar>

+ 9 - 8
src/views/coupons/item.tsx

@@ -4,6 +4,7 @@ import dayjs from 'dayjs'
 import { Checkbox } from 'vant'
 import activeIcon from './images/activeIcon.png'
 import inactiveIcon from './images/inactiveIcon.png'
+import { coupontypeDetail } from '@/constant'
 
 export default defineComponent({
   name: 'coupon-item',
@@ -38,7 +39,7 @@ export default defineComponent({
         key={item.couponIssueId}
       >
         {/* 可使用的优惠券 & 有选择按钮的 */}
-        {item.useState === 'USABLE' && this.isSelect && (
+        {item.usageStatus === 0 && this.isSelect && (
           <img
             class={styles['img-icon']}
             src={item.checked ? activeIcon : inactiveIcon}
@@ -47,26 +48,26 @@ export default defineComponent({
         <div class={styles.top}>
           <div class={styles.price}>
             <span class={styles.suffix}>¥</span>
-            <span class={styles.number}>{item.discountPrice}</span>
+            <span class={styles.number}>{item.faceValue}</span>
           </div>
 
-          <div class={styles.type}>{item.couponName}</div>
+          <div class={styles.type}>{coupontypeDetail[item.typeDetail]}</div>
         </div>
 
         <div class={styles.bottom}>
           <div class={styles.condition}>
             <span class={styles.conditionTag}>
-              {item.useLimit > 0 ? `满${item.useLimit}可用` : '无门槛'}
+              {item.fullAmount > 0 ? `满${item.fullAmount}可用` : '无门槛'}
             </span>
           </div>
           <div class={styles.useTime}>
-            有效期:{dayjs(item.startTime).format('YYYY.MM.DD')}~
-            {dayjs(item.endTime).format('YYYY.MM.DD')}
+            有效期:{dayjs(item.useStartDate).format('YYYY.MM.DD')}~
+            {dayjs(item.useDeadlineDate).format('YYYY.MM.DD')}
           </div>
         </div>
 
-        {item.useState === 'USED' && <div class={styles.iconUsed}></div>}
-        {item.useState === 'EXPIRED' && <div class={styles.iconExpired}></div>}
+        {item.useState === 1 && <div class={styles.iconUsed}></div>}
+        {item.usageStatus === 2 && <div class={styles.iconExpired}></div>}
       </div>
     )
   }

+ 20 - 30
src/views/order-detail/use-coupons/index.tsx

@@ -5,20 +5,6 @@ import { defineComponent } from 'vue'
 import ChoiceCoupon from './choice-coupon'
 import styles from './index.module.less'
 
-/*
- * 订单类型对应优惠券类型
- */
-export const couponEnum = {
-  UNIVERSAL: 'UNIVERSAL',
-  VIP: 'VIP',
-  PINAO_ROOM: 'PIANO',
-  GOODS: 'MALL',
-  MUSIC: 'MUSIC',
-  PRACTICE: 'SPARRING',
-  LIVE: 'LIVE',
-  VIDEO: 'VIDEO'
-}
-
 export default defineComponent({
   name: 'use-conpon',
   props: {
@@ -38,6 +24,14 @@ export default defineComponent({
       // 优惠券使用金额
       type: Number,
       default: 0
+    },
+    useSystem: {
+      type: String,
+      default: 'MEC'
+    },
+    typeDetail: {
+      type: String,
+      default: ''
     }
   },
   emits: ['couponSelect'],
@@ -55,7 +49,7 @@ export default defineComponent({
   computed: {
     couponCount() {
       const limitCount = this.useCouponList.map((list: any) => {
-        return Number(list.discountPrice || 0)
+        return Number(list.faceValue || 0)
       })
       let count = 0
       if (this.disabled) {
@@ -69,14 +63,9 @@ export default defineComponent({
             : 0
       }
       return count
-    },
-    couponCategory() {
-      // 如果订单类型不在优惠券类型里面,则默认查询通用券
-      return couponEnum[this.orderType] || 'UNIVERSAL'
     }
   },
   mounted() {
-    // this.getUseableCoupon()
     this.getList()
   },
   methods: {
@@ -84,16 +73,18 @@ export default defineComponent({
       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',
-            orderUse: 1,
-            page: 1,
-            rows: 100
+        const res = await request.post(
+          `${state.platformApi}/sysCouponCode/queryPage`,
+          {
+            data: {
+              useSystem: this.useSystem,
+              typeDetail: this.typeDetail,
+              usageStatus: 0,
+              page: 1,
+              rows: 100
+            }
           }
-        })
+        )
         this.dataLoading = false
         const result = res.data || {}
         // 处理重复请求数据
@@ -197,7 +188,6 @@ export default defineComponent({
           {/* 优化体验 */}
           {this.popupLoading && (
             <ChoiceCoupon
-              couponCategory={this.couponCategory}
               useCoupon={this.useCouponList}
               orderAmount={this.orderAmount}
               couponList={this.list}

+ 2 - 2
vite.config.ts

@@ -11,9 +11,9 @@ function resolve(dir: string) {
 }
 // https://vitejs.dev/config/
 // https://github.com/vitejs/vite/issues/1930 .env
-const proxyUrl = 'https://test.dayaedu.com/'
+// const proxyUrl = 'https://test.dayaedu.com/'
 // const proxyUrl = 'https://dev.colexiu.com/'
-// const proxyUrl = 'http://192.168.3.143:8000/'
+const proxyUrl = 'http://192.168.3.26:8000/'
 export default defineConfig({
   base: './',
   plugins: [