certificateList.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="pages">
  3. <mescroll-body class="certificateList-wrap" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  4. <view class="certificate">
  5. <view v-for="(item,index) in certificateList" :key="index" class="certificate-item">
  6. <image :src="$getInnerImg + 'certificate.png'" class="certificate-item-img" mode="scaleToFill"></image>
  7. <view class="certificate-item-text">
  8. <view class="num">证书编号:{{item.num}}</view>
  9. <view class="time">颁发日期:{{item.time}}</view>
  10. </view>
  11. <view class="certificate-item-icon"><text class="iconfont icon-jiantou"></text></view>
  12. </view>
  13. </view>
  14. </mescroll-body>
  15. </view>
  16. </template>
  17. <script>
  18. // 引入mescroll-mixins.js
  19. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  20. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  21. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  22. export default {
  23. mixins: [MescrollMixin], // 使用mixin
  24. components: {
  25. MescrollBody,
  26. },
  27. data() {
  28. return {
  29. $getInnerImg:this.$getInnerImg,
  30. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  31. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  32. downOption: {
  33. // ...
  34. },
  35. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  36. upOption: {
  37. page: {
  38. size: 10 // 每页数据的数量,默认10
  39. },
  40. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  41. empty: {
  42. tip: '暂无相关数据'
  43. }
  44. },
  45. params:{
  46. tokenhead:'',
  47. token:'',
  48. },
  49. certificateList:[
  50. {
  51. num:"0999999",
  52. time:'2019-01-02 12:32',
  53. },
  54. {
  55. num:"0999999",
  56. time:'2019-01-02 12:32',
  57. },
  58. ],
  59. }
  60. },
  61. onShow() {
  62. let serf = this;
  63. //检查登录,获取token
  64. // let loginRes = this.checkLogin('/pages/index/index', '2');
  65. // if(!loginRes){return false;}
  66. // serf.params.token=loginRes[0];
  67. },
  68. onLoad() {
  69. let self = this;
  70. uni.getStorage({
  71. key:'token',
  72. success: function (res) {
  73. self.params.token = res.data;
  74. // console.log(res.data);
  75. }
  76. });
  77. uni.getStorage({
  78. key:'tokenhead',
  79. success: function (res) {
  80. self.params.tokenhead = res.data;
  81. // console.log(res.data);
  82. }
  83. });
  84. },
  85. methods: {
  86. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  87. mescrollInit(mescroll) {
  88. this.mescroll = mescroll;
  89. },
  90. /*下拉刷新的回调, 有三种处理方式:*/
  91. downCallback(){
  92. // 第2种: 下拉刷新和上拉加载调同样的接口, 那么不用第1种方式, 直接mescroll.resetUpScroll()即可
  93. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  94. },
  95. /*上拉加载的回调*/
  96. upCallback(page) {
  97. let pageNum = page.num; // 页码, 默认从1开始
  98. let pageSize = page.size; // 页长, 默认每页10条
  99. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  100. let thetoken = this.params.tokenhead + this.params.token;
  101. console.log('thetoken',thetoken);
  102. this.$api.http.get(this.config.apiBaseurl+'/pre/own',{params:this.params,header: {Authorization:thetoken}}).then(data => {
  103. console.log('1111111111',data);
  104. // 接口返回的当前页数据列表 (数组)
  105. let curPageData = data.data.data.list;
  106. // console.log('curPageData',curPageData);
  107. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  108. let curPageLen = curPageData.length;
  109. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  110. // let totalPage = data.xxx;
  111. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  112. let totalSize = data.data.data.total;
  113. // this.mescrollList = curPageData;
  114. // 接口返回的是否有下一页 (true/false)
  115. // let hasNext = data.xxx;
  116. //设置列表数据
  117. if(page.num == 1) this.certificateList = []; //如果是第一页需手动置空列表
  118. this.certificateList = this.certificateList.concat(curPageData); //追加新数据
  119. // console.log('page.num',page.num);
  120. console.log('this.certificateList',JSON.parse(JSON.stringify(this.certificateList)));
  121. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  122. this.mescroll.endBySize(curPageLen, totalSize);
  123. // setTimeout(()=>{
  124. // this.mescroll.endSuccess(curPageLen)
  125. // },20)
  126. }).catch(err => {
  127. this.mescroll.endErr()
  128. console.log(err)
  129. });
  130. },
  131. }
  132. }
  133. </script>
  134. <style>
  135. @import url("./certificateList.css");
  136. </style>