耀实惠小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
4.8 KiB

  1. <template>
  2. <view class="coupon">
  3. <view class="position-fixed top-0 left-0 bg-white vw-100 zIndex-2">
  4. <u-tabs font-size="34" :list="list" :is-scroll="false" :current="current" @change="change" active-color="#01AEEA" />
  5. </view>
  6. <view class="coupon-container" v-if="couponData.length>0">
  7. <view class="items" v-for="item in couponData" :key="item.id">
  8. <text class="title font-28">优惠券</text>
  9. <text class="price font-40">{{item.name}}</text>
  10. <text>有效期至{{item.validTime}}</text>
  11. <button class="btn" type="default" @click="chooseCoup(item)">立即使用</button>
  12. <view class="position-absolute zIndex-1 coupon-invalid" v-if="item.useFlag == 1">
  13. <view class="coupon-invalid-image position-absolute">
  14. <image :src="IMG_URL + 'my/invalid.png'" mode="widthFix"></image>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <view v-if="!couponData.length">
  20. <u-empty margin-top="450" text="暂无优惠券~" mode="list" ></u-empty>
  21. </view>
  22. </view>
  23. </template>
  24. <!-- invalid -->
  25. <script>
  26. import { IMG_URL } from '@/env.js'
  27. export default {
  28. data () {
  29. return {
  30. IMG_URL,
  31. list: [{
  32. name: '待使用'
  33. }, {
  34. name: '已过期'
  35. }],
  36. options: {},
  37. current: 0,
  38. couponData: [],
  39. pageNo: 1,
  40. pageSize: 10,
  41. total: null,
  42. isLock: true,
  43. }
  44. },
  45. onLoad(options) {
  46. this.options = options
  47. this.getCouponPage()
  48. },
  49. onPullDownRefresh() {
  50. this.couponData = [];
  51. this.pageNo = 1;
  52. this.total = null;
  53. this.isLock = true;
  54. this.getCouponPage()
  55. },
  56. onReachBottom() {
  57. if(this.isLock){
  58. this.isLock = false;
  59. if(this.total !== null && this.pageNo * this.pageSize >= this.total){
  60. this.$Toast('没有更多数据了哦!');
  61. setTimeout(()=>{
  62. this.isLock = true;
  63. },3000)
  64. return
  65. }
  66. this.pageNo+=1;
  67. this.getCouponPage();
  68. }
  69. },
  70. methods: {
  71. getCouponPage() {
  72. uni.showLoading();
  73. const params = {
  74. pageNo: this.pageNo,
  75. pageSize: this.pageSize,
  76. type: this.current,
  77. id: this.options?.id || null
  78. }
  79. this.$api('getCouponPage',params).then(res => {
  80. let { code, result, message} = res;
  81. if(code == 200) {
  82. if(this.total == null) {
  83. this.total = result.total;
  84. }
  85. // 处理 图片
  86. this.couponData = this.couponData.concat(result.records)
  87. console.log(result);
  88. }else {
  89. this.$Toast(message);
  90. }
  91. uni.hideLoading()
  92. uni.stopPullDownRefresh()
  93. this.isLock = true;
  94. }).catch(err => {
  95. uni.hideLoading()
  96. this.isLock = true;
  97. uni.stopPullDownRefresh()
  98. this.$Toast(err.message);
  99. })
  100. },
  101. chooseCoup(item) {
  102. if (this.options?.id) {
  103. uni.$emit('coupon', item)
  104. uni.navigateBack({
  105. delta: 1
  106. })
  107. } else {
  108. this.$tools.navigateTo({
  109. url: '/pagesC/goodsInfo/goodsInfo?type=home&id='+ item.goodsId
  110. })
  111. }
  112. },
  113. change(index) {
  114. this.current = index;
  115. this.couponData = [];
  116. this.pageNo = 1;
  117. this.total = null;
  118. this.isLock = true;
  119. this.getCouponPage()
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. .coupon{
  126. &-container {
  127. padding: 100rpx 20rpx 20rpx;
  128. box-sizing: border-box;
  129. }
  130. &-invalid {
  131. width: 100%;
  132. height: 100%;
  133. top: 0;
  134. left: 0;
  135. border-radius: 10rpx;
  136. background: rgba(0,0,0,0.3);
  137. &-image {
  138. width: 200rpx;
  139. right: 40rpx;
  140. bottom: 20rpx;
  141. }
  142. }
  143. .items{
  144. margin-bottom: 40rpx;
  145. background: url('https://hanhai-image-dev.oss-cn-guangzhou.aliyuncs.com/blindbox/youhuiquan.png') no-repeat;
  146. background-size: cover;
  147. position: relative;
  148. display: flex;
  149. flex-direction: column;
  150. justify-content: center;
  151. padding: 40rpx 30rpx;
  152. border-radius: 10rpx;
  153. text{
  154. margin-top: 20rpx;
  155. color: #FFFFFF;
  156. font-size: 24rpx;
  157. }
  158. .title{
  159. font-size: 30rpx;
  160. }
  161. .price{
  162. font-size: 36rpx;
  163. }
  164. .btn{
  165. position: absolute;
  166. right: 15rpx;
  167. top: 100rpx;
  168. width: 146rpx;
  169. height: 58rpx;
  170. padding: 0rpx;
  171. // border: 1rpx solid #fb7b5e;
  172. border-radius: 17rpx;
  173. box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16);
  174. background: #ffffff;
  175. font-size: 24rpx;
  176. display: flex;
  177. justify-content: center;
  178. align-items: center;
  179. }
  180. }
  181. }
  182. .noCoupon {
  183. text-align: center;
  184. }
  185. .giving-box {
  186. width: 602rpx;
  187. .giving-title {
  188. padding:40rpx 0;
  189. width: 100%;
  190. font-size: 37rpx;
  191. color: #000000;
  192. text-align: center;
  193. }
  194. .giving-cont {
  195. padding: 0 41rpx;
  196. .input-box {
  197. background-color: #F5F5F5;
  198. display: flex;
  199. justify-content: space-between;
  200. align-items: center;
  201. padding: 10rpx 21rpx;
  202. font-size: 30rpx;
  203. color: #000000;
  204. margin-bottom: 24rpx;
  205. border-radius: 10rpx;
  206. }
  207. }
  208. .giving-btn {
  209. padding-bottom: 30rpx;
  210. margin-top: 85rpx;
  211. .custom-style {
  212. width: 374rpx;
  213. height: 77rpx;
  214. background-color: #000000;
  215. color: #FFFfff;
  216. }
  217. }
  218. }
  219. </style>