index.vue 14 KB

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