supplier.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="pages">
  3. <view class="supplier-page translate open" >
  4. <view class="search-wrap search-left-color">
  5. <view class="search">
  6. <view class="searchTxt">
  7. <uni-search-bar placeholder="搜索供应商关键词" @confirm="searchsupplier" @input="searchsupplier" ></uni-search-bar>
  8. </view>
  9. </view>
  10. </view>
  11. <!-- 搜索 结束 -->
  12. <view class="simplepage-wrap">
  13. <mescroll-body ref="mescrollRef0" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  14. <view>
  15. <view v-for="(item,index) in supplierlist" :key="index" @click="supplierclick(item.id)" class="simplepage-item">{{item.compName}}</view>
  16. </view>
  17. </mescroll-body>
  18. </view>
  19. </view>
  20. <!-- 供应商结束 -->
  21. </view>
  22. </template>
  23. <script>
  24. // 引入mescroll-mixins.js
  25. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  26. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  27. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  28. import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
  29. export default {
  30. mixins: [MescrollMixin], // 使用mixin
  31. components: {
  32. MescrollBody,
  33. uniSearchBar,
  34. },
  35. data() {
  36. return {
  37. params:{
  38. token:'',
  39. tokenhead:'',
  40. key:'',
  41. },
  42. supplierlist:[],
  43. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  44. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  45. downOption: {
  46. // ...
  47. },
  48. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  49. upOption: {
  50. page: {
  51. size: 10 // 每页数据的数量,默认10
  52. },
  53. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  54. empty: {
  55. tip: '暂无相关数据'
  56. }
  57. },
  58. }
  59. },
  60. onShow() {
  61. let self = this;
  62. //检查登录,获取token
  63. // let loginRes = this.checkLogin('/pages/index/index', '2');
  64. // if(!loginRes){return false;}
  65. // serf.params.token=loginRes[0];
  66. uni.getStorage({
  67. key:'token',
  68. success: function (res) {
  69. self.params.token = res.data;
  70. // console.log(res.data);
  71. }
  72. });
  73. uni.getStorage({
  74. key:'tokenhead',
  75. success: function (res) {
  76. self.params.tokenhead = res.data;
  77. // console.log(res.data);
  78. }
  79. });
  80. },
  81. onLoad() {
  82. },
  83. methods: {
  84. searchsupplier(e){
  85. console.log(e);
  86. this.params.key = e.value;
  87. this.mescroll.resetUpScroll();
  88. },
  89. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  90. mescrollInit(mescroll) {
  91. this.mescroll = mescroll;
  92. },
  93. downCallback(){
  94. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  95. },
  96. /*上拉加载的回调*/
  97. upCallback(page) {
  98. let pageNum = page.num; // 页码, 默认从1开始
  99. let pageSize = page.size; // 页长, 默认每页10条
  100. this.params = Object.assign(this.params,{page:pageNum,rows:pageSize});
  101. let thetoken = this.params.tokenhead+this.params.token;
  102. this.$api.http.get(this.config.apiBaseurl+'/company/cp/search',{header: {Authorization:thetoken},params:{key:this.params.key}}).then(data => {
  103. if(data.data.code=='1001'){
  104. // uni.redirectTo({
  105. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  106. // });
  107. };
  108. console.log(data);
  109. // 接口返回的当前页数据列表 (数组)
  110. let curPageData = data.data.data;
  111. console.log('curPageData',curPageData);
  112. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  113. let curPageLen = curPageData.length;
  114. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  115. // let totalPage = data.xxx;
  116. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  117. let totalSize = data.data.total;
  118. // 接口返回的是否有下一页 (true/false)
  119. // let hasNext = data.xxx;
  120. //设置列表数据
  121. if(page.num == 1) this.supplierlist = []; //如果是第一页需手动置空列表
  122. this.supplierlist = this.supplierlist.concat(curPageData); //追加新数据
  123. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  124. this.mescroll.endBySize(curPageLen, totalSize);
  125. // setTimeout(()=>{
  126. // this.mescroll.endSuccess(curPageLen)
  127. // },20)
  128. }).catch(err => {
  129. this.mescroll.endErr()
  130. console.log(err)
  131. });
  132. },
  133. //跳转详情
  134. supplierclick(id){
  135. console.log(id);
  136. uni.navigateTo({
  137. url:`/pages/supplier/supplierdetail/supplierdetail?id=${id}`
  138. })
  139. }
  140. }
  141. }
  142. </script>
  143. <style scoped>
  144. /* @import url("./supplier.css"); */
  145. .simplepage-wrap{padding-left: 24rpx;}
  146. .simplepage-item{padding: 24rpx 0;border-bottom: 1px solid #eee;}
  147. </style>