lex 1 год назад
Родитель
Сommit
ee7852760d

+ 15 - 15
src/student/music-group/pre-apply/order-detail.tsx

@@ -82,13 +82,13 @@ export default defineComponent({
         })
         state.goodsInfos = goodsInfos
 
-        if (!addressDetails.value.id) {
-          addressDetails.value = data.addresses || {}
-        }
+        // if (!addressDetails.value.id) {
+        //   addressDetails.value = data.addresses || {}
+        // }
 
         // 判断运费状态
         // 如果没有购买商品,有购买教材则『到付』 其它则免运费
-        console.log(hasInstrument, hasTextbook)
+        // console.log(hasInstrument, hasTextbook)
         if (!hasInstrument && hasTextbook) {
           state.freight = '到付'
         } else {
@@ -251,10 +251,10 @@ export default defineComponent({
      */
     const buyOrchestra = async (callback: any) => {
       // 请选择收货地址
-      if (!addressDetails.value.id) {
-        showToast('请选择收货地址')
-        return
-      }
+      // if (!addressDetails.value.id) {
+      //   showToast('请选择收货地址')
+      //   return
+      // }
 
       if (!state.agreeStatus) {
         showToast('请先阅读并同意《管乐团平台服务协议》')
@@ -275,7 +275,7 @@ export default defineComponent({
           data: {
             orderNo: state.orderNo,
             orderType: 'ORCHESTRA',
-            receiveAddress: addressDetails.value.id
+            receiveAddress: null
           }
         })
         // console.log(data)
@@ -334,10 +334,10 @@ export default defineComponent({
       }
 
       // 获取收货地址
-      let details = sessionStorage.getItem('addressDetails')
-      details = details ? JSON.parse(details) : {}
-      addressDetails.value = details
-      sessionStorage.removeItem('addressDetails')
+      // let details = sessionStorage.getItem('addressDetails')
+      // details = details ? JSON.parse(details) : {}
+      // addressDetails.value = details
+      // sessionStorage.removeItem('addressDetails')
 
       getOrderDetails()
     })
@@ -346,11 +346,11 @@ export default defineComponent({
         {browser().isApp && <OHeader border={false} />}
         <div class={styles.cartConfirm}>
           {/* 只有乐团购买的时候显示收货地址 */}
-          {orderType.value === 'ORCHESTRA' && (
+          {/* {orderType.value === 'ORCHESTRA' && (
             <div class={styles.cartConfirmBox}>
               <Addres item={addressDetails.value} />
             </div>
-          )}
+          )} */}
 
           <CellGroup style={{ margin: 0 }}>
             {state.goodsInfos &&

+ 251 - 26
src/student/music-group/pre-goods-apply/index.tsx

@@ -28,6 +28,7 @@ import { browser, getUrlCode, moneyFormat } from '@/helpers/utils'
 import request from '@/helpers/request'
 import { useRoute, useRouter } from 'vue-router'
 import { goWechatAuth, setLogout } from '@/state'
+import ODialog from '@/components/o-dialog'
 
 // 乐团交付,乐团停止或关闭,有新的交付团;则不允许报名
 const classList: any = []
@@ -60,11 +61,26 @@ export default defineComponent({
       classStatus: false,
       subjectStatus: false,
       registerInfo: {}, // 乐团信息
+      goodsInfo: {} as any, // 商品
+      textBookInfo: {} as any, // 教材
+      inspectInfo: {} as any, // 乐器检查
+      vipYearInfo: {} as any, // 学练工具
+      inspectStatus: true,
       // 是否开启微信登录(测试使用)默认为false
       testIsWeixin: true,
+      details: [] as any, //
       pattern: /^1(3|4|5|6|7|8|9)\d{9}$/,
       nameReg: /^[\u4E00-\u9FA5]+$/,
-      subjectChangeStatus: false // 更换声部时
+      subjectChangeStatus: false, // 更换声部时
+      paymentType: '',
+      musicPaymentType: '', // 乐团中对应支付方式
+      dialogStatus: false,
+      dialogMessage: '',
+      dialogConfig: {} as any,
+      orderInfo: {
+        needPrice: 0,
+        originalPrice: 0
+      }
     })
     const forms = reactive({
       username: null,
@@ -76,8 +92,8 @@ export default defineComponent({
       registerSubjectId: '',
       registerSubjectTxt: null, // 所在声部
       parentName: null,
-      groupBuyType: null,
-      phone: null
+      groupBuyType: '' as any,
+      phone: null as any
     })
 
     // 获取乐团报名信息
@@ -159,9 +175,10 @@ export default defineComponent({
           ...forms
         }
         // 判断是否已报过名
-        if (state.detail.id) {
-          params.id = state.detail.id
-        }
+        // if (state.detail.id) {
+        //   params.id = state.detail.id
+        // }
+        // 开始报名
         await request.post('/api-student/orchestraRegister/save', {
           hideLoading: false,
           data: {
@@ -169,6 +186,82 @@ export default defineComponent({
             code: state.code
           }
         })
+
+        // 判断是否购买乐器
+        if (forms.groupBuyType === 'GROUP_BUY') {
+          // 重新计算金额
+          calcPrice()
+          const params: any = [] // 支付参数
+
+          // 学练工具
+          const vipYear = state.vipYearInfo
+          params.push({
+            goodsId: vipYear.goodsId,
+            goodsNum: 1,
+            goodsType: vipYear.goodsType,
+            paymentCashAmount: vipYear.currentPrice, // 现金支付金额
+            paymentCouponAmount: 0 // 优惠券金额
+          })
+
+          // 商品
+          const goodsInfo = state.goodsInfo
+          params.push({
+            goodsId: goodsInfo.goodsId,
+            goodsNum: 1,
+            goodsType: goodsInfo.goodsType,
+            paymentCashAmount: goodsInfo.currentPrice, // 现金支付金额
+            paymentCouponAmount: 0 // 优惠券金额
+          })
+
+          // 教材
+          const textBookInfo = state.textBookInfo
+          params.push({
+            goodsId: textBookInfo.goodsId,
+            goodsNum: 1,
+            goodsType: textBookInfo.goodsType,
+            paymentCashAmount: textBookInfo.currentPrice, // 现金支付金额
+            paymentCouponAmount: 0 // 优惠券金额
+          })
+
+          // 检查
+          if (state.inspectStatus) {
+            const inspectInfo = state.inspectInfo
+            params.push({
+              goodsId: inspectInfo.goodsId,
+              goodsNum: 1,
+              goodsType: inspectInfo.goodsType,
+              paymentCashAmount: inspectInfo.currentPrice, // 现金支付金额
+              paymentCouponAmount: 0 // 优惠券金额
+            })
+          }
+
+          // 创建订单
+          const { data } = await request.post('/api-student/userPaymentOrder/executeOrder', {
+            hideLoading: false,
+            data: {
+              paymentType: state.musicPaymentType || state.paymentType,
+              bizId: route.query.id, // 乐团编号
+              orderType: 'ORCHESTRA',
+              paymentCashAmount: state.orderInfo.needPrice || 0,
+              paymentCouponAmount: 0,
+              goodsInfos: params,
+              orderName: '乐团报名缴费',
+              orderDesc: '乐团报名缴费'
+            }
+          })
+
+          console.log(data)
+          router.push({
+            path: '/orderDetail',
+            query: {
+              pm: 1, // h5乐团报名
+              config: JSON.stringify({ ...data.paymentConfig, paymentType: data.paymentType }),
+              orderNo: data.orderNo
+            }
+          })
+        } else {
+          //
+        }
       } catch {
         //
       }
@@ -198,12 +291,108 @@ export default defineComponent({
       }
     }
 
+    // 查询未支付订单
+    const paymentOrderUnpaid = async () => {
+      try {
+        const { data } = await request.get('/api-student/userPaymentOrder/unpaid')
+        // 判断是否有待支付订单
+        if (data.id) {
+          state.dialogMessage = '您有待支付的订单,是否继续支付'
+          state.dialogStatus = true
+          state.dialogConfig = data
+        }
+      } catch {
+        //
+      }
+    }
+
+    // 获取支付渠道
+    const sysParamConfig = async () => {
+      try {
+        const { data } = await request.get('/api-student/sysParamConfig/queryByParamName', {
+          params: {
+            paramName: 'payment_service_provider'
+          }
+        })
+        state.paymentType = data.paramValue || ''
+      } catch {
+        //
+      }
+    }
+
+    // 获取商品信息
+    const registerGoods = async () => {
+      try {
+        const { data } = await request.get(
+          '/api-student/orchestraRegister/registerGoods/' + route.query.id,
+          {
+            params: {
+              subjectId: forms.registerSubjectId
+            }
+          }
+        )
+
+        state.musicPaymentType = data.paymentServiceProvider || ''
+        // 初始化数据商品数据
+        const details = data.details || []
+        details.forEach((item: any) => {
+          if (item.goodsType === 'INSTRUMENTS') {
+            const img = item.goodsUrl ? item.goodsUrl.split(',')[0] : ''
+            state.goodsInfo = { ...item, goodsUrl: img }
+          } else if (item.goodsType === 'TEXTBOOK') {
+            const img = item.goodsUrl ? item.goodsUrl.split(',')[0] : ''
+            state.textBookInfo = { ...item, goodsUrl: img }
+          } else if (item.goodsType === 'INSTRUMENT_INSPECT') {
+            state.inspectInfo = { ...item }
+          } else if (item.goodsType === 'VIP_YEAR') {
+            state.vipYearInfo = { ...item }
+          }
+          state.details = details
+        })
+
+        calcPrice()
+      } catch {
+        //
+      }
+    }
+
+    // 初始化金额
+
+    const calcPrice = () => {
+      // const details = state.details
+      const tempPrice = {
+        needPrice: 0, //需要支付金额
+        originalPrice: 0 // 原价
+      }
+      // 商品
+      tempPrice.needPrice += parseFloat(state.goodsInfo.currentPrice || 0)
+      tempPrice.originalPrice += parseFloat(state.goodsInfo.originalPrice || 0)
+      // 学练工具
+      tempPrice.needPrice += parseFloat(state.vipYearInfo.currentPrice || 0)
+      tempPrice.originalPrice += parseFloat(state.vipYearInfo.originalPrice || 0)
+      // 教材
+      tempPrice.needPrice += parseFloat(state.textBookInfo.currentPrice || 0)
+      tempPrice.originalPrice += parseFloat(state.textBookInfo.originalPrice || 0)
+
+      // 检查乐器
+      if (state.inspectStatus) {
+        tempPrice.needPrice += parseFloat(state.inspectInfo.currentPrice || 0)
+        tempPrice.originalPrice += parseFloat(state.inspectInfo.originalPrice || 0)
+      }
+      state.orderInfo = tempPrice
+    }
+
     onMounted(async () => {
       // state.code = route.query.code || ''
       // console.log('pre register code: ' + state.code)
       await getSubjects()
       await studentRegister()
 
+      sysParamConfig()
+      // 查询未支付订单
+      // registerGoods()
+      paymentOrderUnpaid()
+
       // 判断是否有授权码
       // if (!props.code) {
       //   setLogout()
@@ -458,29 +647,26 @@ export default defineComponent({
               <CellGroup class={[styles.applyCellGroup, styles.groupBuy]} border={false}>
                 <Cell border={false}>
                   {{
-                    icon: () => (
-                      <Image
-                        src={'https://cloud-coach.ks3-cn-beijing.ksyuncs.com/1696816717584.png'}
-                        class={styles.goodsImg}
-                      />
-                    ),
+                    icon: () => <Image src={state.vipYearInfo.goodsUrl} class={styles.goodsImg} />,
                     value: () => (
-                      <div class={styles.goodsInfo}>
+                      <div class={styles.vipYearInfo}>
                         <div class={styles.goodsTitle}>
-                          管乐AI学练工具 <img src={icon12} />
+                          {state.vipYearInfo.goodsName} <img src={icon12} />
                         </div>
                         <p class={styles.goodsTips}>乐团首次训练之日起生效</p>
                         <p class={[styles.goodsMemo, 'van-multi-ellipsis--l2']}>
-                          乐团云教材、课件,乐团声部、合奏、考级等
+                          {state.vipYearInfo.description}
                         </p>
                         <div class={styles.goodsPrice}>
                           <div class={styles.priceGroup}>
                             团购价:
                             <p>
-                              <span>¥</span> 2,900.00
+                              <span>¥</span> {state.vipYearInfo.currentPrice}
                             </p>
                           </div>
-                          <div class={styles.priceOrigin}>原价: ¥2,900.00</div>
+                          <div class={styles.priceOrigin}>
+                            原价: ¥{state.vipYearInfo.originalPrice}
+                          </div>
                         </div>
                       </div>
                     )
@@ -497,20 +683,21 @@ export default defineComponent({
                     value: () => (
                       <div class={styles.goodsInfo}>
                         <div class={styles.goodsTitle}>
-                          管乐AI学练工具 <img src={iconFree} />
+                          {state.goodsInfo.goodsName} <img src={iconFree} />
                         </div>
-                        <p class={styles.goodsTips}>乐团首次训练之日起生效</p>
                         <p class={[styles.goodsMemo, 'van-multi-ellipsis--l2']}>
-                          乐团云教材、课件,乐团声部、合奏、考级等
+                          {state.goodsInfo.description}
                         </p>
                         <div class={styles.goodsPrice}>
                           <div class={styles.priceGroup}>
                             团购价:
                             <p>
-                              <span>¥</span> 2,900.00
+                              <span>¥</span> {state.goodsInfo.currentPrice}
                             </p>
                           </div>
-                          <div class={styles.priceOrigin}>原价: ¥2,900.00</div>
+                          <div class={styles.priceOrigin}>
+                            原价: ¥{state.goodsInfo.originalPrice}
+                          </div>
                         </div>
                       </div>
                     )
@@ -525,10 +712,10 @@ export default defineComponent({
                         <div class={styles.baoTitle}>下校检查乐器 1-2次/学期</div>
                         <div class={styles.baoPrice}>
                           <p>
-                            <span class={styles.prefix}>¥</span> 300.00
+                            <span class={styles.prefix}>¥</span> {state.inspectInfo.currentPrice}
                             <span class={styles.suffix}>/年</span>
                           </p>
-                          <Checkbox></Checkbox>
+                          <Checkbox v-model={state.inspectStatus}></Checkbox>
                         </div>
                       </div>
                     )
@@ -543,7 +730,7 @@ export default defineComponent({
                       <span class={styles.numFont}>
                         <span>¥ </span>
 
-                        {moneyFormat(10)}
+                        {moneyFormat(state.orderInfo.needPrice)}
                       </span>
                     </p>
                   </div>
@@ -673,14 +860,52 @@ export default defineComponent({
             showToolbar
             columns={state.subjectList}
             onCancel={() => (state.subjectStatus = false)}
-            onConfirm={(val: any) => {
+            onConfirm={async (val: any) => {
               const selectedOption = val.selectedOptions[0]
               forms.registerSubjectId = selectedOption.value
               forms.registerSubjectTxt = selectedOption.text
               state.subjectStatus = false
+
+              // 更新商品信息
+              await registerGoods()
+
+              forms.groupBuyType = 'GROUP_BUY'
             }}
           />
         </Popup>
+
+        <ODialog
+          title="提示"
+          v-model:show={state.dialogStatus}
+          message={state.dialogMessage}
+          confirmButtonText="继续支付"
+          cancelButtonText="取消订单"
+          showCancelButton
+          onConfirm={() => {
+            const paymentConfig = state.dialogConfig.paymentConfig
+
+            router.push({
+              path: '/orderDetail',
+              query: {
+                pm: 1, // h5乐团报名
+                config: JSON.stringify({
+                  ...paymentConfig.paymentConfig,
+                  paymentType: paymentConfig.paymentType
+                }),
+                orderNo: paymentConfig.orderNo
+              }
+            })
+          }}
+          onCancel={async () => {
+            try {
+              await request.post(
+                '/api-student/userPaymentOrder/cancelPayment/' + state.dialogConfig.orderNo
+              )
+            } catch {
+              //
+            }
+          }}
+        />
       </div>
     )
   }