index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view>
  3. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="选择优惠券"></u-navbar>
  4. <view class="coupon-title">可用优惠券:{{ total }}</view>
  5. <view class="coupon-list">
  6. <u-radio-group v-model="radiovalue1" placement="column" @change="changeChechk()">
  7. <view class="flex coupon-list-item" v-for="(item,index) in list" :key="index" :style="{backgroundImage:`url(${ index == isActive ? backOn : backOff })`}">
  8. <view class="flex coupon-list-item-info">
  9. <view class="money">
  10. <!-- <view class="">¥<text>{{ item.discount / 100 }}</text></view> -->
  11. <view class="price flex">
  12. <text>{{ item.discount / 100 }}</text>
  13. <text>元</text>
  14. </view>
  15. </view>
  16. <view class="flex content">
  17. <view class=" title ells-one">{{ item.title }}</view>
  18. <view class="txt ells-one top">适用范围:{{ item.useAreaDesc || '-' }}</view>
  19. <view class="txt">
  20. 使用期限:{{ $parseTime(item.validStart, '{y}.{m}.{d}')}}-{{$parseTime(item.validEnd, '{y}.{m}.{d}')}}
  21. </view>
  22. </view>
  23. </view>
  24. <view class="uradio">
  25. <u-radio :customStyle="{ marginBottom: '8px' }" :name="item.id" activeColor="#E96737" size="24" @change="exclusive(index)">
  26. </u-radio>
  27. </view>
  28. </view>
  29. </u-radio-group>
  30. </view>
  31. <view class="flex empty" v-if="!list.length">
  32. <view class="center">
  33. <image class="center-img" src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/nodata_1.png" mode=""></image>
  34. <view class="center-font">暂无优惠券</view>
  35. </view>
  36. <!-- <u-empty text="数据为空" mode="order" /> -->
  37. </view>
  38. <view class="footer-fixed">
  39. <view class="flex btn">
  40. <button type="default" @click="exchange">确认</button>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import env from '../../config/env.js'
  47. import $http from '@/utils/request.js'
  48. export default {
  49. data() {
  50. return {
  51. checked: false,
  52. actionIndex: 0,
  53. pageNum: 1,
  54. total: 0,
  55. list: [],
  56. listNum: '', //可用优惠券数量
  57. radiovalue1: '', //选中项的下标
  58. couponId: '', //选中项的id
  59. boxId: '',
  60. ticketId: '',
  61. isActive: undefined,
  62. backOn: "https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/coupon_bkg2.png",
  63. backOff: "https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/coupon_bkg1.png",
  64. };
  65. },
  66. onShow() {
  67. this.pageList()
  68. this.exclusive()
  69. },
  70. onLoad(opthios) {
  71. this.boxId = opthios.boxId
  72. if (opthios.ticketId) {
  73. this.ticketId = opthios.ticketId
  74. }
  75. if (opthios.couponId) {
  76. this.couponId = opthios.couponId
  77. this.radiovalue1 = opthios.couponId
  78. }
  79. },
  80. methods: {
  81. pageList() {
  82. this.list = []
  83. this.getList()
  84. },
  85. getList() {
  86. let _this = this
  87. uni.showLoading({
  88. title: '加载中'
  89. });
  90. $http.post(`/api/v1/mp/user/ticket/order/coupon/listPage?pageNum=${_this.pageNum}&pageSize=20`, {}).then(
  91. res => {
  92. uni.hideLoading();
  93. if (res.code == 0) {
  94. this.listNum = res.rows.length
  95. res.rows.forEach(item => {
  96. let useAreaDesc = JSON.parse(item.useArea)
  97. item.useAreaDesc = useAreaDesc.desc
  98. })
  99. _this.list = [..._this.list, ...res.rows]
  100. _this.total = res.total
  101. for (var i = 0; i < _this.list.length; i++) {
  102. if(_this.list[i].id == _this.couponId){
  103. _this.isActive = i
  104. }
  105. }
  106. }
  107. }).catch(() => {
  108. uni.hideLoading();
  109. })
  110. },
  111. exclusive(index) {
  112. this.isActive = index
  113. },
  114. // 点击切换事件
  115. changeChechk(e) {
  116. if (this.couponId == e) {
  117. this.radiovalue1 = -1
  118. this.isActive = -1
  119. this.couponId = []
  120. return
  121. } else {
  122. this.couponId = [e]
  123. return
  124. }
  125. },
  126. // 点击确认事件
  127. exchange() {
  128. let data = {
  129. userCouponIds: this.couponId,
  130. autoCoupon: 0,
  131. boxId: this.boxId,
  132. ticketId: this.ticketId,
  133. orderNum: 1
  134. }
  135. $http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
  136. if (res.code == 0) {
  137. let pages = getCurrentPages()
  138. let page = pages[pages.length - 2]
  139. let payInfo = {
  140. ...res.data,
  141. picUrl: env.filePublic + res.data.picUrl.split(',')[0],
  142. couponDiscount: res.data && res.data.couponList && res.data.couponList.length &&
  143. res
  144. .data.couponList[0].discount,
  145. couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
  146. .couponList[0].id,
  147. listNum: this.listNum
  148. }
  149. page.$vm.payInfo = payInfo
  150. uni.navigateBack({
  151. delta: 1
  152. })
  153. }
  154. })
  155. }
  156. },
  157. onReachBottom() {
  158. // 判断是否有数据
  159. if (this.total > this.pageNum * 20) {
  160. setTimeout(() => {
  161. ++this.pageNum
  162. this.getList()
  163. }, 500)
  164. } else {
  165. uni.$u.toast('已经到底了')
  166. }
  167. },
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. .coupon {
  172. &-title {
  173. position: fixed;
  174. z-index: 10;
  175. width: 100%;
  176. padding: 24rpx 32rpx;
  177. background-color: #FFFFFF;
  178. }
  179. &-list {
  180. margin-top: 100rpx;
  181. padding: 0 20rpx 100rpx;
  182. &-item {
  183. justify-content: space-between;
  184. padding: 20rpx;
  185. // background-color: #FFFFFF;
  186. margin-bottom: 20rpx;
  187. background-size: 100%;
  188. &-info {
  189. flex: 1;
  190. justify-content: flex-start;
  191. height: 175rpx;
  192. image {
  193. width: 84rpx;
  194. height: 132rpx;
  195. margin-right: 20rpx;
  196. }
  197. .content {
  198. width: 445rpx;
  199. height: 150rpx;
  200. flex-direction: column;
  201. align-items: flex-start;
  202. justify-content: space-between;
  203. .txt {
  204. font-size: 24rpx;
  205. line-height: 24rpx;
  206. color: #999999;
  207. }
  208. }
  209. .content .title {
  210. font-size: 36rpx;
  211. color: #333;
  212. line-height: 40rpx;
  213. // font-weight: bold;
  214. }
  215. .money {
  216. width: 220rpx;
  217. height: 100%;
  218. margin:0 10rpx 0;
  219. .price {
  220. position: absolute;
  221. color: #fff;
  222. z-index: 0;
  223. text:first-child {
  224. line-height: 150rpx;
  225. font-size: 70rpx;
  226. padding-right: 20rpx;
  227. }
  228. text:last-child {
  229. font-size: 40rpx;
  230. }
  231. }
  232. }
  233. }
  234. .uradio {
  235. position: absolute;right: 40rpx;
  236. }
  237. .circle {
  238. width: 40rpx;
  239. height: 40rpx;
  240. border-radius: 50%;
  241. border: 1px solid;
  242. }
  243. .action {
  244. width: 30rpx;
  245. height: 30rpx;
  246. border-radius: 50%;
  247. background-color: $uni-bg-color;
  248. }
  249. }
  250. }
  251. }
  252. .empty {
  253. height: 60vh;
  254. .center {
  255. text-align: center;
  256. &-img {
  257. width: 228rpx;
  258. height: 320rpx;
  259. }
  260. &-font {
  261. font-size: 30rpx;
  262. font-weight: 400;
  263. color: #999999;
  264. margin-bottom: 250rpx;
  265. }
  266. }
  267. }
  268. .footer-fixed {
  269. position: fixed;
  270. bottom: var(--window-bottom);
  271. left: 0;
  272. right: 0;
  273. z-index: 11;
  274. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  275. background: #fff;
  276. // 设置ios刘海屏底部横线安全区域
  277. padding-bottom: constant(safe-area-inset-bottom);
  278. padding-bottom: env(safe-area-inset-bottom);
  279. .btn {
  280. padding: 20rpx 0;
  281. /deep/ button {
  282. width: 441rpx;
  283. height: 88rpx;
  284. line-height: 88rpx;
  285. font-size: 36rpx;
  286. color: #fff;
  287. background-color: #F9822C;
  288. border: none;
  289. border-radius: 44rpx;
  290. }
  291. }
  292. }
  293. </style>