coupon.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="container">
  3. <scroll-view class="coupon-list" :scroll-y="true" :scroll-top="scrollTop">
  4. <view class="item" @tap="getCoupon" :data-index="item.id" v-for="(item, index) in couponList" :key="index">
  5. <view class="tag">{{ item.tag }}</view>
  6. <view class="content">
  7. <view class="left">
  8. <view class="discount">{{ item.discount }}元</view>
  9. <view class="min">满{{ item.min }}元使用</view>
  10. </view>
  11. <view class="right">
  12. <view class="name">{{ item.name }}</view>
  13. <view class="time" v-if="item.days != 0">有效期:{{ item.days }}天</view>
  14. <view class="time" v-else>有效期:{{ item.startTime }} - {{ item.endTime }}</view>
  15. </view>
  16. </view>
  17. <view class="condition">
  18. <text class="txt">{{ item.desc }}</text>
  19. <image :src="item.pic" class="icon"></image>
  20. </view>
  21. </view>
  22. <view class="page" v-if="showPage">
  23. <view :class="'prev ' + (page <= 1 ? 'disabled' : '')" @tap="prevPage">上一页</view>
  24. <view :class="'next ' + (count / limit < page ? 'disabled' : '')" @tap="nextPage">下一页</view>
  25. </view>
  26. </scroll-view>
  27. </view>
  28. </template>
  29. <script>
  30. var util = require('../../../utils/util.js');
  31. var api = require('../../../config/api.js');
  32. var app = getApp();
  33. export default {
  34. data() {
  35. return {
  36. couponList: [],
  37. page: 1,
  38. limit: 10,
  39. count: 0,
  40. scrollTop: 0,
  41. showPage: false
  42. };
  43. }
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */,
  47. onLoad: function (options) {
  48. this.getCouponList();
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {},
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow: function () {},
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {},
  62. /**
  63. * 生命周期函数--监听页面卸载
  64. */
  65. onUnload: function () {},
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh: function () {},
  70. /**
  71. * 页面上拉触底事件的处理函数
  72. */
  73. onReachBottom: function () {},
  74. /**
  75. * 用户点击右上角分享
  76. */
  77. onShareAppMessage: function () {},
  78. methods: {
  79. getCouponList: function () {
  80. let that = this;
  81. that.setData({
  82. scrollTop: 0,
  83. showPage: false,
  84. couponList: []
  85. });
  86. // 页面渲染完成
  87. uni.showLoading({
  88. title: '加载中'
  89. });
  90. util.request(api.CouponList, {
  91. page: that.page,
  92. limit: that.limit
  93. }).then(function (res) {
  94. if (res.errno === 0) {
  95. that.setData({
  96. scrollTop: 0,
  97. couponList: res.data.list,
  98. showPage: true,
  99. count: res.data.total
  100. });
  101. }
  102. uni.hideLoading();
  103. });
  104. },
  105. getCoupon(e) {
  106. if (!app.globalData.hasLogin) {
  107. uni.navigateTo({
  108. url: '/pages/auth/login/login'
  109. });
  110. }
  111. let couponId = e.currentTarget.dataset.index;
  112. util.request(
  113. api.CouponReceive,
  114. {
  115. couponId: couponId
  116. },
  117. 'POST'
  118. ).then((res) => {
  119. if (res.errno === 0) {
  120. uni.showToast({
  121. title: '领取成功'
  122. });
  123. } else {
  124. util.showErrorToast(res.errmsg);
  125. }
  126. });
  127. },
  128. nextPage: function (event) {
  129. var that = this;
  130. if (this.page > that.count / that.limit) {
  131. return true;
  132. }
  133. that.setData({
  134. page: that.page + 1
  135. });
  136. this.getCouponList();
  137. },
  138. prevPage: function (event) {
  139. if (this.page <= 1) {
  140. return false;
  141. }
  142. var that = this;
  143. that.setData({
  144. page: that.page - 1
  145. });
  146. this.getCouponList();
  147. }
  148. }
  149. };
  150. </script>
  151. <style>
  152. page {
  153. background: #f4f4f4;
  154. min-height: 100%;
  155. }
  156. .container {
  157. background: #f4f4f4;
  158. min-height: 100%;
  159. padding-top: 30rpx;
  160. }
  161. .coupon-list {
  162. width: 750rpx;
  163. height: 100%;
  164. overflow: hidden;
  165. }
  166. .item {
  167. position: relative;
  168. height: 290rpx;
  169. width: 700rpx;
  170. background: linear-gradient(to right, #cfa568, #e3bf79);
  171. margin-bottom: 30rpx;
  172. margin-left: 30rpx;
  173. margin-right: 30rpx;
  174. padding-top: 52rpx;
  175. }
  176. .tag {
  177. height: 32rpx;
  178. background: #a48143;
  179. padding-left: 16rpx;
  180. padding-right: 16rpx;
  181. position: absolute;
  182. left: 20rpx;
  183. color: #fff;
  184. top: 20rpx;
  185. font-size: 20rpx;
  186. text-align: center;
  187. line-height: 32rpx;
  188. }
  189. .content {
  190. margin-top: 24rpx;
  191. margin-left: 40rpx;
  192. display: flex;
  193. margin-right: 40rpx;
  194. flex-direction: row;
  195. }
  196. .content .left {
  197. flex: 1;
  198. }
  199. .discount {
  200. font-size: 50rpx;
  201. color: #b4282d;
  202. }
  203. .min {
  204. color: #fff;
  205. }
  206. .content .right {
  207. width: 400rpx;
  208. }
  209. .name {
  210. font-size: 44rpx;
  211. color: #fff;
  212. margin-bottom: 14rpx;
  213. }
  214. .time {
  215. font-size: 24rpx;
  216. color: #fff;
  217. line-height: 30rpx;
  218. }
  219. .condition {
  220. position: absolute;
  221. width: 100%;
  222. bottom: 0;
  223. left: 0;
  224. height: 78rpx;
  225. background: rgba(0, 0, 0, 0.08);
  226. padding: 24rpx 40rpx;
  227. display: flex;
  228. flex-direction: row;
  229. }
  230. .condition .txt {
  231. display: block;
  232. height: 30rpx;
  233. flex: 1;
  234. overflow: hidden;
  235. font-size: 24rpx;
  236. line-height: 30rpx;
  237. color: #fff;
  238. }
  239. .condition .icon {
  240. margin-left: 30rpx;
  241. width: 24rpx;
  242. height: 24rpx;
  243. }
  244. .page {
  245. width: 750rpx;
  246. height: 108rpx;
  247. background: #fff;
  248. margin-bottom: 20rpx;
  249. }
  250. .page view {
  251. height: 108rpx;
  252. width: 50%;
  253. float: left;
  254. font-size: 29rpx;
  255. color: #333;
  256. text-align: center;
  257. line-height: 108rpx;
  258. }
  259. .page .prev {
  260. border-right: 1px solid #d9d9d9;
  261. }
  262. .page .disabled {
  263. color: #ccc;
  264. }
  265. </style>