index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="page" :style="{'height':countsList.length>0?'':'100vh'}">
  3. <view class="flex-col" v-if="countsList.length === 0">
  4. <view class="flex-row justify-center">
  5. <image class="empty" src="/static/imageIcon/empty.png" mode="widthFix"></image>
  6. </view>
  7. <view class="emptyText flex-row justify-center">
  8. <text>暂无内容</text>
  9. </view>
  10. </view>
  11. <view v-else>
  12. <view class="flex-col" v-for="(item,index) in countsList" :key="index">
  13. <view class="row-list flex-row justify-start">
  14. <view class="h-text flex-col justify-center ">
  15. <view class="money">
  16. <text class="money" v-if="item.discountsType == 2">{{item.discount}}折</text>
  17. <text class="money" v-else>{{`减` + item.discountsPrice}}</text>
  18. </view>
  19. <view class="desc">
  20. <text>满{{ item.reachPrice }}可用</text>
  21. </view>
  22. </view>
  23. <view class="h-center-content flex-col justify-around">
  24. <view class="h-value">
  25. <text>{{ item.name }}</text>
  26. </view>
  27. <!-- <view class="title">-->
  28. <!-- 使用平台:<text v-if="item.strategyType == '0'">全平台</text>-->
  29. <!-- <text v-else-if="item.strategyType == '1'">个人优惠卷</text>-->
  30. <!-- </view>-->
  31. <view class="title">
  32. 使用次数:{{ item.degree }}
  33. </view>
  34. <view class="title">
  35. <text v-if="item.validType == 1">领取后{{ item.effectiveDays }}天内有效</text>
  36. <view v-else>
  37. <view>使用期限:{{item.startTime.substring(0,10)}} </view>
  38. <view> 至 {{item.endTime.substring(0,10)}}</view>
  39. </view>
  40. </view>
  41. <view class="title flex-row">
  42. <text @click.stop="showRemark(item)">使用规则</text>
  43. <u-icon v-if="item.id == showRemarkId" name="arrow-down-fill" color="" size="12"></u-icon>
  44. <u-icon v-else name="play-right-fill" color="" size="12"></u-icon>
  45. </view>
  46. </view>
  47. <view class="h-right-content flex-col justify-center ">
  48. <view class="btn" @click="gotoReceiveCoupon(item)">
  49. <text>立即领取</text>
  50. </view>
  51. </view>
  52. </view>
  53. <view v-if="showRemarkId == item.id" class="remark">
  54. <view v-if="item.unavailableWeeklyTimes || item.unavailableTimeRanges">
  55. 不可用日期:
  56. <view v-if="item.unavailableWeeklyTimes">{{ parseWeeklyTimes(item.unavailableWeeklyTimes) }}</view>
  57. <view v-if="item.unavailableTimeRanges">{{ parseTimeRanges(item.unavailableTimeRanges) }}</view>
  58. </view>
  59. <view v-if="item.delayEffectiveDays > 0">
  60. 生效时间:
  61. <text>购买后{{item.delayEffectiveDays}}天生效</text>
  62. </view>
  63. <view>
  64. 可用门店:
  65. <text>{{ item.useStoreDesc }}</text>
  66. </view>
  67. <view>
  68. 适用项目:
  69. <text>{{ item.useServiceDesc }}</text>
  70. </view>
  71. <view v-if="item.remark !=null">
  72. 使用说明:
  73. <text>{{ item.remark }}</text>
  74. </view>
  75. <text v-else class="remarkText">该优惠券暂无使用说明</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. export default {
  83. data() {
  84. return {
  85. countsList: [],
  86. showRemarkId: '',
  87. };
  88. },
  89. computed: {
  90. // 解析 unavailableWeeklyTimes,将 "3,4,5" 转换为 ["星期二", "星期三", "星期四"]
  91. parseWeeklyTimes() {
  92. return function(times) {
  93. if (!times) return '';
  94. const arr = times.split(',');
  95. const weekMap = {
  96. '1': '星期日',
  97. '2': '星期一',
  98. '3': '星期二',
  99. '4': '星期三',
  100. '5': '星期四',
  101. '6': '星期五',
  102. '7': '星期六'
  103. };
  104. return arr.map(item => weekMap[item]).join('、');
  105. };
  106. },
  107. // 解析 unavailableTimeRanges,将 JSON 字符串转换为可读格式
  108. parseTimeRanges() {
  109. return function(ranges) {
  110. if (!ranges) return '';
  111. try {
  112. const arr = JSON.parse(ranges);
  113. return arr.map(item => {
  114. const begin = item.beginTime?.split?.(' ')?.[0] || '';
  115. const end = item.endTime?.split?.(' ')?.[0] || '';
  116. return begin && end ? `${begin} - ${end}` : '';
  117. }).filter(Boolean).join(';');
  118. } catch (e) {
  119. return '';
  120. }
  121. };
  122. }
  123. },
  124. onLoad(option) {
  125. this.getUserDiscountsList()
  126. },
  127. methods: {
  128. showRemark(item) {
  129. if (this.showRemarkId == item.id) {
  130. this.showRemarkId = ''
  131. } else {
  132. this.showRemarkId = item.id
  133. }
  134. },
  135. // 领取优惠劵
  136. gotoReceiveCoupon(item) {
  137. this.$api.claimCoupon({id: item.id}).then((res) => {
  138. uni.showToast({
  139. title: "领取成功"
  140. })
  141. // 查询可领取的优惠劵
  142. this.getUserDiscountsList();
  143. })
  144. },
  145. // 查询可领取的优惠劵
  146. getUserDiscountsList() {
  147. let that = this;
  148. // 用户绑定门店
  149. this.$api.getUserDiscountsList().then((res) => {
  150. console.log(res.data.data)
  151. this.countsList = res.data.data;
  152. }).catch(() => {
  153. uni.showToast({
  154. title: "操作失败"
  155. })
  156. })
  157. },
  158. },
  159. };
  160. </script>
  161. <style lang="scss" scoped>
  162. @import '/common/css/common.css';
  163. @import './index.rpx.scss';
  164. </style>