index.vue 7.9 KB

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