banner.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <view>
  3. <!--components/banner/banner.wxml-->
  4. <!-- 顶部banner -->
  5. <template name="banner">
  6. <view class=" pdlr30 sat" style="padding-bottom: 30rpx;box-shadow: 0 5px 30px rgba(255,255,255,0.2);">
  7. <!-- 顶部banner -->
  8. <view v-if="bannerList.length>0" class="banner r20">
  9. <swiper class="swiper" @change="swiperChange" :current="swiperCurrent" autoplay="true"
  10. circular="true" duration="1000">
  11. <block v-for="(item, index) in bannerList" :key="index">
  12. <swiper-item autoplay="true">
  13. <contact-button :img-url="item.pic" class-name="banner-img" v-if="item.type == 8"></contact-button>
  14. <block v-else>
  15. <image lazy-load="true" :src="item.pic"
  16. mode="aspectFill" @tap="getUrl2" :data-type="item.type"
  17. :data-content="item.content" :data-merchant="url"></image>
  18. </block>
  19. </swiper-item>
  20. </block>
  21. </swiper>
  22. <view class="dotse dflex">
  23. <block v-for="(item, index) in bannerList" :key="index">
  24. <view :class="'dot ' + (index == swiperCurrent ? ' active' : '')" :data-current="index"
  25. @tap="dotEvent">
  26. </view>
  27. </block>
  28. </view>
  29. </view>
  30. <view class="gy-nav ddflex" v-if="navBannerList&&navBannerList.length>0">
  31. <view class="li" v-for="(item,index) in navBannerList" :key="index" @click="jumpPage(item)">
  32. <image :src="item.pic"></image>
  33. </view>
  34. </view>
  35. <!-- <view class="gy-nav ddflex" v-if="appId == 'ZQcE7DsNhdymuX2'">
  36. <view class="li" v-for="(item,index) in navBannerList" :key="index" @click="jumpPage(item)">
  37. <image :src="item.pic"></image>
  38. </view>
  39. </view> -->
  40. <block v-else>
  41. <block v-if="districtTemplate.contentId == 1 || !districtTemplate.module">
  42. <view class="nav dflex" v-if="categoryList.length>0"><!-- :style="'height:' + swiperHeight" -->
  43. <swiper :class="districtTemplate.content.lines==1&&districtTemplate.lineNumber==3?'swiper2':districtTemplate.content.lines==2&&districtTemplate.lineNumber==3?'swiper3':districtTemplate.content.lines==1&&districtTemplate.lineNumber==4?'swiper4':districtTemplate.content.lines==1&&districtTemplate.lineNumber==5?'swiper5':'swiper1'" @change="swiperGridFun"
  44. :current="swiperGridcurrent">
  45. <block v-for="(item, index) in categoryList" :key="index">
  46. <swiper-item autoplay="true" class="dflex grid">
  47. <block v-for="(it, idx) in item" :key="idx">
  48. <navigator
  49. :url="'/product/list/list?id=' + it.id + '&title=' + it.title + '' + web"
  50. hover-class="none" :class="districtTemplate.lineNumber == 3 ? 'li3' : districtTemplate.lineNumber == 5 ? 'li5' : 'li'">
  51. <image lazy-load="true" :src="it.icon"></image>{{it.title}}
  52. </navigator>
  53. </block>
  54. </swiper-item>
  55. </block>
  56. </swiper>
  57. <view class="dots1 dflex" v-if="categoryList.length>1">
  58. <block v-for="(item, index) in categoryList" :key="index">
  59. <view :class="'dot1 ' + (index == swiperGridcurrent ? ' active' : '')"
  60. :data-current="index" @tap="dotGrid"></view>
  61. </block>
  62. </view>
  63. </view>
  64. </block>
  65. </block>
  66. </view>
  67. <view class="notice" v-if="config.Index_Notice && config.Index_Notice != 0">{{config.Index_Notice}}</view>
  68. <view class="idx-wechat ddflex" v-if="isShowZhuli" @click="showWechat">
  69. <image src="../../static/images/zhuli.png"></image>
  70. <view class="fflex">
  71. <view class="idx-wechat-tit">添加享团的小助理</view>
  72. <text>1v1专属服务</text>
  73. </view>
  74. <view class="idx-wechat-btn">立即添加</view>
  75. </view>
  76. <block v-if="isShowWechat">
  77. <view class="pop-ceng" @click="hideWechat"></view>
  78. <view class="pop-wechat">
  79. <image :src="zhuli.pic" class="wechat-img" show-menu-by-longpress="true"></image>
  80. <view class="changan ddflex">
  81. <image src="../../static/images/changan.png"></image>
  82. <view class="fflex">
  83. <view>长按识别二维码</view>
  84. <view>添加微信获取优惠信息</view>
  85. </view>
  86. </view>
  87. </view>
  88. </block>
  89. <coupons :couponList="couponList" v-if="couponList.length>0"></coupons>
  90. <interactive :pageList="officeList" v-if="officeList.length>0"></interactive>
  91. </template>
  92. </view>
  93. </template>
  94. <script>
  95. // components/banner/banner.js
  96. // 走马灯,广告
  97. const app = getApp();
  98. const req = require("../../utils/request.js");
  99. const api = require("../../utils/api.js");
  100. const route = require("../../utils/route.js");
  101. import coupons from '../../template/coupons/index.vue';
  102. import interactive from '../../template/interactive/index.vue';
  103. export default {
  104. components: {
  105. coupons,
  106. interactive
  107. },
  108. data() {
  109. return {
  110. swiperGridcurrent: 0,
  111. swiperCurrent: 0,
  112. categoryList: [],
  113. navBannerList: [],
  114. appId: req.header.appId,
  115. isShowZhuli: false,
  116. zhuli: '',
  117. isShowWechat: false
  118. };
  119. },
  120. props: {
  121. bannerList: Array, //广告图
  122. couponList: Array,//优惠券
  123. officeList: Array,//互动
  124. web: String, //跳转地址
  125. url: String, //跳转地址
  126. // categoryList: Array,
  127. districtTemplate: Object, //金刚区模板配置
  128. config: Object, //系统配置
  129. },
  130. mounted() {
  131. if (this.districtTemplate.contentId == 1 || !this.districtTemplate.module) {
  132. // if (this.districtTemplate.number == 0) {
  133. this.getCategory()
  134. }
  135. // console.log(this.districtTemplate, "5464564654",this.bannerList)
  136. this.getNavBanner();
  137. this.getZhuli();
  138. },
  139. watch: {
  140. },
  141. beforeMount() {},
  142. methods: {
  143. showWechat(){
  144. this.isShowWechat = true;
  145. },
  146. hideWechat(){
  147. this.isShowWechat = false;
  148. },
  149. getZhuli(){
  150. req.getRequest('/api/content/list',{code: 'zhuli'},data=>{
  151. if(data&&data.length > 0){
  152. this.isShowZhuli = true;
  153. req.getRequest('/api/content/detail',{id: data[0].id},res=>{
  154. this.zhuli = res;
  155. })
  156. }
  157. })
  158. },
  159. getNavBanner(){
  160. let that = this;
  161. req.getRequest('/api/banner', {
  162. code: '00123'
  163. }, data => {
  164. that.navBannerList = data
  165. });
  166. },
  167. getRqeDatas() {
  168. let that = this; //顶部banner
  169. let ad = that.homeTemplate.filter(it => it.module == that.templateType.module_ad);
  170. if (ad && ad.length > 0 && ad[0].state == 0) {
  171. this.getBannerList(ad[0].module, ad[0].contentId);
  172. }
  173. },
  174. /**
  175. * 轮播切换
  176. */
  177. swiperChange({
  178. detail
  179. }) {
  180. // console.log(detail.source,"789456")
  181. // 防止轮播左右疯狂切换
  182. if (detail.source == 'autoplay' || detail.source == 'touch') {
  183. if (this.current == 0 && this.swiperCurrent > 1) {
  184. //卡死时,重置current为正确索引
  185. this.setData({
  186. current: this.swiperCurrent
  187. });
  188. } else {
  189. //正常轮转时,记录正确页码索引
  190. this.setData({
  191. swiperCurrent: detail.current
  192. });
  193. }
  194. }
  195. },
  196. getBannerList(module, contentId) {
  197. //banner图
  198. let that = this;
  199. req.getRequest('/api/banner', {
  200. groupId: contentId
  201. }, data => {
  202. if (module == that.templateType.module_ad) {
  203. that.setData({
  204. bannerList: data
  205. });
  206. } else {
  207. that.setData({
  208. popAdList: data[0]
  209. });
  210. }
  211. });
  212. },
  213. jumpPage(dt){
  214. let url = '';
  215. if (dt.type * 1 == 9 && dt.content != "") {
  216. url = "/product/list/list?id=" + dt.content;
  217. }else{
  218. url = dt.content;
  219. }
  220. uni.navigateTo({
  221. url: url
  222. })
  223. },
  224. async getUrl2(e) {
  225. console.log(e)
  226. var dt = e.currentTarget.dataset;
  227. var url = "";
  228. var id = "";
  229. var acid = "";
  230. if (dt.content != "") {
  231. let conunt = dt.content.split("_");
  232. id = conunt[1];
  233. acid = conunt[0];
  234. }
  235. if (dt.type * 1 == 2 && dt.content != "") {
  236. url = "product/detail/detail?id=" + dt.content;
  237. } else if (dt.type * 1 == 3) {
  238. url = dt.content;
  239. console.log('urlgetUrl2===',url)
  240. if(!url){
  241. req.msg('功能待接入')
  242. return false
  243. }
  244. if(url=='pages/index/index'||url=='pages/matchList/index'||url=='pages/interactive/index'||url=='pages/found/found'||url=='pages/user/user'){
  245. app.globalData.switchTab(url)
  246. return false
  247. }else{
  248. if(url.indexOf('http')!=-1){
  249. if(url.indexOf('${salesno}')!=-1){
  250. // 如果打开的分享的销售员微页
  251. if(req.getStorage('shareId')){
  252. url = url.replace(/\${salesno}/g,'salesno='+req.getStorage('shareId'))
  253. }else{
  254. // 如果自己是销售员
  255. if(req.getStorage('userInfo').saleNo){
  256. url = url.replace(/\${salesno}/g,'salesno='+req.getStorage('userInfo').saleNo)
  257. }else{
  258. //当前绑定的微页或推荐的微页
  259. let salesno = await new Promise((r,j)=>{
  260. req.getLocation(res => {
  261. const to = {
  262. latitude: res.latitude,
  263. longitude: res.longitude
  264. };
  265. req.getRequest('/api/visiting/card/recommendCardInfo', to, res => {
  266. r(res.jobNumber?res.jobNumber:'')
  267. })
  268. });
  269. })
  270. url = url.replace(/\${salesno}/g,'salesno='+salesno)
  271. }
  272. }
  273. }
  274. app.globalData.openPage('pages/web/web?url='+encodeURIComponent(url));
  275. return false
  276. }
  277. }
  278. } else if (dt.type * 1 == 4) {
  279. url = "product/groupDetail/groupDetail?acid=" + acid + "&id=" + id;
  280. } else if (dt.type * 1 == 5) {
  281. url = "product/coupon/coupon";
  282. } else if (dt.type * 1 == 6) {
  283. url = "pages/live/live";
  284. } else if (dt.type * 1 == 7) {
  285. url = "product/groupList/groupList" + dt.merchant;
  286. } else if (dt.type * 1 == 9 && dt.content != "") {
  287. url = "product/list/list?id=" + dt.content + '&title=' + dt.title + this.web;
  288. } else if (dt.type * 1 == 10) {
  289. url = "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" + dt.content;
  290. // console.log(
  291. // url); // url=`plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${dt.content}`
  292. } else if (dt.type * 1 == 11) {
  293. url = "activity/group/index/index" + dt.merchant;
  294. } else if (dt.type * 1 == 12) {
  295. url = "activity/seckill/seckill" + dt.merchant;
  296. } else if (dt.type * 1 == 13) {
  297. url = "activity/bargain/index/index" + dt.merchant;
  298. } else if (dt.type * 1 == 14) {
  299. url = "activity/newbornZone/newbornZone" + dt.merchant;
  300. } else if (dt.type * 1 == 15 && dt.content != "") {
  301. url = "activity/newbornDetails/newbornDetails?acid=" + acid + "&id=" + id;
  302. } else if (dt.type * 1 == 16 && dt.content != "") {
  303. url = "activity/seckillDetails/seckillDetails?acid=" + acid + "&id=" + id;
  304. } else if (dt.type * 1 == 17 && dt.content != "") {
  305. url = "activity/bargain/detail/detail?acid=" + acid + "&id=" + id;
  306. } else if (dt.type * 1 == 18 && dt.content != "") {
  307. url = "activity/group/detail/detail?acid=" + acid + "&id=" + id;
  308. } else if (dt.type * 1 == 19 && dt.content != "") {//文章内容
  309. url = "topic/content/content?id=" + dt.content + "&type=" + 1;//1为普通文章内容
  310. } else if (dt.type * 1 == 21 && dt.content != "") {//专题类型
  311. url = "pages/topic/topic?id=" + dt.content;
  312. } else if (dt.type * 1 == 27 && dt.content != "") {
  313. url = "match/activityDetail/activityDetail?id=" + dt.content;
  314. } else{
  315. url = "";
  316. }
  317. if (dt.type * 1 == 6) app.globalData.switchTab(url);
  318. else app.globalData.openPage(url);
  319. this.hideAd();
  320. },
  321. hideAd() {
  322. //关闭广告
  323. // if(this.data.first==false){
  324. this.setData({
  325. isLayerAd: false
  326. }); // }
  327. },
  328. getCategory() {
  329. //产品分类
  330. let that = this;
  331. route.getCategory({
  332. pid: 0
  333. }, res => {
  334. res = res.map((it, index) => {
  335. it.index = index;
  336. return it;
  337. });
  338. let newList = [];
  339. if(this.districtTemplate.module){
  340. if(this.districtTemplate.content.lines ==1){
  341. if(this.districtTemplate.lineNumber == 3){
  342. newList = this.group(res, 3);
  343. }else if(this.districtTemplate.lineNumber == 4){
  344. newList = this.group(res, 4);
  345. }else{
  346. newList = this.group(res, 5);
  347. }
  348. }else{
  349. if(this.districtTemplate.lineNumber == 3){
  350. newList = this.group(res, 6);
  351. }else if(this.districtTemplate.lineNumber == 4){
  352. newList = this.group(res, 8);
  353. }else{
  354. newList = this.group(res, 10);
  355. }
  356. }
  357. // let newList = this.group(res, 8);
  358. // let data = newList; // .filter(it => it.length >= 8)
  359. // console.log(data,"858888888")
  360. // if(this.districtTemplate.lineNumber == 4){
  361. // if (data[0]&&data[0].length <= 4) {
  362. // this.setData({
  363. // swiperHeight: '240rpx'
  364. // });
  365. // } else {
  366. // this.setData({
  367. // swiperHeight: '400rpx'
  368. // });
  369. // }
  370. // }
  371. // if(this.districtTemplate.lineNumber == 3){
  372. // if (data[0]&&data[0].length <= 3) {
  373. // this.setData({
  374. // swiperHeight: '240rpx'
  375. // });
  376. // } else {
  377. // this.setData({
  378. // swiperHeight: '400rpx'
  379. // });
  380. // }
  381. // }
  382. // if(this.districtTemplate.lineNumber == 5){
  383. // if (data[0]&&data[0].length <= 5) {
  384. // this.setData({
  385. // swiperHeight: '240rpx'
  386. // });
  387. // } else {
  388. // this.setData({
  389. // swiperHeight: '400rpx'
  390. // });
  391. // }
  392. // }
  393. // console.log(newList, data);
  394. }else{
  395. newList = this.group(res, 8);
  396. }
  397. that.categoryList = newList;
  398. console.log('默认栏目==',that.categoryList)
  399. });
  400. },
  401. swiperGridFun({
  402. detail
  403. }) {
  404. let that = this
  405. if (detail.source !== "touch") return;
  406. if (!this.districtTemplate) {
  407. if (this.categoryList[detail.current].length <= 4) {
  408. this.setData({
  409. swiperHeight: '200rpx'
  410. })
  411. } else {
  412. this.setData({
  413. swiperHeight: '400rpx'
  414. })
  415. }
  416. }
  417. this.setData({
  418. swiperGridcurrent: detail.current
  419. });
  420. // console.log('swiperHeight', this.swiperHeight);
  421. },
  422. // 九宫格
  423. dotGrid(e) {
  424. let that = this
  425. if (!this.districtTemplate) {
  426. if (this.categoryList[e.currentTarget.dataset.current].length <= 4) {
  427. this.setData({
  428. swiperHeight: '100px'
  429. })
  430. } else {
  431. this.setData({
  432. swiperHeight: '200px'
  433. })
  434. }
  435. }
  436. this.setData({
  437. swiperGridcurrent: e.currentTarget.dataset.current
  438. });
  439. },
  440. group(array, subGroupLength) {
  441. let index = 0;
  442. let newArray = [];
  443. while (index < array.length) {
  444. newArray.push(array.slice(index, index += subGroupLength));
  445. }
  446. return newArray;
  447. }
  448. }
  449. };
  450. </script>
  451. <style>
  452. @import "./banner.css";
  453. </style>