index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view class="content">
  3. <!-- <view class="page-section page-section-spacing swiper">
  4. <swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration">
  5. <swiper-item v-for="(item, index) in bannerList" :key="index">
  6. <image style="width: 100%; height: 100%;" :src="item"></image>
  7. </swiper-item>
  8. </swiper>
  9. </view> -->
  10. <!-- <uni-section class="mb-10" title="热门优惠" type="line"> -->
  11. <view class="mainList">
  12. <uni-list>
  13. <uni-list-item v-for="(item, index) in list" :key="index">
  14. <!-- 自定义 header -->
  15. <template v-slot:header>
  16. <image class="slot-image" :src="fileUrl + item.photo" @click="btn(item)"></image>
  17. </template>
  18. <!-- 自定义 body -->
  19. <template v-slot:body>
  20. <view class="slot-body titleBox" @click="btn(item)">
  21. <view class="slot-box slot-title">{{ item.name }}</view>
  22. <view class="slot-box slot-text">积分:{{ item.integral }}</view>
  23. <view class="slot-box slot-text">剩余:{{ item.remainCount }}</view>
  24. </view>
  25. </template>
  26. <!-- 自定义 footer-->
  27. <template v-slot:footer>
  28. <button type="default" class="receive" :class="{ remainCount: item.remainCount == 0 }" size="mini" @click="itemClick(item)">领取</button>
  29. </template>
  30. </uni-list-item>
  31. </uni-list>
  32. </view>
  33. <!-- </uni-section> -->
  34. <uni-load-more :status="more" />
  35. <popup ref="popup" :popupInfo="popupInfo" @confirm="popupBtnClick" @close="popupBtnClick"></popup>
  36. </view>
  37. </template>
  38. <script>
  39. import login from '../../api/login.js';
  40. import { BASE_URL } from '../../env.js';
  41. import voucher from '../../api/voucher.js';
  42. import popup from '../../components/popup.vue'
  43. const appid = uni.getAccountInfoSync().miniProgram.appId;
  44. export default {
  45. components: {
  46. popup
  47. },
  48. data() {
  49. return {
  50. bannerList: [],
  51. fileUrl: BASE_URL.fileUrl,
  52. list: [],
  53. page: 0,
  54. size: 10,
  55. more: 'more',
  56. popupInfo: {
  57. msgType: 'success',
  58. cancelText: '关闭',
  59. confirmText: '确认',
  60. title: '通知',
  61. content: '默认消息'
  62. },
  63. };
  64. },
  65. onLoad: async function() {
  66. const config = await login.getJson();
  67. const { bannerList } = config.data;
  68. this.bannerList = bannerList;
  69. this.query();
  70. },
  71. methods: {
  72. async query() {
  73. this.page += 1;
  74. this.more = 'loading';
  75. // 此处是查询函数
  76. const res = await voucher.getList({ pageNum: this.page, pageSize: this.size });
  77. this.list.push(...res.rows)
  78. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  79. this.more = this.page >= Math.ceil(res.total / this.size) ? 'noMore' : 'more';
  80. },
  81. // 领取
  82. async itemClick(item) {
  83. if (item.remainCount == 0) return;
  84. // 领取流程
  85. const res = await voucher.receivevoucher(item.discountId);
  86. if (res.code == 200) {
  87. this.popupInfo.content = '领取成功'
  88. this.$refs.popup.open();
  89. }
  90. },
  91. // 详情
  92. btn(item) {
  93. uni.navigateTo({ url: `/pages/goods/details?id=${item.discountId}` });
  94. },
  95. popupBtnClick() {
  96. this.list = [];
  97. this.page = 0;
  98. this.query();
  99. }
  100. },
  101. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  102. onReachBottom() {
  103. if(this.more != 'noMore') {
  104. this.more = 'more';
  105. this.query();
  106. }
  107. }
  108. };
  109. </script>
  110. <style scoped>
  111. .content {
  112. width: 100%;
  113. height: 100vh;
  114. padding-bottom: 15rpx;
  115. background: #F8F8F8;
  116. }
  117. .mainList {
  118. width: 100%;
  119. /* margin: 30rpx auto; */
  120. }
  121. .mainText {
  122. width: 100%;
  123. color: #000000;
  124. font-size: 34rpx;
  125. text-align: left;
  126. font-weight: 550;
  127. opacity: 0.5;
  128. margin-bottom: 50rpx;
  129. }
  130. .receive {
  131. display: flex;
  132. justify-content: center;
  133. align-items: center;
  134. width: 120rpx;
  135. background-color: #f60;
  136. color: #FFFFFF;
  137. font-size: 24rpx;
  138. border-radius: 10rpx;
  139. height: 2.5em;
  140. margin-top: 30rpx;
  141. }
  142. button {
  143. margin: unset;
  144. padding: unset;
  145. }
  146. button:after {
  147. border: unset;
  148. }
  149. </style>
  150. <style>
  151. .slot-box {
  152. position: relative;
  153. }
  154. .slot-image {
  155. width: 130rpx;
  156. height: 120rpx;
  157. }
  158. .status {
  159. position: absolute;
  160. left: 0;
  161. top: 0;
  162. font-size: 12px;
  163. color: #fff;
  164. background: #999;
  165. }
  166. .uni-list-item__container {
  167. flex: none !important;
  168. width: 90%;
  169. padding: 12px 5% !important;
  170. }
  171. .titleBox {
  172. width: 70%;
  173. margin-left: 10px;
  174. display: block;
  175. }
  176. .slot-title {
  177. width: 100%;
  178. font-weight: 600;
  179. color: #000;
  180. line-height: 2em;
  181. overflow: hidden;
  182. white-space: nowrap;
  183. text-overflow: ellipsis;
  184. display: block;
  185. }
  186. .slot-text {
  187. display: block;
  188. width: 100%;
  189. font-size: 22rpx;
  190. color: #999;
  191. overflow: hidden;
  192. white-space: nowrap;
  193. text-overflow: ellipsis;
  194. }
  195. .slot-footer {
  196. margin-left: 3%;
  197. }
  198. .footerIcon {
  199. line-height: 3em;
  200. }
  201. .remainCount {
  202. background-color: #999 !important;
  203. }
  204. .swiper {
  205. height: 45vw;
  206. overflow: hidden;
  207. }
  208. /**/
  209. .uni-section .uni-section-header {
  210. padding: 12px 20px !important;
  211. }
  212. </style>