goodList.vue 14 KB

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