index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view>
  3. <navbar v-model="screenHeight" title-color="#ffffff" background="#c30d24" :iSimmersive="false" :placeholder="true" title="领劵中心"></navbar>
  4. <mescroll-body ref="mescrollRef"
  5. @init="mescrollInit"
  6. @down="downCallback"
  7. @up="upCallback"
  8. :down="downOption"
  9. :up="upOption"
  10. :height="screenHeight+'px'"
  11. >
  12. <view class="list-wrap">
  13. <view class="list-box">
  14. <view class="list-item" v-for="(item, index) in result" :key="index">
  15. <view class="l">
  16. <view>¥<text>{{item.amount}}</text></view>
  17. <view v-if="item.price > 0">满{{item.price}}可用</view>
  18. <view v-else>无门槛</view>
  19. </view>
  20. <view class="m">
  21. <text>{{item.name}}</text>
  22. <text>到期:{{ item.end_time }}</text>
  23. </view>
  24. <view class="r" :class="{'active':item.is_receive == 1,'disable': item.is_receive==2}">
  25. <text @click="onReceive(index)">{{item.is_receive ? (item.is_receive == 1 ? "已领" : "领完") : "领劵"}}</text>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </mescroll-body>
  31. <authorize v-model="isAuthShow"></authorize>
  32. </view>
  33. </template>
  34. <script>
  35. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  36. import navbar from "@/components/navbar/navbar";
  37. import authorize from "@/components/authorize/authorize";
  38. export default {
  39. mixins: [MescrollMixin],
  40. components: {
  41. navbar,authorize
  42. },
  43. data() {
  44. return {
  45. screenHeight: 0,
  46. isAuthShow: false,
  47. scrollNum: 0,
  48. downOption: {
  49. auto: false
  50. },
  51. upOption: {
  52. use: true, // 是否启用上拉加载; 默认true
  53. auto: false, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
  54. isLock: false, // 是否锁定上拉加载,默认false;
  55. isBoth: true, // 上拉加载时,如果滑动到列表顶部是否可以同时触发下拉刷新;默认true,两者可同时触发;
  56. page: {
  57. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  58. size: 10, // 每页数据的数量
  59. time: null // 加载第一页数据服务器返回的时间; 防止用户翻页时,后台新增了数据从而导致下一页数据重复;
  60. },
  61. noMoreSize: 3, // 如果列表已无数据,可设置列表的总数量要大于等于5条才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
  62. offset: 80, // 距底部多远时,触发upCallback(仅mescroll-uni生效, 对于mescroll-body则需在pages.json设置"onReachBottomDistance")
  63. bgColor: "transparent", // 背景颜色 (建议在pages.json中再设置一下backgroundColorTop)
  64. textColor: "gray", // 文本颜色 (当bgColor配置了颜色,而textColor未配置时,则textColor会默认为白色)
  65. textLoading: '加载中 ...', // 加载中的提示文本
  66. textNoMore: '-- END --', // 没有更多数据的提示文本
  67. },
  68. result: []
  69. }
  70. },
  71. onPageScroll(obj){
  72. this.scrollNum = obj.scrollTop;
  73. },
  74. onShow() {
  75. this.$store.dispatch("usersStatus").then(()=>{
  76. this.isAuthShow = false;
  77. this.downCallback();
  78. }).catch(()=>{
  79. this.isAuthShow = true;
  80. this.mescroll.showEmpty();
  81. });
  82. },
  83. methods: {
  84. downCallback(){
  85. setTimeout(()=>{
  86. this.mescroll.resetUpScroll();
  87. },200);
  88. },
  89. triggerDownScroll(){
  90. this.mescroll.triggerDownScroll();
  91. },
  92. onReceive(index){
  93. if(this.$utils.in_array(this.result[index].is_receive,[1,2])){
  94. return ;
  95. }
  96. this.$http.getCouponList({
  97. id: this.result[index].id
  98. }).then(res=>{
  99. if(res.status){
  100. this.$utils.msg(res.info);
  101. }else{
  102. this.$utils.msg(res.info);
  103. }
  104. this.result[index].is_receive = res.data;
  105. }).catch(err=>{
  106. this.$utils.msg("网络出错,请检查是否已连接");
  107. });
  108. },
  109. upCallback(page) {
  110. this.$http.getCouponLoad({
  111. page: page.num
  112. }).then((result)=>{
  113. this.mescroll.endByPage(result.data.list.length, result.data.total);
  114. if(result.status==1){
  115. if(page.num == 1) this.result = [];
  116. this.result = this.result.concat(result.data.list);
  117. }else if(result.status == -1){
  118. this.mescroll.endErr();
  119. }
  120. }).catch(error=>{
  121. this.mescroll.endErr();
  122. });
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .list-wrap{
  129. width: 100%;
  130. margin-top: 20rpx;
  131. .list-item{
  132. width: 92%;
  133. height: 200rpx;
  134. border-radius: 10rpx;
  135. background-color: #fff;
  136. margin: 0 auto 20rpx auto;
  137. font-size: 26rpx;
  138. position: relative;
  139. .l{
  140. position: absolute;
  141. width: 220rpx;
  142. height: 160rpx;
  143. top: 20rpx;
  144. left: 0;
  145. border-right: 1px dashed #cccccc;
  146. view{
  147. color: #c30d24;
  148. display: block;
  149. text-align: center;
  150. height: 60rpx;
  151. line-height: 40rpx;
  152. }
  153. view:first-child{
  154. font-size: 32rpx;
  155. height: 100rpx;
  156. line-height: 120rpx;
  157. color: #c30d24;
  158. text{
  159. font-size: 50rpx;
  160. font-style: normal;
  161. font-weight: bold;
  162. }
  163. }
  164. }
  165. .m{
  166. padding: 0 110rpx 0 220rpx;
  167. height: 160rpx;
  168. text-align: center;
  169. text{
  170. display: block;
  171. }
  172. text:first-child{
  173. padding-top: 50rpx;
  174. line-height: 50rpx;
  175. font-size: 32rpx;
  176. color: #333;
  177. }
  178. text:last-child{
  179. height: 50rpx;
  180. line-height: 50rpx;
  181. font-size: 25rpx; color: #999;
  182. }
  183. }
  184. .r {
  185. &:before {
  186. z-index: 11;
  187. content: " ";
  188. position: absolute;
  189. top: -16rpx;
  190. left: -16rpx;
  191. width: 32rpx;
  192. height: 32rpx;
  193. background-color: #f6f6f6;
  194. border-radius: 100rpx;
  195. }
  196. &:after {
  197. z-index: 11;
  198. content: " ";
  199. position: absolute;
  200. bottom: -16rpx;
  201. left: -16rpx;
  202. width: 32rpx;
  203. height: 32rpx;
  204. background-color: #f6f6f6;
  205. border-radius: 100rpx;
  206. }
  207. z-index: 1;
  208. position: absolute;
  209. right: 0;
  210. top: 0;
  211. width: 110rpx;
  212. height: 200rpx;
  213. line-height: 200rpx;
  214. float: right;
  215. text-align: center;
  216. background-color: #c30d24;
  217. background-image: url(~@/static/images/coupon-circle.png);
  218. background-repeat: repeat-y;
  219. background-position: -4rpx center;
  220. background-size: 12rpx;
  221. text{
  222. font-size: 30rpx;
  223. color: #fff;
  224. display: block;
  225. text-align: center;
  226. }
  227. }
  228. .active{
  229. background-color: #6b8df9;
  230. }
  231. .disable{
  232. background-color: #dbdadd;
  233. }
  234. }
  235. }
  236. </style>