promotionList.vue 17 KB

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