subject.vue 6.2 KB

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