Parcourir la source

默认展示充电权益和优惠券

zuy il y a 1 an
Parent
commit
155d167b68

+ 0 - 1
src/components/station-charge-coupon/station-charge-coupon.vue

@@ -15,7 +15,6 @@
         <view
             class="item mt-20 "
             v-for="(item, index) in rightsList"
-            :class="item.status==0?'inactive':''"
             :key="index">
 
           <image class="full-percent" src="/pages-charge/static/discount-bg.png"></image>

+ 29 - 8
src/pages-charge/appointment/appointment.vue

@@ -158,14 +158,14 @@
           <view class="fs-28 lh-28 color-000 fw-500">优惠</view>
           <block v-if="checkedUserRightsOrCoupon&&checkedUserRightsOrCoupon.userRights">
             <view class="fs-28 lh-28 ml-auto" style="color: #f43636"
-            >{{ ((checkedUserRightsOrCoupon?.userRights?.discount||0)/10).toFixed(1) }}折
+            >{{ ((checkedUserRightsOrCoupon?.userRights?.discount || 0) / 10).toFixed(1) }}折
             </view
             >
             <uni-icons type="right" size="16" color="#CACACA"></uni-icons>
           </block>
           <block v-else-if="checkedUserRightsOrCoupon&&checkedUserRightsOrCoupon.userCoupon">
             <view class="fs-28 lh-28 ml-auto" style="color: #f43636"
-            >{{ ((checkedUserRightsOrCoupon?.userCoupon?.discount||0)/100).toFixed(2) }}元
+            >{{ ((checkedUserRightsOrCoupon?.userCoupon?.discount || 0) / 100).toFixed(2) }}元
             </view
             >
             <!--            <view class="fs-28 lh-28 color-666 ml-8">权益待领取</view>-->
@@ -297,7 +297,7 @@
 
 <script setup lang="ts">
 import {cancelAppointmentCharge, changeAppointmentTime, fetchChargeStatus, fetchStationByConnectorIdOrShortId, fetchStationPriceDesc, startAppointmentCharge, startCharge,} from "@/api/charge";
-import {fetchProfile} from "@/api/user";
+import {fetchProfile, listStationAvailableRightsAndCoupons} from "@/api/user";
 import {onLoad, onShow} from "@dcloudio/uni-app";
 import {ref} from "vue";
 import ChargeMachine from "../machines/charge-machine/charge-machine.vue";
@@ -357,8 +357,8 @@ const activity = ref();
 const stationId = ref();
 
 const handleShowStationChargeCoupon = () => {
-  let {rightsId,couponId} = checkedUserRightsOrCoupon.value;
-  station_charge_coupon_ref.value?.open(stationId.value,rightsId,couponId);
+  let {rightsId, couponId} = checkedUserRightsOrCoupon.value;
+  station_charge_coupon_ref.value?.open(stationId.value, rightsId, couponId);
 }
 
 const handleCheckedUserRightsAndCoupon = (data: any) => {
@@ -713,11 +713,11 @@ const submit = () => {
   if (chargeType.value === 1) {
     query += "isBooking=false";
   }
-  let {rightsId,couponId} = checkedUserRightsOrCoupon.value;
-  if (rightsId &&rightsId >= 0) {
+  let {rightsId, couponId} = checkedUserRightsOrCoupon.value;
+  if (rightsId && rightsId >= 0) {
     query += `&userRechargeRightsId=${rightsId}`;
   }
-  if (couponId &&couponId >= 0) {
+  if (couponId && couponId >= 0) {
     query += `&userCouponId=${couponId}`;
   }
   console.log(query)
@@ -786,6 +786,26 @@ const _checkStartCharge = () => {
   });
 };
 
+/**
+ * 设置当前用户在该站点的默认充电权益或优惠券
+ */
+const fetchUserStationDefaultRightsAndCoupon = () => {
+  listStationAvailableRightsAndCoupons(stationId.value).then((res) => {
+    let {userRechargeRightsList, userCouponList} = res;
+    let couponList = (userCouponList || []).sort((a: any, b: any) => new Date(a.endTime).getTime() - new Date(b.endTime).getTime());
+    let rightsList = (userRechargeRightsList || []).sort((a: any, b: any) => new Date(a.endTime).getTime() - new Date(b.endTime).getTime());
+    checkedUserRightsOrCoupon.value.stationId = stationId.value;
+    if (rightsList && rightsList.length > 0) {
+      checkedUserRightsOrCoupon.value.userRights = rightsList[0];
+      checkedUserRightsOrCoupon.value.rightsId = rightsList[0].rightsId;
+    } else if (couponList && couponList.length > 0) {
+      checkedUserRightsOrCoupon.value.userCoupon = couponList[0];
+      checkedUserRightsOrCoupon.value.couponId = couponList[0].couponId;
+    }
+    console.log(res)
+  });
+}
+
 onLoad((_options: any) => {
   // sn=SN100523042860091 测试环境
   console.log("options", _options);
@@ -799,6 +819,7 @@ onLoad((_options: any) => {
         let {station, equipment} = res;
         if (station) {
           stationId.value = station.StationID;
+          fetchUserStationDefaultRightsAndCoupon();
         }
         if (equipment && equipment.connectorInfos && equipment.connectorInfos.length) {
           sn = equipment.connectorInfos[0].connectorId;