index.vue 12 KB

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