小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 lines
7.6 KiB

  1. <template>
  2. <view ref="container">
  3. <image :src="`${$VUE_APP_RESOURCES_URL}/images/banner_coupon.png`" mode="widthFix" class="tui-coupon-banner"></image>
  4. <view class="tui-coupon-list">
  5. <view class="tui-coupon-item tui-top20" v-for="(item, index) in couponsList" :key="index">
  6. <image :src="`${$VUE_APP_RESOURCES_URL}/images/bg_coupon_3x.png`" class="tui-coupon-bg" mode="widthFix"></image>
  7. <view class="tui-coupon-item-left">
  8. <view class="tui-coupon-price-box" :class="{ 'tui-color-grey': item.isUse }">
  9. <view class="tui-coupon-price-sign"></view>
  10. <view class="tui-coupon-price" :class="{ 'tui-price-small': false }">{{ item.couponPrice }}</view>
  11. </view>
  12. <view class="tui-coupon-intro">{{ item.useMinPrice }}元可用</view>
  13. </view>
  14. <view class="tui-coupon-item-right">
  15. <view class="tui-coupon-content">
  16. <view class="tui-coupon-title-box">
  17. <view class="tui-coupon-btn" v-if="item.ctype === 0" :class="{ 'tui-bg-grey': item.isUse }">通用劵</view>
  18. <view class="tui-coupon-btn" v-else-if="item.ctype === 1" :class="{ 'tui-bg-grey': item.isUse }">商品券</view>
  19. <view class="tui-coupon-btn" v-else :class="{ 'tui-bg-grey': item.isUse }">未知</view>
  20. <view class="tui-coupon-title">{{ item.cname }}</view>
  21. </view>
  22. <view class="tui-coupon-rule">
  23. <view class="tui-rule-box tui-padding-btm">
  24. <view class="tui-coupon-circle"></view>
  25. <view class="tui-coupon-text">不可叠加使用</view>
  26. </view>
  27. <view class="tui-rule-box">
  28. <view class="tui-coupon-circle"></view>
  29. <view class="tui-coupon-text" v-if="item.endTime !== 0">{{ item.endTime }} 到期</view>
  30. <!-- <view class="tui-coupon-text" v-if="item.endTime !== 0">{{ item.startTime }} - {{ item.endTime }}</view> -->
  31. <view class="tui-coupon-text" v-else>不限时</view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="tui-btn-box">
  37. <tui-button type="danger" width="152rpx" height="52rpx" :size="24" shape="circle" :plain="true" v-if="item.isUse === true">已领取</tui-button>
  38. <tui-button type="danger" width="152rpx" height="52rpx" :size="24" shape="circle" :plain="true" v-else-if="item.isUse === 2">已领完</tui-button>
  39. <tui-button type="danger" width="152rpx" height="52rpx" :size="24" shape="circle" v-else @click="getCoupon(item.id, index)">立即领取</tui-button>
  40. </view>
  41. </view>
  42. </view>
  43. <Loading :loaded="loadend" :loading="loading"></Loading>
  44. <!--暂无优惠券-->
  45. <view class="noCommodity" v-if="couponsList.length === 0 && page > 1">
  46. <view class="noPictrue">
  47. <image :src="`${$VUE_APP_RESOURCES_URL}/images/noCoupon.png`" class="image" />
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import { getCoupon, getCouponReceive } from '@/api/user'
  54. import Loading from '@/components/Loading'
  55. import DataFormatT from '@/components/DataFormatT'
  56. export default {
  57. name: 'getCoupon',
  58. components: {
  59. Loading,
  60. DataFormatT,
  61. },
  62. props: {},
  63. data: function() {
  64. return {
  65. page: 1,
  66. limit: 10,
  67. couponsList: [],
  68. loading: false,
  69. loadend: false,
  70. }
  71. },
  72. mounted: function() {
  73. this.getUseCoupons()
  74. },
  75. onReachBottom() {
  76. !this.loading && this.getUseCoupons()
  77. },
  78. methods: {
  79. getCoupon: function(id, index) {
  80. let that = this
  81. let list = that.couponsList
  82. getCouponReceive(id)
  83. .then(function(res) {
  84. list[index].isUse = true
  85. uni.showToast({
  86. title: '领取成功',
  87. icon: 'success',
  88. duration: 2000,
  89. })
  90. })
  91. .catch(function(err) {
  92. uni.showToast({
  93. title: err.msg || err.response.data.msg || err.response.data.message,
  94. icon: 'none',
  95. duration: 2000,
  96. })
  97. })
  98. },
  99. getUseCoupons() {
  100. if (this.loading) return //阻止下次请求(false可以进行请求);
  101. if (this.loadend) return //阻止结束当前请求(false可以进行请求);
  102. this.loading = true
  103. let q = { page: this.page, limit: this.limit }
  104. getCoupon(q).then(res => {
  105. this.loading = false
  106. //apply();js将一个数组插入另一个数组;
  107. this.couponsList.push.apply(this.couponsList, res.data)
  108. this.loadend = res.data.length < this.limit //判断所有数据是否加载完成;
  109. this.page = this.page + 1
  110. })
  111. },
  112. },
  113. }
  114. </script>
  115. <style lang="less" scoped>
  116. page {
  117. background-color: #f5f5f5;
  118. }
  119. .container {
  120. padding-bottom: env(safe-area-inset-bottom);
  121. }
  122. .tui-coupon-list {
  123. width: 100%;
  124. padding: 0 25rpx;
  125. box-sizing: border-box;
  126. }
  127. .tui-coupon-banner {
  128. width: 100%;
  129. }
  130. .tui-coupon-item {
  131. width: 100%;
  132. height: 210rpx;
  133. position: relative;
  134. display: flex;
  135. align-items: center;
  136. padding-right: 30rpx;
  137. box-sizing: border-box;
  138. overflow: hidden;
  139. }
  140. .tui-coupon-bg {
  141. width: 100%;
  142. height: 210rpx;
  143. position: absolute;
  144. left: 0;
  145. top: 0;
  146. z-index: 1;
  147. }
  148. .tui-coupon-sign {
  149. height: 110rpx;
  150. width: 110rpx;
  151. position: absolute;
  152. z-index: 9;
  153. top: -30rpx;
  154. right: 40rpx;
  155. }
  156. .tui-coupon-item-left {
  157. width: 218rpx;
  158. height: 210rpx;
  159. position: relative;
  160. z-index: 2;
  161. display: flex;
  162. align-items: center;
  163. justify-content: center;
  164. flex-direction: column;
  165. flex-shrink: 0;
  166. }
  167. .tui-coupon-price-box {
  168. display: flex;
  169. color: #e41f19;
  170. align-items: flex-end;
  171. }
  172. .tui-coupon-price-sign {
  173. font-size: 30rpx;
  174. }
  175. .tui-coupon-price {
  176. font-size: 70rpx;
  177. line-height: 68rpx;
  178. font-weight: bold;
  179. }
  180. .tui-price-small {
  181. font-size: 58rpx !important;
  182. line-height: 56rpx !important;
  183. }
  184. .tui-coupon-intro {
  185. background: #f7f7f7;
  186. padding: 8rpx 10rpx;
  187. font-size: 26rpx;
  188. line-height: 26rpx;
  189. font-weight: 400;
  190. color: #666;
  191. margin-top: 18rpx;
  192. }
  193. .tui-coupon-item-right {
  194. flex: 1;
  195. height: 210rpx;
  196. position: relative;
  197. z-index: 2;
  198. display: flex;
  199. align-items: center;
  200. justify-content: space-between;
  201. padding-left: 24rpx;
  202. box-sizing: border-box;
  203. overflow: hidden;
  204. }
  205. .tui-coupon-content {
  206. width: 82%;
  207. display: flex;
  208. flex-direction: column;
  209. justify-content: center;
  210. }
  211. .tui-coupon-title-box {
  212. display: flex;
  213. align-items: center;
  214. }
  215. .tui-coupon-btn {
  216. padding: 6rpx;
  217. background: #ffebeb;
  218. color: #e41f19;
  219. font-size: 25rpx;
  220. line-height: 25rpx;
  221. display: flex;
  222. align-items: center;
  223. justify-content: center;
  224. transform: scale(0.9);
  225. transform-origin: 0 center;
  226. border-radius: 4rpx;
  227. flex-shrink: 0;
  228. }
  229. .tui-color-grey {
  230. color: #888 !important;
  231. }
  232. .tui-bg-grey {
  233. background: #f0f0f0 !important;
  234. color: #888 !important;
  235. }
  236. .tui-coupon-title {
  237. width: 100%;
  238. font-size: 26rpx;
  239. color: #333;
  240. white-space: nowrap;
  241. overflow: hidden;
  242. text-overflow: ellipsis;
  243. }
  244. .tui-coupon-rule {
  245. padding-top: 52rpx;
  246. }
  247. .tui-rule-box {
  248. display: flex;
  249. align-items: center;
  250. transform: scale(0.8);
  251. transform-origin: 0 100%;
  252. }
  253. .tui-padding-btm {
  254. padding-bottom: 6rpx;
  255. }
  256. .tui-coupon-circle {
  257. width: 8rpx;
  258. height: 8rpx;
  259. background: rgb(160, 160, 160);
  260. border-radius: 50%;
  261. }
  262. .tui-coupon-text {
  263. font-size: 28rpx;
  264. line-height: 28rpx;
  265. font-weight: 400;
  266. color: #666;
  267. padding-left: 8rpx;
  268. white-space: nowrap;
  269. }
  270. .tui-top20 {
  271. margin-top: 20rpx;
  272. }
  273. .tui-coupon-title {
  274. font-size: 28rpx;
  275. line-height: 28rpx;
  276. }
  277. .tui-coupon-radio {
  278. transform: scale(0.7);
  279. transform-origin: 100% center;
  280. }
  281. .tui-btn-box {
  282. position: absolute;
  283. width: 146rpx;
  284. height: 52rpx;
  285. right: 20rpx;
  286. bottom: 40rpx;
  287. z-index: 10;
  288. }
  289. </style>