searchresults.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="pages">
  3. <view class="search-wrap nomal-bottom">
  4. <view class="search">
  5. <view class="searchTxt">
  6. <uni-search-bar :placeholder="searchtxt" @confirm="search" @input="search" ></uni-search-bar>
  7. </view>
  8. </view>
  9. </view>
  10. <!-- 搜索 结束 -->
  11. <mescroll-body class="wrap" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  12. <view class="results write-radius">
  13. <view v-for="(item,index) in dataList" :key="index" @click="productdetails(item.id)" class="results-item">
  14. <view class="results-item-img-wrap"><image :src="$getimg+item.pic|miniImg(50)+'/thumbnail/358x358'" mode="scaleToFill" class="results-item-img"></image></view>
  15. <view class="results-item-info">
  16. <view class="results-item-info-til">{{item.name}}</view>
  17. <view class="results-item-info-brand">{{item.brandName}}</view>
  18. <!-- <view class="results-item-info-addr">{{item.placeOfProduction}}</view> -->
  19. <view class="results-item-info-label">
  20. <text v-if="item.postage" class="postage">包邮</text>
  21. </view>
  22. <view class="item-spec f-ellipsis">
  23. <text>规格:</text><text>{{item.spec}}</text>
  24. </view>
  25. <view class="results-item-info-company f-ellipsis">{{item.compName}}</view>
  26. <view class="results-item-info-price">
  27. <text class="rmb">¥</text>
  28. <text class="price">{{item.price}}</text>
  29. <text class="unit">/{{item.unit}}</text>
  30. <!-- <text class="minsell">4000斤起售</text> -->
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </mescroll-body>
  36. </view>
  37. </template>
  38. <script>
  39. // 引入mescroll-mixins.js
  40. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  41. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  42. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  43. import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
  44. export default {
  45. mixins: [MescrollMixin], // 使用mixin
  46. components: {
  47. MescrollBody,
  48. uniSearchBar,
  49. },
  50. data() {
  51. return {
  52. searchtxt:'产品名称',
  53. params:{
  54. token:'',
  55. keyword:'',
  56. productCategoryId:'',
  57. },
  58. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  59. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  60. downOption: {
  61. // ...
  62. },
  63. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  64. upOption: {
  65. page: {
  66. size: 10 // 每页数据的数量,默认10
  67. },
  68. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  69. empty: {
  70. tip: '暂无相关数据'
  71. }
  72. },
  73. // 列表数据
  74. dataList:[],
  75. }
  76. },
  77. onShow() {
  78. let serf = this;
  79. //检查登录,获取token
  80. // let loginRes = this.checkLogin('/pages/index/index', '2');
  81. // if(!loginRes){return false;}
  82. // serf.params.token=loginRes[0];
  83. },
  84. onLoad(option) {
  85. if(option.productCategoryId){
  86. this.params.productCategoryId = option.productCategoryId;
  87. this.searchtxt = option.name;
  88. }
  89. if(option.keyword){
  90. this.params.keyword = option.keyword;
  91. this.searchtxt = option.keyword;
  92. }
  93. // console.log(this.params.keyword);
  94. },
  95. methods: {
  96. //搜索
  97. search(e) {
  98. console.log(e);
  99. this.params.keyword = e.value;
  100. this.params.productCategoryId = '';
  101. this.searchtxt = e.value;
  102. this.downCallback();
  103. // this.poorList = [];
  104. // this.params.farmerName = e.value;
  105. // this.pagination = Object.assign(this.pagination,{"farmerName":e.value});
  106. // this.pagination.pageNo = 1;
  107. // this.getPoorList(this.pagination)
  108. },
  109. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  110. mescrollInit(mescroll) {
  111. this.mescroll = mescroll;
  112. },
  113. downCallback(){
  114. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  115. },
  116. /*上拉加载的回调*/
  117. upCallback(page) {
  118. let pageNum = page.num; // 页码, 默认从1开始
  119. let pageSize = page.size; // 页长, 默认每页10条
  120. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  121. this.$api.http.get(this.config.apiBaseurl+'/product/search',{params: this.params}).then(data => {
  122. if(data.data.code=='1001'){
  123. // uni.redirectTo({
  124. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  125. // });
  126. };
  127. console.log('data',JSON.parse(JSON.stringify(data)));
  128. // 接口返回的当前页数据列表 (数组)
  129. let curPageData = data.data.data.list;
  130. console.log('curPageData',JSON.parse(JSON.stringify(curPageData)));
  131. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  132. let curPageLen = curPageData.length;
  133. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  134. let totalPage = data.data.data.totalPage;
  135. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  136. let totalSize = data.data.data.total;
  137. // 接口返回的是否有下一页 (true/false)
  138. // let hasNext = data.xxx;
  139. console.log('totalPage',totalPage,'curPageLen',curPageLen);
  140. //设置列表数据
  141. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  142. this.dataList = this.dataList.concat(curPageData); //追加新数据
  143. // 请求成功,隐藏加载状态
  144. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  145. this.mescroll.endByPage(curPageLen, totalPage);
  146. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  147. // this.mescroll.endBySize(curPageLen, totalSize);
  148. // setTimeout(()=>{
  149. // this.mescroll.endSuccess(curPageLen)
  150. // },20)
  151. }).catch(err => {
  152. this.mescroll.endErr()
  153. console.log(err)
  154. });
  155. },
  156. //跳转详情
  157. productdetails(id){
  158. uni.navigateTo({
  159. url:`/pages/product/product?id=${id}`
  160. })
  161. },
  162. }
  163. }
  164. </script>
  165. <style scoped>
  166. @import url("./searchresults.css");
  167. </style>