couponSelect.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <view class="container">
  3. <scroll-view class="coupon-list" :scroll-y="true" :scroll-top="scrollTop">
  4. <view class="my-coupon-list">
  5. <view class="my-coupon-item" @tap="selectCoupon" :data-id="item.id" :data-cid="item.cid"
  6. v-for="(item, index) in couponList" :key="index" v-if="couponList.length>0">
  7. <view class="coupon-left">
  8. <view v-if="item.voucherType == 1" style="color: #d77958;">
  9. ¥
  10. <text class="coupon-amount">{{ item.discount }}</text>
  11. </view>
  12. <view v-if="item.voucherType == 2">
  13. <text class="coupon-amount">{{ item.discount / 10 }}</text>
  14. </view>
  15. <view class="coupon-type">
  16. <!-- {{item.name}} -->
  17. <span v-if="item.voucherType == 1">立减券</span>
  18. <span v-if="item.voucherType == 2">折扣券</span>
  19. </view>
  20. <view class="coupon-btn active-btn" :data-goodsvalue="item.goodsValue" @tap="goService">立即使用
  21. </view>
  22. </view>
  23. <view class="coupon-content">
  24. <view class="coupon-name">{{ item.name }}</view>
  25. <view class="coupon-date">有效期开始:{{ item.startTime }}</view>
  26. <view class="coupon-date">有效期结束:{{ item.endTime }}</view>
  27. </view>
  28. </view>
  29. <view class="no-list" v-if="couponList == 0">暂无优惠券</view>
  30. </view>
  31. </scroll-view>
  32. <view class="unselect" @tap="unselectCoupon">不选择优惠券</view>
  33. </view>
  34. </template>
  35. <script>
  36. var util = require('../../../utils/util.js');
  37. var api = require('../../../config/api.js');
  38. var app = getApp();
  39. export default {
  40. data() {
  41. return {
  42. couponList: [],
  43. cartId: 0,
  44. couponId: 0,
  45. userCouponId: 0,
  46. grouponLinkId: 0,
  47. scrollTop: 0,
  48. grouponRulesId: ''
  49. };
  50. }
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */
  54. ,
  55. onLoad: function(options) {},
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function() {},
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function() {
  64. // 页面显示
  65. uni.showLoading({
  66. title: '加载中...'
  67. });
  68. try {
  69. var cartId = uni.getStorageSync('cartId');
  70. if (!cartId) {
  71. cartId = 0;
  72. }
  73. var couponId = uni.getStorageSync('couponId');
  74. if (!couponId) {
  75. couponId = 0;
  76. }
  77. var userCouponId = uni.getStorageSync('userCouponId');
  78. if (!userCouponId) {
  79. userCouponId = 0;
  80. }
  81. var grouponRulesId = uni.getStorageSync('grouponRulesId');
  82. if (!grouponRulesId) {
  83. grouponRulesId = 0;
  84. }
  85. this.setData({
  86. cartId: cartId,
  87. couponId: couponId,
  88. userCouponId: userCouponId,
  89. grouponRulesId: grouponRulesId
  90. });
  91. } catch (e) {
  92. console.log('CatchClause', e);
  93. console.log('CatchClause', e);
  94. // Do something when catch error
  95. console.log(e);
  96. }
  97. this.getCouponList();
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function() {},
  103. /**
  104. * 生命周期函数--监听页面卸载
  105. */
  106. onUnload: function() {},
  107. /**
  108. * 页面相关事件处理函数--监听用户下拉动作
  109. */
  110. onPullDownRefresh: function() {},
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom() {},
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage: function() {},
  119. methods: {
  120. getCouponList: function() {
  121. let that = this;
  122. that.setData({
  123. couponList: []
  124. });
  125. // 页面渲染完成
  126. uni.showToast({
  127. title: '加载中...',
  128. icon: 'loading',
  129. duration: 2000
  130. });
  131. util.request(api.CouponSelectList, {
  132. cartId: that.cartId,
  133. grouponRulesId: that.grouponRulesId
  134. }).then(function(res) {
  135. if (res.errno === 0) {
  136. let list = [];
  137. for (var i = 0; i < res.data.list.length; i++) {
  138. if (res.data.list[i].available) {
  139. list.push(res.data.list[i]);
  140. }
  141. }
  142. that.setData({
  143. couponList: list
  144. });
  145. }
  146. uni.hideToast();
  147. });
  148. },
  149. selectCoupon: function(e) {
  150. try {
  151. uni.setStorageSync('couponId', e.currentTarget.dataset.cid);
  152. uni.setStorageSync('userCouponId', e.currentTarget.dataset.id);
  153. } catch (error) {
  154. console.log('CatchClause', error);
  155. console.log('CatchClause', error);
  156. }
  157. uni.navigateBack();
  158. },
  159. unselectCoupon: function() {
  160. // 如果优惠券ID设置-1,则表示订单不使用优惠券
  161. try {
  162. uni.setStorageSync('couponId', -1);
  163. uni.setStorageSync('userCouponId', -1);
  164. } catch (error) {
  165. console.log('CatchClause', error);
  166. console.log('CatchClause', error);
  167. }
  168. uni.navigateBack();
  169. },
  170. goService() {
  171. console.log('占位:函数 goService 未声明');
  172. }
  173. }
  174. };
  175. </script>
  176. <style>
  177. page {
  178. background: #f4f4f4;
  179. min-height: 100%;
  180. }
  181. .container {
  182. background: #f4f4f4;
  183. min-height: 100%;
  184. padding-top: 30rpx;
  185. height: 100vh;
  186. }
  187. .coupon-list {
  188. width: 750rpx;
  189. height: 100%;
  190. overflow: hidden;
  191. }
  192. .unselect {
  193. height: 82rpx;
  194. line-height: 82rpx;
  195. border: 2px solid #d77858;
  196. width: 704rpx;
  197. border-radius: 80rpx;
  198. color: #d77858;
  199. font-size: 30rpx;
  200. text-align: center;
  201. margin-bottom: 30rpx;
  202. margin-left: 30rpx;
  203. margin-right: 30rpx;
  204. position: absolute;
  205. bottom: 60rpx;
  206. }
  207. .item {
  208. position: relative;
  209. height: 290rpx;
  210. width: 700rpx;
  211. background: linear-gradient(to right, #cfa568, #e3bf79);
  212. margin-bottom: 30rpx;
  213. margin-left: 30rpx;
  214. margin-right: 30rpx;
  215. padding-top: 52rpx;
  216. }
  217. .tag {
  218. height: 32rpx;
  219. background: #a48143;
  220. padding-left: 16rpx;
  221. padding-right: 16rpx;
  222. position: absolute;
  223. left: 20rpx;
  224. color: #fff;
  225. top: 20rpx;
  226. font-size: 20rpx;
  227. text-align: center;
  228. line-height: 32rpx;
  229. }
  230. .content {
  231. margin-top: 24rpx;
  232. margin-left: 40rpx;
  233. display: flex;
  234. margin-right: 40rpx;
  235. flex-direction: row;
  236. }
  237. .content .left {
  238. flex: 1;
  239. }
  240. .discount {
  241. font-size: 50rpx;
  242. color: #b4282d;
  243. }
  244. .min {
  245. color: #fff;
  246. }
  247. .content .right {
  248. width: 400rpx;
  249. }
  250. .name {
  251. font-size: 44rpx;
  252. color: #fff;
  253. margin-bottom: 14rpx;
  254. }
  255. .time {
  256. font-size: 24rpx;
  257. color: #fff;
  258. line-height: 30rpx;
  259. }
  260. .condition {
  261. position: absolute;
  262. width: 100%;
  263. bottom: 0;
  264. left: 0;
  265. height: 78rpx;
  266. background: rgba(0, 0, 0, 0.08);
  267. padding: 24rpx 40rpx;
  268. display: flex;
  269. flex-direction: row;
  270. }
  271. .condition .txt {
  272. display: block;
  273. height: 30rpx;
  274. flex: 1;
  275. overflow: hidden;
  276. font-size: 24rpx;
  277. line-height: 30rpx;
  278. color: #fff;
  279. }
  280. .condition .icon {
  281. margin-left: 30rpx;
  282. width: 24rpx;
  283. height: 24rpx;
  284. }
  285. .container .no-list {
  286. margin: 36rpx 0 0;
  287. text-align: center;
  288. color: #999;
  289. font-size: 28rpx;
  290. }
  291. .my-coupon-list {
  292. padding: 20rpx 24rpx;
  293. width: 750rpx;
  294. height: 100%;
  295. overflow: hidden;
  296. }
  297. .my-coupon-item {
  298. border-radius: 18rpx;
  299. background: #fff;
  300. height: 190rpx;
  301. margin: 0 0 20rpx;
  302. display: flex;
  303. justify-content: space-between;
  304. padding: 0 20rpx 0 0;
  305. width: 706rpx;
  306. }
  307. .coupon-left {
  308. background: #FEEBD7;
  309. width: 230rpx;
  310. display: flex;
  311. flex-direction: column;
  312. align-items: center;
  313. justify-content: space-between;
  314. height: 190rpx;
  315. padding: 18rpx 0 30rpx;
  316. }
  317. .coupon-left .coupon-amount {
  318. font-size: 48rpx;
  319. font-weight: bold;
  320. color: #D77958;
  321. }
  322. .coupon-left .coupon-type {
  323. font-size: 24rpx;
  324. font-weight: bold;
  325. white-space: nowrap;
  326. overflow: hidden;
  327. text-overflow: ellipsis;
  328. width: 220rpx;
  329. text-align: center;
  330. color: #D77958;
  331. }
  332. .coupon-left .coupon-btn {
  333. background: #D77958;
  334. color: #fff;
  335. width: 120rpx;
  336. height: 32rpx;
  337. line-height: 32rpx;
  338. font-size: 22rpx;
  339. margin-top: 10rpx;
  340. border-radius: 30rpx;
  341. text-align: center;
  342. }
  343. .coupon-left .coupon-btn.active-btn {
  344. background: #D77958;
  345. }
  346. .coupon-content {
  347. margin: 0 20rpx 0 30rpx;
  348. display: flex;
  349. flex-direction: column;
  350. justify-content: space-between;
  351. padding: 40rpx 0;
  352. flex: 1;
  353. }
  354. .coupon-content view.coupon-name {
  355. color: #333;
  356. font-size: 30rpx;
  357. font-weight: bold;
  358. white-space: nowrap;
  359. overflow: hidden;
  360. text-overflow: ellipsis;
  361. width: 400rpx;
  362. }
  363. .coupon-content view.coupon-date {
  364. color: #999;
  365. font-size: 20rpx;
  366. }
  367. .coupon-right {
  368. width: 84rpx;
  369. height: 114rpx;
  370. padding-top: 30rpx;
  371. }
  372. .coupon-status {
  373. width: 84rpx;
  374. height: 84rpx;
  375. }
  376. </style>