focusme.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="pages">
  3. <mescroll-body class="wrap" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  4. <view class="focusme">
  5. <view v-for="(item,index) in focusmelist" :key="index" class="focusme-item">
  6. <view class="focusme-item-photo">
  7. <image class="focusme-item-photo-img" :src="item.img" mode=""></image>
  8. </view>
  9. <view class="focusme-item-text">
  10. <view class="focusme-item-name">{{item.name}} <text class="type">{{item.type}}</text></view>
  11. <view class="focusme-item-addr">{{item.addr}}</view>
  12. <view class="focusme-item-care">关心:<text v-for="(careitem,careindex) in item.care" :key="careindex">{{careitem}},</text></view>
  13. </view>
  14. <view class="focusme-item-call" @click="callnumber(item.phonenumber)">
  15. <svg class="icon focusme-item-call-icon" aria-hidden="true">
  16. <use xlink:href="#icondianhua"></use>
  17. </svg>
  18. </view>
  19. </view>
  20. </view>
  21. </mescroll-body>
  22. </view>
  23. </template>
  24. <script>
  25. // 引入mescroll-mixins.js
  26. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  27. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  28. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  29. export default {
  30. mixins: [MescrollMixin], // 使用mixin
  31. components: {
  32. MescrollBody,
  33. },
  34. data() {
  35. return {
  36. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  37. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  38. downOption: {
  39. // ...
  40. },
  41. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  42. upOption: {
  43. page: {
  44. size: 10 // 每页数据的数量,默认10
  45. },
  46. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  47. empty: {
  48. tip: '暂无相关数据'
  49. }
  50. },
  51. params:{
  52. tokenhead:'',
  53. token:'',
  54. },
  55. focusmelist:[
  56. // {
  57. // img:"http://placekitten.com/90/90",
  58. // name:'周飞向',
  59. // type:'养殖大户',
  60. // addr:'贵州大亨油茶科技有限公司',
  61. // care:["油茶","茶","芝麻"],
  62. // phonenumber:'13655544126',
  63. // },
  64. // {
  65. // img:"http://placekitten.com/90/90",
  66. // name:'张永清',
  67. // type:'农户',
  68. // addr:'贵州毕节',
  69. // care:["林下食用菌"],
  70. // phonenumber:'13655544126',
  71. // },
  72. ],
  73. }
  74. },
  75. onShow() {
  76. let serf = this;
  77. //检查登录,获取token
  78. // let loginRes = this.checkLogin('/pages/index/index', '2');
  79. // if(!loginRes){return false;}
  80. // serf.params.token=loginRes[0];
  81. },
  82. onLoad() {
  83. let self = this;
  84. uni.getStorage({
  85. key:'token',
  86. success: function (res) {
  87. self.params.token = res.data;
  88. // console.log(res.data);
  89. }
  90. });
  91. uni.getStorage({
  92. key:'tokenhead',
  93. success: function (res) {
  94. self.params.tokenhead = res.data;
  95. // console.log(res.data);
  96. }
  97. });
  98. },
  99. methods: {
  100. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  101. mescrollInit(mescroll) {
  102. this.mescroll = mescroll;
  103. },
  104. /*下拉刷新的回调, 有三种处理方式:*/
  105. downCallback(){
  106. // 第2种: 下拉刷新和上拉加载调同样的接口, 那么不用第1种方式, 直接mescroll.resetUpScroll()即可
  107. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  108. },
  109. /*上拉加载的回调*/
  110. upCallback(page) {
  111. let pageNum = page.num; // 页码, 默认从1开始
  112. let pageSize = page.size; // 页长, 默认每页10条
  113. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  114. let thetoken = this.params.tokenhead + this.params.token;
  115. console.log('thetoken',thetoken);
  116. this.$api.http.get(this.config.apiBaseurl+'/pre/own',{params:this.params,header: {Authorization:thetoken}}).then(data => {
  117. console.log('1111111111',data);
  118. if(data.data.code=='1001'){
  119. // uni.redirectTo({
  120. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  121. // });
  122. };
  123. console.log(data);
  124. // 接口返回的当前页数据列表 (数组)
  125. let curPageData = data.data.data.list;
  126. // console.log('curPageData',curPageData);
  127. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  128. let curPageLen = curPageData.length;
  129. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  130. // let totalPage = data.xxx;
  131. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  132. let totalSize = data.data.data.total;
  133. // this.mescrollList = curPageData;
  134. // 接口返回的是否有下一页 (true/false)
  135. // let hasNext = data.xxx;
  136. //设置列表数据
  137. if(page.num == 1) this.mescrollList = []; //如果是第一页需手动置空列表
  138. this.mescrollList = this.mescrollList.concat(curPageData); //追加新数据
  139. // console.log('page.num',page.num);
  140. console.log('this.mescrollList',JSON.parse(JSON.stringify(this.mescrollList)));
  141. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  142. this.mescroll.endBySize(curPageLen, totalSize);
  143. // setTimeout(()=>{
  144. // this.mescroll.endSuccess(curPageLen)
  145. // },20)
  146. }).catch(err => {
  147. this.mescroll.endErr()
  148. console.log(err)
  149. });
  150. },
  151. //打电话
  152. callnumber(number){
  153. uni.makePhoneCall({
  154. phoneNumber: number
  155. });
  156. },
  157. }
  158. }
  159. </script>
  160. <style scoped>
  161. /* @import url("../usercenter.css"); */
  162. .focusme-item{display: flex;position: relative;align-items: center;background-color: #fff;padding: 24rpx 24rpx 17rpx 24rpx;margin-bottom: 8rpx;}
  163. .focusme-item::after{content: '';width: calc( 100% - 24rpx );height: 1px;background-color: #eee;position: absolute;right: 0;bottom: 0;}
  164. .focusme-item-photo{width: 90rpx;height: 90rpx;overflow: hidden;border-radius: 50%;margin-right: 30rpx;}
  165. .focusme-item-photo-img{width: 100%;height: 100%;}
  166. .focusme-item-text{flex: 1;}
  167. .focusme-item-name{margin-bottom: 4rpx;font-size: 34rpx;font-weight: 500;color: #333;line-height: 48rpx;}
  168. .focusme-item-name .type{margin-left: 24rpx;font-size: 24rpx;font-weight: 400;color: #6BBC6D;line-height: 33rpx;}
  169. .focusme-item-care,
  170. .focusme-item-addr{font-size: 28rpx;font-weight: 400;color: #666;line-height: 40rpx;}
  171. .focusme-item-call-icon{width: 58rpx;height: 58rpx;}
  172. </style>