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.integral }}</view>
  23. <view class="slot-box slot-text">剩余:{{ item.remainCount }}</view>
  24. </view>
  25. </template>
  26. <!-- 自定义 footer-->
  27. <template v-slot:footer>
  28. <view @click="btn(item)">查看</view>
  29. <!-- <button type="default" class="receive" :class="{ remainCount: item.remainCount == 0 }" size="mini" @click="itemClick(item)">领取</button> -->
  30. </template>
  31. </uni-list-item>
  32. </uni-list>
  33. </view>
  34. <!-- </uni-section> -->
  35. <uni-load-more :status="more" />
  36. <popup ref="popup" :popupInfo="popupInfo" @confirm="popupBtnClick" @close="popupBtnClick"></popup>
  37. </view>
  38. </template>
  39. <script>
  40. import login from '../../api/login.js';
  41. import { BASE_URL } from '../../env.js';
  42. import voucher from '../../api/voucher.js';
  43. import popup from '../../components/popup.vue'
  44. const appid = uni.getAccountInfoSync().miniProgram.appId;
  45. export default {
  46. components: {
  47. popup
  48. },
  49. data() {
  50. return {
  51. bannerList: [],
  52. fileUrl: BASE_URL.fileUrl,
  53. list: [],
  54. page: 0,
  55. size: 10,
  56. more: 'more',
  57. popupInfo: {
  58. msgType: 'success',
  59. cancelText: '关闭',
  60. confirmText: '确认',
  61. title: '通知',
  62. content: '默认消息'
  63. },
  64. };
  65. },
  66. onLoad: async function() {
  67. const config = await login.getJson();
  68. const { bannerList } = config.data;
  69. this.bannerList = bannerList;
  70. this.query();
  71. },
  72. methods: {
  73. async query() {
  74. this.page += 1;
  75. this.more = 'loading';
  76. // 此处是查询函数
  77. const res = await voucher.getList({ pageNum: this.page, pageSize: this.size });
  78. this.list.push(...res.rows)
  79. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  80. this.more = this.page >= Math.ceil(res.total / this.size) ? 'noMore' : 'more';
  81. },
  82. // 领取
  83. async itemClick(item) {
  84. if (item.remainCount == 0) return;
  85. // 领取流程
  86. const res = await voucher.receivevoucher(item.discountId);
  87. if (res.code == 200) {
  88. this.popupInfo.content = '领取成功'
  89. this.$refs.popup.open();
  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: 100%;
  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>