couponSelect.vue 10 KB

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