index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <script setup lang="ts">
  2. import router from '@/router'
  3. definePage({
  4. name: 'voucherDetail',
  5. islogin: true,
  6. style: {
  7. navigationBarTitleText: '抵扣券详情',
  8. navigationStyle: 'custom',
  9. },
  10. })
  11. const StaticUrl = import.meta.env.VITE_STATIC_BASE_URL
  12. const couponId = ref('')
  13. const couponInfo = ref<Api.AppCouponDetailsVO>()
  14. // 状态映射
  15. const statusMap = new Map([
  16. [2, '可用'],
  17. [1, '已使用'],
  18. [5, '已过期'],
  19. [7, '无效'],
  20. ])
  21. const { send } = useRequest(
  22. (id: string) => Apis.app.get_smqjh_system_app_api_membercoupon_findbyid({ params: { id } }),
  23. { immediate: false },
  24. ).onSuccess((res) => {
  25. couponInfo.value = res.data.data
  26. })
  27. onLoad((options: any) => {
  28. couponId.value = options.id || ''
  29. if (couponId.value) {
  30. send(couponId.value)
  31. }
  32. })
  33. // 计算剩余天数
  34. const remainingDays = computed(() => {
  35. if (!couponInfo.value?.expirationTime)
  36. return ''
  37. const expire = new Date(couponInfo.value.expirationTime).getTime()
  38. const now = Date.now()
  39. const diff = expire - now
  40. if (diff <= 0)
  41. return '已过期'
  42. const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  43. const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
  44. return `${days}天${hours}小时`
  45. })
  46. // 计算支付倒计时
  47. function getCountdownTime(orderCreateTime?: string): number {
  48. if (!orderCreateTime)
  49. return 0
  50. const createTime = new Date(orderCreateTime).getTime()
  51. const expireTime = createTime + 30 * 60 * 1000 // 30分钟
  52. const remaining = expireTime - Date.now()
  53. return remaining > 0 ? remaining : 0
  54. }
  55. // 去使用
  56. function handleUse() {
  57. router.pushTab({ name: 'home' })
  58. useTabbar().setTabbarItemActive('home')
  59. }
  60. // 查看订单详情
  61. function handleViewOrder() {
  62. router.pushTab({ name: 'order' })
  63. useTabbar().setTabbarItemActive('order')
  64. }
  65. // 取消订单(占位)
  66. async function handleCancelOrder() {
  67. // useGlobalToast().show('功能开发中')
  68. await useUserStore().handleCommonCancelOrderJY(couponInfo.value?.orderNumber as string)
  69. send(couponId.value)
  70. }
  71. // 付款(占位)
  72. function handlePay() {
  73. // useGlobalToast().show('功能开发中')
  74. useUserStore().handleCommonGoXiaoJuPay(couponInfo.value?.orderNumber as string)
  75. }
  76. </script>
  77. <template>
  78. <view v-if="couponInfo" class="min-h-100vh bg-#f5f5f5 pb200rpx pt20rpx">
  79. <!-- 顶部券信息 -->
  80. <view class="mx24rpx rounded-16rpx bg-white px28rpx py32rpx">
  81. <view class="flex items-center">
  82. <image :src="`${StaticUrl}/smqjh-reful-juan.png`" class="mr12rpx h32rpx w32rpx" />
  83. <view class="text-30rpx font-semibold">
  84. 抵扣{{ couponInfo.discountMoney }}元(满{{ couponInfo.amountMoney }}可用)
  85. </view>
  86. </view>
  87. </view>
  88. <!-- 券信息卡片 -->
  89. <view class="mx24rpx mt20rpx rounded-16rpx bg-white px28rpx py32rpx">
  90. <view class="mb20rpx text-30rpx font-semibold">
  91. 券信息
  92. </view>
  93. <view class="text-26rpx text-#666 leading-48rpx">
  94. <view>券ID:{{ couponInfo.allowanceId || couponInfo.id }}</view>
  95. <view>批次号:{{ couponInfo.batchId || '-' }}</view>
  96. <view>状态:{{ couponInfo.lockStatus === 1 ? '已冻结' : statusMap.get(couponInfo.useStatus as number) || '-' }}</view>
  97. <view>面值:¥{{ couponInfo.discountMoney }}</view>
  98. </view>
  99. </view>
  100. <!-- 有效期卡片 -->
  101. <view class="mx24rpx mt20rpx rounded-16rpx bg-white px28rpx py32rpx">
  102. <view class="mb20rpx text-30rpx font-semibold">
  103. 有效期
  104. </view>
  105. <view class="text-26rpx text-#666 leading-48rpx">
  106. <view>开始:{{ couponInfo.getTime || '-' }}</view>
  107. <view>结束:{{ couponInfo.expirationTime || '-' }}</view>
  108. <view v-if="couponInfo.useStatus === 1">
  109. 使用:{{ couponInfo.orderPayTime || '-' }}
  110. </view>
  111. <view v-else>
  112. 剩余:{{ remainingDays }}
  113. </view>
  114. </view>
  115. </view>
  116. <!-- 使用记录(已使用状态) -->
  117. <view v-if="couponInfo.useStatus === 1" class="mx24rpx mt20rpx rounded-16rpx bg-white px28rpx py32rpx">
  118. <view class="mb20rpx text-30rpx font-semibold">
  119. 使用记录
  120. </view>
  121. <view class="text-26rpx text-#666 leading-48rpx">
  122. <view>订单号:{{ couponInfo.orderNumber || '-' }}</view>
  123. <view>油站:{{ couponInfo.storeName || '-' }}</view>
  124. <view>油号:{{ couponInfo.itemName || '-' }}</view>
  125. <view>枪号:{{ couponInfo.gunNo ? `${couponInfo.gunNo}号枪` : '-' }}</view>
  126. <view>订单金额:¥{{ couponInfo.totalMoney ? (couponInfo.totalMoney) : 0 }}</view>
  127. <view>抵扣金额:¥{{ couponInfo.discountMoney }}</view>
  128. <view>实付金额:¥{{ couponInfo.realMoney ? (couponInfo.realMoney) : 0 }}</view>
  129. </view>
  130. </view>
  131. <!-- 冻结信息(已冻结状态) -->
  132. <view v-if="couponInfo.lockStatus === 1 && couponInfo.useStatus === 2" class="mx24rpx mt20rpx rounded-16rpx bg-white px28rpx py32rpx">
  133. <view class="mb20rpx text-30rpx font-semibold">
  134. 冻结信息
  135. </view>
  136. <view class="mb16rpx flex items-center text-26rpx text-#ff4d3a">
  137. <wd-icon name="info-circle" size="28rpx" color="#ff4d3a" class="mr8rpx" />
  138. 当前券被订单占用
  139. </view>
  140. <view class="text-26rpx text-#666 leading-48rpx">
  141. <view>订单号:{{ couponInfo.orderNumber || '-' }}</view>
  142. <view>下单时间:{{ couponInfo.orderCreateTime || '-' }}</view>
  143. <view class="flex items-center">
  144. 支付剩余时间:<wd-count-down :time="getCountdownTime(couponInfo.orderCreateTime)" format="mm分ss秒" />
  145. </view>
  146. <view>订单金额:¥{{ couponInfo.totalMoney ? (couponInfo.totalMoney) : 0 }}</view>
  147. <view>抵扣金额:¥{{ couponInfo.discountMoney }}</view>
  148. </view>
  149. </view>
  150. <!-- 无效原因(无效状态) -->
  151. <view v-if="couponInfo.useStatus === 7" class="mx24rpx mt20rpx rounded-16rpx bg-white px28rpx py32rpx">
  152. <view class="mb20rpx text-30rpx font-semibold">
  153. 无效原因
  154. </view>
  155. <view class="mb16rpx flex items-center text-26rpx text-#ff4d3a">
  156. <wd-icon name="info-circle" size="28rpx" color="#ff4d3a" class="mr8rpx" />
  157. 此券无法使用
  158. </view>
  159. <view class="text-26rpx text-#666">
  160. 原因:油站已下线
  161. </view>
  162. </view>
  163. <!-- 使用规则卡片 -->
  164. <view class="mx24rpx mt20rpx rounded-16rpx bg-white px28rpx py32rpx">
  165. <view class="mb20rpx text-30rpx font-semibold">
  166. 使用规则
  167. </view>
  168. <view class="text-26rpx text-#666 leading-44rpx">
  169. <view>·订单满{{ couponInfo.amountMoney }}元可用</view>
  170. <view>·抵扣金额:{{ couponInfo.discountMoney }}元</view>
  171. <view>·每单限用1张,不与其他优惠同享</view>
  172. <view>·使用全部合作油站</view>
  173. <view>·不支持部分特殊油站</view>
  174. </view>
  175. </view>
  176. <!-- 状态说明卡片 -->
  177. <view class="mx24rpx mt20rpx rounded-16rpx bg-white px28rpx py32rpx">
  178. <view class="mb20rpx text-30rpx font-semibold">
  179. 状态说明
  180. </view>
  181. <view class="text-26rpx text-#666">
  182. <template v-if="couponInfo.lockStatus === 1 && couponInfo.useStatus === 2">
  183. 此券已被当前订单占用,如需使用其他抵扣券,请先取消订单或完成支付
  184. </template>
  185. <template v-else-if="couponInfo.useStatus === 2">
  186. 当前状态正常,可在下单时使用
  187. </template>
  188. <template v-else-if="couponInfo.useStatus === 1">
  189. 此抵扣券已使用,您可以在活动期间关注新抵扣券
  190. </template>
  191. <template v-else-if="couponInfo.useStatus === 7">
  192. 此抵扣券因合作变动无法使用,您可以联系客服处理。
  193. </template>
  194. <template v-else>
  195. 此券当前不可用
  196. </template>
  197. </view>
  198. </view>
  199. <!-- 底部按钮 -->
  200. <FixedLayout>
  201. <!-- 可用状态 -->
  202. <wd-button
  203. v-if="couponInfo.useStatus === 2 && couponInfo.lockStatus !== 1"
  204. block
  205. size="large"
  206. @click="handleUse"
  207. >
  208. 去使用
  209. </wd-button>
  210. <!-- 已使用状态 -->
  211. <wd-button
  212. v-else-if="couponInfo.useStatus === 1"
  213. block
  214. size="large"
  215. @click="handleViewOrder"
  216. >
  217. 查看订单详情
  218. </wd-button>
  219. <!-- 已冻结状态 -->
  220. <view v-else-if="couponInfo.lockStatus === 1 && couponInfo.useStatus === 2" class="flex items-center gap-24rpx">
  221. <wd-button plain block size="large" custom-class="flex-1 cancel-btn" @click="handleCancelOrder">
  222. 取消订单
  223. </wd-button>
  224. <wd-button block size="large" custom-class="flex-1" @click="handlePay">
  225. 付款
  226. </wd-button>
  227. </view>
  228. </FixedLayout>
  229. </view>
  230. </template>
  231. <style lang="scss" scoped>
  232. :deep(.cancel-btn) {
  233. border-color: var(--them-color) !important;
  234. color: var(--them-color) !important;
  235. }
  236. </style>