goodList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <!-- 商品列表 -->
  3. <view v-show="!isSortType" :style="{padding:'0 '+prConfig+'px'}">
  4. <view class="index-product-wrapper" :class="bgStyle===0?'':'borderRadius15'" :style="{ marginTop: mbConfig*2 + 'rpx', background: themeColor }" v-if="tempArr.length">
  5. <!-- 单列 -->
  6. <block v-if="itemStyle == 0">
  7. <view class="list-box listA" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
  8. <view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr" :key="index" @click="goDetail(item)">
  9. <view class="pictrue">
  10. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '1'">秒杀</span>
  11. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '2'">砍价</span>
  12. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '3'">拼团</span>
  13. <image :src="item.image" mode="aspectFill"></image>
  14. <view class="activityFrame" v-if="item.activity_frame.image" :style="'background-image: url('+item.activity_frame.image+');'"></view>
  15. </view>
  16. <view class="text-info text-add" >
  17. <view>
  18. <view class="title line2" v-if="titleShow">{{ item.store_name }}</view>
  19. <slot name="center"></slot>
  20. <view class="old-price" v-if="opriceShow">
  21. <text v-if="item.award_price*1>0">¥</text>
  22. {{ item.ot_price }}
  23. </view>
  24. </view>
  25. <view class="price" :style="'color:'+fontColor">
  26. <view v-if="priceShow">
  27. <template v-if="item.award_price*1>0">
  28. <text>¥</text>
  29. {{ item.price }}
  30. </template>
  31. <template v-else>
  32. {{ item.price*1 }}
  33. <text>积分</text>
  34. </template>
  35. </view>
  36. <view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor" :class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </block>
  42. <!-- 两列 -->
  43. <block v-if="itemStyle == 1">
  44. <view class="list-box listC" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
  45. <view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr" :key="index" @click="goDetail(item)">
  46. <view class="pictrue">
  47. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '1'">秒杀</span>
  48. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '2'">砍价</span>
  49. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '3'">拼团</span>
  50. <image :src="item.image" mode="aspectFill"></image>
  51. <!-- #ifndef APP-PLUS -->
  52. <video
  53. v-if="product_video_status && item.video_link"
  54. :src="item.video_link"
  55. :controls="false"
  56. :show-center-play-btn="false"
  57. :id="`video${item.id}`"
  58. :poster="item.image"
  59. objectFit="cover"
  60. class="video"
  61. loop
  62. muted
  63. ></video>
  64. <!-- #endif -->
  65. <view class="activityFrame" v-if="item.activity_frame.image" :style="'background-image: url('+item.activity_frame.image+');'"></view>
  66. </view>
  67. <view class="text-info">
  68. <view class="title line1" v-if="titleShow">{{ item.store_name }}</view>
  69. <slot name="center"></slot>
  70. <view class="old-price" v-if="opriceShow">
  71. <template v-if="item.award_price*1>0">
  72. <text>¥</text>
  73. {{ item.ot_price }}
  74. </template>
  75. <template v-else>
  76. {{ item.ot_price*1 }}
  77. <text>积分</text>
  78. </template>
  79. </view>
  80. <view class="price" :style="'color:'+fontColor">
  81. <view v-if="priceShow">
  82. <template v-if="item.award_price*1>0">
  83. <text>¥</text>
  84. {{ item.price }}
  85. </template>
  86. <template v-else>
  87. {{ item.price*1 }}
  88. <text>积分</text>
  89. </template>
  90. </view>
  91. <view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor" :class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </block>
  97. <!-- 三列 -->
  98. <block v-if="itemStyle == 2">
  99. <view class="list-box listB" :class="tempArr.length > 0 ? 'fadeIn on' : ''">
  100. <view class="item" :class="conStyle?'borderRadius15':''" v-for="(item, index) in tempArr" :key="index" @click="goDetail(item)">
  101. <view class="pictrue">
  102. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '1'">秒杀</span>
  103. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '2'">砍价</span>
  104. <span class="pictrue_log pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '3'">拼团</span>
  105. <image :src="item.image" mode="aspectFill"></image>
  106. <view class="activityFrame" v-if="item.activity_frame.image" :style="'background-image: url('+item.activity_frame.image+');'"></view>
  107. </view>
  108. <view class="text-info text-add">
  109. <view>
  110. <view class="title line1" v-if="titleShow">{{ item.store_name }}</view>
  111. <slot name="center"></slot>
  112. <view class="old-price" v-if="opriceShow">
  113. <template v-if="item.award_price*1>0">
  114. <text>¥</text>
  115. {{ item.ot_price }}
  116. </template>
  117. <template v-else>
  118. {{ item.ot_price*1 }}
  119. <text>积分</text>
  120. </template>
  121. </view>
  122. </view>
  123. <view class="price" :style="'color:'+fontColor">
  124. <view v-if="priceShow">
  125. <template v-if="item.award_price*1>0">
  126. <text>¥</text>
  127. {{ item.price }}
  128. </template>
  129. <template v-else>
  130. {{ item.price*1 }}
  131. <text>积分</text>
  132. </template>
  133. </view>
  134. <view class="txt" :style="'border:1px solid '+labelColor+';color:'+labelColor" :class="priceShow?'':'on'" v-if="item.checkCoupon && couponShow">券</view>
  135. </view>
  136. </view>
  137. </view>
  138. </view>
  139. </block>
  140. </view>
  141. <!-- 大图 -->
  142. <block v-if="itemStyle == 3 && tempArr.length" :style="{ marginTop: mbConfig + 'rpx' }">
  143. <view class="listBig" :class="bgStyle===0?'':'borderRadius15'" :style="{ background: themeColor }">
  144. <view class="itemBig" :class="conStyle?'borderRadius15':''" v-for="(item,index) in tempArr" :key="index" @click="goDetail(item)">
  145. <view class="img-box">
  146. <span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '1'">秒杀</span>
  147. <span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '2'">砍价</span>
  148. <span class="pictrue_log_big pictrue_log_class" :style="'background-color:'+labelColor" v-if="item.activity && item.activity.type === '3'">拼团</span>
  149. <image :src="item.recommend_image" mode="aspectFill" v-if="item.recommend_image"></image>
  150. <image :src="item.image" mode="aspectFill" v-else></image>
  151. </view>
  152. <view class="name line2"><span class="coupon" :style="'border:1px solid '+labelColor+';color:'+labelColor" v-if="item.checkCoupon && couponShow">券</span><span v-if="titleShow">{{item.store_name}}</span></view>
  153. <slot name="center"></slot>
  154. <view class="price" :style="'color:'+fontColor"><span v-if="priceShow">¥<span class="num">{{item.price}}</span></span><span class="old-price"
  155. v-if="opriceShow">¥{{item.ot_price}}</span></view>
  156. </view>
  157. </view>
  158. </block>
  159. </view>
  160. </template>
  161. <script>
  162. import {
  163. getProductslist
  164. } from '@/api/store.js';
  165. export default {
  166. name: 'goodList',
  167. props: {
  168. dataConfig: {
  169. type: Object,
  170. default: () => {}
  171. },
  172. isSortType: {
  173. type: String | Number,
  174. default: 0
  175. }
  176. },
  177. data() {
  178. return {
  179. tempArr: [],
  180. // scrollTop:0,
  181. mbConfig: this.dataConfig.mbConfig.val,
  182. numConfig: this.dataConfig.numConfig.val,
  183. themeColor: this.dataConfig.themeColor.color[0].item,
  184. itemStyle: this.dataConfig.itemStyle.type,
  185. sortType: this.dataConfig.goodsSort.type,
  186. type: this.dataConfig.tabConfig.tabVal || 0,
  187. selectId: this.dataConfig.selectConfig.activeValue, //分类id
  188. storeLabelId: this.dataConfig.goodsLabel.activeValue, //标签id
  189. productIds: this.dataConfig.goodsList.ids || [],
  190. opriceShow: this.dataConfig.opriceShow.val, //商品原价
  191. priceShow: this.dataConfig.priceShow.val, //商品价格
  192. titleShow: this.dataConfig.titleShow.val, //商品名称
  193. couponShow: this.dataConfig.couponShow.val, //商品优惠券
  194. prConfig: this.dataConfig.prConfig.val, //左右边距
  195. bgStyle: this.dataConfig.bgStyle.type,//背景样式
  196. conStyle: this.dataConfig.conStyle.type,//内容样式
  197. fontColor: this.dataConfig.fontColor.color?this.dataConfig.fontColor.color[0].item:'',
  198. labelColor: this.dataConfig.labelColor.color?this.dataConfig.labelColor.color[0].item:'',
  199. canPlay: false,
  200. product_video_status: false,
  201. confirm_video_status: false,
  202. confirm_video_result: false,
  203. };
  204. },
  205. watch: {
  206. tempArr() {
  207. // #ifndef APP-PLUS
  208. this.$nextTick(() => {
  209. if (this.itemStyle != 1) {
  210. return;
  211. }
  212. if (this.product_video_status) {
  213. uni.getNetworkType({
  214. success: (res) => {
  215. if (['wifi', 'unknown'].includes(res.networkType)) {
  216. // 监听
  217. this.observeVideo();
  218. }
  219. if (['2g', '3g', '4g', '5g'].includes(res.networkType)) {
  220. if (this.$store.state.app.autoplay) {
  221. // 监听
  222. this.observeVideo();
  223. } else{
  224. this.$eventHub.$emit('confirm_video_status');
  225. }
  226. }
  227. }
  228. });
  229. }
  230. });
  231. // #endif
  232. }
  233. },
  234. created() {
  235. // #ifndef APP-PLUS
  236. this.$eventHub.$on('product_video_status', result => {
  237. this.product_video_status = result;
  238. });
  239. this.$eventHub.$on('product_video_observe', () => {
  240. this.observeVideo();
  241. });
  242. // #endif
  243. },
  244. mounted() {
  245. this.productslist();
  246. },
  247. // onPageScroll({scrollTop}) {
  248. // // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  249. // this.scrollTop = scrollTop;
  250. // },
  251. methods: {
  252. observeVideo() {
  253. let observer = uni.createIntersectionObserver(this, { observeAll: true });
  254. observer.relativeToViewport().observe('.video', res => {
  255. if (res.intersectionRatio) {
  256. uni.createVideoContext(res.id, this).play();
  257. } else{
  258. uni.createVideoContext(res.id, this).pause();
  259. }
  260. });
  261. },
  262. productslist() {
  263. let limit = this.$config.LIMIT;
  264. let data = {};
  265. if (this.type == 1) {
  266. data = {
  267. ids: this.productIds.join(','),
  268. };
  269. } else {
  270. data = {
  271. priceOrder: this.sortType == 2 ? 'desc' : '',
  272. salesOrder: this.sortType == 1 ? 'desc' : '',
  273. selectId: this.selectId[this.selectId.length-1] || 0,
  274. store_label_id: this.storeLabelId.join(',') || '',
  275. limit: this.numConfig
  276. };
  277. }
  278. getProductslist(data).then(res => {
  279. this.tempArr = res.data;
  280. });
  281. },
  282. goDetail(item) {
  283. this.$emit('detail', item);
  284. }
  285. }
  286. };
  287. </script>
  288. <style lang="scss">
  289. // 这里可以自行配置
  290. $border-radius: 10px;
  291. .text-add {
  292. display: flex;
  293. flex-direction: column;
  294. justify-content: space-between;
  295. }
  296. .listBig {
  297. padding: 1px 20rpx 20rpx 20rpx;
  298. .borderRadius15{
  299. image{
  300. border-radius: $border-radius $border-radius 0 0;
  301. }
  302. }
  303. .itemBig {
  304. width: 100%;
  305. margin-top: 20rpx;
  306. background-color: #fff;
  307. padding-bottom: 15rpx;
  308. .img-box {
  309. width: 100%;
  310. height: 284rpx;
  311. position: relative;
  312. .pictrue_log_big{
  313. border-radius: $border-radius 0 $border-radius 0;
  314. }
  315. image {
  316. width: 100%;
  317. height: 100%;
  318. }
  319. }
  320. .name {
  321. font-size: 28rpx;
  322. font-weight: bold;
  323. margin-top: 16rpx;
  324. padding: 0 8px;
  325. .coupon {
  326. display: inline-block;
  327. text-align: center;
  328. width: 32rpx;
  329. border-radius: 4rpx;
  330. font-size: 20rpx;
  331. font-weight: normal;
  332. margin-right: 10rpx;
  333. }
  334. }
  335. .price {
  336. font-weight: bold;
  337. font-size: 12px;
  338. margin-top: 10rpx;
  339. padding: 0 8px;
  340. .num {
  341. font-size: 32rpx;
  342. margin-right: 10rpx;
  343. }
  344. .old-price {
  345. color: #aaa;
  346. font-weight: normal;
  347. text-decoration: line-through;
  348. }
  349. }
  350. }
  351. }
  352. .index-product-wrapper {
  353. .list-box {
  354. display: flex;
  355. flex-wrap: wrap;
  356. justify-content: space-between;
  357. padding: 20rpx 20rpx 0;
  358. .item {
  359. width: 345rpx;
  360. margin-bottom: 20rpx;
  361. background-color: #fff;
  362. overflow: hidden;
  363. position: relative;
  364. &.on {
  365. border-radius: 0;
  366. }
  367. .pictrue {
  368. width: 347rpx;
  369. height: 347rpx;
  370. position: relative;
  371. }
  372. .pictrue_log {
  373. width: 92rpx;
  374. height: 44rpx;
  375. font-size: 26rpx;
  376. line-height: 44rpx;
  377. border-radius: 0 0 $border-radius 0!important;
  378. }
  379. image {
  380. width: 100%;
  381. // height: 346rpx;
  382. height: 100%;
  383. display: block;
  384. }
  385. .text-info {
  386. padding: 10rpx 20rpx 15rpx;
  387. .title {
  388. color: #222222;
  389. }
  390. .old-price {
  391. margin-top: 4rpx;
  392. font-size: 26rpx;
  393. color: #aaaaaa;
  394. text-decoration: line-through;
  395. text {
  396. margin-right: 2px;
  397. font-size: 20rpx;
  398. }
  399. }
  400. .price {
  401. display: flex;
  402. align-items: flex-end;
  403. font-size: 36rpx;
  404. font-weight: 550;
  405. text {
  406. padding-bottom: 4rpx;
  407. font-size: 26rpx;
  408. font-weight: normal;
  409. }
  410. .txt {
  411. display: flex;
  412. align-items: center;
  413. justify-content: center;
  414. width: 28rpx;
  415. height: 28rpx;
  416. margin-left: 15rpx;
  417. margin-bottom: 10rpx;
  418. border-radius: 4rpx;
  419. font-size: 20rpx;
  420. font-weight: normal;
  421. &.on {
  422. margin-left: 0;
  423. }
  424. }
  425. }
  426. }
  427. }
  428. &.on {
  429. display: flex;
  430. }
  431. &.listA {
  432. .item {
  433. display: flex;
  434. width: 100%;
  435. .pictrue {
  436. width: 220rpx;
  437. height: 220rpx;
  438. }
  439. .text-info {
  440. // width: 490rpx;
  441. flex: 1
  442. }
  443. }
  444. }
  445. &.listC {
  446. .item{
  447. width: 48.5%;
  448. }
  449. .pictrue {
  450. width: 100%;
  451. height: 345rpx;
  452. }
  453. .video {
  454. position: absolute;
  455. top: 0;
  456. left: 0;
  457. width: 100%;
  458. height: 345rpx;
  459. border-radius: $border-radius $border-radius 0 0;
  460. }
  461. .activityFrame {
  462. border-radius: $border-radius $border-radius 0 0;
  463. }
  464. }
  465. &.listB {
  466. justify-content: inherit;
  467. .item {
  468. width: 31.6%;
  469. margin-right: 16rpx;
  470. .pictrue {
  471. width: 100%;
  472. height: 220rpx;
  473. }
  474. &:nth-child(3n) {
  475. margin-right: 0;
  476. }
  477. }
  478. }
  479. }
  480. }
  481. </style>