index.vue 11 KB

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