index.vue 13 KB

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