home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view class="container">
  3. <view class="search">
  4. <uni-search-bar radius="100" placeholder="搜索" clearButton="auto" cancelButton="none" bgColor="#ffffff" @confirm="goToGoodList" />
  5. </view>
  6. <view>
  7. <swiper class="swiper" :indicator-dots="false" :autoplay="true" :interval="3000" :duration="500">
  8. <swiper-item v-for="(item,index) in advertList" :key="index">
  9. <cover-image :src="item.imgPath"></cover-image>
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. <view class="entrance">
  14. <view class="entrance-col" @click="goToGoodList(null, 3)">
  15. <view class="entrance-button caizhai">自助采摘</view>
  16. </view>
  17. <view class="entrance-col" @click="goToGoodList(null, 4)">
  18. <view class="entrance-button zhongzhi">共享种植</view>
  19. </view>
  20. <view class="entrance-col" @click="goToGoodList(null, 2)">
  21. <view class="entrance-button paimai">拍 卖</view>
  22. </view>
  23. </view>
  24. <view class="index-title">
  25. <view class="title-text">精品推荐</view>
  26. <view class="title-tip">直播带货,视频推荐</view>
  27. </view>
  28. <view class="content-box video-box">
  29. <view class="video-col" style="margin-right: 11px;" v-if="liveTelecast" @click="goToLiveList(1)">
  30. <view class="video-title">直播大厅
  31. <view class="circular">
  32. <text class="iconfont iconfangxiang"></text>
  33. </view>
  34. </view>
  35. <cover-image class="video-img" :src="liveTelecast.imgUrl"></cover-image>
  36. <view class="video-name">{{liveTelecast.liveName}}</view>
  37. </view>
  38. <view class="video-col" style="margin-left: 11px;" v-if="shortVideo" @click="goToLiveList(2)">
  39. <view class="video-title">短视频推荐
  40. <view class="circular">
  41. <text class="iconfont iconfangxiang"></text>
  42. </view>
  43. </view>
  44. <cover-image class="video-img" :src="shortVideo.coverUrl"></cover-image>
  45. <view class="video-name">{{shortVideo.videoName}}</view>
  46. </view>
  47. </view>
  48. <view class="index-title">
  49. <view class="title-text">今日特惠</view>
  50. <view class="title-tip">精品特价,限量抢购</view>
  51. </view>
  52. <view class="content-box" style="width: calc(100% - 24px);margin-left: 12px; display: flex;justify-content: space-between;">
  53. <view class="discount-col" v-for="(item,index) in discountList" :key="index" @click="goToGoodDetails(item)">
  54. <cover-image class="discount-img" :src="item.imgPath"></cover-image>
  55. <view class="discount-name">{{item.productName}}</view>
  56. <view class="discount-price">
  57. <text class="sale-icon">¥</text>
  58. <text class="sale-price">{{item.bizPrice}}</text>
  59. <text class="price">原价:{{item.originalPrice}}</text>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="index-title" style="margin-bottom: 4px;">
  64. <view class="title-text">猜你喜欢</view>
  65. </view>
  66. <scroll-view class="content-box" scroll-y="true" refresher-enabled="true" :refresher-triggered="triggered"
  67. @refresherrefresh="onRefresh" @refresherrestore="onRestore">
  68. <view class="goods-row" v-for="(item,index) in goodsList" :key="index" @click="goToGoodDetails(item)">
  69. <cover-image class="goods-img" :src="item.imgPath"></cover-image>
  70. <view class="goods-info">
  71. <view class="goods-name">{{item.productName}}</view>
  72. <view class="goods-number">{{item.sellCount}}人付款</view>
  73. <text class="goods-price">
  74. <text class="sale-icon">¥</text>
  75. <text class="sale-price">{{item.bizPrice}}</text>
  76. <text class="price">原价:{{item.originalPrice}}</text>
  77. <text class="iconfont icongengduo"></text>
  78. </text>
  79. </view>
  80. </view>
  81. </scroll-view>
  82. <u-top-tips ref="uTips"></u-top-tips>
  83. </view>
  84. </template>
  85. <script>
  86. const NET = require('../../utils/request')
  87. const API = require('../../config/api')
  88. export default {
  89. data() {
  90. return {
  91. liveTelecast: null,
  92. shortVideo: null,
  93. advertList: [],
  94. discountList: [],
  95. triggered: false,
  96. goodsList: [],
  97. }
  98. },
  99. onLoad() {},
  100. onReady() {
  101. this.getBaseInfo()
  102. setTimeout(() => {
  103. this.triggered = true;
  104. }, 1000)
  105. },
  106. methods: {
  107. // 查询数据
  108. getBaseInfo() {
  109. NET.request(API.getAdvert, {}, 'GET').then(res => {
  110. this.advertList = res.data
  111. }).catch(error => {
  112. this.$refs.uTips.show({
  113. title: '获取广告列表失败',
  114. type: 'warning',
  115. })
  116. })
  117. NET.request(API.getLiveTelecast + '/1/1', {}, 'GET').then(res => {
  118. this.liveTelecast = res.data.list.length ? res.data.list[0] : null
  119. }).catch(error => {
  120. this.$refs.uTips.show({
  121. title: '获取直播列表失败',
  122. type: 'warning',
  123. })
  124. })
  125. NET.request(API.getShortVideo + '/1/1', {}, 'GET').then(res => {
  126. this.shortVideo = res.data.list.length ? res.data.list[0] : null
  127. }).catch(error => {
  128. this.$refs.uTips.show({
  129. title: '获取短视频列表失败',
  130. type: 'warning',
  131. })
  132. })
  133. NET.request(API.getPreferentialGoods, {}, 'GET').then(res => {
  134. this.discountList = res.data
  135. }).catch(error => {
  136. this.$refs.uTips.show({
  137. title: '获取今日特惠商品列表失败',
  138. type: 'warning',
  139. })
  140. })
  141. },
  142. // 下拉刷新
  143. onRefresh() {
  144. this.getPreferGoodsList()
  145. },
  146. // 刷新终止
  147. onRestore() {
  148. this.triggered = 'restore'
  149. },
  150. // 获取猜你喜欢商品列表
  151. getPreferGoodsList() {
  152. NET.request(API.getPreferGoods, {}, 'GET').then(res => {
  153. this.triggered = false;
  154. this.goodsList = res.data
  155. }).catch(error => {
  156. this.$refs.uTips.show({
  157. title: '获取猜你喜欢商品列表失败',
  158. type: 'warning',
  159. })
  160. })
  161. },
  162. // 跳转商品列表
  163. goToGoodList(data, type) {
  164. uni.navigateTo({
  165. url: '/pagesGood/goodList?goodType=' + (type ? type : (1 + '&goodName=' + data.value))
  166. });
  167. },
  168. // 跳转直播大厅
  169. goToLiveList(type) {
  170. uni.navigateTo({
  171. url: '/pagesGood/videoList?videoType=' + type
  172. });
  173. },
  174. // 跳转商品详情
  175. goToGoodDetails(item) {
  176. uni.navigateTo({
  177. url: '/pagesGood/goodDetails?goodId=' + item.productId + '&goodType=' + item.productType
  178. });
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="less" scoped>
  184. .container {
  185. background-size: 128px 124px;
  186. background-position: center 510px;
  187. background-repeat: no-repeat;
  188. background-image: url(@/static/images/indexBg.png);
  189. .search {
  190. width: 100%;
  191. position: absolute;
  192. z-index: 10;
  193. .uni-searchbar {
  194. background-color: transparent;
  195. }
  196. }
  197. .swiper {
  198. height: 175px;
  199. background-color: #6CA63A;
  200. position: relative;
  201. z-index: -1;
  202. }
  203. .entrance {
  204. width: calc(100% - 24px);
  205. height: 100px;
  206. margin-top: -16px;
  207. margin-left: 12px;
  208. display: flex;
  209. justify-content: space-between;
  210. background-color: #FFFFFF;
  211. border-radius: 15px;
  212. box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.35);
  213. .entrance-col {
  214. width: 96px;
  215. height: 72px;
  216. margin-top: 15px;
  217. background-size: 96px 56px;
  218. background-position: center 10px;
  219. background-repeat: no-repeat;
  220. background-image: url(@/static/images/entrance.png);
  221. .entrance-button {
  222. width: 96px;
  223. height: 72px;
  224. padding-top: 60px;
  225. box-sizing: border-box;
  226. text-align: center;
  227. font-size: 15px;
  228. font-family: PingFang SC;
  229. color: #52A63A;
  230. line-height: 12px;
  231. background-size: 50px;
  232. background-position: center top;
  233. background-repeat: no-repeat;
  234. }
  235. .caizhai {
  236. background-image: url(@/static/images/caizhai.png);
  237. }
  238. .zhongzhi {
  239. background-image: url(@/static/images/zhongzhi.png);
  240. }
  241. .paimai {
  242. background-image: url(@/static/images/paimai.png);
  243. }
  244. }
  245. }
  246. .index-title {
  247. width: calc(100% - 24px);
  248. border-left: 1px solid #6CA63A;
  249. padding: 2px 0 2px 5px;
  250. margin: 15px 12px 10px 12px;
  251. .title-text {
  252. height: 20px;
  253. margin-bottom: 2px;
  254. line-height: 20px;
  255. font-size: 15px;
  256. font-family: PingFang SC;
  257. color: #6CA63A;
  258. }
  259. .title-tip {
  260. height: 14px;
  261. line-height: 14px;
  262. font-size: 12px;
  263. font-family: PingFang SC;
  264. color: #666666;
  265. }
  266. }
  267. .content-box {
  268. width: 100%;
  269. .discount-col {
  270. width: calc(50% - 6px);
  271. background: #FFFFFF;
  272. box-shadow: 1px 2px 19px 0px rgba(0, 0, 0, 0.09);
  273. border-radius: 5px;
  274. padding-bottom: 10px;
  275. overflow: hidden;
  276. .discount-img {
  277. height: 170px;
  278. object-fit: cover;
  279. }
  280. .discount-name {
  281. height: 12px;
  282. margin: 7px 6px 10px 6px;
  283. font-size: 12px;
  284. font-family: PingFang SC;
  285. color: #343434;
  286. line-height: 14px;
  287. }
  288. .discount-price {
  289. width: calc(100% - 12px);
  290. margin-left: 6px;
  291. height: 18px;
  292. line-height: 18px;
  293. font-family: PingFang SC;
  294. white-space: nowrap;
  295. text-overflow: ellipsis;
  296. overflow: hidden;
  297. .sale-icon {
  298. font-size: 12px;
  299. color: #6CA63A;
  300. }
  301. .sale-price {
  302. font-size: 18px;
  303. color: #6CA63A;
  304. margin-right: 5px;
  305. }
  306. .price {
  307. font-size: 10px;
  308. text-decoration: line-through;
  309. color: #A67954;
  310. }
  311. }
  312. }
  313. .goods-row {
  314. width: calc(100% - 24px);
  315. height: 104px;
  316. margin: 6px 0 12px 12px;
  317. background: #FFFFFF;
  318. box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.09);
  319. border-radius: 5px;
  320. overflow: hidden;
  321. display: flex;
  322. .goods-img {
  323. width: 104px;
  324. height: 104px;
  325. object-fit: cover;
  326. }
  327. .goods-info {
  328. width: calc(100% - 104px);
  329. padding: 10px 10px 10px 12px;
  330. box-sizing: border-box;
  331. .goods-name {
  332. height: 36px;
  333. font-size: 15px;
  334. font-family: PingFang SC;
  335. color: #333333;
  336. line-height: 18px;
  337. overflow: hidden;
  338. text-overflow: ellipsis;
  339. display: -webkit-box;
  340. -webkit-line-clamp: 2;
  341. -webkit-box-orient: vertical;
  342. word-wrap: break-word;
  343. }
  344. .goods-number {
  345. height: 16px;
  346. font-size: 12px;
  347. font-family: PingFang SC;
  348. color: #666666;
  349. line-height: 16px;
  350. margin: 6px 0 4px 0;
  351. }
  352. .goods-price {
  353. height: 24px;
  354. line-height: 24px;
  355. font-family: PingFang SC;
  356. .sale-icon {
  357. font-size: 12px;
  358. color: #6CA63A;
  359. margin-left: -2px;
  360. }
  361. .sale-price {
  362. font-size: 22px;
  363. color: #6CA63A;
  364. margin-right: 6px;
  365. }
  366. .price {
  367. font-size: 12px;
  368. text-decoration: line-through;
  369. color: #A67954;
  370. }
  371. .iconfont {
  372. float: right;
  373. color: #999999;
  374. font-size: 32px;
  375. line-height: 28px;
  376. }
  377. }
  378. }
  379. }
  380. }
  381. .video-box {
  382. width: calc(100% - 24px);
  383. margin-left: 12px;
  384. box-sizing: border-box;
  385. background: #FFFFFF;
  386. box-shadow: 1px 2px 19px 0px rgba(0, 0, 0, 0.09);
  387. border-radius: 5px;
  388. padding: 15px 15px 12px 15px;
  389. display: flex;
  390. .video-col {
  391. width: calc(50% - 11px);
  392. .video-title {
  393. height: 16px;
  394. line-height: 16px;
  395. margin-bottom: 8px;
  396. font-size: 15px;
  397. font-family: PingFang SC;
  398. color: #343434;
  399. white-space: nowrap;
  400. .circular {
  401. width: 16px;
  402. height: 16px;
  403. background-color: #6BA539;
  404. border-radius: 50%;
  405. margin-left: 6px;
  406. text-align: right;
  407. display: inline-grid;
  408. .iconfont {
  409. font-size: 14px;
  410. color: #FFFFFF;
  411. font-weight: bold;
  412. }
  413. }
  414. }
  415. .video-img {
  416. width: 100%;
  417. height: 145px;
  418. object-fit: cover;
  419. }
  420. .video-name {
  421. height: 16px;
  422. margin-top: 10px;
  423. line-height: 16px;
  424. text-align: center;
  425. font-size: 15px;
  426. font-family: PingFang SC;
  427. color: #343434;
  428. }
  429. }
  430. }
  431. }
  432. </style>