index.vue 13 KB

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