coupon.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="coupon">
  3. <mescroll-uni @getData="getCouponData" refs="mescroll" :size="10">
  4. <block slot="list">
  5. <block v-if="couponData.length">
  6. <view
  7. class="coupon-item"
  8. v-for="(item, index) in couponData"
  9. :key="index"
  10. :style="{ backgroundImage: 'url(' + $util.img('upload/uniapp/shop_uniapp/member/coupon_bg.png') + ')' }"
  11. @click="isChecked(item)"
  12. >
  13. <view class="coupon-title">
  14. <text class="coupon-money uni-using-hide">
  15. <text>¥</text>
  16. {{ parseInt(item.money) }}
  17. </text>
  18. <text class="uni-using-hide">满{{ parseInt(item.at_least) }}可用</text>
  19. </view>
  20. <view class="coupon-content">
  21. <text class="coupon-name uni-line-hide">{{ item.coupon_name }}</text>
  22. <text class="coupon-time">{{ item.expireTime }}</text>
  23. </view>
  24. <view class="checkbox-wrap"><text class="checkbox iconfont" :class="item.checked ? 'iconfuxuankuang1 color-base-text' : 'iconfuxuankuang2'"></text></view>
  25. </view>
  26. </block>
  27. <ns-empty v-else-if="!couponData.length && emptyShow"></ns-empty>
  28. </block>
  29. </mescroll-uni>
  30. <view class="footer-wrap" v-if="couponData.length"><button type="primary" @click="save()" :disabled="!Boolean(couponArr.length)">发放优惠券</button></view>
  31. <loading-cover ref="loadingCover"></loading-cover>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. emptyShow: false,
  39. memberId: 0,
  40. couponData: [],
  41. couponArr: [],
  42. repeatFlag: false
  43. };
  44. },
  45. onLoad(option) {
  46. option.member_id ? (this.memberId = option.member_id) : this.$util.redirectTo('/pages/member/list', {}, 'redirectTo');
  47. if (!this.$util.checkToken('/pages/member/detail?member_id=' + this.memberId)) return;
  48. },
  49. methods: {
  50. isChecked(item) {
  51. item.checked = !item.checked;
  52. if (item.checked) this.couponArr.push(item.coupon_type_id);
  53. else this.couponArr.splice(this.couponArr.indexOf(item.coupon_type_id), 1);
  54. },
  55. getCouponData(mescroll) {
  56. let data = {
  57. page_size: mescroll.size,
  58. page: mescroll.num,
  59. member_id: this.memberId,
  60. status: 1
  61. };
  62. this.mescroll = mescroll;
  63. this.$api.sendRequest({
  64. url: '/coupon/shopapi/coupon/lists',
  65. data: data,
  66. success: res => {
  67. let newArr = [];
  68. let msg = res.message;
  69. if (res.code == 0 && res.data) {
  70. newArr = res.data.list;
  71. } else {
  72. this.$util.showToast({ title: msg });
  73. }
  74. mescroll.endSuccess(newArr.length);
  75. //设置列表数据
  76. if (mescroll.num == 1) this.dataList = []; //如果是第一页需手动制空列表
  77. newArr.forEach(v => {
  78. this.$set(v, 'checked', false);
  79. if (v.validity_type == 0) v.expireTime = '有效期:' + this.$util.timeStampTurnTime(v.end_time);
  80. else if (v.validity_type == 1) v.expireTime = '领取之日起' + v.fixed_term + '天有效';
  81. });
  82. this.couponData = this.couponData.concat(newArr); //追加新数据
  83. this.emptyShow = true;
  84. if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
  85. }
  86. });
  87. },
  88. save() {
  89. if (this.repeatFlag) return;
  90. this.repeatFlag = true;
  91. let parent = this.couponArr.toString();
  92. this.$api.sendRequest({
  93. url: '/coupon/shopapi/coupon/send',
  94. data: {
  95. member_id: this.memberId,
  96. parent: parent
  97. },
  98. success: res => {
  99. this.repeatFlag = false;
  100. if (res.code == 0) {
  101. this.$util.showToast({
  102. title: '优惠券发放成功'
  103. });
  104. setTimeout(() => {
  105. this.$util.redirectTo('/pages/member/list');
  106. }, 1000);
  107. } else {
  108. this.$util.showToast({
  109. title: res.message
  110. });
  111. }
  112. }
  113. });
  114. }
  115. }
  116. };
  117. </script>
  118. <style lang="scss">
  119. .coupon {
  120. overflow: hidden;
  121. }
  122. .disabled {
  123. background-color: #ccc;
  124. }
  125. .coupon-item {
  126. display: flex;
  127. margin: 30rpx 30rpx 0;
  128. height: 170rpx;
  129. background-size: contain;
  130. background-repeat: no-repeat;
  131. .coupon-title {
  132. padding-left: 10rpx;
  133. display: flex;
  134. align-items: center;
  135. justify-content: center;
  136. flex-direction: column;
  137. width: 198rpx;
  138. color: #fff;
  139. box-sizing: border-box;
  140. }
  141. .coupon-content {
  142. display: flex;
  143. flex-direction: column;
  144. padding: 0 30rpx;
  145. width: 356rpx;
  146. .coupon-name {
  147. margin-top: 10rpx;
  148. line-height: 1.5;
  149. height: 86rpx;
  150. }
  151. .coupon-time {
  152. margin-top: 10rpx;
  153. border-top: 2rpx dashed $color-line;
  154. padding-top: 6rpx;
  155. font-size: $font-size-tag;
  156. }
  157. }
  158. .coupon-money {
  159. text-align: center;
  160. font-size: 50rpx;
  161. text {
  162. font-size: 30rpx;
  163. }
  164. }
  165. .checkbox {
  166. color: $color-tip;
  167. margin-right: 10rpx;
  168. }
  169. }
  170. .footer-wrap {
  171. position: fixed;
  172. width: 100%;
  173. bottom: 0;
  174. padding: 40rpx 0;
  175. z-index: 10;
  176. /* #ifdef MP */
  177. padding-bottom: 40rpx;
  178. padding-bottom: 40rpx;
  179. /* #endif */
  180. /* #ifndef MP */
  181. padding-bottom: calc(constant(safe-area-inset-bottom) + 100rpx);
  182. padding-bottom: calc(env(safe-area-inset-bottom) + 100rpx);
  183. /* #endif */
  184. }
  185. </style>