coupon.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <view class="coupon-page">
  3. <view class="list-container">
  4. <view v-for="(item, index) in couponList" :key="index"
  5. :class="['coupon-box']">
  6. <view class="coupon-card">
  7. <view v-if="query.title == 'select'" :class="{ 'radio-selected': item.selected, 'radio-select': !item.selected }" @click="handleSelect(item, index)">
  8. <image v-show="item.selected" src="../../static/other/selected.png"></image>
  9. </view>
  10. <view class="left-content">
  11. <view class="coupon-title">
  12. <view>{{ item.couponName }}</view>
  13. <!-- <view v-if="item.discountType == 3">满{{ item.thresholdAmount }}减{{ item.discountValue }}</view>
  14. <view v-else>满{{ item.thresholdAmount }}可用</view> -->
  15. </view>
  16. <view class="coupon-time">
  17. <view v-if="item.validityType == 2">领券{{item.validDays }}天后失效</view>
  18. <view v-else-if="item.validityType == 3">长期有效</view>
  19. <view v-else>有效期至{{ item.expirationTimeString }}</view>
  20. </view>
  21. <view class="coupon-msg">
  22. <view v-if="item.couponType== '1'">满减券*1</view>
  23. <view v-if="item.couponType== '2'">折扣券*1</view>
  24. <view v-if="item.couponType== '3'">兑换券*1</view>
  25. <view class="icon-circle" @click="item.showMsg = !item.showMsg">
  26. 详细信息
  27. <view :class="{ 'circle': item.showMsg, 'default': !item.showMsg }"></view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="right-action">
  32. <view class="amount-box" v-if="item.couponType == '1'">
  33. <text class="unit">¥</text>
  34. <text class="val">{{ item.discountValue }}</text>
  35. </view>
  36. <view class="amount-box" v-else-if="item.couponType == '2'">
  37. <text class="val">{{ item.ruleDiscountRate }}</text>
  38. <text class="unit">折</text>
  39. </view>
  40. <view class="amount-box" v-else>
  41. <text class="val">兑换</text>
  42. </view>
  43. <view class="action-btn active" @click.stop="goIdentify(item)">去使用</view>
  44. </view>
  45. </view>
  46. <view class="coupon-message" v-show="item.showMsg">
  47. <view class="message-item">
  48. <view>券类型:{{ item.couponType== '1'?'兑换券':item.couponType== '2'?'折扣券':item.couponType== '3'?'满减券':'' }}</view>
  49. <view v-if="item.locality">限定地区:仅{{ item.locality }}地区使用</view>
  50. <view v-if="item.relatedName">限定项目:{{ item.relatedName }}</view>
  51. <view>限定手机:仅限登录手机号为{{ getPhone() }}使用</view>
  52. </view>
  53. </view>
  54. </view>
  55. <u-empty v-if="couponList.length === 0" mode="coupon" marginTop="100"></u-empty>
  56. </view>
  57. <view v-if="couponList.length != 0" class="usedRecord" @click="toRecord">使用记录<u-icon name="arrow-right" size="28rpx" top="1" color="#333"></u-icon></view>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. getCoupon
  63. } from '@/api/index';
  64. export default {
  65. data() {
  66. return {
  67. query: {},
  68. couponList: [],
  69. }
  70. },
  71. onLoad(query) {
  72. this.query = query;
  73. getApp().globalData.couponSelected = {}
  74. },
  75. onShow() {
  76. this.getData();
  77. },
  78. methods: {
  79. getPhone() {
  80. const phone = uni.getStorageSync('phone')
  81. const phoneStr = `${phone.slice(0,3)}****${phone.slice(7,11)}`
  82. return phoneStr
  83. },
  84. getData() {
  85. let params = {
  86. receiveOpenId: uni.getStorageSync('wx_copenid')
  87. }
  88. getCoupon(params).then(res => {
  89. if (res.data.code == 200) {
  90. if(res.data.data && res.data.data.length > 0) {
  91. this.couponList = res.data.data.map(item => {
  92. return {
  93. ...item,
  94. selected: false,
  95. showMsg: false
  96. }
  97. })
  98. }
  99. }
  100. });
  101. },
  102. goIdentify(item) {
  103. if (this.query.title == 'select') {
  104. uni.setStorageSync('couponData', item);
  105. uni.navigateBack();
  106. // uni.navigateTo({
  107. // url: `/pages/identify/pay_order?couponId=${item.id}&couponMoney=${item.discountValue}`
  108. // })
  109. // uni.$emit('returnData', item)
  110. } else {
  111. uni.switchTab({
  112. url: '/pages/identify/identify'
  113. })
  114. }
  115. },
  116. handleSelect(item, index) {
  117. this.couponList[index].selected = !this.couponList[index].selected
  118. this.couponList.map((sub, ind) => {
  119. if(sub.id != item.id) {
  120. sub.selected = false
  121. }
  122. })
  123. const selectObj = this.couponList.filter(a => a.selected)
  124. if(selectObj) {
  125. uni.navigateBack(-1)
  126. getApp().globalData.couponSelected = selectObj
  127. }
  128. },
  129. toRecord() {
  130. uni.navigateTo({
  131. url: '/pages/my/record',
  132. })
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .coupon-page {
  139. min-height: 100vh;
  140. background: linear-gradient(to bottom, #d7f3f9, #f3f3f3);
  141. .list-container {
  142. padding: 20rpx 24rpx;
  143. height: calc(100vh - 4vh);
  144. .coupon-box{
  145. margin-bottom: 24rpx;
  146. position: relative;
  147. border-radius: 16rpx;
  148. background-color: #fff;
  149. }
  150. .coupon-card {
  151. display: flex;
  152. align-items: center;
  153. flex-wrap: wrap;
  154. overflow: hidden;
  155. transition: opacity 0.3s;
  156. .radio-select{
  157. width: 36rpx;
  158. height: 36rpx;
  159. border-radius: 50%;
  160. margin-left: 20rpx;
  161. border: 2rpx solid #869198;
  162. }
  163. .radio-selected{
  164. width: 36rpx;
  165. height: 36rpx;
  166. border-radius: 50%;
  167. margin-left: 20rpx;
  168. image{
  169. display: block;
  170. width: 36rpx;
  171. height: 36rpx;
  172. border-radius: 50%;
  173. }
  174. }
  175. .left-content {
  176. flex: 1;
  177. padding: 30rpx;
  178. border-right: 2rpx dashed #eee;
  179. .coupon-title {
  180. font-size: 30rpx;
  181. font-weight: bold;
  182. color: #333;
  183. margin-bottom: 10rpx;
  184. }
  185. .coupon-time {
  186. font-size: 22rpx;
  187. color: #999;
  188. margin-bottom: 20rpx;
  189. }
  190. .coupon-msg{
  191. color: #333;
  192. display: flex;
  193. align-items: center;
  194. justify-content: space-between;
  195. font-size: 24rpx;
  196. .icon-circle{
  197. color: #999;
  198. display: flex;
  199. align-items: center;
  200. justify-content: space-between;
  201. .circle{
  202. width: 0;
  203. height: 0;
  204. border-left: 10rpx solid transparent;
  205. border-right: 10rpx solid transparent;
  206. border-bottom: 16rpx solid #999;
  207. transform: rotate(180deg);
  208. }
  209. .default{
  210. width: 0;
  211. height: 0;
  212. border-left: 10rpx solid transparent;
  213. border-right: 10rpx solid transparent;
  214. border-bottom: 16rpx solid #999;
  215. }
  216. }
  217. }
  218. }
  219. .right-action {
  220. width: 220rpx;
  221. padding: 28rpx;
  222. display: flex;
  223. align-items: center;
  224. flex-direction: column;
  225. justify-content: center;
  226. background-color: #E8FBFA;
  227. border-radius: 0 16rpx 16rpx 0;
  228. .amount-box {
  229. color: #03C8BE;
  230. margin-bottom: 16rpx;
  231. .unit {
  232. font-size: 24rpx;
  233. margin-right: 4rpx;
  234. }
  235. .val {
  236. font-size: 50rpx;
  237. font-weight: bold;
  238. }
  239. }
  240. .action-btn {
  241. width: 140rpx;
  242. height: 54rpx;
  243. border-radius: 40rpx;
  244. font-size: 24rpx;
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. &.active {
  249. background-color: #03C8BE;
  250. color: #fff;
  251. }
  252. &.disabled {
  253. background-color: transparent;
  254. border: 2rpx solid #03C8BE;
  255. color: #03C8BE;
  256. }
  257. }
  258. }
  259. }
  260. .coupon-message{
  261. border-top: 1rpx solid #EEEEEE;
  262. padding: 30rpx;
  263. color: #999;
  264. font-size: 24rpx;
  265. }
  266. }
  267. .usedRecord{
  268. height: 4vh;
  269. text-align: center;
  270. color: #333;
  271. display: flex;
  272. align-items: center;
  273. justify-content: center;
  274. font-size: 28rpx;
  275. }
  276. }
  277. </style>