index.vue 8.2 KB

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