promotionList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <template>
  2. <!-- 促销列表 -->
  3. <view class="index-product-wrapper" v-show="!isSortType" :style="[bottomBgColor]">
  4. <view :style="{ height: navBdH + 'px' }" class="nav-bd-box">
  5. <view
  6. class="nav-bd"
  7. :class="{
  8. 'nav-bd2': dataConfig.styleConfig.tabVal == 1,
  9. 'nav-bd3': dataConfig.styleConfig.tabVal == 2,
  10. 'nav-bd4': dataConfig.styleConfig.tabVal == 3,
  11. 'nav-bd5': dataConfig.styleConfig.tabVal == 4
  12. }"
  13. :style="{
  14. position: sticky ? 'fixed' : 'static',
  15. top: positionTop + 'px',
  16. background: sticky ? '#FFFFFF' : 'none'
  17. }"
  18. >
  19. <scroll-view class="scroll-view" scroll-x="true">
  20. <view class="item" v-for="(item, index) in explosiveMoney" :index="index" :class="{ on: index == ProductNavindex }" @click="ProductNavTab(item, index)">
  21. <view v-if="dataConfig.styleConfig.tabVal == 4" class="image-wrap">
  22. <image :src="item.image" class="image"></image>
  23. </view>
  24. <view class="txt" :style="[index == ProductNavindex ? textColor : {}]">{{ item.chiild[0].val }}</view>
  25. <view v-if="[1, 2].includes(dataConfig.styleConfig.tabVal)" class="line" :style="[index == ProductNavindex ? lineColor : {}]"></view>
  26. <view class="label" v-if="dataConfig.styleConfig.tabVal == 0 && item.chiild[1].val" :style="[index == ProductNavindex ? decorateColor : {}]">
  27. {{ item.chiild[1].val }}
  28. </view>
  29. </view>
  30. </scroll-view>
  31. </view>
  32. </view>
  33. <goodList ref="goodLists" v-if="goodDataConfig" :dataConfig="goodDataConfig" @detail="goDetail"></goodList>
  34. </view>
  35. </template>
  36. <script>
  37. // import {
  38. // getProductslist
  39. // } from '@/api/store.js';
  40. import goodList from './goodList.vue';
  41. export default {
  42. name: 'promotionList',
  43. props: {
  44. dataConfig: {
  45. type: Object,
  46. default: () => {}
  47. },
  48. isSortType: {
  49. type: String | Number,
  50. default: 0
  51. },
  52. productVideoStatus: {
  53. type: Boolean,
  54. default: false
  55. },
  56. positionTop: {
  57. type: Number,
  58. default: 0
  59. }
  60. },
  61. components: {
  62. goodList
  63. },
  64. data() {
  65. return {
  66. tempArr: [],
  67. iSshowH: false,
  68. ProductNavindex: 0,
  69. explosiveMoney: this.dataConfig.tabConfig.list,
  70. numConfig: this.dataConfig.tabConfig.list[0].numConfig.val,
  71. // imgStyle: this.dataConfig.imgStyle.type,
  72. mbConfig: 0,
  73. themeColor: '',
  74. titleShow: 0, //标题是否显示
  75. opriceShow: 0, //划线价是否显示
  76. priceShow: 0, //价格是否显示
  77. couponShow: 0, //优惠券标签是否显示
  78. titleConfig: 0, //标题位置
  79. fontColor: '',
  80. labelColor: '',
  81. txtColor: '',
  82. infoColor: '',
  83. goodType: this.dataConfig.tabConfig.list[0].tabVal,
  84. loadend: false,
  85. loading: false,
  86. limit: this.$config.LIMIT,
  87. page: 1,
  88. canPlay: false,
  89. autoplay: false,
  90. activeValue: this.dataConfig.tabConfig.list[0],
  91. goodDataConfig: null,
  92. sticky: false,
  93. navBdH: 0
  94. };
  95. },
  96. computed: {
  97. decorateColor() {
  98. if (this.dataConfig.toneConfig.tabVal) {
  99. let color = this.dataConfig.decorateColor.color;
  100. let background = `linear-gradient(90deg, ${color[0].item} 0%, ${color[1].item} 100%)`;
  101. if (this.dataConfig.styleConfig.tabVal == 2) {
  102. color = this.dataConfig.decorateColor2.color;
  103. background = color[0].item;
  104. }
  105. return {
  106. background: background
  107. };
  108. } else {
  109. return {
  110. background: `linear-gradient(90deg, var(--view-gradient) 0%, var(--view-theme) 100%)`
  111. };
  112. }
  113. },
  114. textColor() {
  115. if (this.dataConfig.toneConfig.tabVal) {
  116. let color = this.dataConfig.textColor.color[0].item;
  117. let bgColor = this.dataConfig.decorateColor.color;
  118. let background = '';
  119. if ([0, 1, 2].includes(this.dataConfig.styleConfig.tabVal)) {
  120. color = this.dataConfig.textColor.color[0].item;
  121. console.log(this.dataConfig, color);
  122. } else if ([3, 4].includes(this.dataConfig.styleConfig.tabVal)) {
  123. color = '#ffffff';
  124. background = `linear-gradient(90deg, ${bgColor[0].item} 0%, ${bgColor[1].item} 100%)`;
  125. } else if (this.dataConfig.styleConfig.tabVal == 1) {
  126. color = '#282828';
  127. }
  128. return {
  129. color: color,
  130. background: background
  131. };
  132. } else {
  133. if (this.dataConfig.styleConfig.tabVal == 1) {
  134. return {
  135. color: '#282828'
  136. };
  137. } else if ([3, 4].includes(this.dataConfig.styleConfig.tabVal)) {
  138. return {
  139. background: 'linear-gradient(90deg, var(--view-gradient) 0, var(--view-theme) 100%)',
  140. color: '#ffffff'
  141. };
  142. } else {
  143. return {
  144. color: 'var(--view-theme)'
  145. };
  146. }
  147. }
  148. },
  149. bottomBgColor() {
  150. return {
  151. padding: `${this.dataConfig.topConfig.val * 2}rpx ${this.dataConfig.prConfig.val * 2}rpx ${this.dataConfig.bottomConfig.val * 2}rpx`,
  152. 'margin-top': `${this.dataConfig.mbConfig.val * 2}rpx`,
  153. background: this.dataConfig.bottomBgColor.color[0].item
  154. };
  155. },
  156. lineColor() {
  157. let diy = this.dataConfig.toneConfig.tabVal;
  158. let type = this.dataConfig.styleConfig.tabVal;
  159. let color = this.dataConfig.decorateColor.color;
  160. let bgColor = `linear-gradient(90deg, ${color[0].item} 0%, ${color[1].item} 100%)`;
  161. if (type == 1) {
  162. return {
  163. background: diy ? bgColor : 'linear-gradient(90deg, var(--view-gradient) 0, var(--view-theme) 100%)'
  164. };
  165. } else if (type == 2) {
  166. return {
  167. 'border-bottom-color': diy ? this.dataConfig.textColor2.color[0].item : 'var(--view-theme)'
  168. };
  169. }
  170. }
  171. },
  172. watch: {
  173. activeValue: {
  174. handler(value) {
  175. let that = this;
  176. let type = that.goodType == 0 ? 3 : that.goodType;
  177. let goodDataConfig = {
  178. styleConfig: {
  179. tabVal: 1
  180. },
  181. goodsList: this.activeValue.goodsList,
  182. brandList: this.activeValue.brandConfig,
  183. classList: {
  184. classVal: this.activeValue.selectConfig.activeValue
  185. },
  186. goodsLabel: this.activeValue.goodsLabel,
  187. typeConfig: {
  188. activeValue: type
  189. },
  190. goodsSort: {
  191. tabVal: this.activeValue.goodsSort
  192. },
  193. numberConfig: {
  194. val: that.numConfig
  195. },
  196. bntStyleConfig: this.dataConfig.bntStyleConfig,
  197. cartConfig: this.dataConfig.cartConfig,
  198. bntConfig: this.dataConfig.bntConfig,
  199. filletImg: {
  200. type: 0,
  201. val: 8
  202. },
  203. checkboxInfo: {
  204. type: [0, 1, 2, 3, 4, 5]
  205. },
  206. toneConfig: {
  207. tabVal: 0
  208. },
  209. toneCartConfig: this.dataConfig.toneCartConfig,
  210. bntBgColor: this.dataConfig.bntBgColor,
  211. goodsName: {
  212. tabVal: 1
  213. },
  214. goodsNameColor: {
  215. color: [
  216. {
  217. item: '#333333'
  218. }
  219. ]
  220. },
  221. goodsPriceColor: {
  222. color: [
  223. {
  224. item: 'var(--view-theme)'
  225. }
  226. ]
  227. },
  228. topConfig: {
  229. val: 0
  230. },
  231. prConfig: {
  232. val: 0
  233. },
  234. bottomConfig: {
  235. val: 0
  236. },
  237. mbConfig: {
  238. val: 0
  239. },
  240. bottomBgColor: {
  241. color: [
  242. {
  243. item: ''
  244. }
  245. ]
  246. },
  247. fillet: this.dataConfig.fillet,
  248. name: 'promotionList'
  249. };
  250. that.goodDataConfig = goodDataConfig;
  251. },
  252. immediate: true
  253. },
  254. goodType: {
  255. handler(value) {
  256. //value !== undefined && this.getGroomList();
  257. },
  258. immediate: true
  259. },
  260. tempArr() {
  261. // #ifndef APP-PLUS
  262. this.$nextTick(() => {
  263. if (this.productVideoStatus) {
  264. uni.getNetworkType({
  265. success: (res) => {
  266. if (['wifi', 'unknown'].includes(res.networkType)) {
  267. // 监听
  268. this.observeVideo();
  269. }
  270. if (['2g', '3g', '4g', '5g'].includes(res.networkType)) {
  271. if (this.$store.state.app.autoplay) {
  272. // 监听
  273. this.observeVideo();
  274. } else {
  275. this.$eventHub.$emit('confirm_video_status');
  276. }
  277. }
  278. }
  279. });
  280. }
  281. });
  282. // #endif
  283. }
  284. },
  285. created() {
  286. // #ifndef APP-PLUS
  287. this.$eventHub.$on('product_video_observe', () => {
  288. this.observeVideo();
  289. });
  290. // #endif
  291. // this.getGroomList();
  292. let that = this;
  293. let type = that.goodType == 0 ? 3 : that.goodType;
  294. let goodDataConfig = {
  295. styleConfig: {
  296. tabVal: 1
  297. },
  298. goodsList: this.activeValue.goodsList,
  299. brandList: this.activeValue.brandConfig,
  300. classList: {
  301. classVal: this.activeValue.selectConfig.activeValue
  302. },
  303. goodsLabel: this.activeValue.goodsLabel,
  304. typeConfig: {
  305. activeValue: type
  306. },
  307. goodsSort: {
  308. tabVal: this.activeValue.goodsSort
  309. },
  310. numberConfig: {
  311. val: that.numConfig
  312. },
  313. bntStyleConfig: this.dataConfig.bntStyleConfig,
  314. cartConfig: this.dataConfig.cartConfig,
  315. bntConfig: this.dataConfig.bntConfig,
  316. filletImg: {
  317. type: 0,
  318. val: 8
  319. },
  320. checkboxInfo: {
  321. type: [0, 1, 2, 3, 4, 5]
  322. },
  323. toneConfig: {
  324. tabVal: 0
  325. },
  326. toneCartConfig: this.dataConfig.toneCartConfig,
  327. bntBgColor: this.dataConfig.bntBgColor,
  328. goodsName: {
  329. tabVal: 1
  330. },
  331. goodsNameColor: {
  332. color: [
  333. {
  334. item: '#333333'
  335. }
  336. ]
  337. },
  338. goodsPriceColor: {
  339. color: [
  340. {
  341. item: 'var(--view-theme)'
  342. }
  343. ]
  344. },
  345. topConfig: {
  346. val: 0
  347. },
  348. prConfig: {
  349. val: 0
  350. },
  351. bottomConfig: {
  352. val: 0
  353. },
  354. mbConfig: {
  355. val: 0
  356. },
  357. bottomBgColor: {
  358. color: [
  359. {
  360. item: ''
  361. }
  362. ]
  363. },
  364. fillet: this.dataConfig.fillet,
  365. name: 'promotionList'
  366. };
  367. that.goodDataConfig = goodDataConfig;
  368. },
  369. mounted() {
  370. let view = uni.createSelectorQuery().in(this).select('.nav-bd');
  371. let views = uni.createSelectorQuery().in(this).select('.nav-bd-box');
  372. view
  373. .boundingClientRect((data) => {
  374. this.navBdH = data.height;
  375. })
  376. .exec();
  377. if (!this.dataConfig.slideConfig.tabVal) {
  378. uni.$on('onPageScroll', () => {
  379. views
  380. .boundingClientRect((data) => {
  381. this.sticky = data.top <= this.positionTop;
  382. })
  383. .exec();
  384. });
  385. }
  386. },
  387. methods: {
  388. observeVideo() {
  389. this.autoplay = true;
  390. // let observer = uni.createIntersectionObserver(this, { observeAll: true });
  391. // observer.relativeToViewport().observe('.video', res => {
  392. // if (res.intersectionRatio) {
  393. // uni.createVideoContext(res.id, this).play();
  394. // } else{
  395. // uni.createVideoContext(res.id, this).pause();
  396. // }
  397. // });
  398. },
  399. // 促销列表的点击事件;
  400. changeTab(item) {
  401. this.goodType = item.tabVal;
  402. this.activeValue = item;
  403. // this.tempArr = [];
  404. // this.page = 1;
  405. // this.loadend = false;
  406. // let onloadH = true;
  407. // this.getGroomList(onloadH);
  408. },
  409. // 精品推荐
  410. getGroomList(onloadH) {
  411. let that = this;
  412. let type = that.goodType == 0 ? 3 : that.goodType;
  413. if (that.loadend) return false;
  414. if (that.loading) return false;
  415. if (onloadH) {
  416. that.$set(that, 'iSshowH', true);
  417. }
  418. let datas = {
  419. page: that.page,
  420. limit: this.numConfig
  421. };
  422. if (type == 1) {
  423. datas.ids = that.activeValue.goodsList.ids.join();
  424. } else if (type == 2) {
  425. datas.brand_id = that.activeValue.brandConfig.brandVal.join();
  426. } else if (type == 3) {
  427. datas.cate_id = that.activeValue.selectConfig.activeValue.join();
  428. } else if (type == 4) {
  429. datas.store_label_id = that.activeValue.goodsLabel.activeValue.join();
  430. }
  431. getProductslist(datas)
  432. .then(({ data }) => {
  433. that.$set(that, 'iSshowH', false);
  434. let maxPage = Math.ceil(this.numConfig / this.limit);
  435. let list = data,
  436. loadend = list.length < that.limit || that.page >= maxPage;
  437. let tempArr = that.$util.SplitArray(list, that.tempArr);
  438. that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
  439. that.loadend = loadend;
  440. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  441. that.page = that.page + 1;
  442. that.loading = false;
  443. })
  444. .catch((res) => {
  445. that.loading = false;
  446. that.loadTitle = '加载更多';
  447. });
  448. },
  449. // 首发新品切换
  450. ProductNavTab(item, index) {
  451. this.ProductNavindex = index;
  452. this.changeTab(item);
  453. },
  454. goDetail(item) {
  455. this.$emit('detail', item);
  456. }
  457. }
  458. };
  459. </script>
  460. <style lang="scss">
  461. // 这里可以自行配置
  462. $border-radius: 10px;
  463. .index-product-wrapper {
  464. &.on {
  465. min-height: 1500rpx;
  466. }
  467. .nav-bd {
  468. position: relative;
  469. top: 0;
  470. right: 0;
  471. left: 0;
  472. z-index: 99;
  473. &.nav-bd2 {
  474. .item {
  475. position: relative;
  476. padding: 18rpx 0;
  477. margin-right: 56rpx;
  478. &:first-child {
  479. // margin-left: 24rpx;
  480. }
  481. &:last-child {
  482. margin-right: 24rpx;
  483. }
  484. &.on {
  485. .txt {
  486. font-weight: 500;
  487. font-size: 32rpx;
  488. color: #333333;
  489. }
  490. // .line {
  491. // background: linear-gradient(90deg, var(--view-gradient) 0, var(--view-theme) 100%);
  492. // }
  493. }
  494. .txt {
  495. position: relative;
  496. z-index: 1;
  497. font-size: 28rpx;
  498. line-height: 44rpx;
  499. }
  500. .line {
  501. position: absolute;
  502. bottom: 22rpx;
  503. left: 0;
  504. width: 100%;
  505. height: 8rpx;
  506. border-radius: 4rpx;
  507. }
  508. }
  509. }
  510. &.nav-bd3 {
  511. .item {
  512. position: relative;
  513. padding: 18rpx 0;
  514. margin-right: 56rpx;
  515. &:first-child {
  516. // margin-left: 24rpx;
  517. }
  518. &:last-child {
  519. margin-right: 24rpx;
  520. }
  521. &.on {
  522. .txt {
  523. font-weight: 500;
  524. font-size: 32rpx;
  525. color: #e93323;
  526. }
  527. // .line {
  528. // border-bottom-color: var(--view-theme);
  529. // }
  530. }
  531. .txt {
  532. font-size: 28rpx;
  533. line-height: 44rpx;
  534. }
  535. .line {
  536. position: absolute;
  537. bottom: 8rpx;
  538. left: 50%;
  539. width: 64rpx;
  540. height: 64rpx;
  541. border: 4rpx solid transparent;
  542. border-radius: 50%;
  543. transform: translateX(-50%);
  544. }
  545. }
  546. }
  547. &.nav-bd4 {
  548. .item {
  549. padding: 16rpx 0;
  550. margin-right: 16rpx;
  551. &:first-child {
  552. // margin-left: 20rpx;
  553. }
  554. &:last-child {
  555. margin-right: 20rpx;
  556. }
  557. &.on {
  558. .txt {
  559. background: linear-gradient(90deg, #ff7931 0%, #e93323 100%);
  560. font-size: 26rpx;
  561. color: #ffffff;
  562. }
  563. }
  564. .txt {
  565. height: 48rpx;
  566. padding: 0 20rpx;
  567. border-radius: 24rpx;
  568. font-size: 28rpx;
  569. line-height: 48rpx;
  570. }
  571. }
  572. }
  573. &.nav-bd5 {
  574. padding-left: 20rpx;
  575. .item {
  576. padding: 20rpx 0;
  577. margin-right: 16rpx;
  578. &:first-child {
  579. // margin-left: 24rpx;
  580. }
  581. &:last-child {
  582. margin-right: 24rpx;
  583. }
  584. &.on {
  585. .image-wrap {
  586. border-color: var(--view-theme);
  587. background: #ffffff;
  588. }
  589. .txt {
  590. // background: linear-gradient(90deg, #FF7931 0%, #E93323 100%);
  591. color: #ffffff;
  592. }
  593. }
  594. .image-wrap {
  595. display: flex;
  596. justify-content: center;
  597. align-items: center;
  598. width: 104rpx;
  599. height: 104rpx;
  600. border: 3rpx solid transparent;
  601. border-radius: 50%;
  602. margin: 0 auto;
  603. }
  604. .image {
  605. width: 92rpx;
  606. height: 92rpx;
  607. border: 1rpx solid #eeeeee;
  608. border-radius: 50%;
  609. }
  610. .txt {
  611. height: 40rpx;
  612. padding: 0 12rpx;
  613. border-radius: 20rpx;
  614. margin-top: 8rpx;
  615. font-size: 24rpx;
  616. line-height: 40rpx;
  617. color: #333333;
  618. }
  619. }
  620. }
  621. .scroll-view {
  622. white-space: nowrap;
  623. }
  624. .item {
  625. display: inline-block;
  626. padding: 20rpx 0 14rpx;
  627. margin-right: 66rpx;
  628. text-align: center;
  629. &:first-child {
  630. // margin-left: 36rpx;
  631. }
  632. &:last-child {
  633. margin-right: 36rpx;
  634. }
  635. &.on {
  636. .txt {
  637. font-weight: 500;
  638. color: #e93323;
  639. }
  640. .label {
  641. background: linear-gradient(90deg, #ff7931 0%, #e93323 100%);
  642. font-size: 22rpx;
  643. color: #ffffff;
  644. }
  645. }
  646. .txt {
  647. font-size: 30rpx;
  648. line-height: 42rpx;
  649. color: #282828;
  650. }
  651. .label {
  652. display: inline-block;
  653. height: 38rpx;
  654. padding: 0 12rpx;
  655. border-radius: 19rpx;
  656. margin-top: 6rpx;
  657. font-size: 24rpx;
  658. line-height: 38rpx;
  659. color: #999999;
  660. }
  661. }
  662. }
  663. }
  664. </style>