index.vue 11 KB

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