list.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <app-layout>
  3. <view class="page">
  4. <view class="coupon-item" v-for="item in list" :key="item.id">
  5. <image class="coupon-bg" :src="couponImg[item.is_receive == '0' ? 'coupon_enabled' : 'coupon_disabled']" ></image>
  6. <view class="coupon-left dir-left-nowrap" @click="toDetail(item.id)">
  7. <view class="coupon-price t-omit box-grow-0">
  8. <template v-if="item.type == 2">
  9. <text>{{item.sub_price | keepNumbers}}</text>
  10. </template>
  11. <template v-else>
  12. <text>{{item.discount | keepNumbers}}</text>
  13. </template>
  14. </view>
  15. <view class="box-grow-1 dir-top-nowrap main-center coupon-content">
  16. <view class="t-omit" style="width:auto;display:block;">{{item.name}}</view>
  17. <view class="min_price t-omit" v-if="item.min_price > 0">满{{item.min_price | keepNumbers}}可用</view>
  18. <view v-else>无门槛使用</view>
  19. <view v-if="item.discount_limit">优惠上限:¥{{item.discount_limit | keepNumbers}}</view>
  20. </view>
  21. </view>
  22. <view class="use-btn" @click="receive(item)" v-if="item.is_receive == `0`">
  23. <view class="use" style="text-align: center">立即领取</view>
  24. </view>
  25. <button class="use use-btn" style="color:#b4b4b4;" v-else-if="item.is_receive == `1`">已领取</button>
  26. <view class="coupon-info" @click="toDetail(item.id)">
  27. <view v-if="item.expire_type == `1`">领取后{{item.expire_day}}天过期</view>
  28. <view v-if="item.expire_type == `2`">有效日期: {{item.begin_time}} - {{item.end_time}}</view>
  29. <view class="t-omit" v-if="item.appoint_type == `3`">适用范围:全场通用</view>
  30. <view class="t-omit" v-else-if="item.appoint_type == `4`">适用范围:仅限当面付活动使用</view>
  31. <view class="t-omit" v-else-if="item.appoint_type == `5`">适用范围:仅限礼品卡使用</view>
  32. <view class="t-omit" v-else-if="item.appoint_type == `2`">
  33. <text>适用商品:</text>
  34. <text v-for="(goods,index) in item.goods" :key="goods.id">
  35. <text>{{index != 0 ? '、' : ''}}{{goods.name}}</text>
  36. </text>
  37. </view>
  38. <view class="t-omit" v-else-if="item.appoint_type == `1`">
  39. <text>适用分类:</text>
  40. <text v-for="(cat,index) in item.cat" :key="cat.id">
  41. <text>{{index != 0 ? '、' : ''}}{{cat.name}}</text>
  42. </text>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </app-layout>
  48. </template>
  49. <script>
  50. import {mapGetters, mapState} from "vuex";
  51. export default {
  52. data() {
  53. return {
  54. list: [],
  55. loading: false,
  56. page: 2,
  57. }
  58. },
  59. computed: {
  60. ...mapState({
  61. couponImg: state => state.mallConfig.__wxapp_img.coupon,
  62. }),
  63. ...mapGetters({
  64. userInfo: 'user/info',
  65. })
  66. },
  67. methods: {
  68. getList() {
  69. let that = this;
  70. that.$request({
  71. url: that.$api.coupon.list,
  72. method: 'get',
  73. }).then(response => {
  74. uni.hideLoading();
  75. that.$hideLoading();
  76. if (response.code === 0) {
  77. that.list = response.data.list;
  78. } else {
  79. uni.showToast({
  80. title: response.msg,
  81. icon: 'none',
  82. duration: 1000
  83. });
  84. }
  85. }).catch(() => {
  86. uni.hideLoading();
  87. that.$hideLoading();
  88. });
  89. },
  90. getMore() {
  91. let that = this;
  92. uni.showLoading({
  93. title: '加载中...'
  94. });
  95. that.$request({
  96. url: that.$api.coupon.list,
  97. data: {
  98. page: that.page
  99. },
  100. }).then(e => {
  101. uni.hideLoading();
  102. if (e.code == 0) {
  103. if (e.data.list.length > 0) {
  104. that.list = that.list.concat(e.data.list);
  105. that.page++;
  106. }
  107. } else {
  108. uni.showToast({
  109. title: e.msg,
  110. icon: 'none',
  111. duration: 1000
  112. });
  113. }
  114. }).catch(e => {
  115. uni.hideLoading();
  116. });
  117. },
  118. toDetail(id) {
  119. uni.navigateTo({
  120. url: '/pages/coupon/details/details?id=' + id
  121. });
  122. },
  123. receive(coupon) {
  124. let that = this;
  125. if(that.loading) {
  126. return false
  127. }
  128. that.loading = true;
  129. uni.showLoading({
  130. title: '领取中...'
  131. });
  132. that.$request({
  133. url: that.$api.coupon.receive,
  134. data: {
  135. coupon_id: coupon.id
  136. },
  137. }).then(response => {
  138. that.loading = false;
  139. uni.hideLoading();
  140. if (response.code === 0) {
  141. setTimeout(function (row) {
  142. that.$store.dispatch('page/actionSetCoupon', {
  143. list: [Object.assign(coupon, response.data)],
  144. type: 'receive'
  145. });
  146. that.getList();
  147. }, 200)
  148. } else {
  149. uni.showToast({
  150. title: response.msg,
  151. icon: 'none',
  152. duration: 1000
  153. });
  154. that.getList();
  155. }
  156. }).catch(() => {
  157. uni.hideLoading();
  158. that.$event.on(that.$const.EVENT_USER_LOGIN).then(() => {
  159. that.receive(coupon);
  160. });
  161. });
  162. },
  163. },
  164. onLoad() { this.$commonLoad.onload();
  165. },
  166. onShow() {
  167. this.$showLoading({
  168. text: '加载中...'
  169. });
  170. this.getList();
  171. },
  172. filters: {
  173. keepNumbers(n) {
  174. return Number(n);
  175. }
  176. },
  177. onReachBottom() {
  178. this.getMore();
  179. },
  180. }
  181. </script>
  182. <style scoped lang="scss">
  183. .page {
  184. padding: #{20rpx} #{25rpx};
  185. width: 100%;
  186. }
  187. .coupon-item {
  188. height: #{275rpx};
  189. position: relative;
  190. margin-bottom: #{20rpx};
  191. }
  192. .coupon-bg {
  193. height: #{160rpx};
  194. width: 100%;
  195. }
  196. .coupon-left {
  197. position: absolute;
  198. left: #{20rpx};
  199. top: #{30rpx};
  200. color: #fff;
  201. width: 70%;
  202. }
  203. .coupon-left .coupon-price {
  204. float: left;
  205. max-width: 55%;
  206. width: auto;
  207. height: #{92rpx};
  208. line-height: #{92rpx};
  209. margin-right: #{20rpx};
  210. }
  211. .coupon-left .min_price {
  212. width: auto;
  213. }
  214. .coupon-price text {
  215. font-size: #{60rpx};
  216. }
  217. .use {
  218. height: #{56rpx};
  219. line-height: #{58rpx};
  220. background-color: #fff;
  221. width: #{160rpx};
  222. border-radius: #{28rpx};
  223. font-size: #{24rpx};
  224. color: #caa76e;
  225. }
  226. .use-btn {
  227. height: #{55rpx};
  228. width: #{160rpx};
  229. border-radius: #{27.5rpx};
  230. position: absolute;
  231. right: #{20rpx};
  232. border: 0;
  233. top: #{48rpx};
  234. }
  235. .coupon-info {
  236. position: absolute;
  237. top: #{160rpx};
  238. left: 0;
  239. right: 0;
  240. height: #{115rpx};
  241. background-color: #fff;
  242. border: #{2rpx} solid #cfcfcf;
  243. border-top: 0;
  244. padding: #{20rpx} #{25rpx};
  245. font-size: #{26rpx};
  246. color: #666;
  247. border-bottom-left-radius: #{15rpx};
  248. border-bottom-right-radius: #{15rpx};
  249. }
  250. .discount_limit {
  251. width: #{286rpx};
  252. text-align: center;
  253. color: #ffffff;
  254. }
  255. .coupon-content {
  256. font-size: $uni-font-size-general-one;
  257. line-height: 1.1;
  258. }
  259. </style>