index.vue 5.1 KB

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