Selaa lähdekoodia

套餐上架优化,添加限定条件提示

lighter 3 kuukautta sitten
vanhempi
commit
ea25809dca

+ 8 - 0
src/api/package-mall.js

@@ -31,6 +31,14 @@ export function getPurchasedPackageItems(id) {
   })
 }
 
+export function getPatientAgeAndGender(patientId) {
+  return request({
+    url: '/packageMall/getPatientAgeAndGender',
+    method: 'get',
+    params: {patientId}
+  })
+}
+
 export function refund(id, tradeNo) {
   return request({
     url: '/packageMall/refund',

+ 4 - 1
src/views/hospital-service/self-service/package-mall/MallPackage.vue

@@ -9,10 +9,13 @@
               :desc="item.description"
               :title="item.name"
               :thumb="item.thumbPath"
+              :origin-price="item.originPrice"
               @click="toPackageDetail(item)"
           >
             <template #price>
-              ¥ {{item.price.toFixed(2)}}
+              <span style="color: orangered">
+                ¥ {{item.discountPrice.toFixed(2)}}
+              </span>
             </template>
           </van-card>
         </div>

+ 94 - 7
src/views/hospital-service/self-service/package-mall/PackageDetail.vue

@@ -15,7 +15,12 @@
       </template>
       <template #price>
         <span v-if="from === '0'">
-          ¥ {{ detail.price?.toFixed(2) }}
+          <span style="color: orangered">
+            ¥ {{ detail.discountPrice?.toFixed(2) }}
+          </span>
+          <span style="margin-left: 8px; color: gray; text-decoration: line-through">
+            ¥ {{ detail.originPrice?.toFixed(2) }}
+          </span>
         </span>
         <span v-else>
           ¥ {{ detail.purchasePrice?.toFixed(2) }}
@@ -39,8 +44,24 @@
       <div v-for="item in detail.items">
         <div class="item-box">
           <div class="item-name">{{ item.hisName }}</div>
+          <div>
+            <van-tag v-if="item.genderRestriction" type="danger" style="margin-right: 8px">
+              限 {{item.genderRestriction === 1 ? '男性' : '女性'}}
+            </van-tag>
+            <van-tag v-if="item.minAgeRestriction" type="warning" style="margin-right: 8px">
+              最小年龄 {{item.minAgeRestriction}}岁
+            </van-tag>
+            <van-tag v-if="item.maxAgeRestriction" type="warning" style="margin-right: 8px">
+              最大年龄 {{item.maxAgeRestriction}}岁
+            </van-tag>
+          </div>
           <div v-if="from === '0'" class="item-price-quantity">
-            <div class="price">¥ {{ item.price?.toFixed(2) }}</div>
+            <div class="price">
+              ¥ {{ item.discountPrice?.toFixed(2) }}
+              <span style="margin-left: 12px;color: gray;text-decoration: line-through">
+                ¥ {{item.originPrice?.toFixed(2)}}
+              </span>
+            </div>
             <div class="quantity">x{{ item.quantity }}</div>
           </div>
           <div v-else class="item-price-quantity">
@@ -51,7 +72,7 @@
       </div>
     </div>
     <div v-if="from === '0'" class="buy-box">
-      <van-button block type="success" @click="toCashier">购买</van-button>
+      <van-button block type="success" @click="checkConflict">购买</van-button>
     </div>
   </window-size>
 </template>
@@ -59,9 +80,14 @@
 <script setup>
 import router from "@/router";
 import {onMounted, ref} from "vue";
-import {getPackageDetail, getPurchasedPackageItems, refund} from "@/api/package-mall";
+import {
+  getPackageDetail,
+  getPurchasedPackageItems,
+  getPatientAgeAndGender,
+  refund
+} from "@/api/package-mall";
 import store from "@/store";
-import {showConfirmDialog, showDialog} from "vant";
+import {showConfirmDialog, showDialog, showToast} from "vant";
 
 const routeParams = router.currentRoute.value.params
 const from = ref('0')
@@ -88,16 +114,77 @@ function showDesc() {
   })
 }
 
+function checkConflict() {
+  let packageItems = detail.value.items
+  getPatientAgeAndGender(routeParams.patientId).then(res => {
+    let patientGender = res.gender
+    let patientAge = res.age
+    for (let i = 0; i < packageItems.length; i++) {
+      let item = packageItems[i]
+      let genderRestriction = item.genderRestriction
+      let minAgeRestriction = item.minAgeRestriction
+      let maxAgeRestriction = item.maxAgeRestriction
+
+      if (!checkGenderConflict(genderRestriction, patientGender)) {
+        return
+      }
+
+      if (!checkMinAgeRestriction(minAgeRestriction, patientAge)) {
+        return;
+      }
+
+      if (!checkMaxAgeRestriction(maxAgeRestriction, patientAge)) {
+        return
+      }
+    }
+    toCashier()
+  })
+}
+
+function checkGenderConflict(genderRestriction, patientGender) {
+  if (genderRestriction && genderRestriction !== patientGender) {
+    let genderDesc = genderRestriction === 1 ? '男性' : '女性'
+    showToast({
+      position: 'top',
+      message: `此套餐限定${genderDesc}购买,您无法购买,敬请谅解。`
+    })
+    return false
+  }
+  return true
+}
+
+function checkMinAgeRestriction(minAgeRestriction, patientAge) {
+  if (minAgeRestriction && patientAge && patientAge < minAgeRestriction) {
+    showToast({
+      position: 'top',
+      message: `此套餐限定最小年龄${minAgeRestriction}岁,您无法购买,敬请谅解。`
+    });
+    return false
+  }
+  return true
+}
+
+function checkMaxAgeRestriction(maxAgeRestriction, patientAge) {
+  if (maxAgeRestriction && patientAge && patientAge > maxAgeRestriction) {
+    showToast({
+      position: 'top',
+      message: `此套餐限定最大年龄${maxAgeRestriction}岁,您无法购买,敬请谅解。`
+    })
+    return false
+  }
+  return true
+}
+
 function toCashier() {
   const createOrderRequest = {
     body: `医院套餐(${detail.value.name})`,
     orderType: 10,
     wxmallPackageId: detail.value.id,
-    totalFee: detail.value.price,
+    totalFee: detail.value.discountPrice,
     patientId: routeParams.patientId,
     fundpayAmt: 0,
     acctpayAmt: 0,
-    cashpayAmt: detail.value.price,
+    cashpayAmt: detail.value.discountPrice,
     couponAmt: 0,
   }
   store.dispatch({