index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <view class="pages index">
  3. <!-- <u-notice-bar mode="vertical" type="success" bg-color="#fdf6ec" color="#feaa36" :list="rollbuylist"></u-notice-bar> -->
  4. <view class="search-wrap">
  5. <view class="search">
  6. <view class="searchTxt">
  7. <!-- <uni-search-bar @confirm="search" @input="search" ></uni-search-bar> -->
  8. <uni-search-bar @confirm="search" ></uni-search-bar>
  9. </view>
  10. </view>
  11. </view>
  12. <!-- 搜索 结束 -->
  13. <view class="appAdv nomal-bottom">
  14. <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">
  15. <swiper-item v-for="(item,index) in advertiseList" :key="index">
  16. <view class="adv-item" :class="{active:index==currentswiper}" @click="jumLink(item.url)">
  17. <image :src="$getimg+item.pic|miniImg(75)+'/thumbnail/600x300'" class="pic" mode="scaleToFill"></image>
  18. </view>
  19. </swiper-item>
  20. </swiper>
  21. <view class="rollbuy" v-if="rollbuytext">{{rollbuytext}}</view>
  22. </view>
  23. <!-- 轮播结束 -->
  24. <!-- <view class="quick-links wrap write-radius nomal-bottom">
  25. <navigator class="quick-links-item" url="/pages/supplier/supplier">
  26. <view class="quick-links-item-til">供应商</view>
  27. <view class="quick-links-item-subtil">保供稳价</view>
  28. <view class="quick-links-item-img"><image src="/static/img/quick-links-04.png" mode="scaleToFill"></image></view>
  29. </navigator>
  30. <navigator class="quick-links-item" url="/pages/inbuild/inbuild">
  31. <view class="quick-links-item-til">产品溯源</view>
  32. <view class="quick-links-item-subtil">低价货源</view>
  33. <view class="quick-links-item-img"><image src="/static/img/quick-links-02.png" mode="scaleToFill"></image></view>
  34. </navigator>
  35. <navigator class="quick-links-item" url="/pages/inbuild/inbuild">
  36. <view class="quick-links-item-til">基地展示</view>
  37. <view class="quick-links-item-subtil">轻松卖货</view>
  38. <view class="quick-links-item-img"><image src="/static/img/quick-links-03.png" mode="scaleToFill"></image></view>
  39. </navigator>
  40. <navigator class="quick-links-item" url="/pages/inbuild/inbuild">
  41. <view class="quick-links-item-til">价格行情</view>
  42. <view class="quick-links-item-subtil">全国走货</view>
  43. <view class="quick-links-item-img"><image src="/static/img/quick-links-01.png" mode="scaleToFill"></image></view>
  44. </navigator>
  45. </view> -->
  46. <view class="subject">
  47. <view class="subject-item" v-for="(item,index) in subjectList" @click="gosubject(item.id,item.title)">
  48. <view class="subject-item-img"><image :src="item.pic" class="img" mode="scaleToFill"></image></view>
  49. <view class="subject-item-til">{{item.title}}</view>
  50. </view>
  51. </view>
  52. <!-- 快速导航 结束 -->
  53. <view class="main-body wrap24">
  54. <view class="main-body-til noborder color">
  55. <view class="til">供应商</view>
  56. <view class="con">
  57. <navigator class="quick-links-item" url="/pages/supplier/supplier">
  58. 更多&gt;
  59. </navigator>
  60. </view>
  61. </view>
  62. <scroll-view class="supplier-list" scroll-x="true">
  63. <view class="" style="padding: 0 16rpx 24rpx;">
  64. <view class="suppliers">
  65. <view class="supplier-list-item" v-for="(item,index) in supplierList" :key="item.id" @click="supplierclick(item.id)" >
  66. <view class="supplier-list-item-img">
  67. <image v-if="item.files[0]" :src="item.files[0].fileUrl ||'/static/img/defaultsupplierlogo.png'" class="img" mode="aspectFit"></image>
  68. <image v-else src="/static/img/defaultsupplierlogo.png" class="img" mode="scaleToFill"></image>
  69. </view>
  70. <view class="supplier-list-item-til">{{item.compName}}</view>
  71. </view>
  72. </view>
  73. </view>
  74. </scroll-view>
  75. </view>
  76. <!-- 供应商结束 -->
  77. <view class="category nomal-bottom">
  78. <view class="category-item category-item-all" @click="category()" :class="{active:categoryall==true}">全部</view>
  79. <scroll-view scroll-x="true" class="scroll-X category-scroll-view">
  80. <view v-for="(item,index) in categorylink" :key="index" @click="categoryclick(index)" :class="{active:index==ins && notall==true}" class="category-item">{{item.name}}</view>
  81. </scroll-view>
  82. <navigator class="category-item category-item-more" url="/pages/productcategory/productcategory">更多&gt;</navigator>
  83. <!-- <navigator v-for="(item,index) in categorylink" :key="index" class="category-item" :url="'pages/searchresults/searchresults?type=' + item">{{item}}</navigator> -->
  84. </view>
  85. <!-- 分类链接结束 -->
  86. <mescroll-body class="wrap" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  87. <view class="indexproduct">
  88. <view class="item-wrap" v-for="(item,index) in mescrollList" :key="index">
  89. <view class="item" :data-id="item.id" @click="jumpDetails(item.id)">
  90. <view class="item-img-wrap">
  91. <image :src="$getimg+item.pic|miniImg(50)+'/thumbnail/358x354'||'/static/img/inbuild.png'" class="item-img cover-img" mode="scaleToFill"></image>
  92. </view>
  93. <view class="item-text-wrap">
  94. <view class="merchant f-ellipsis">
  95. {{item.brandName}}
  96. <!-- <text v-if="item.postage" class="postage">包邮</text> -->
  97. </view>
  98. <view class="item-til f-ellipsis">{{item.name}}</view>
  99. <view class="item-addr f-ellipsis">{{item.umsCompanyInfo}}</view>
  100. <view class="item-price-info">
  101. <text class="rmb" v-if="item.price">¥</text>
  102. <text class="price" :class="!item.price?'noprice':''">{{item.price||"暂无价格"}}</text>
  103. <text class="unit" v-if="item.unit">/{{item.unit}}</text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </mescroll-body>
  110. <!-- 商品展示结束 -->
  111. <uni-popup ref="promotionPopup" type="center">
  112. <view class="promotion" v-if="promotion.pic">
  113. <image class="image" :src="promotion.pic" mode="aspectFit" @click="jumLink(promotion.url)"></image>
  114. <view class="close-wrap">
  115. <!-- <text class="iconfont iconjiahao close" @click="closePromotion()"></text> -->
  116. <image src="../../static/img/close.png" class="imgclose" mode="scaleToFill" @click="closePromotion()"></image>
  117. </view>
  118. </view>
  119. </uni-popup>
  120. </view>
  121. </template>
  122. <script>
  123. // #ifdef H5
  124. import { mapMutations } from 'vuex';
  125. // #endif
  126. import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
  127. // 引入mescroll-mixins.js
  128. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  129. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  130. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  131. // import uNoticeBar from '@/components/u-notice-bar/u-notice-bar.vue'
  132. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  133. import { debounce } from '@/utils/util.js'
  134. let timer = null;
  135. export default {
  136. mixins: [MescrollMixin], // 使用mixin
  137. components: {
  138. MescrollBody,
  139. uniSearchBar,
  140. // uNoticeBar,
  141. uniPopup
  142. },
  143. data() {
  144. return {
  145. params:{
  146. token:'',
  147. tokenhead:'',
  148. keyword:'',
  149. productCategoryId:'',
  150. // productCategoryName:'',
  151. },
  152. rollbuylist:[],
  153. //轮播数据
  154. advertiseList:[],
  155. swiper: {
  156. indicatorDots: true,
  157. autoplay: false,
  158. interval: 9000,
  159. duration: 500,
  160. previousmargin:'55rpx',
  161. nextmargin:'55rpx'
  162. },
  163. currentswiper:0,
  164. categorylink:[],
  165. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  166. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  167. downOption: {
  168. // ...
  169. },
  170. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  171. upOption: {
  172. page: {
  173. size: 10 // 每页数据的数量,默认10
  174. },
  175. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  176. empty: {
  177. tip: '暂无相关数据'
  178. }
  179. },
  180. // 列表数据
  181. mescrollList:[],
  182. //category active
  183. ins:null,
  184. //category all
  185. categoryall:true,
  186. notall:false,
  187. thispage:'',
  188. //专题列表
  189. subjectList:[],
  190. //推广弹窗
  191. promotion:new Object(),
  192. supplierList:[],
  193. supplierparams:Object.assign({},{pageNum:1,pageSize:5}),
  194. buylistparams:Object.assign({},{pageNum:1,pageSize:100}),
  195. rollbuytext:'',//购买弹出的内容
  196. }
  197. },
  198. onLoad() {
  199. let serf = this;
  200. //检查登录,获取token
  201. // let loginRes = this.checkLogin('/pages/index/index', '2');
  202. // if(!loginRes){return false;}
  203. // serf.params.token=loginRes[0];
  204. let locationLocaturl = window.location.search;
  205. function getUrlParams(url) {
  206. if (decodeURIComponent(url).indexOf('?') > -1) {
  207. var result = [];
  208. var urlParamsArr = decodeURIComponent(url).split('?');
  209. urlParamsArr.shift();
  210. let newUrlParamsArr = urlParamsArr.join('&').split('&');
  211. for (var i = 0; i < newUrlParamsArr.length; i++) {
  212. var paramKey = newUrlParamsArr[i].split('=')[0];
  213. var paramValue = newUrlParamsArr[i].split('=')[1];
  214. result.push({
  215. key: paramKey,
  216. value: paramValue
  217. });
  218. }
  219. return result;
  220. } else {
  221. console.log('该URL中不含参数');
  222. }
  223. };
  224. this.thispage = `/pages/index/index`;
  225. let locationArr = getUrlParams(locationLocaturl);
  226. if(!locationArr){
  227. window.location.replace(this.config.loginUrl);
  228. return
  229. };
  230. let itemtoken = locationArr.find(function(locationArr) {
  231. return locationArr.key === 'token';
  232. });
  233. let itemtokenHead = locationArr.find(function(locationArr) {
  234. return locationArr.key === 'tokenHead';
  235. });
  236. if (itemtoken) {
  237. this.params.token = itemtoken.value;
  238. }
  239. if (itemtokenHead) {
  240. this.params.tokenhead = itemtokenHead.value;
  241. }
  242. if(this.params.tokenhead&&this.params.token){
  243. let thetoken = this.params.tokenhead+this.params.token;
  244. this.$api.http.get(this.config.apiBaseurl+'/wechat/h5/info', {header: {Authorization:thetoken}}).then(res => {
  245. let userInfo = res.data;
  246. userInfo.accessToken = this.params.token;
  247. userInfo.tokenhead = this.params.tokenhead;
  248. this.setLogin(userInfo);
  249. }).then(res =>{
  250. //产品跳转
  251. uni.getStorage({
  252. key:'productID',
  253. success: res => {
  254. console.log('productID',res.data);
  255. this.jumpDetails(res.data);
  256. uni.removeStorage({
  257. key:'productID'
  258. });
  259. }
  260. });
  261. //产品跳转
  262. }).catch(err => {
  263. if(err.data.message =='暂未登录或token已经过期'){
  264. let loginurl = `${this.config.apiBaseurl}/wechat/h5/authorize?returnUrl=${this.thispage}`
  265. console.log('loginurl',loginurl);
  266. window.location.replace(loginurl);
  267. return
  268. }
  269. console.log(err)
  270. });
  271. };
  272. //首页内容页信息展示
  273. this.$api.http.get(this.config.apiBaseurl+'/home/content', {header: {Authorization:this.params.tokenhead+this.params.token}}).then(res => {
  274. console.log('content',res)
  275. this.advertiseList = res.data.data.advertiseList;
  276. }).catch(err => {
  277. console.log(err)
  278. });
  279. //获取产品分类
  280. this.$api.http.get(this.config.apiBaseurl+'/product/categorySearch', {header: {Authorization:this.params.tokenhead+this.params.token}}).then(res => {
  281. console.log('产品分类',res)
  282. this.categorylink = res.data.data;
  283. }).catch(err => {
  284. console.log(err)
  285. });
  286. //首页内容页信息展示
  287. this.gethomecontent();
  288. //供应商列表
  289. // this.getsupplierlist()
  290. },
  291. mounted() {
  292. },
  293. onShow() {
  294. this.getrollbuylist();//获取购买滚动信息
  295. },
  296. onHide() {
  297. clearInterval(timer);
  298. },
  299. methods: {
  300. // #ifdef H5
  301. ...mapMutations(['setLogin']),
  302. // #endif
  303. //搜索
  304. search(e) {
  305. console.log(e);
  306. // url:`/pages/searchresults/searchresults?id=${e}`,
  307. uni.navigateTo({
  308. url:`/pages/searchresults/searchresults?keyword=${e.value}`
  309. })
  310. },
  311. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  312. mescrollInit(mescroll) {
  313. this.mescroll = mescroll;
  314. },
  315. /*下拉刷新的回调, 有三种处理方式:*/
  316. downCallback(){
  317. // 第2种: 下拉刷新和上拉加载调同样的接口, 那么不用第1种方式, 直接mescroll.resetUpScroll()即可
  318. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  319. },
  320. /*上拉加载的回调*/
  321. upCallback(page) {
  322. let pageNum = page.num; // 页码, 默认从1开始
  323. let pageSize = page.size; // 页长, 默认每页10条
  324. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  325. this.$api.http.get(this.config.apiBaseurl+'/product/search',{params: this.params}).then(data => {
  326. if(data.data.code=='1001'){
  327. // uni.redirectTo({
  328. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  329. // });
  330. };
  331. // console.log(data);
  332. // 接口返回的当前页数据列表 (数组)
  333. let curPageData = data.data.data.list;
  334. // console.log('curPageData',curPageData);
  335. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  336. let curPageLen = curPageData.length;
  337. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  338. let totalPage = data.data.data.totalPage;
  339. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  340. let totalSize = data.data.data.total;
  341. // this.mescrollList = curPageData;
  342. // 接口返回的是否有下一页 (true/false)
  343. // let hasNext = data.xxx;
  344. //设置列表数据
  345. if(page.num == 1) this.mescrollList = []; //如果是第一页需手动置空列表
  346. this.mescrollList = this.mescrollList.concat(curPageData); //追加新数据
  347. // console.log('page.num',page.num);
  348. console.log('this.mescrollList',JSON.parse(JSON.stringify(this.mescrollList)));
  349. // 请求成功,隐藏加载状态
  350. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  351. // this.mescroll.endByPage(curPageLen, totalPage);
  352. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  353. this.mescroll.endBySize(curPageLen, totalSize);
  354. console.log('pageSize',pageSize,'curPageLen',curPageLen,'totalSize',totalSize);
  355. // setTimeout(()=>{
  356. // this.mescroll.endSuccess(curPageLen)
  357. // },20)
  358. }).catch(err => {
  359. this.mescroll.endErr()
  360. console.log(err)
  361. });
  362. },
  363. //分类点击
  364. categoryclick(num){
  365. this.categoryall = false;
  366. this.notall = true;
  367. this.ins=num;
  368. this.nowtype = this.categorylink[num].name;
  369. // console.log(this.categorylink[this.ins]);
  370. this.params.productCategoryId = this.categorylink[this.ins].id;
  371. // this.params.productCategoryName = this.categorylink[this.ins].productCategoryName;
  372. console.log('this.params',this.params);
  373. this.downCallback();
  374. },
  375. //全部分类点击
  376. category(){
  377. this.categoryall = true;
  378. this.notall = false;
  379. this.params.productCategoryId = '';
  380. this.downCallback();
  381. },
  382. //轮播链接跳转
  383. jumLink(url){
  384. function handleBrowsingItemLink(link){
  385. const browsingItemLinkHttp = link.substr(0, 7).toLowerCase();
  386. const browsingItemLinkHttps = link.substr(0, 8).toLowerCase();
  387. if (browsingItemLinkHttp === "http://" || browsingItemLinkHttps === "https://") {
  388. return link
  389. }
  390. return `http://${link}`
  391. }
  392. url = handleBrowsingItemLink(url);
  393. if(!url){uni.showToast({
  394. title:'地址无效'
  395. })}
  396. window.location.assign(url);
  397. // uni.navigateTo({
  398. // url:`/pages/product/product?id=${id}`,
  399. // fail(err) {
  400. // console.log(err)
  401. // }
  402. // })
  403. },
  404. //产品跳转链接
  405. jumpDetails(id){
  406. uni.navigateTo({
  407. url:`/pages/product/product?id=${id}`,
  408. fail(err) {
  409. console.log(err)
  410. }
  411. })
  412. },
  413. //swiperchange
  414. swiperchange(e){
  415. this.currentswiper = e.detail.current;
  416. },
  417. //获取购买滚动信息
  418. getrollbuylist(){
  419. this.$api.http.get(this.config.apiBaseurl+'/home/roll-buy', {header: {Authorization:this.params.tokenhead+this.params.token},params: this.buylistparams}).then(res => {
  420. // console.log('getrollbuylist',res.data.data.list);
  421. let list = res.data.data.list;
  422. this.rollbuylist = [];
  423. for(let item in list){
  424. // console.log('item',list[item])
  425. // this.rollbuylist.push(list[item].memberName.replace(/.(?=.)/g, '*')+' 购买了 '+list[item].productName+' 价值 '+list[item].money+'元');
  426. this.rollbuylist.push(list[item].memberName.replace(/.(?=.)/g, '*')+' 购买了 '+list[item].productName);
  427. }
  428. this.showbuy();
  429. // console.log('this.rollbuylist',this.rollbuylist)
  430. // this.rollbuylist = res.data.data.rollbuylist;
  431. }).catch(err => {
  432. console.log(err)
  433. });
  434. },
  435. showbuy(){
  436. // console.log('this.rollbuylist',this.rollbuylist);
  437. let self = this;
  438. var i = 0;
  439. timer = setInterval(function(){
  440. // console.log(self.rollbuylist[i]);
  441. self.rollbuytext = self.rollbuylist[i];
  442. setTimeout(function(){self.rollbuytext = ''},2000);
  443. i++;
  444. if(i > self.rollbuylist.length-1){
  445. i=0
  446. // clearInterval(timer);
  447. // self.getrollbuylist();
  448. }
  449. },4000);
  450. },
  451. //首页内容页信息展示
  452. gethomecontent(){
  453. this.$api.http.get(this.config.apiBaseurl+'/home/content', {header: {Authorization:this.params.tokenhead+this.params.token}}).then(res => {
  454. console.log('首页内容页信息展示gethomecontent',res.data);
  455. let homecontent = res.data.data;
  456. //获取专题列表
  457. this.subjectList = homecontent.subjectList;
  458. // console.log('this.subjectList',this.subjectList);
  459. //获取专题列表 end
  460. //推广弹窗
  461. // this.isTime();
  462. // this.$refs.promotionPopup.open();//推广弹窗
  463. if(homecontent.promote){
  464. this.promotion = homecontent.promote[0];
  465. this.$refs.promotionPopup.open();
  466. }
  467. // console.log('this.promotion',this.promotion)
  468. //推广弹窗 end
  469. //供应商列表
  470. this.supplierList =homecontent.companyInfos;
  471. }).catch(err => {
  472. console.log(err)
  473. });
  474. },
  475. //产品跳转链接
  476. gosubject(id,title){
  477. uni.navigateTo({
  478. url:`/pages/subject/subject?subjectId=${id}&title=${title}`,
  479. fail(err) {
  480. console.log(err)
  481. }
  482. })
  483. },
  484. //供应商跳转详情
  485. supplierclick(id){
  486. console.log(id);
  487. uni.navigateTo({
  488. url:`/pages/supplier/supplierdetail/supplierdetail?id=${id}`
  489. })
  490. },
  491. //供应商列表
  492. // getsupplierlist(){
  493. // this.$api.http.get(this.config.apiBaseurl+'/company/cp/page', {header: {Authorization:this.params.tokenhead+this.params.token},params: this.supplierparams}).then(res => {
  494. // // console.log('供应商列表getsupplierlist',res.data);
  495. // // let supplierlist = res.data.data;
  496. // this.supplierList = res.data.data;
  497. // console.log('供应商列表getsupplierlist',JSON.parse(JSON.stringify(this.supplierList)))
  498. // }).catch(err => {
  499. // console.log(err)
  500. // });
  501. // },
  502. //关闭推广弹窗
  503. closePromotion(){
  504. this.$refs.promotionPopup.close();
  505. }
  506. }
  507. }
  508. </script>
  509. <style>
  510. @import url("./index.css");
  511. </style>