index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.money }}</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. this.query();
  90. }
  91. },
  92. // 详情
  93. btn(item) {
  94. uni.navigateTo({ url: `/pages/goods/details?id=${item.discountId}` });
  95. },
  96. popupBtnClick() {
  97. this.list = [];
  98. this.page = 0;
  99. this.query();
  100. }
  101. },
  102. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  103. onReachBottom() {
  104. if(this.more != 'noMore') {
  105. this.more = 'more';
  106. this.query();
  107. }
  108. }
  109. };
  110. </script>
  111. <style scoped>
  112. .content {
  113. width: 100%;
  114. height: 100vh;
  115. padding-bottom: 15rpx;
  116. background: #F8F8F8;
  117. }
  118. .mainList {
  119. width: 90%;
  120. margin: 30rpx auto;
  121. }
  122. .mainText {
  123. width: 100%;
  124. color: #000000;
  125. font-size: 34rpx;
  126. text-align: left;
  127. font-weight: 550;
  128. opacity: 0.5;
  129. margin-bottom: 50rpx;
  130. }
  131. .receive {
  132. display: flex;
  133. justify-content: center;
  134. align-items: center;
  135. width: 120rpx;
  136. background-color: #f60;
  137. color: #FFFFFF;
  138. font-size: 24rpx;
  139. border-radius: 10rpx;
  140. height: 2.5em;
  141. margin-top: 30rpx;
  142. }
  143. button {
  144. margin: unset;
  145. padding: unset;
  146. }
  147. button:after {
  148. border: unset;
  149. }
  150. </style>
  151. <style>
  152. .slot-box {
  153. position: relative;
  154. }
  155. .slot-image {
  156. width: 130rpx;
  157. height: 120rpx;
  158. }
  159. .status {
  160. position: absolute;
  161. left: 0;
  162. top: 0;
  163. font-size: 12px;
  164. color: #fff;
  165. background: #999;
  166. }
  167. .uni-list-item__container {
  168. flex: none !important;
  169. width: 90%;
  170. padding: 12px 5% !important;
  171. }
  172. .titleBox {
  173. width: 70%;
  174. margin-left: 10px;
  175. display: block;
  176. }
  177. .slot-title {
  178. width: 100%;
  179. font-weight: 600;
  180. color: #000;
  181. line-height: 2em;
  182. overflow: hidden;
  183. white-space: nowrap;
  184. text-overflow: ellipsis;
  185. display: block;
  186. }
  187. .slot-text {
  188. display: block;
  189. width: 100%;
  190. font-size: 22rpx;
  191. color: #999;
  192. overflow: hidden;
  193. white-space: nowrap;
  194. text-overflow: ellipsis;
  195. }
  196. .slot-footer {
  197. margin-left: 3%;
  198. }
  199. .footerIcon {
  200. line-height: 3em;
  201. }
  202. .remainCount {
  203. background-color: #999 !important;
  204. }
  205. .swiper {
  206. height: 45vw;
  207. overflow: hidden;
  208. }
  209. /**/
  210. .uni-section .uni-section-header {
  211. padding: 12px 20px !important;
  212. }
  213. </style>