list.vue 9.0 KB

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