station-coupon.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <style-dialog
  3. v-if="visible"
  4. @close="handleClose"
  5. title="优惠领取">
  6. <view class="page pt-20 pr-40 pl-40">
  7. <view class="tab-list flex-align-end">
  8. <view class="fs-28 color-666 mt-20 w50" :class="mode===0?'active':''" @click="changeTab(0)">权益卡</view>
  9. <view class="fs-28 color-666 mt-20 w50" :class="mode===1?'active':''" @click="changeTab(1)">优惠券</view>
  10. </view>
  11. <view v-if="mode===0">
  12. <view
  13. class="item mt-20 "
  14. v-for="(item, index) in rightsList"
  15. :key="index">
  16. <image class="full-percent" src="/pages-charge/static/discount-bg.png"></image>
  17. <view class="absolute-full flex pt-8 pb-8">
  18. <view class="left flex-justify-center pl-48">
  19. <view class="item-content_left">
  20. <view class="flex-align-end">
  21. <view class="item-header__left">
  22. <image class="width-84" src="/static/images/discount-rights-card.png" mode="widthFix"></image>
  23. <view class="fs-48 lh-58 color-000 fw-500 ml-16">
  24. {{ (item.discount / 10).toFixed(1) }}折
  25. </view>
  26. <view class="fs-26 color-999 ml-16" v-if="mode === 0"
  27. >抵扣充电服务费
  28. </view>
  29. </view>
  30. </view>
  31. <block>
  32. <view class="fs-26 color-999 mt-8"
  33. @click.stop="to(`/pages-common/activity/activity?id=${item.activityId}`)">
  34. <view class="fs-26 color-999">到期时间:{{ item.endTime }}</view>
  35. <view class="flex-align-center" v-if="mode === 0">
  36. <view class="fs-24 color-999">充值{{ ((item.amountMin || 0) / 100).toFixed(2) }}元,享受{{ (item.discount / 10).toFixed(1) }}折服务费权益,有效期{{item.validity}}天
  37. <!-- <text class="color-primary">详细规则</text>
  38. <text class="fs-24 ml-4 color-primary">>></text>-->
  39. </view>
  40. </view>
  41. </view>
  42. </block>
  43. </view>
  44. <view class="item-content_right">
  45. <text class="item-content_right-charge item-status ml-10" @tap.stop="handleCharge(item)">去充值</text>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view style="width: 100%;text-align: center;display: flex;flex-direction: column;align-content: center;align-items: center;">
  51. <image v-if="!rightsList||rightsList.length==0"
  52. style="width: 240rpx;" mode="widthFix"
  53. src="/static/images/search-empty.png"></image>
  54. <!-- <text style="font-size: 22rpx;">暂无权益</text>-->
  55. </view>
  56. <!-- <view style="width: 100%;text-align: center;">
  57. <image v-if="!rightsList||rightsList.length==0" style="width: 240rpx;" mode="widthFix" src="/static/images/search-empty.png"></image>
  58. </view>-->
  59. </view>
  60. <view v-if="mode===1">
  61. <view
  62. class="item mt-20 "
  63. v-for="(item, index) in couponList"
  64. :class="item.collected?'inactive':''"
  65. :key="index">
  66. <image class="full-percent" src="/static/images/discount-bg.png"></image>
  67. <view class="absolute-full flex pt-8 pb-8">
  68. <view class="left flex-justify-center pl-48">
  69. <view class="item-content_left">
  70. <view class="flex-align-end">
  71. <view class="item-header__left">
  72. <image
  73. class="width-84"
  74. src="/static/images/discount-coupon.png"
  75. mode="widthFix"
  76. ></image>
  77. <view></view>
  78. <view class="fs-48 lh-58 color-000 fw-500 ml-16" v-if="item.couponType=='FullDiscount'">
  79. {{ ((item.discount || 0) / 100).toFixed(2) }}元
  80. </view>
  81. <view class="fs-48 lh-58 color-000 fw-500 ml-16" v-else>
  82. {{ (item.discount / 10).toFixed(1) }}折
  83. </view>
  84. <view class="fs-26 color-999 ml-16">
  85. 充电服务费:{{ item.couponType == 'FullDiscount' ? '满减券' : '折扣券' }}
  86. </view>
  87. </view>
  88. </view>
  89. <block>
  90. <view class="fs-26 color-999 mt-8"
  91. @click.stop="to(`/pages-common/activity/activity?id=${item.activityId}`)">
  92. <view class="fs-26 color-999">到期时间:{{ item.endTime }}</view>
  93. <view class="flex-align-center">
  94. <view class="fs-26 color-999">服务费门槛:{{ ((item.minServiceMoney || 0) / 100).toFixed(2) }}元
  95. <text class="color-primary">详细规则</text>
  96. <text class="fs-24 ml-4 color-primary">>></text>
  97. </view>
  98. </view>
  99. </view>
  100. </block>
  101. </view>
  102. <view class="item-content_right">
  103. <view class="item-status ml-10" @tap.stop="handleCollectCoupon(item,index)">{{ item.collected ? '已领取' : '领取' }}</view>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <view style="width: 100%;text-align: center;display: flex;flex-direction: column;align-content: center;align-items: center;">
  109. <image v-if="!couponList||couponList.length==0"
  110. style="width: 240rpx;" mode="widthFix"
  111. src="/static/images/search-empty.png"></image>
  112. <!-- <text style="font-size: 22rpx;">暂无优惠券</text>-->
  113. </view>
  114. </view>
  115. </view>
  116. >
  117. </style-dialog>
  118. </template>
  119. <script setup lang="ts">
  120. import {onPullDownRefresh} from "@dcloudio/uni-app";
  121. import {ref} from "vue";
  122. import {collectCoupon, listAvailableCoupons, listAvailableRights} from "@/api/user";
  123. import {to} from "@/utils/navigate";
  124. const mode = ref(0);
  125. const rightsList = ref<any[]>([]);
  126. const couponList = ref<any[]>([]);
  127. const stationId = ref(null);
  128. const visible = ref(false);
  129. const handleClose = () => {
  130. visible.value = false;
  131. }
  132. onPullDownRefresh(() => {
  133. loadData();
  134. });
  135. const changeTab = (tab: number) => {
  136. mode.value = tab;
  137. }
  138. const handleCharge = (rights:any) => {
  139. to(`/pages-user/wallet-recharge/wallet-recharge?discount=${rights.amountMin}`)
  140. }
  141. const handleCollectCoupon = (coupon: any, index: number) => {
  142. if (coupon.collected) return;
  143. collectCoupon(coupon.id).then((res) => {
  144. console.log(res)
  145. uni.showToast({
  146. title: "领券成功",
  147. icon: "success"
  148. });
  149. couponList.value[index].collected = true;
  150. }).catch(e => {
  151. console.error(e)
  152. if (e.errMsg) {
  153. uni.showToast({
  154. title: e.errMsg,
  155. icon: "none"
  156. });
  157. }
  158. });
  159. }
  160. const loadData = () => {
  161. uni.showLoading({
  162. title: "加载中",
  163. });
  164. Promise.all([listAvailableCoupons(stationId.value), listAvailableRights(stationId.value)]).then((values) => {
  165. console.log(values)
  166. uni.hideLoading();
  167. couponList.value = values[0].list||[];
  168. rightsList.value = values[1].list||[];
  169. })
  170. /* listAvailableCoupons(stationId.value).then((res) => {
  171. console.log(res)
  172. uni.hideLoading();
  173. couponList.value = res.list;
  174. });*/
  175. }
  176. const open = (sid: any) => {
  177. visible.value = true;
  178. stationId.value = sid;
  179. loadData()
  180. }
  181. defineExpose({
  182. open
  183. })
  184. </script>
  185. <style lang="scss" scoped>
  186. .page {
  187. min-height: 100vh;
  188. width: 100%;
  189. background-color: #f6f7fa;
  190. .item {
  191. position: relative;
  192. min-height: 220rpx;
  193. border-radius: 20rpx;
  194. overflow: hidden;
  195. background: #fff;
  196. .left {
  197. flex-grow: 1;
  198. }
  199. .right {
  200. flex-shrink: 0;
  201. .btn {
  202. border-radius: 8rpx;
  203. border: 1px solid var(--color-primary);
  204. color: var(--color-primary);
  205. width: 144rpx;
  206. height: 56rpx;
  207. }
  208. }
  209. }
  210. .tab-list {
  211. width: 100%;
  212. .w50 {
  213. width: 50%;
  214. text-align: center;
  215. }
  216. .active {
  217. color: var(--color-primary);
  218. }
  219. }
  220. }
  221. .item-status {
  222. font-size: 24rpx;
  223. padding: 0rpx 6rpx;
  224. color: var(--color-primary);
  225. border: 2rpx solid var(--color-primary);
  226. border-radius: 6rpx;
  227. }
  228. .item-header__left {
  229. display: inline-flex;
  230. align-items: flex-end;
  231. }
  232. .item-header__right {
  233. padding: 5rpx;
  234. display: flex;
  235. //justify-content: flex-end;
  236. }
  237. .inactive {
  238. cursor: not-allowed;
  239. pointer-events: none;
  240. .item-status {
  241. font-size: 24rpx;
  242. padding: 0rpx 6rpx;
  243. color: #ccc !important;
  244. border: 2rpx solid #ccc;
  245. border-radius: 6rpx;
  246. }
  247. .color-primary {
  248. color: #ccc !important;
  249. }
  250. }
  251. .item-content_left {
  252. flex-grow: 1;
  253. display: flex;
  254. flex-direction: column;
  255. justify-content: space-around;
  256. }
  257. .item-content_right {
  258. width: 120rpx;
  259. display: flex;
  260. align-items: center;
  261. align-content: center;
  262. }
  263. </style>