life.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <template>
  2. <view class="">
  3. <!-- 金刚区 -->
  4. <view class="zw-pages-content">
  5. <!-- 宜格优选 -->
  6. <!-- <view class="service-boxs " v-if="adVal && yiSever">
  7. <view class="service-title">
  8. <text>{{adVal.adName}}</text>
  9. <text class="moer-text" @click.stop="$openPage(adVal)">更多 <text
  10. class="moer-icon iconfont_yige">&#xe65f;</text> </text>
  11. </view>
  12. <view class="service-content">
  13. <scroll-view class="district-service" scroll-x="true">
  14. <div class="district-service-items">
  15. <block v-for="item in yiSever.themeModuleVoList">
  16. <view class="district-service-item" @click.stop="$openPage(item)">
  17. <image :src="item.moduleImage" mode="aspectFit"></image>
  18. </view>
  19. </block>
  20. </div>
  21. </scroll-view>
  22. </view>
  23. </view> -->
  24. <!-- 宜格优选 -->
  25. <view class="zw-service-box theme-service zw-interval" v-if="adVal && yiSever">
  26. <view class="service-title">
  27. <text>{{adVal.adName}}</text>
  28. <text class="moer-text" @click.stop="$openPage(adVal)">更多 <text
  29. class="moer-icon iconfont_yige">&#xe65f;</text> </text>
  30. </view>
  31. <view class="service-content">
  32. <u-row gutter="20">
  33. <u-col span="6" v-for="item in yiSever.themeModuleVoList">
  34. <view class="service-item lazy-img" @click.stop="$openPage(item)">
  35. <u-image class="service-img" :src="item.moduleImage" mode="aspectFit"
  36. :lazy-load="true"></u-image>
  37. </view>
  38. </u-col>
  39. </u-row>
  40. </view>
  41. </view>
  42. <!-- 广告banner -->
  43. <view class="banner" v-show="adBanner">
  44. <zw-swiper @getBanner="onAdBanner" ref="adBanner" :autoLoad="false" :height="200"
  45. :keyword="$keys.SH_ACTIVITY" :StorageKey="$keys.SH_ACTIVITY" />
  46. <!-- <image class="life-img" src="./life_banner.png" mode="aspectFill"></image> -->
  47. </view>
  48. <!-- 人气热卖 -->
  49. <view class="hot-box" v-if="hotList && hotList.length > 0">
  50. <view class="hot-title">
  51. 人气热卖
  52. </view>
  53. <view class="hot-goods">
  54. <scroll-view class="scroll-box" scroll-x :show-scrollbar="false" @scroll="scrollGoods">
  55. <block v-for="item in hotList">
  56. <view class="hot-goods-item" :key="item.id"
  57. @click="goProductDetails('/pages/product/goods/goods?id=' + item.id)">
  58. <!-- <image :src="item.cover" mode="aspectFit"></image> -->
  59. <view class="hot-goods-img lazy-img">
  60. <u-image class="service-img" :src="item.cover" mode="aspectFit" :lazy-load="true" />
  61. </view>
  62. <text class="hot-goods-price">
  63. <rich-text :nodes="$mUtil.priceBigSmall(item.min_sale_price)"></rich-text>
  64. </text>
  65. </view>
  66. </block>
  67. </scroll-view>
  68. <view class="indicator">
  69. <view class="line-bar"
  70. :style="{'transform':'translateX('+translateX + 'px)', 'width': lineBarWidth +'px'}">
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 商品 -->
  76. <view class="goods-box" v-if="goodsList && goodsList.length > 0">
  77. <view class="goods-item" v-for="item in goodsList"
  78. @click="goProductDetails('/pages/product/goods/goods?id=' + item.id)">
  79. <!-- <image :src="item.cover" mode="aspectFill"></image> -->
  80. <view class="goods-img lazy-img">
  81. <u-image class="service-img" :src="item.cover" mode="aspectFit" :lazy-load="true" />
  82. </view>
  83. <view class="goods-info">
  84. <view class="goods-title">{{item.title}}</view>
  85. <view class="goods-price">
  86. <rich-text :nodes="$mUtil.priceBigSmall(item.min_sale_price)"></rich-text>
  87. <text class="line-price">¥ {{ item.max_market_price }}</text>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. <EmptyDate v-else-if="status !== 'loading'" />
  93. <loadMore v-if="goodsList.length > 0 || status === 'loading'" :status="status"></loadMore>
  94. </view>
  95. </view>
  96. </template>
  97. <script>
  98. import Mixin from "./module/Mixin.js";
  99. import kongKim from "./module/kong-kim.vue";
  100. import {
  101. getBannerList,
  102. getThemeModule
  103. } from "@/api/government.js"
  104. export default {
  105. mixins: [Mixin],
  106. components: {
  107. kongKim
  108. },
  109. data() {
  110. return {
  111. adBanner: false,
  112. activityAd: [],
  113. translateX: 0,
  114. lineBarWidth: 0,
  115. params: {
  116. page: 1,
  117. limit: 6
  118. },
  119. hotList: [], // 人气热卖
  120. goodsList: [], // 猜你喜欢
  121. status: "more",
  122. adVal: null,
  123. yiSever: null,
  124. }
  125. },
  126. created() {
  127. // this.hotGoods()
  128. // this.guessLike()
  129. },
  130. mounted() {},
  131. methods: {
  132. init() {
  133. try {
  134. this.$nextTick(() => {
  135. this.$refs.adBanner.init()
  136. })
  137. } catch (e) {
  138. //TODO handle the exception
  139. }
  140. this.params = {
  141. page: 1,
  142. limit: 6
  143. };
  144. this.hotGoods();
  145. this.getAD();
  146. this.guessLike();
  147. },
  148. getAD() {
  149. getBannerList(this.$keys.YigeShop).then(res => {
  150. const data = res.data || []
  151. this.adVal = data[0] || null;
  152. this.getTheme();
  153. });
  154. },
  155. onAdBanner(data) {
  156. if (data && data.length > 0) {
  157. this.adBanner = true
  158. } else {
  159. this.adBanner = false
  160. }
  161. },
  162. getTheme() {
  163. getThemeModule(this.$keys.YI_SERVE).then(res => {
  164. this.yiSever = res.data || null;
  165. });
  166. },
  167. goProductDetails(url) {
  168. uni.navigateTo({
  169. url: url,
  170. });
  171. },
  172. scrollGoods(e) {
  173. // 获取滚动条所在位置
  174. let scrollLeft = e.detail.scrollLeft;
  175. // 获取当前屏幕宽度
  176. const screenWidth = uni.upx2px(660)
  177. // 获取item的宽度(px)
  178. let itemWidth = uni.upx2px(160);
  179. // 根据滚动条所在位置计算当前所在的item
  180. let index = scrollLeft / itemWidth;
  181. // 移动滚动条
  182. this.translateX = index * (uni.upx2px(124) / this.hotList.length); // 滚动条的宽度 / item的总数量
  183. },
  184. // 获取人气热卖商品
  185. hotGoods() {
  186. this.$http.get('/goods/month', {
  187. limit: 10,
  188. num: 1
  189. }).then(res => {
  190. if (res && res.code == 200) {
  191. this.hotList = res.list
  192. this.lineBarWidth = 4 / this.hotList.length * uni.upx2px(124)
  193. }
  194. })
  195. },
  196. /**猜你喜欢 */
  197. guessLike() {
  198. this.status = 'loading';
  199. this.$http.get(`/goods/smart`, {
  200. page: this.params.page,
  201. limit: this.params.limit,
  202. }).then((res) => {
  203. if (res && res.code == 200) {
  204. this.goodsList = this.params.page == 1 ? res.page.list : this.goodsList.concat(res.page
  205. .list);
  206. if (res.page.totalPage <= res.page.currPage) {
  207. this.status = "noMore";
  208. } else {
  209. this.status = "more";
  210. }
  211. // console.log(this.goodsList)
  212. }
  213. }).catch(err => {
  214. this.status = "noMore";
  215. })
  216. },
  217. moreGoods() {
  218. if (this.status == 'more') {
  219. this.params.page++;
  220. this.guessLike();
  221. }
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. @import './sever.scss';
  228. .banner {
  229. margin-top: $zw-gap;
  230. width: 100%;
  231. height: 200rpx;
  232. .life-img {
  233. width: 100%;
  234. height: 100%;
  235. }
  236. }
  237. .service-box {
  238. margin-top: $zw-gap;
  239. width: 100%;
  240. display: flex;
  241. justify-content: space-between;
  242. align-items: stretch;
  243. .service-item {
  244. width: calc(50% - 10rpx);
  245. height: 200rpx;
  246. background-color: red;
  247. border-radius: 10rpx;
  248. display: flex;
  249. flex-direction: column;
  250. justify-content: center;
  251. align-items: center;
  252. image {
  253. width: 80rpx;
  254. height: 50rpx;
  255. }
  256. text {
  257. font-size: 28rpx;
  258. }
  259. }
  260. }
  261. .discount-box {
  262. margin-top: $zw-gap;
  263. border-radius: 20rpx;
  264. overflow: hidden;
  265. width: 100%;
  266. height: 400rpx;
  267. background-color: skyblue;
  268. display: flex;
  269. justify-content: space-between;
  270. align-items: stretch;
  271. .discount-max {
  272. width: 400rpx;
  273. height: 100%;
  274. image {
  275. width: 100%;
  276. height: 100%;
  277. }
  278. }
  279. .discount-min {
  280. width: calc(100% - 420rpx);
  281. height: 100%;
  282. margin-left: 20rpx;
  283. .discount-min-item {
  284. width: 100%;
  285. height: calc(50% - 10rpx);
  286. // height:190rpx;
  287. image {
  288. width: 100%;
  289. height: 100%;
  290. }
  291. &:last-child {
  292. margin-top: 20rpx;
  293. }
  294. }
  295. }
  296. }
  297. .hot-box {
  298. margin-top: $zw-gap;
  299. background-color: #fff;
  300. border-radius: 16rpx;
  301. box-shadow: 0 2rpx 12rpx 0 rgba(0, 0, 0, 0.1);
  302. .hot-title {
  303. width: 100%;
  304. height: 100rpx;
  305. padding: 0 20rpx;
  306. font-size: 38rpx;
  307. font-weight: bold;
  308. line-height: 100rpx;
  309. border-bottom: 1rpx solid #EDEDED;
  310. }
  311. .hot-example {
  312. width: 100%;
  313. padding: 20rpx;
  314. display: flex;
  315. justify-content: space-between;
  316. align-items: stretch;
  317. border-bottom: 1rpx solid #EDEDED;
  318. image {
  319. width: 160rpx;
  320. height: 160rpx;
  321. }
  322. .example-info {
  323. width: calc(100% - 160rpx);
  324. padding-left: 20rpx;
  325. display: flex;
  326. flex-direction: column;
  327. justify-content: space-between;
  328. .example-name {
  329. font-size: 32rpx;
  330. font-weight: bold;
  331. }
  332. .example-hint {
  333. font-size: 26rpx;
  334. }
  335. .example-price {
  336. display: flex;
  337. justify-content: space-between;
  338. align-items: flex-end;
  339. text {
  340. color: red;
  341. font-size: 28rpx;
  342. font-weight: bold;
  343. }
  344. .example-btn {
  345. color: #fff;
  346. background-color: red;
  347. width: 180rpx;
  348. height: 50rpx;
  349. font-size: 34rpx;
  350. text-align: center;
  351. line-height: 50rpx;
  352. border-radius: 25rpx;
  353. }
  354. }
  355. }
  356. }
  357. .hot-goods {
  358. width: 100%;
  359. // display: flex;
  360. // flex-direction: column;
  361. // align-items: stretch;
  362. padding: 40rpx 30rpx;
  363. .scroll-box {
  364. width: 100%;
  365. margin-bottom: 36rpx;
  366. white-space: nowrap;
  367. // ::v-deep ::-webkit-scrollbar {
  368. // // 滚动条整体样式
  369. // display: block;
  370. // width: 124rpx !important;
  371. // height: 14rpx !important;
  372. // // -webkit-appearance: auto !important;
  373. // background: #EDEDED;
  374. // // overflow: auto !important;
  375. // }
  376. // ::v-deep ::-webkit-scrollbar-thumb {
  377. // // 滚动条里面小方块
  378. // // width: 124rpx !important;
  379. // // height: 14rpx !important;
  380. // border-radius: 10rpx !important;
  381. // // box-shadow: inset 0 0 5rpx rgba(0, 0, 0, 0.2) !important;
  382. // background-color: #F5D680 !important;
  383. // }
  384. // ::v-deep ::-webkit-scrollbar-track {
  385. // // 滚动条
  386. // // width: 124rpx !important;
  387. // // height: 14rpx !important;
  388. // border-radius: 10rpx !important;
  389. // // box-shadow: inset 0 0 5rpx rgba(0, 0, 0, 0.2) !important;
  390. // background-color: #EDEDED !important;
  391. // }
  392. }
  393. .indicator {
  394. display: flex;
  395. margin: 0 auto;
  396. width: 124rpx; // 滚动条宽度
  397. height: 14rpx;
  398. background-color: #EDEDED;
  399. border-radius: 10rpx;
  400. .line-bar {
  401. width: 50rpx; // (显示的item数量 / item的总数量) * 滚动条宽度
  402. background-color: #F5D680;
  403. transition-duration: .3s;
  404. border-radius: 10rpx;
  405. }
  406. }
  407. .hot-goods-item {
  408. display: inline-block;
  409. width: 140rpx;
  410. margin-right: 23rpx;
  411. .hot-goods-img {
  412. width: 140rpx;
  413. height: 140rpx;
  414. }
  415. .hot-goods-name {
  416. width: 100%;
  417. font-size: 26rpx;
  418. font-weight: bold;
  419. }
  420. .hot-goods-price {
  421. font-size: 30rpx;
  422. text-align: center;
  423. }
  424. }
  425. }
  426. }
  427. .goods-box {
  428. display: flex;
  429. flex-wrap: wrap;
  430. width: 100%;
  431. margin-top: $zw-gap;
  432. .goods-item {
  433. width: 336rpx;
  434. height: 512rpx;
  435. margin-right: 18rpx;
  436. margin-bottom: 38rpx;
  437. background: #ffffff;
  438. border-radius: 18rpx;
  439. overflow: hidden;
  440. box-shadow: 0 2rpx 12rpx 0 rgba(0, 0, 0, 0.1);
  441. &:nth-child(2n) {
  442. margin-right: 0;
  443. }
  444. .goods-img {
  445. width: 336rpx;
  446. height: 336rpx;
  447. border-radius: 18rpx 18rpx 0 0;
  448. vertical-align: middle;
  449. }
  450. .goods-info {
  451. padding: 0 20rpx 20rpx;
  452. padding-top: 14rpx;
  453. height: calc(100% - 336rpx);
  454. display: flex;
  455. flex-direction: column;
  456. justify-content: space-between;
  457. .goods-title {
  458. // height: 90rpx;
  459. margin-bottom: 10rpx;
  460. overflow: hidden;
  461. text-overflow: ellipsis;
  462. display: -webkit-box;
  463. -webkit-box-orient: vertical;
  464. -webkit-line-clamp: 2;
  465. }
  466. .goods-price {
  467. display: flex;
  468. align-items: baseline;
  469. color: #FF6600;
  470. font-size: 36rpx;
  471. .line-price {
  472. font-size: 22rpx;
  473. color: #999999;
  474. margin-left: 16rpx;
  475. text-decoration: line-through;
  476. }
  477. }
  478. }
  479. }
  480. }
  481. .service-boxs {
  482. .service-content {
  483. width: 100%;
  484. padding: 0 20rpx;
  485. height: calc(100% - 100rpx);
  486. display: flex;
  487. justify-content: center;
  488. align-items: center;
  489. // padding: 30rpx;
  490. .district-service {
  491. width: 100%;
  492. white-space: nowrap;
  493. height: 222rpx;
  494. .district-service-items {
  495. display: flex;
  496. align-items: stretch;
  497. .district-service-item {
  498. width: 145rpx;
  499. height: 222rpx;
  500. border-radius: 20rpx;
  501. margin-right: 25rpx;
  502. &:last-child {
  503. margin-right: 0;
  504. }
  505. image {
  506. width: 145rpx;
  507. height: 222rpx;
  508. border-radius: 20rpx;
  509. }
  510. }
  511. }
  512. }
  513. // <scroll-view class="district-service" scroll-x="true">
  514. // <div class="district-service-items">
  515. // <block v-for="item in yiSever.themeModuleVoList">
  516. // <view class="district-service-item" @click.stop="$openPage(item)">
  517. // <image :src="item.moduleImage" mode="aspectFit"></image>
  518. // </view>
  519. // </block>
  520. // </div>
  521. // </scroll-view>
  522. }
  523. }
  524. </style>