couponList.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <view class="main">
  3. <view class="body-Discount margin-top-sm">
  4. <view class="collar">
  5. <!-- <view class="title-Discount">
  6. 领券
  7. </view> -->
  8. <view class="couponList">
  9. <view class="couponItem" v-for="(item,index) in list" :key="index">
  10. <view class="couponItem-subject">
  11. <view class="couponItem-subject-left">
  12. <view class="couponItem-subject-price">
  13. <text class="couponItem-subject-icon">{{item.type==1?'¥':''}}</text>
  14. <text class="couponItem-subject-price-min">{{item.type==1?item.money/100:item.discount.substring(0,item.discount.indexOf(".")+2)}}</text>
  15. <view class="couponItem-subject-price-reduce">{{item.name}}</view>
  16. </view>
  17. </view>
  18. <view class="couponItem-subject-right">
  19. <view class="couponItem-subject-right-header">
  20. <span class="couponItem-subject-right-header-icon">{{item.type==1?'满减':'折扣'}}</span>
  21. {{item.title}}
  22. </view>
  23. <button :data-index="index" @click="collectCoupons(item,index)" v-if="item.is_receive==0" class="couponItem-subject-right-btn">领取</button>
  24. <button v-else class="iscouponItem-subject-right-btn">已领取</button>
  25. <view class="closing-date" v-if="item.expire_type == 2">
  26. {{item.start_time}} - {{item.end_time}}
  27. </view>
  28. <view class="" v-else>
  29. 有效期:{{item.effective_days}}天
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <u-empty text="暂无数据" :show="show" mode="order" margin-top="250"></u-empty>
  38. <view class="cu-tabbar-height"></view>
  39. <view class="cu-tabbar-height"></view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. list: [],
  47. pageindex: 1,
  48. show: false
  49. }
  50. },
  51. methods: {
  52. getcoupon: async function() {
  53. let res = await this.$request.post("/api/v1/coupon/couponList", {
  54. page: this.pageindex
  55. })
  56. console.log(res)
  57. if (res.status == 0) {
  58. if (this.pageindex > res.data.last_page) {
  59. uni.showToast({
  60. title: "没有更多了",
  61. icon: "none"
  62. })
  63. } else {
  64. this.list = this.list.concat(res.data.data)
  65. this.list.forEach((item, index) => {
  66. item.start_time = this.$util.formatDate(item.start_time)
  67. item.end_time = this.$util.formatDate(item.end_time)
  68. })
  69. let i = this.list.length
  70. while (i--) {
  71. if (this.list[i].position_type == 2) {
  72. this.list.splice(i, 1)
  73. }
  74. }
  75. this.pageindex++
  76. }
  77. }
  78. if (this.list.length == 0) {
  79. this.show = true
  80. } else {
  81. this.show = false
  82. }
  83. },
  84. collectCoupons: async function(item, index) {
  85. if (item.num == 0) {
  86. uni.showToast({
  87. title: "该优惠卷数量不足",
  88. icon: "none"
  89. })
  90. return false
  91. }
  92. let res = await this.$request.post("/api/v1/coupon/receiveCoupon", {
  93. coupon_id: item.id
  94. })
  95. console.log(res)
  96. if (res.status == 0) {
  97. uni.showToast({
  98. title: "领取成功"
  99. })
  100. this.list[index].is_receive = 1
  101. this.$forceUpdate()
  102. }
  103. }
  104. },
  105. onLoad() {
  106. },
  107. onShow() {
  108. this.getcoupon()
  109. }
  110. }
  111. </script>
  112. <style>
  113. /* 优惠券样式 */
  114. .discount {
  115. position: relative;
  116. display: inline-block;
  117. margin-right: 5px;
  118. margin-left: 15px;
  119. padding: 0 9px 0 12px;
  120. border-top: 1px solid rgb(11, 115, 186);
  121. border-bottom: 1px solid rgb(11, 115, 186);
  122. height: 16px;
  123. line-height: 16px;
  124. color: rgb(11, 115, 186);
  125. font-size: 10px;
  126. }
  127. .discount::before {
  128. content: "";
  129. left: 0;
  130. width: 7px;
  131. position: absolute;
  132. top: -1px;
  133. height: 18px;
  134. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAkCAMAAACpD3pbAAAAPFBMVEUAAAD////kOTzqaGr+9vb4zc32vL3sdXfnTE/mRUfxmpz87O3yn6HqZ2npXWDlQEP97e33xsf3xsbxl5nHV2NIAAAAAXRSTlMAQObYZgAAAJpJREFUOMvllEsSwiAQRMnjF8g/3v+uKhIrjhHK0l16B4+C7hlALS07qSyS2kVlKnHmCpqdNvwYwTdY6yKGX7AeKtb+jmN3jLuYMMEd5XYBUMZ6cO/BHHhr7ut6wizxHOhvM+kUT5S5I77ZsGWU1kbsExsmiSdMBVc3l9a0tJaDdR+CVcryWtRBFLXYkku1oae955Xnv5Y+j/UKs1MGwyraxf4AAAAASUVORK5CYII=);
  135. background-size: 15px 18px;
  136. background-repeat: no-repeat;
  137. }
  138. .discount::after {
  139. right: 0;
  140. width: 4px;
  141. background-position: -11px 0;
  142. content: "";
  143. position: absolute;
  144. top: -1px;
  145. height: 18px;
  146. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAkCAMAAACpD3pbAAAAPFBMVEUAAAD////kOTzqaGr+9vb4zc32vL3sdXfnTE/mRUfxmpz87O3yn6HqZ2npXWDlQEP97e33xsf3xsbxl5nHV2NIAAAAAXRSTlMAQObYZgAAAJpJREFUOMvllEsSwiAQRMnjF8g/3v+uKhIrjhHK0l16B4+C7hlALS07qSyS2kVlKnHmCpqdNvwYwTdY6yKGX7AeKtb+jmN3jLuYMMEd5XYBUMZ6cO/BHHhr7ut6wizxHOhvM+kUT5S5I77ZsGWU1kbsExsmiSdMBVc3l9a0tJaDdR+CVcryWtRBFLXYkku1oae955Xnv5Y+j/UKs1MGwyraxf4AAAAASUVORK5CYII=);
  147. background-size: 15px 18px;
  148. background-repeat: no-repeat;
  149. }
  150. /* 优惠头部 */
  151. .header-Discount {
  152. position: relative;
  153. height: 46px;
  154. line-height: 46px;
  155. padding-left: 10px;
  156. font-size: 15px;
  157. color: #333;
  158. text-align: center;
  159. font-weight: 700;
  160. }
  161. .body-Discount {
  162. padding: 0 18px;
  163. font-size: 13px;
  164. color: #333;
  165. margin-bottom: 50px;
  166. }
  167. .body-Discount>.collar {
  168. position: relative;
  169. padding-bottom: 9px;
  170. }
  171. .body-Discount>.collar>.title-Discount {
  172. height: 40px;
  173. line-height: 40px;
  174. color: #262626;
  175. font-weight: 700;
  176. }
  177. .body-Discount>.collar .couponList>.couponItem {
  178. color: rgb(11, 115, 186);
  179. margin-bottom: 18px;
  180. padding: 12px 10px;
  181. border-top: 6px solid currentColor;
  182. box-shadow: 0 0 6px 0 rgba(0, 0, 0, .1);
  183. border-radius: 6px;
  184. }
  185. .body-Discount>.collar .couponList>.couponItem>.couponItem-subject {
  186. display: flex;
  187. min-height: 58px;
  188. color: rgb(11, 115, 186);
  189. }
  190. .body-Discount>.collar .couponList>.couponItem>.couponItem-subject>.couponItem-subject-left {
  191. width: 220rpx;
  192. margin-right: 10px;
  193. line-height: 1;
  194. text-align: center;
  195. display: flex;
  196. flex-direction: column;
  197. justify-content: center;
  198. overflow: hidden;
  199. }
  200. .couponItem-subject-price {
  201. overflow: hidden;
  202. text-overflow: ellipsis;
  203. white-space: nowrap;
  204. line-height: 1;
  205. text-align: center;
  206. }
  207. .couponItem-subject-icon {
  208. font-size: 14px;
  209. display: inline-block;
  210. vertical-align: bottom;
  211. margin: 0 4px 3px 0;
  212. }
  213. .couponItem-subject-price-min {
  214. position: relative;
  215. top: 1px;
  216. font-size: 36px;
  217. letter-spacing: 0;
  218. }
  219. .couponItem-subject-price-reduce {
  220. font-size: 14px;
  221. margin-top: 5px;
  222. }
  223. .couponItem-subject-right {
  224. flex: 1;
  225. position: relative;
  226. }
  227. .couponItem-subject-right-header {
  228. height: 36px;
  229. line-height: 18px;
  230. overflow: hidden;
  231. text-overflow: ellipsis;
  232. display: -webkit-box;
  233. -webkit-line-clamp: 1;
  234. -webkit-box-orient: vertical;
  235. font-size: 12px;
  236. color: #666;
  237. }
  238. .couponItem-subject-right-header-icon {
  239. background-color: rgb(11, 115, 186);
  240. color: #fff;
  241. font-size: 12px;
  242. display: inline-block;
  243. padding: 0 6px 0 12px;
  244. height: 14px;
  245. margin-right: 4px;
  246. line-height: 14px;
  247. position: relative;
  248. border-radius: 0 3px 3px 0;
  249. }
  250. .couponItem-subject-right-header-icon::before {
  251. position: absolute;
  252. z-index: 1;
  253. content: "";
  254. width: 0;
  255. top: 0;
  256. left: -7px;
  257. height: 0;
  258. border-top: 7px solid #fff;
  259. border-right: 7px solid transparent;
  260. border-bottom: 7px solid #fff;
  261. border-left: 7px solid #fff;
  262. }
  263. .couponItem-subject-right-header-icon::after {
  264. content: ".";
  265. position: absolute;
  266. color: #fff;
  267. left: 5px;
  268. top: -6px;
  269. font-size: 20px;
  270. }
  271. .couponItem-subject-right-btn {
  272. background-color: rgb(11, 115, 186);
  273. color: #fff;
  274. font-size: 12px;
  275. position: absolute;
  276. right: 0;
  277. bottom: 0;
  278. width: 68px;
  279. height: 20px;
  280. line-height: 20px;
  281. text-align: center;
  282. border-radius: 10px;
  283. box-sizing: border-box;
  284. z-index: 2;
  285. }
  286. .iscouponItem-subject-right-btn {
  287. background-color: #dcdcdc;
  288. color: #fff;
  289. font-size: 12px;
  290. position: absolute;
  291. right: 0;
  292. bottom: 0;
  293. width: 68px;
  294. height: 20px;
  295. line-height: 20px;
  296. text-align: center;
  297. border-radius: 10px;
  298. box-sizing: border-box;
  299. z-index: 2;
  300. }
  301. .desc-style {
  302. padding: 5px 18px 10px 18px;
  303. line-height: 1.3;
  304. position: relative;
  305. font-size: 12px;
  306. max-height: 46px;
  307. overflow: hidden;
  308. color: #666;
  309. background-color: white;
  310. }
  311. .closing-date {
  312. /* padding-right: 68px; */
  313. position: absolute;
  314. left: -18rpx;
  315. bottom: 0;
  316. box-sizing: border-box;
  317. width: 100%;
  318. line-height: 20px;
  319. font-size: 10px;
  320. color: #8c8c8c;
  321. }
  322. </style>