index.vue 13 KB

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