index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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" :style="{height: (swiperHeight-30-12)+'px'}" :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" :style="{height: (swiperHeight-30-12)+'px'}" :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%', height: ((swiperHeight-18)*44/34)+'px'}"></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: #56a83a;
  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 #56a83a;
  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: #56a83a;
  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. white-space: nowrap;
  299. text-overflow: ellipsis;
  300. overflow: hidden;
  301. height: 12px;
  302. margin: 7px 6px 10px 6px;
  303. font-size: 12px;
  304. font-family: PingFang SC;
  305. color: #343434;
  306. line-height: 14px;
  307. }
  308. .discount-price {
  309. width: calc(100% - 12px);
  310. margin-left: 6px;
  311. height: 18px;
  312. line-height: 18px;
  313. font-family: PingFang SC;
  314. white-space: nowrap;
  315. text-overflow: ellipsis;
  316. overflow: hidden;
  317. .sale-icon {
  318. font-size: 12px;
  319. color: #56a83a;
  320. }
  321. .sale-price {
  322. font-size: 18px;
  323. color: #56a83a;
  324. margin-right: 5px;
  325. }
  326. .price {
  327. font-size: 10px;
  328. text-decoration: line-through;
  329. color: #A67954;
  330. }
  331. }
  332. }
  333. .goods-row {
  334. width: calc(100% - 24px);
  335. height: 104px;
  336. margin: 6px 0 12px 12px;
  337. background: #FFFFFF;
  338. box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.09);
  339. border-radius: 5px;
  340. overflow: hidden;
  341. display: flex;
  342. .goods-img {
  343. width: 104px;
  344. height: 104px;
  345. object-fit: cover;
  346. }
  347. .goods-info {
  348. width: calc(100% - 104px);
  349. padding: 10px 10px 10px 12px;
  350. box-sizing: border-box;
  351. .goods-name {
  352. height: 36px;
  353. font-size: 15px;
  354. font-family: PingFang SC;
  355. color: #333333;
  356. line-height: 18px;
  357. overflow: hidden;
  358. text-overflow: ellipsis;
  359. display: -webkit-box;
  360. -webkit-line-clamp: 2;
  361. -webkit-box-orient: vertical;
  362. word-wrap: break-word;
  363. }
  364. .goods-number {
  365. height: 16px;
  366. font-size: 12px;
  367. font-family: PingFang SC;
  368. color: #666666;
  369. line-height: 16px;
  370. margin: 6px 0 4px 0;
  371. }
  372. .goods-price {
  373. height: 24px;
  374. line-height: 24px;
  375. font-family: PingFang SC;
  376. .sale-icon {
  377. font-size: 12px;
  378. color: #56a83a;
  379. margin-left: -2px;
  380. }
  381. .sale-price {
  382. font-size: 22px;
  383. color: #56a83a;
  384. margin-right: 6px;
  385. }
  386. .price {
  387. font-size: 12px;
  388. text-decoration: line-through;
  389. color: #A67954;
  390. }
  391. .iconfont {
  392. float: right;
  393. color: #999999;
  394. font-size: 32px;
  395. line-height: 28px;
  396. }
  397. }
  398. }
  399. }
  400. }
  401. .video-box {
  402. width: calc(100% - 24px);
  403. margin-left: 12px;
  404. box-sizing: border-box;
  405. background: #FFFFFF;
  406. box-shadow: 1px 2px 19px 0px rgba(0, 0, 0, 0.09);
  407. border-radius: 5px;
  408. padding: 15px 15px 12px 15px;
  409. display: flex;
  410. .video-col {
  411. width: calc(50% - 11px);
  412. .video-title {
  413. height: 16px;
  414. line-height: 16px;
  415. margin-bottom: 8px;
  416. font-size: 15px;
  417. font-family: PingFang SC;
  418. color: #343434;
  419. white-space: nowrap;
  420. .circular {
  421. width: 16px;
  422. height: 16px;
  423. background-color: #56a83a;
  424. border-radius: 50%;
  425. margin-left: 6px;
  426. text-align: right;
  427. display: inline-grid;
  428. .iconfont {
  429. font-size: 14px;
  430. color: #FFFFFF;
  431. font-weight: bold;
  432. }
  433. }
  434. }
  435. .video-img {
  436. width: 100%;
  437. height: 145px;
  438. object-fit: cover;
  439. border-radius: 5px;
  440. }
  441. .video-name {
  442. height: 16px;
  443. margin-top: 10px;
  444. line-height: 16px;
  445. text-align: center;
  446. font-size: 15px;
  447. font-family: PingFang SC;
  448. color: #343434;
  449. }
  450. }
  451. }
  452. }
  453. </style>