discount.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="page pt-20 pr-40 pl-40">
  3. <view class="fs-28 color-666 mt-20" v-if="mode === 0">充电优惠权益卡</view>
  4. <view
  5. class="item mt-20"
  6. v-for="(item, index) in list"
  7. v-if="mode >= 0"
  8. :key="index"
  9. @click="checkDiscount(index)"
  10. >
  11. <image
  12. class="full-percent"
  13. src="/pages-charge/static/discount-bg.png"
  14. ></image>
  15. <view class="absolute-full flex pt-8 pb-8">
  16. <view class="left flex-column flex-justify-center pl-48">
  17. <view class="flex-align-end">
  18. <image
  19. class="width-92"
  20. src="/pages-charge/static/discount-coupon.png"
  21. mode="widthFix"
  22. ></image>
  23. <view class="fs-48 lh-58 color-000 fw-500 ml-16"
  24. >{{ item.discountFormat }}折</view
  25. >
  26. <view class="fs-26 color-999 ml-16" v-if="mode === 0"
  27. >充电服务费</view
  28. >
  29. </view>
  30. <view class="flex-align-center" v-if="mode === 0">
  31. <view class="fs-26 color-999 mt-24"
  32. >权益余额{{ item.rightsBalanceFormat }}元|</view
  33. >
  34. <view class="fs-26 color-999 mt-24"
  35. >{{ item.endTimeFormat }}到期</view
  36. >
  37. </view>
  38. <block v-if="mode === 1">
  39. <view class="fs-26 color-999 mt-24">{{ item.rightsDesc }}</view>
  40. <view
  41. class="fs-26 color-999 mt-8"
  42. @click.stop="
  43. to(`/pages-common/activity/activity?id=${activity.id}`)
  44. "
  45. >
  46. <text>有效期{{ item.validity }}天,</text>
  47. <text class="color-primary">详细规则</text>
  48. <text class="fs-24 ml-4 color-primary">>></text>
  49. </view>
  50. </block>
  51. </view>
  52. <view v-if="mode === 0" class="right width-80 flex-center">
  53. <style-checkbox
  54. :size="48"
  55. :checked="checkIndex === index"
  56. :iconsize="17"
  57. ></style-checkbox>
  58. </view>
  59. <view
  60. v-if="mode === 1"
  61. class="right flex-center"
  62. :style="{
  63. width: '210rpx',
  64. borderLeft: '1px dashed rgba(0, 0, 0, 0.10)',
  65. }"
  66. >
  67. <view class="btn flex-center fs-28" @click.stop="toCharge(index)"
  68. >前往充值</view
  69. >
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script setup lang="ts">
  76. import { onLoad, onShow } from "@dcloudio/uni-app";
  77. import { ref } from "vue";
  78. import { to } from "../../utils/navigate";
  79. import { fetchProfile } from "@/api/user";
  80. const mode = ref(-1);
  81. const list = ref<any[]>([]);
  82. const activity = ref();
  83. const checkIndex = ref(-1);
  84. const needRefresh = ref(false);
  85. const toCharge = (index: number) => {
  86. needRefresh.value = true;
  87. to(
  88. "/pages-user/wallet-recharge/wallet-recharge?back=1&value=" +
  89. list.value[index].amountMin
  90. );
  91. };
  92. const setUserRecharge = (_list: any[]) => {
  93. _list.forEach((item: any) => {
  94. item.endTimeFormat = item.endTime.split(" ")[0];
  95. item.rightsBalanceFormat = Number(
  96. (Number(item.rightsBalance) / 100).toFixed(2)
  97. );
  98. });
  99. list.value = _list;
  100. mode.value = 0;
  101. };
  102. const checkDiscount = (index: number) => {
  103. checkIndex.value = index;
  104. getApp<any>().globalData.lastData.discount = {
  105. index,
  106. };
  107. };
  108. onLoad((options: any) => {
  109. if (getApp<any>().globalData.user) {
  110. if (getApp<any>().globalData.user.userRechargeRightsList.length) {
  111. setUserRecharge(getApp<any>().globalData.user.userRechargeRightsList);
  112. checkIndex.value = options.index ? Number(options.index) : 0;
  113. } else {
  114. const _activity = getApp<any>().globalData.user.activityList.find(
  115. (item: any) => item.id === options.id
  116. );
  117. _activity.rechargeRightsList.forEach((item: any) => {
  118. item.discountFormat = Number((Number(item.discount) / 10).toFixed(2));
  119. });
  120. list.value = _activity.rechargeRightsList;
  121. activity.value = _activity;
  122. mode.value = 1;
  123. }
  124. }
  125. });
  126. onShow(() => {
  127. if (needRefresh.value) {
  128. needRefresh.value = false;
  129. uni.showLoading({
  130. title: "加载中",
  131. });
  132. fetchProfile().then((res) => {
  133. uni.hideLoading();
  134. if (res.userRechargeRightsList.length) {
  135. setUserRecharge(res.userRechargeRightsList);
  136. checkDiscount(0)
  137. }
  138. });
  139. }
  140. });
  141. </script>
  142. <style lang="scss" scoped>
  143. .page {
  144. min-height: 100vh;
  145. width: 100%;
  146. background-color: #f6f7fa;
  147. .item {
  148. position: relative;
  149. height: 240rpx;
  150. border-radius: 20rpx;
  151. overflow: hidden;
  152. background: #fff;
  153. .left {
  154. flex-grow: 1;
  155. }
  156. .right {
  157. flex-shrink: 0;
  158. .btn {
  159. border-radius: 8rpx;
  160. border: 1px solid var(--color-primary);
  161. color: var(--color-primary);
  162. width: 144rpx;
  163. height: 56rpx;
  164. }
  165. }
  166. }
  167. }
  168. </style>