index.vue 13 KB

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