123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <template>
- <view class="pages">
- <view class="supplier-page translate open" >
- <view class="search-wrap search-left-color">
- <view class="search">
- <view class="searchTxt">
- <uni-search-bar placeholder="搜索供应商关键词" @confirm="searchsupplier" @input="searchsupplier" ></uni-search-bar>
- </view>
- </view>
- </view>
- <!-- 搜索 结束 -->
- <view class="simplepage-wrap">
- <mescroll-body ref="mescrollRef0" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
- <view>
- <view v-for="(item,index) in supplierlist" :key="index" @click="supplierclick(item.id)" class="simplepage-item">{{item.compName}}</view>
- </view>
- </mescroll-body>
- </view>
- </view>
- <!-- 供应商结束 -->
- </view>
- </template>
- <script>
- // 引入mescroll-mixins.js
- import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
- // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
- import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
-
- import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
- export default {
- mixins: [MescrollMixin], // 使用mixin
- components: {
- MescrollBody,
- uniSearchBar,
-
-
- },
- data() {
- return {
- params:{
- token:'',
- tokenhead:'',
- key:'',
- },
- supplierlist:[],
- mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
- // 下拉刷新的配置(可选, 绝大部分情况无需配置)
- downOption: {
- // ...
- },
- // 上拉加载的配置(可选, 绝大部分情况无需配置)
- upOption: {
- page: {
- size: 10 // 每页数据的数量,默认10
- },
- noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
- empty: {
- tip: '暂无相关数据'
- }
- },
-
- }
- },
- onShow() {
- let self = this;
- //检查登录,获取token
- // let loginRes = this.checkLogin('/pages/index/index', '2');
- // if(!loginRes){return false;}
- // serf.params.token=loginRes[0];
- uni.getStorage({
- key:'token',
- success: function (res) {
- self.params.token = res.data;
- // console.log(res.data);
- }
- });
- uni.getStorage({
- key:'tokenhead',
- success: function (res) {
- self.params.tokenhead = res.data;
- // console.log(res.data);
- }
- });
- },
- onLoad() {
-
- },
- methods: {
- searchsupplier(e){
- console.log(e);
- this.params.key = e.value;
- this.mescroll.resetUpScroll();
- },
- /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
- mescrollInit(mescroll) {
- this.mescroll = mescroll;
- },
- downCallback(){
- this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
- },
- /*上拉加载的回调*/
- upCallback(page) {
- let pageNum = page.num; // 页码, 默认从1开始
- let pageSize = page.size; // 页长, 默认每页10条
- this.params = Object.assign(this.params,{page:pageNum,rows:pageSize});
- let thetoken = this.params.tokenhead+this.params.token;
- this.$api.http.get(this.config.apiBaseurl+'/company/cp/search',{header: {Authorization:thetoken},params:{key:this.params.key}}).then(data => {
- if(data.data.code=='1001'){
- // uni.redirectTo({
- // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
- // });
- };
- console.log(data);
- // 接口返回的当前页数据列表 (数组)
- let curPageData = data.data.data;
- console.log('curPageData',curPageData);
- // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
- let curPageLen = curPageData.length;
- // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
- // let totalPage = data.xxx;
- // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
- let totalSize = data.data.total;
- // 接口返回的是否有下一页 (true/false)
- // let hasNext = data.xxx;
-
- //设置列表数据
- if(page.num == 1) this.supplierlist = []; //如果是第一页需手动置空列表
- this.supplierlist = this.supplierlist.concat(curPageData); //追加新数据
-
- //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
- this.mescroll.endBySize(curPageLen, totalSize);
-
- // setTimeout(()=>{
- // this.mescroll.endSuccess(curPageLen)
- // },20)
-
- }).catch(err => {
- this.mescroll.endErr()
- console.log(err)
-
- });
- },
- //跳转详情
- supplierclick(id){
- console.log(id);
- uni.navigateTo({
- url:`/pages/supplier/supplierdetail/supplierdetail?id=${id}`
- })
- }
- }
- }
- </script>
- <style scoped>
- /* @import url("./supplier.css"); */
- .simplepage-wrap{padding-left: 24rpx;}
- .simplepage-item{padding: 24rpx 0;border-bottom: 1px solid #eee;}
- </style>
|