index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <view class="pages index">
  3. <view class="search-wrap">
  4. <view class="search">
  5. <view class="searchTxt">
  6. <!-- <uni-search-bar @confirm="search" @input="search" ></uni-search-bar> -->
  7. <uni-search-bar @confirm="search" ></uni-search-bar>
  8. </view>
  9. </view>
  10. </view>
  11. <!-- 搜索 结束 -->
  12. <view class="appAdv nomal-bottom">
  13. <swiper class="swiper" @change="swiperchange" :indicator-dots="swiper.indicatorDots" :previous-margin="swiper.previousmargin" :next-margin="swiper.nextmargin" :autoplay="swiper.autoplay" :interval="swiper.interval" :duration="swiper.duration">
  14. <swiper-item v-for="(item,index) in advertiseList" :key="index">
  15. <view class="adv-item" :class="{active:index==currentswiper}" @click="jumLink(item.url)">
  16. <image :src="$getimg+item.pic|miniImg(75)+'/thumbnail/600x300'" class="pic" mode="scaleToFill"></image>
  17. </view>
  18. </swiper-item>
  19. </swiper>
  20. </view>
  21. <!-- 轮播结束 -->
  22. <view class="quick-links wrap write-radius nomal-bottom">
  23. <navigator class="quick-links-item" url="/pages/supplier/supplier">
  24. <view class="quick-links-item-til">供应商</view>
  25. <view class="quick-links-item-subtil">保供稳价</view>
  26. <view class="quick-links-item-img"><image src="/static/img/quick-links-04.png" mode="scaleToFill"></image></view>
  27. </navigator>
  28. <navigator class="quick-links-item" url="/pages/inbuild/inbuild">
  29. <view class="quick-links-item-til">产品溯源</view>
  30. <view class="quick-links-item-subtil">低价货源</view>
  31. <view class="quick-links-item-img"><image src="/static/img/quick-links-02.png" mode="scaleToFill"></image></view>
  32. </navigator>
  33. <navigator class="quick-links-item" url="/pages/inbuild/inbuild">
  34. <view class="quick-links-item-til">基地展示</view>
  35. <view class="quick-links-item-subtil">轻松卖货</view>
  36. <view class="quick-links-item-img"><image src="/static/img/quick-links-03.png" mode="scaleToFill"></image></view>
  37. </navigator>
  38. <navigator class="quick-links-item" url="/pages/inbuild/inbuild">
  39. <view class="quick-links-item-til">价格行情</view>
  40. <view class="quick-links-item-subtil">全国走货</view>
  41. <view class="quick-links-item-img"><image src="/static/img/quick-links-01.png" mode="scaleToFill"></image></view>
  42. </navigator>
  43. </view>
  44. <!-- 快速导航 结束 -->
  45. <view class="category nomal-bottom">
  46. <view class="category-item category-item-all" @click="category()" :class="{active:categoryall==true}">全部</view>
  47. <scroll-view scroll-x="true" class="scroll-X category-scroll-view">
  48. <view v-for="(item,index) in categorylink" :key="index" @click="categoryclick(index)" :class="{active:index==ins && notall==true}" class="category-item">{{item.name}}</view>
  49. </scroll-view>
  50. <navigator class="category-item category-item-more" url="/pages/productcategory/productcategory">更多</navigator>
  51. <!-- <navigator v-for="(item,index) in categorylink" :key="index" class="category-item" :url="'pages/searchresults/searchresults?type=' + item">{{item}}</navigator> -->
  52. </view>
  53. <!-- 分类链接结束 -->
  54. <mescroll-body class="wrap" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  55. <view class="indexproduct">
  56. <view class="item-wrap" v-for="(item,index) in mescrollList" :key="index">
  57. <view class="item" :data-id="item.id" @click="jumpDetails(item.id)">
  58. <view class="item-img-wrap">
  59. <image :src="$getimg+item.pic|miniImg(60)+'/thumbnail/358x354'||'/static/img/inbuild.png'" class="item-img" mode="aspectFit"></image>
  60. </view>
  61. <view class="item-text-wrap">
  62. <view class="merchant f-ellipsis">
  63. {{item.brandName}}
  64. <!-- <text v-if="item.postage" class="postage">包邮</text> -->
  65. </view>
  66. <view class="item-til f-ellipsis">{{item.name}}</view>
  67. <view class="item-addr f-ellipsis">{{item.umsCompanyInfo}}</view>
  68. <view class="item-price-info"><text class="rmb">¥</text><text class="price">{{item.price}}</text><text class="unit" v-if="item.unit">/{{item.unit}}</text></view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </mescroll-body>
  74. <!-- 商品展示结束 -->
  75. </view>
  76. </template>
  77. <script>
  78. // #ifdef H5
  79. import { mapMutations } from 'vuex';
  80. // #endif
  81. import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
  82. // 引入mescroll-mixins.js
  83. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  84. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  85. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  86. export default {
  87. mixins: [MescrollMixin], // 使用mixin
  88. components: {
  89. MescrollBody,
  90. uniSearchBar,
  91. },
  92. data() {
  93. return {
  94. params:{
  95. token:'',
  96. tokenhead:'',
  97. keyword:'',
  98. productCategoryId:'',
  99. // productCategoryName:'',
  100. },
  101. //轮播数据
  102. advertiseList:[],
  103. swiper: {
  104. indicatorDots: true,
  105. autoplay: false,
  106. interval: 9000,
  107. duration: 500,
  108. previousmargin:'55rpx',
  109. nextmargin:'55rpx'
  110. },
  111. currentswiper:0,
  112. categorylink:[],
  113. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  114. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  115. downOption: {
  116. // ...
  117. },
  118. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  119. upOption: {
  120. page: {
  121. size: 10 // 每页数据的数量,默认10
  122. },
  123. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  124. empty: {
  125. tip: '暂无相关数据'
  126. }
  127. },
  128. // 列表数据
  129. mescrollList:[],
  130. //category active
  131. ins:null,
  132. //category all
  133. categoryall:true,
  134. notall:false,
  135. thispage:'',
  136. }
  137. },
  138. onLoad() {
  139. let serf = this;
  140. //检查登录,获取token
  141. // let loginRes = this.checkLogin('/pages/index/index', '2');
  142. // if(!loginRes){return false;}
  143. // serf.params.token=loginRes[0];
  144. let locationLocaturl = window.location.search;
  145. function getUrlParams(url) {
  146. if (decodeURIComponent(url).indexOf('?') > -1) {
  147. var result = [];
  148. var urlParamsArr = decodeURIComponent(url).split('?');
  149. urlParamsArr.shift();
  150. let newUrlParamsArr = urlParamsArr.join('&').split('&');
  151. for (var i = 0; i < newUrlParamsArr.length; i++) {
  152. var paramKey = newUrlParamsArr[i].split('=')[0];
  153. var paramValue = newUrlParamsArr[i].split('=')[1];
  154. result.push({
  155. key: paramKey,
  156. value: paramValue
  157. });
  158. }
  159. return result;
  160. } else {
  161. console.log('该URL中不含参数');
  162. }
  163. };
  164. this.thispage = `/pages/index/index`;
  165. let locationArr = getUrlParams(locationLocaturl);
  166. if(!locationArr){
  167. window.location.replace(this.config.loginUrl);
  168. return
  169. };
  170. let itemtoken = locationArr.find(function(locationArr) {
  171. return locationArr.key === 'token';
  172. });
  173. let itemtokenHead = locationArr.find(function(locationArr) {
  174. return locationArr.key === 'tokenHead';
  175. });
  176. if (itemtoken) {
  177. this.params.token = itemtoken.value;
  178. }
  179. if (itemtokenHead) {
  180. this.params.tokenhead = itemtokenHead.value;
  181. }
  182. if(this.params.tokenhead&&this.params.token){
  183. let thetoken = this.params.tokenhead+this.params.token;
  184. this.$api.http.get(this.config.apiBaseurl+'/wechat/h5/info', {header: {Authorization:thetoken}}).then(res => {
  185. let userInfo = res.data;
  186. userInfo.accessToken = this.params.token;
  187. userInfo.tokenhead = this.params.tokenhead;
  188. this.setLogin(userInfo);
  189. }).catch(err => {
  190. if(err.data.message =='暂未登录或token已经过期'){
  191. let loginurl = `${this.config.apiBaseurl}/wechat/h5/authorize?returnUrl=${this.thispage}`
  192. console.log('loginurl',loginurl);
  193. window.location.replace(loginurl);
  194. return
  195. }
  196. console.log(err)
  197. });
  198. };
  199. //首页内容页信息展示
  200. this.$api.http.get(this.config.apiBaseurl+'/home/content', {header: {Authorization:this.params.tokenhead+this.params.token}}).then(res => {
  201. console.log('content',res)
  202. this.advertiseList = res.data.data.advertiseList;
  203. }).catch(err => {
  204. console.log(err)
  205. });
  206. //获取产品分类
  207. this.$api.http.get(this.config.apiBaseurl+'/product/categorySearch', {header: {Authorization:this.params.tokenhead+this.params.token}}).then(res => {
  208. console.log('产品分类',res)
  209. this.categorylink = res.data.data;
  210. }).catch(err => {
  211. console.log(err)
  212. });
  213. },
  214. onShow() {
  215. },
  216. methods: {
  217. // #ifdef H5
  218. ...mapMutations(['setLogin']),
  219. // #endif
  220. //搜索
  221. search(e) {
  222. console.log(e);
  223. // url:`/pages/searchresults/searchresults?id=${e}`,
  224. uni.navigateTo({
  225. url:`/pages/searchresults/searchresults?keyword=${e.value}`
  226. })
  227. },
  228. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  229. mescrollInit(mescroll) {
  230. this.mescroll = mescroll;
  231. },
  232. /*下拉刷新的回调, 有三种处理方式:*/
  233. downCallback(){
  234. // 第2种: 下拉刷新和上拉加载调同样的接口, 那么不用第1种方式, 直接mescroll.resetUpScroll()即可
  235. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  236. },
  237. /*上拉加载的回调*/
  238. upCallback(page) {
  239. let pageNum = page.num; // 页码, 默认从1开始
  240. let pageSize = page.size; // 页长, 默认每页10条
  241. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  242. this.$api.http.get(this.config.apiBaseurl+'/product/search',{params: this.params}).then(data => {
  243. if(data.data.code=='1001'){
  244. // uni.redirectTo({
  245. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  246. // });
  247. };
  248. console.log(data);
  249. // 接口返回的当前页数据列表 (数组)
  250. let curPageData = data.data.data.list;
  251. // console.log('curPageData',curPageData);
  252. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  253. let curPageLen = curPageData.length;
  254. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  255. let totalPage = data.data.data.totalPage;
  256. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  257. let totalSize = data.data.data.total;
  258. // this.mescrollList = curPageData;
  259. // 接口返回的是否有下一页 (true/false)
  260. // let hasNext = data.xxx;
  261. //设置列表数据
  262. if(page.num == 1) this.mescrollList = []; //如果是第一页需手动置空列表
  263. this.mescrollList = this.mescrollList.concat(curPageData); //追加新数据
  264. // console.log('page.num',page.num);
  265. console.log('this.mescrollList',JSON.parse(JSON.stringify(this.mescrollList)));
  266. // 请求成功,隐藏加载状态
  267. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  268. // this.mescroll.endByPage(curPageLen, totalPage);
  269. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  270. this.mescroll.endBySize(curPageLen, totalSize);
  271. console.log('pageSize',pageSize,'curPageLen',curPageLen,'totalSize',totalSize);
  272. // setTimeout(()=>{
  273. // this.mescroll.endSuccess(curPageLen)
  274. // },20)
  275. }).catch(err => {
  276. this.mescroll.endErr()
  277. console.log(err)
  278. });
  279. },
  280. //分类点击
  281. categoryclick(num){
  282. this.categoryall = false;
  283. this.notall = true;
  284. this.ins=num;
  285. this.nowtype = this.categorylink[num].name;
  286. // console.log(this.categorylink[this.ins]);
  287. this.params.productCategoryId = this.categorylink[this.ins].id;
  288. // this.params.productCategoryName = this.categorylink[this.ins].productCategoryName;
  289. console.log('this.params',this.params);
  290. this.downCallback();
  291. },
  292. //全部分类点击
  293. category(){
  294. this.categoryall = true;
  295. this.notall = false;
  296. this.params.productCategoryId = '';
  297. this.downCallback();
  298. },
  299. //轮播链接跳转
  300. jumLink(url){
  301. function handleBrowsingItemLink(link){
  302. const browsingItemLinkHttp = link.substr(0, 7).toLowerCase();
  303. const browsingItemLinkHttps = link.substr(0, 8).toLowerCase();
  304. if (browsingItemLinkHttp === "http://" || browsingItemLinkHttps === "https://") {
  305. return link
  306. }
  307. return `http://${link}`
  308. }
  309. url = handleBrowsingItemLink(url);
  310. if(!url){uni.showToast({
  311. title:'地址无效'
  312. })}
  313. window.location.assign(url);
  314. // uni.navigateTo({
  315. // url:`/pages/product/product?id=${id}`,
  316. // fail(err) {
  317. // console.log(err)
  318. // }
  319. // })
  320. },
  321. //产品跳转链接
  322. jumpDetails(id){
  323. uni.navigateTo({
  324. url:`/pages/product/product?id=${id}`,
  325. fail(err) {
  326. console.log(err)
  327. }
  328. })
  329. },
  330. //swiperchange
  331. swiperchange(e){
  332. this.currentswiper = e.detail.current;
  333. }
  334. }
  335. }
  336. </script>
  337. <style scoped>
  338. @import url("./index.css");
  339. </style>