index.vue 19 KB

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