banner.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <template>
  2. <view>
  3. <!--components/banner/banner.wxml-->
  4. <!-- 顶部banner -->
  5. <template name="banner">
  6. <view class="pdlr30 sat">
  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. <button open-type="contact" v-if="item.type == 8">
  14. <image lazy-load="true" :src="item.pic + '?x-oss-process=style/w750-auto'"
  15. mode="aspectFill"></image>
  16. </button>
  17. <block v-else>
  18. <image lazy-load="true" :src="item.pic + '?x-oss-process=style/w750-auto'"
  19. mode="aspectFill" @tap="getUrl2" :data-type="item.type"
  20. :data-content="item.content" :data-merchant="url"></image>
  21. </block>
  22. </swiper-item>
  23. </block>
  24. </swiper>
  25. <view class="dotse dflex">
  26. <block v-for="(item, index) in bannerList" :key="index">
  27. <view :class="'dot ' + (index == swiperCurrent ? ' active' : '')" :data-current="index"
  28. @tap="dotEvent">
  29. </view>
  30. </block>
  31. </view>
  32. </view>
  33. <view class="gy-nav ddflex" v-if="appId == 'ZQcE7DsNhdymuX2'">
  34. <view class="li" v-for="(item,index) in navBannerList" :key="index" @click="jumpPage(item)">
  35. <image :src="item.pic"></image>
  36. </view>
  37. </view>
  38. <block v-else>
  39. <block v-if="districtTemplate.contentId == 1 || !districtTemplate.module">
  40. <view class="nav dflex" v-if="categoryList.length>0"><!-- :style="'height:' + swiperHeight" -->
  41. <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"
  42. :current="swiperGridcurrent">
  43. <block v-for="(item, index) in categoryList" :key="index">
  44. <swiper-item autoplay="true" class="dflex grid">
  45. <block v-for="(it, idx) in item" :key="idx">
  46. <navigator
  47. :url="'/product/list/list?id=' + it.id + '&title=' + it.title + '' + web"
  48. hover-class="none" :class="districtTemplate.lineNumber == 3 ? 'li3' : districtTemplate.lineNumber == 5 ? 'li5' : 'li'">
  49. <image lazy-load="true" :src="it.icon"></image>{{it.title}}
  50. </navigator>
  51. </block>
  52. </swiper-item>
  53. </block>
  54. </swiper>
  55. <view class="dots1 dflex" v-if="categoryList.length>1">
  56. <block v-for="(item, index) in categoryList" :key="index">
  57. <view :class="'dot1 ' + (index == swiperGridcurrent ? ' active' : '')"
  58. :data-current="index" @tap="dotGrid"></view>
  59. </block>
  60. </view>
  61. </view>
  62. </block>
  63. </block>
  64. </view>
  65. <view class="notice" v-if="config.Index_Notice && config.Index_Notice != 0">{{config.Index_Notice}}</view>
  66. </template>
  67. </view>
  68. </template>
  69. <script>
  70. // components/banner/banner.js
  71. // 走马灯,广告
  72. const app = getApp();
  73. const req = require("../../utils/request.js");
  74. const api = require("../../utils/api.js");
  75. const route = require("../../utils/route.js");
  76. export default {
  77. data() {
  78. return {
  79. swiperGridcurrent: 0,
  80. swiperCurrent: 0,
  81. categoryList: [],
  82. navBannerList: [],
  83. appId: req.header.appId
  84. };
  85. },
  86. components: {},
  87. props: {
  88. bannerList: Array, //广告图
  89. web: String, //跳转地址
  90. url: String, //跳转地址
  91. // categoryList: Array,
  92. districtTemplate: Object, //金刚区模板配置
  93. config: Object, //系统配置
  94. },
  95. mounted() {
  96. if (this.districtTemplate.contentId == 1 || !this.districtTemplate.module) {
  97. // if (this.districtTemplate.number == 0) {
  98. this.getCategory()
  99. }
  100. // console.log(this.districtTemplate, "5464564654",this.bannerList)
  101. this.getNavBanner();
  102. },
  103. watch: {
  104. },
  105. beforeMount() {},
  106. methods: {
  107. getNavBanner(){
  108. let that = this;
  109. req.getRequest('/api/banner', {
  110. groupId: '1196269897935630424'
  111. }, data => {
  112. that.navBannerList = data
  113. });
  114. },
  115. getRqeDatas() {
  116. let that = this; //顶部banner
  117. let ad = that.homeTemplate.filter(it => it.module == that.templateType.module_ad);
  118. if (ad && ad.length > 0 && ad[0].state == 0) {
  119. this.getBannerList(ad[0].module, ad[0].contentId);
  120. }
  121. },
  122. /**
  123. * 轮播切换
  124. */
  125. swiperChange({
  126. detail
  127. }) {
  128. // console.log(detail.source,"789456")
  129. // 防止轮播左右疯狂切换
  130. if (detail.source == 'autoplay' || detail.source == 'touch') {
  131. if (this.current == 0 && this.swiperCurrent > 1) {
  132. //卡死时,重置current为正确索引
  133. this.setData({
  134. current: this.swiperCurrent
  135. });
  136. } else {
  137. //正常轮转时,记录正确页码索引
  138. this.setData({
  139. swiperCurrent: detail.current
  140. });
  141. }
  142. }
  143. },
  144. getBannerList(module, contentId) {
  145. //banner图
  146. let that = this;
  147. req.getRequest('/api/banner', {
  148. groupId: contentId
  149. }, data => {
  150. if (module == that.templateType.module_ad) {
  151. that.setData({
  152. bannerList: data
  153. });
  154. } else {
  155. that.setData({
  156. popAdList: data[0]
  157. });
  158. }
  159. });
  160. },
  161. jumpPage(dt){
  162. let url = '';
  163. if (dt.type * 1 == 9 && dt.content != "") {
  164. url = "/product/list/list?id=" + dt.content;
  165. }else{
  166. url = dt.content;
  167. }
  168. uni.navigateTo({
  169. url: url
  170. })
  171. },
  172. getUrl2(e) {
  173. var dt = e.currentTarget.dataset;
  174. var url = "";
  175. var id = "";
  176. var acid = "";
  177. if (dt.content != "") {
  178. let conunt = dt.content.split("_");
  179. id = conunt[1];
  180. acid = conunt[0];
  181. }
  182. if (dt.type * 1 == 2 && dt.content != "") {
  183. url = "product/detail/detail?id=" + dt.content;
  184. } else if (dt.type * 1 == 4) {
  185. url = "product/groupDetail/groupDetail?acid=" + acid + "&id=" + id;
  186. } else if (dt.type * 1 == 5) {
  187. url = "product/coupon/coupon";
  188. } else if (dt.type * 1 == 6) {
  189. url = "service/live/live";
  190. } else if (dt.type * 1 == 7) {
  191. url = "product/groupList/groupList" + dt.merchant;
  192. } else if (dt.type * 1 == 9 && dt.content != "") {
  193. url = "product/list/list?id=" + dt.content;
  194. } else if (dt.type * 1 == 10) {
  195. url = "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" + dt.content;
  196. // console.log(
  197. // url); // url=`plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${dt.content}`
  198. } else if (dt.type * 1 == 11) {
  199. url = "activity/group/index/index" + dt.merchant;
  200. } else if (dt.type * 1 == 12) {
  201. url = "activity/seckill/seckill" + dt.merchant;
  202. } else if (dt.type * 1 == 13) {
  203. url = "activity/bargain/index/index" + dt.merchant;
  204. } else if (dt.type * 1 == 14) {
  205. url = "activity/newbornZone/newbornZone" + dt.merchant;
  206. } else if (dt.type * 1 == 15 && dt.content != "") {
  207. url = "activity/newbornDetails/newbornDetails?acid=" + acid + "&id=" + id;
  208. } else if (dt.type * 1 == 16 && dt.content != "") {
  209. url = "activity/seckillDetails/seckillDetails?acid=" + acid + "&id=" + id;
  210. } else if (dt.type * 1 == 17 && dt.content != "") {
  211. url = "activity/bargain/detail/detail?acid=" + acid + "&id=" + id;
  212. } else if (dt.type * 1 == 18 && dt.content != "") {
  213. url = "activity/group/detail/detail?acid=" + acid + "&id=" + id;
  214. } else if (dt.type * 1 == 19 && dt.content != "") {//文章内容
  215. url = "activity/content/content?id=" + dt.content + "&type=" + 1;//1为普通文章内容
  216. } else if (dt.type * 1 == 21 && dt.content != "") {//专题类型
  217. url = "pages/topic/topic?id=" + dt.content;
  218. } else if (dt.type * 1 == 3 && dt.content != "") {//外链类型
  219. url = dt.content;//1为普通文章内容
  220. } else {
  221. url = "";
  222. }
  223. if (dt.type * 1 == 6) app.globalData.switchTab(url);
  224. else app.globalData.openPage(url);
  225. this.hideAd();
  226. },
  227. hideAd() {
  228. //关闭广告
  229. // if(this.data.first==false){
  230. this.setData({
  231. isLayerAd: false
  232. }); // }
  233. },
  234. getCategory() {
  235. //产品分类
  236. let that = this;
  237. route.getCategory({
  238. pid: 0
  239. }, res => {
  240. res = res.map((it, index) => {
  241. it.index = index;
  242. return it;
  243. });
  244. let newList = [];
  245. if(this.districtTemplate.module){
  246. if(this.districtTemplate.content.lines ==1){
  247. if(this.districtTemplate.lineNumber == 3){
  248. newList = this.group(res, 3);
  249. }else if(this.districtTemplate.lineNumber == 4){
  250. newList = this.group(res, 4);
  251. }else{
  252. newList = this.group(res, 5);
  253. }
  254. }else{
  255. if(this.districtTemplate.lineNumber == 3){
  256. newList = this.group(res, 6);
  257. }else if(this.districtTemplate.lineNumber == 4){
  258. newList = this.group(res, 8);
  259. }else{
  260. newList = this.group(res, 10);
  261. }
  262. }
  263. // let newList = this.group(res, 8);
  264. // let data = newList; // .filter(it => it.length >= 8)
  265. // console.log(data,"858888888")
  266. // if(this.districtTemplate.lineNumber == 4){
  267. // if (data[0]&&data[0].length <= 4) {
  268. // this.setData({
  269. // swiperHeight: '240rpx'
  270. // });
  271. // } else {
  272. // this.setData({
  273. // swiperHeight: '400rpx'
  274. // });
  275. // }
  276. // }
  277. // if(this.districtTemplate.lineNumber == 3){
  278. // if (data[0]&&data[0].length <= 3) {
  279. // this.setData({
  280. // swiperHeight: '240rpx'
  281. // });
  282. // } else {
  283. // this.setData({
  284. // swiperHeight: '400rpx'
  285. // });
  286. // }
  287. // }
  288. // if(this.districtTemplate.lineNumber == 5){
  289. // if (data[0]&&data[0].length <= 5) {
  290. // this.setData({
  291. // swiperHeight: '240rpx'
  292. // });
  293. // } else {
  294. // this.setData({
  295. // swiperHeight: '400rpx'
  296. // });
  297. // }
  298. // }
  299. // console.log(newList, data);
  300. }else{
  301. newList = this.group(res, 8);
  302. }
  303. that.categoryList = newList;
  304. console.log('默认栏目==',that.categoryList)
  305. });
  306. },
  307. swiperGridFun({
  308. detail
  309. }) {
  310. let that = this
  311. if (detail.source !== "touch") return;
  312. if (!this.districtTemplate) {
  313. if (this.categoryList[detail.current].length <= 4) {
  314. this.setData({
  315. swiperHeight: '200rpx'
  316. })
  317. } else {
  318. this.setData({
  319. swiperHeight: '400rpx'
  320. })
  321. }
  322. }
  323. this.setData({
  324. swiperGridcurrent: detail.current
  325. });
  326. // console.log('swiperHeight', this.swiperHeight);
  327. },
  328. // 九宫格
  329. dotGrid(e) {
  330. let that = this
  331. if (!this.districtTemplate) {
  332. if (this.categoryList[e.currentTarget.dataset.current].length <= 4) {
  333. this.setData({
  334. swiperHeight: '100px'
  335. })
  336. } else {
  337. this.setData({
  338. swiperHeight: '200px'
  339. })
  340. }
  341. }
  342. this.setData({
  343. swiperGridcurrent: e.currentTarget.dataset.current
  344. });
  345. },
  346. group(array, subGroupLength) {
  347. let index = 0;
  348. let newArray = [];
  349. while (index < array.length) {
  350. newArray.push(array.slice(index, index += subGroupLength));
  351. }
  352. return newArray;
  353. }
  354. }
  355. };
  356. </script>
  357. <style>
  358. @import "./banner.css";
  359. </style>