index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <view>
  3. <!-- <view class="coupon_status_list">
  4. <view class="coupon_status_item" :class="requestParam.status==0?'active':''" @click="setStatus(0)"> 全部 </view>
  5. <view class="coupon_status_item" :class="requestParam.status==1?'active':''" @click="setStatus(1)"> 待发货 </view>
  6. <view class="coupon_status_item" :class="requestParam.status==2?'active':''" @click="setStatus(2)"> 已发货 </view>
  7. </view> -->
  8. <!-- <view class="to_bottom" v-if="!couponList.length"> </view> -->
  9. <view class="coupon_list" v-if="couponList.length">
  10. <view class="coupon_item" v-for="(item, index) in couponList" :key="index" @click="toUse(item)">
  11. <view class="box_left">
  12. <view class="rebate" v-if="item.rebate_type == 1"> ¥{{ item.rebate }}</view>
  13. <view class="rebate" v-if="item.rebate_type == 2"> 打 {{ item.rebate }} 折</view>
  14. <view class="rebate" v-if="item.rebate_type == 3">
  15. <text v-if="item.rebate_scope.length">
  16. {{ item.rebate_scope[0].product_name }}
  17. </text>
  18. </view>
  19. <view class="std_pay"> 满{{ item.std_pay }}</view>
  20. </view>
  21. <view class="box_right">
  22. <view class="coupon_title">
  23. <view class="coupon_name" v-if="item.rebate_type == 1">满减券</view>
  24. <view class="coupon_name" v-if="item.rebate_type == 2">折扣券</view>
  25. <view class="coupon_name" v-if="item.rebate_type == 3">赠品券</view>
  26. <view class="coupon_status" v-if="item.status == 0">未使用</view>
  27. <view class="coupon_status" v-if="item.status == 1">已使用</view>
  28. <view class="coupon_status" v-if="item.status == 2">已暂停</view>
  29. <view class="coupon_status" v-if="item.status == 3">已过期</view>
  30. <view class="coupon_status" v-if="item.status == 4">已作废</view>
  31. </view>
  32. <view class="coupon_box">
  33. <view class="product_scope">
  34. <text class="" v-if="item.type_id == 1">限定商品可用</text>
  35. <text class="" v-if="item.type_id == 2">全场可用</text>
  36. <text class="" v-if="item.type_id == 3">部分商品不可用</text>
  37. </view>
  38. <view class="coupon_info">
  39. <view class="coupon_exp">{{ item.exp_time }} 到期</view>
  40. </view>
  41. </view>
  42. <view class="to_use" v-if="item.status == 0">
  43. <view class="use_btn">去使用</view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <Empty v-if="!couponList.length" text="----- 还没有优惠券啦 -----" />
  49. <view class="to_bottom" v-if="isLast && couponList.length"> -----到底啦-----</view>
  50. </view>
  51. </template>
  52. <script>
  53. import Empty from "@/components/Empty/Empty.vue";
  54. export default {
  55. components: {
  56. Empty,
  57. },
  58. data() {
  59. return {
  60. // 产品列表
  61. couponList: [],
  62. // 请求参数
  63. requestParam: {
  64. page: 1,
  65. status: 0,
  66. },
  67. // 是否最后一页
  68. isLast: false,
  69. // 是否请求中
  70. isReqing: false,
  71. };
  72. },
  73. onLoad() {
  74. // 登录提示
  75. if (!this.$checkAccess.alterLogin()) return;
  76. // 初始化页码为1
  77. this.requestParam.page = 1;
  78. // 是否是最后一页
  79. this.isLast = false;
  80. // 设置请求中
  81. this.isReqing = true;
  82. // 请求列表
  83. this.$http.request("api/custom_coupon/get_list", this.requestParam).then((re) => {
  84. // 设置非请求中
  85. this.isReqing = false;
  86. // 成功结果
  87. if (re.code == "success") {
  88. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  89. this.couponList = re.data.data;
  90. }
  91. });
  92. },
  93. onShow() {
  94. // 登录提示
  95. if (!this.$checkAccess.alterLogin()) return;
  96. // 没有数据的话,或者请求中,不允许刷新
  97. if (this.couponList.length > 0 || this.isReqing) return;
  98. // 设置请求中
  99. this.isReqing = true;
  100. // 请求列表
  101. this.$http.request("api/custom_coupon/get_list", this.requestParam).then((re) => {
  102. // 设置非请求中
  103. this.isReqing = false;
  104. // 成功结果
  105. if (re.code == "success") {
  106. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  107. this.couponList = re.data.data;
  108. }
  109. });
  110. },
  111. onPullDownRefresh() {
  112. // 登录提示
  113. if (!this.$checkAccess.alterLogin()) return;
  114. // 如果请求中,不允许请求,
  115. if (this.isReqing) return false;
  116. // 初始化页码为1
  117. this.requestParam.page = 1;
  118. // 是否是最后一页
  119. this.isLast = false;
  120. // 设置请求中
  121. this.isReqing = true;
  122. // 请求列表
  123. this.$http.request("api/custom_coupon/get_list", this.requestParam).then((re) => {
  124. // 设置非请求中
  125. this.isReqing = false;
  126. // 成功结果
  127. if (re.code == "success") {
  128. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  129. this.couponList = re.data.data;
  130. }
  131. });
  132. uni.stopPullDownRefresh();
  133. },
  134. onReachBottom() {
  135. // 登录提示
  136. if (!this.$checkAccess.alterLogin()) return;
  137. // 如果页码是0,避免第一页重复
  138. if (this.requestParam.page < 1) return;
  139. // 最后一页不请求
  140. if (this.isLast) return;
  141. // 设置请求中
  142. this.isReqing = true;
  143. // 增加一页
  144. this.requestParam.page = this.requestParam.page + 1;
  145. // 请求列表
  146. this.$http.request("api/custom_coupon/get_list", this.requestParam).then((re) => {
  147. // 设置非请求中
  148. this.isReqing = false;
  149. // 成功结果
  150. if (re.code == "success") {
  151. if (re.data.last_page <= this.requestParam.page) this.isLast = true;
  152. // 追加数据
  153. this.couponList.push(...re.data.data);
  154. }
  155. });
  156. },
  157. methods: {
  158. toUse(item) {
  159. // 没有范围
  160. if (item.type_id == 2) {
  161. uni.switchTab({ url: "/pages/index/index" });
  162. return;
  163. }
  164. // 只有一个商品,直接跳转到对应商品
  165. if (item.product_scope.length == 1) {
  166. uni.navigateTo({
  167. url: "/pages/product/index?product_id=" + item.product_scope[0],
  168. });
  169. return;
  170. }
  171. // 没有范围
  172. if (item.product_scope.length > 1) {
  173. uni.navigateTo({
  174. url: "/pages/coupon/product?coupon_id=" + item.coupon_id,
  175. });
  176. return;
  177. }
  178. },
  179. },
  180. };
  181. </script>
  182. <style lang="less">
  183. .coupon_status_list {
  184. display: block;
  185. height: 60rpx;
  186. color: #666666;
  187. line-height: 60rpx;
  188. background: #ffffff;
  189. padding: 10rpx 35rpx;
  190. .coupon_status_item {
  191. float: left;
  192. font-size: 28rpx;
  193. padding: 0rpx 20rpx;
  194. }
  195. .coupon_status_item.active {
  196. color: #000000;
  197. font-weight: bold;
  198. }
  199. }
  200. .coupon_list {
  201. display: block;
  202. overflow: hidden;
  203. margin: 10rpx auto;
  204. .coupon_item {
  205. height: 200rpx;
  206. display: block;
  207. background: #ffffff;
  208. margin: 10rpx auto;
  209. .box_left {
  210. float: left;
  211. width: 160rpx;
  212. height: 160rpx;
  213. font-size: 20rpx;
  214. text-align: center;
  215. margin-left: 35rpx;
  216. line-height: 60rpx;
  217. margin-top: 20rpx;
  218. background: pink;
  219. .rebate {
  220. width: 120rpx;
  221. height: 60rpx;
  222. margin: 0rpx auto;
  223. line-height: 60rpx;
  224. margin-top: 20rpx;
  225. overflow: hidden;
  226. white-space: nowrap;
  227. text-overflow: ellipsis;
  228. }
  229. }
  230. .box_right {
  231. float: left;
  232. width: 485rpx;
  233. margin-left: 35rpx;
  234. padding-top: 20rpx;
  235. overflow: hidden;
  236. .coupon_title {
  237. width: 485rpx;
  238. max-height: 80rpx;
  239. font-size: 30rpx;
  240. overflow: hidden;
  241. line-height: 40rpx;
  242. padding: 0rpx 0rpx;
  243. .coupon_name {
  244. float: left;
  245. height: 40rpx;
  246. width: 380rpx;
  247. }
  248. .coupon_status {
  249. width: 100rpx;
  250. float: right;
  251. color: #999999;
  252. font-size: 24rpx;
  253. text-align: center;
  254. }
  255. }
  256. .coupon_box {
  257. float: left;
  258. width: 365rpx;
  259. overflow: hidden;
  260. .product_scope {
  261. width: 365rpx;
  262. height: 80rpx;
  263. color: #999999;
  264. font-size: 24rpx;
  265. overflow: hidden;
  266. line-height: 80rpx;
  267. }
  268. .coupon_info {
  269. width: 365rpx;
  270. max-height: 80rpx;
  271. font-size: 30rpx;
  272. overflow: hidden;
  273. line-height: 40rpx;
  274. padding: 0rpx 0rpx;
  275. .coupon_exp {
  276. float: left;
  277. font-size: 20rpx;
  278. }
  279. }
  280. }
  281. .to_use {
  282. float: right;
  283. width: 100rpx;
  284. margin-top: 75rpx;
  285. overflow: hidden;
  286. .use_btn {
  287. color: #ffffff;
  288. width: 100rpx;
  289. height: 40rpx;
  290. font-size: 24rpx;
  291. line-height: 40rpx;
  292. text-align: center;
  293. border-radius: 20rpx;
  294. background-color: #f59a23;
  295. }
  296. }
  297. }
  298. }
  299. }
  300. </style>