index.vue 11 KB

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