index.vue 13 KB

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