productList.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="pages producttype-wrap">
  3. <view class="producttype">
  4. <view class="producttype-nav">
  5. <view v-for="(item,index) in navitem" :key="index" @click="typeclick(index)" :class="{active:index==ins}" class="producttype-nav-item">{{ item.typeName }}</view>
  6. </view>
  7. <view class="producttype-con">
  8. <view class="search">
  9. <view class="searchTxt">
  10. <uni-search-bar :placeholder="searchtxt" @confirm="search" v-model="searchtxt" @input="search" ></uni-search-bar>
  11. </view>
  12. </view>
  13. <!-- 搜索 结束 -->
  14. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :bottom="0" :down="downOption" :up="upOption">
  15. <!-- <view class="product-wrap"> -->
  16. <view v-for="(item,index) in productlist" :key="index" @click="productclick(item.guid)" class="product-item">
  17. <image class="product-item-img" :src="$onlineImg+item.goodsImages | firstImg" mode="scaleToFill"></image>
  18. <view class="product-item-info">
  19. <view class="product-item-til">{{item.goodsName}}</view>
  20. <view class="product-item-code">编号:{{item.goodsCode}}</view>
  21. <view class="product-item-price"><text class="rmb">¥</text> <text class="price">{{item.price}}</text> / KG</view>
  22. </view>
  23. </view>
  24. <!-- </view> -->
  25. </mescroll-body>
  26. </view>
  27. <!-- producttype-con end -->
  28. </view>
  29. <!-- fix-content end -->
  30. </view>
  31. </template>
  32. <script>
  33. // 引入mescroll-mixins.js
  34. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  35. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  36. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  37. import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
  38. export default {
  39. mixins: [MescrollMixin], // 使用mixin
  40. components: {
  41. MescrollBody,
  42. uniSearchBar,
  43. },
  44. data() {
  45. return {
  46. $onlineImg:this.$onlineImg,
  47. useoption:true,
  48. token:'',
  49. params:{
  50. queryStr:'',
  51. productTypeGuid:''
  52. },
  53. searchtxt:'产品名称',
  54. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  55. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  56. downOption: {
  57. // ...
  58. },
  59. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  60. upOption: {
  61. page: {
  62. size: 10 // 每页数据的数量,默认10
  63. },
  64. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  65. empty: {
  66. tip: '暂无相关数据'
  67. }
  68. },
  69. //nav active
  70. ins:0,
  71. //菜单类别
  72. navitem:[],
  73. //热门列表
  74. // hotlist:[
  75. // ],
  76. //productlist
  77. productlist:[],
  78. //显示的分类标题
  79. nowtype:'',
  80. }
  81. },
  82. onShow() {
  83. },
  84. onLoad(option) {
  85. console.log('option',option);
  86. this.token = this.$store.state.token;
  87. this.nowtype = this.navitem[this.ins];
  88. this.params.queryStr = this.nowtype;
  89. if(option.search){
  90. this.nowtype = option.search;
  91. this.searchtxt = option.search;
  92. }
  93. //获取产品分类
  94. this.$api.http.post(this.config.apiBaseurl + '/carbon-h5/wap/goods/getGoodsTypeList',{},{
  95. header: {
  96. Accept:'application/json',
  97. Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  98. },
  99. }).then(res => {
  100. // console.log('产品分类',res);
  101. this.navitem = res.data.retBody;
  102. // console.log('this.navitem',this.navitem);
  103. this.nowtype = this.navitem[this.ins].typeName;
  104. this.params.productTypeGuid = this.navitem[this.ins].guid;
  105. // this.searchtxt = this.navitem[this.ins].typeName;
  106. if(this.useoption&&option.search){
  107. this.params.productTypeGuid = '';
  108. this.params.queryStr = option.search;
  109. this.searchtxt = option.search;
  110. this.ins = null;
  111. }
  112. this.downCallback();
  113. }).then(()=>{
  114. this.useoption = false;
  115. this.params.queryStr = '';
  116. }).catch(err => {
  117. console.log(err)
  118. });
  119. },
  120. methods: {
  121. //搜索
  122. search(e) {
  123. this.params.queryStr = e.value;
  124. this.params.productTypeGuid = '';
  125. this.downCallback();
  126. this.searchtxt = this.params.queryStr||'产品名称';
  127. this.ins = null;
  128. // this.poorList = [];
  129. // this.params.farmerName = e.value;
  130. // this.pagination = Object.assign(this.pagination,{"farmerName":e.value});
  131. // this.pagination.pageNo = 1;
  132. // this.getPoorList(this.pagination)
  133. },
  134. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  135. mescrollInit(mescroll) {
  136. this.mescroll = mescroll;
  137. },
  138. downCallback(){
  139. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  140. },
  141. /*上拉加载的回调*/
  142. upCallback(page) {
  143. let pageNum = page.num; // 页码, 默认从1开始
  144. let pageSize = page.size; // 页长, 默认每页10条
  145. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  146. // console.log('this.params',this.params);
  147. this.$api.http.post(this.config.apiBaseurl + '/carbon-h5/wap/goodsManage/searchByPage',this.params,{
  148. header: {
  149. Accept:'application/json',
  150. Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  151. },
  152. }).then(data => {
  153. if(data.data.code=='1001'){
  154. // uni.redirectTo({
  155. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  156. // });
  157. };
  158. // console.log(data);
  159. // 接口返回的当前页数据列表 (数组)
  160. let curPageData = data.data.retBody;
  161. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  162. let curPageLen = curPageData.length;
  163. this.productlist = curPageData;
  164. console.log('this.productlist',this.productlist);
  165. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  166. // let totalPage = data.xxx;
  167. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  168. let totalSize = data.data.retHead.total;
  169. // 接口返回的是否有下一页 (true/false)
  170. // let hasNext = data.xxx;
  171. //设置列表数据
  172. if(page.num == 1) this.productlist = []; //如果是第一页需手动置空列表
  173. this.productlist = this.productlist.concat(curPageData); //追加新数据
  174. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  175. this.mescroll.endBySize(curPageLen, totalSize);
  176. // setTimeout(()=>{
  177. // this.mescroll.endSuccess(curPageLen)
  178. // },20)
  179. }).catch(err => {
  180. this.mescroll.endErr()
  181. console.log(err)
  182. });
  183. },
  184. //左侧导航点击
  185. typeclick(num){
  186. this.ins=num;
  187. this.nowtype = this.navitem[num].typeName;
  188. // this.params.queryStr = this.nowtype;
  189. this.params.productTypeGuid = this.navitem[this.ins].guid;
  190. // console.table({'this.nowtype':this.nowtype,'this.params.queryStr':this.params.queryStr})
  191. this.downCallback();
  192. // this.searchtxt = this.navitem[num].typeName;
  193. },
  194. //产品点击
  195. productclick(id){
  196. uni.navigateTo({
  197. url:`/pages/product/product?guid=${id}`,
  198. })
  199. },
  200. }
  201. }
  202. </script>
  203. <style scoped>
  204. @import url("./productList.css");
  205. </style>