index.vue 12 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">
  8. <swiper-item>
  9. <cover-image class="" v-for="(item,index) in advertList" :key="index" :src="item.imgPath"></cover-image>
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. <view class="entrance">
  14. <view class="entrance-col" @click="goToGoodList(null, 1)">
  15. <view class="entrance-button caizhai">自助采摘</view>
  16. </view>
  17. <view class="entrance-col" @click="goToGoodList(null, 2)">
  18. <view class="entrance-button zhongzhi">共享种植</view>
  19. </view>
  20. <view class="entrance-col" @click="goToGoodList(null, 3)">
  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">
  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">
  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="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">
  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>
  78. </view>
  79. </view>
  80. </scroll-view>
  81. </view>
  82. </template>
  83. <script>
  84. const NET = require('../../utils/request')
  85. const API = require('../../config/api')
  86. export default {
  87. data() {
  88. return {
  89. liveTelecast: null,
  90. shortVideo: null,
  91. advertList: [],
  92. discountList: [],
  93. triggered: false,
  94. goodsList: [],
  95. }
  96. },
  97. onLoad(options) {
  98. // this.appLoginWx()
  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. setTimeout(() => {
  140. this.triggered = true;
  141. }, 1000)
  142. },
  143. methods: {
  144. // 获取登录权限
  145. appLoginWx() {
  146. uni.getProvider({
  147. service: 'oauth',
  148. success: function(res) {
  149. if (~res.provider.indexOf('weixin')) {
  150. uni.login({
  151. provider: 'weixin',
  152. success: (res2) => {
  153. uni.getUserInfo({
  154. provider: 'weixin',
  155. success: (info) => { //这里请求接口
  156. NET.request(API.WxLogin, {
  157. code: res2.code,
  158. encryptedData: info.encryptedData,
  159. iv: info.iv,
  160. rawData: info.rawData,
  161. signature: info.signature,
  162. }, 'POST').then(res3 => {
  163. if (res.code == 0) {
  164. uni.setStorage({
  165. key: 'token',
  166. data: res3.data.token
  167. });
  168. }
  169. }).catch(res3 => {
  170. uni.showToast({
  171. title: "微信登录授权失败",
  172. icon: "none"
  173. });
  174. })
  175. },
  176. fail: () => {
  177. uni.showToast({
  178. title: "微信登录授权失败",
  179. icon: "none"
  180. });
  181. }
  182. })
  183. },
  184. fail: () => {
  185. uni.showToast({
  186. title: "微信登录授权失败",
  187. icon: "none"
  188. });
  189. }
  190. })
  191. } else {
  192. uni.showToast({
  193. title: '请先安装微信或升级版本',
  194. icon: "none"
  195. });
  196. }
  197. }
  198. });
  199. },
  200. // 下拉刷新
  201. onRefresh() {
  202. this.getPreferGoodsList()
  203. },
  204. // 刷新终止
  205. onRestore() {
  206. this.triggered = 'restore'
  207. },
  208. // 获取猜你喜欢商品列表
  209. getPreferGoodsList() {
  210. NET.request(API.getPreferGoods, {}, 'GET').then(res => {
  211. if (res.code == 0) {
  212. this.triggered = false;
  213. this.goodsList = res.data
  214. } else {
  215. uni.showToast({
  216. title: "获取猜你喜欢商品列表失败",
  217. icon: "none"
  218. })
  219. }
  220. })
  221. },
  222. // 跳转商品列表
  223. goToGoodList(data, type) {
  224. if (type) {
  225. uni.navigateTo({
  226. url: '/pagesGood/goodList?goodType=' + type
  227. });
  228. } else {
  229. uni.navigateTo({
  230. url: '/pagesGood/goodList?goodName=' + data.value + '&goodType=0'
  231. });
  232. }
  233. },
  234. // 跳转商品详情
  235. goToGoodDetails(item) {
  236. uni.navigateTo({
  237. url: '/pagesGood/goodDetails?goodId=' + item.productId
  238. });
  239. }
  240. }
  241. }
  242. </script>
  243. <style lang="less" scoped>
  244. .container {
  245. background-size: 128px 124px;
  246. background-position: center;
  247. background-repeat: no-repeat;
  248. background-image: url(@/static/images/indexBg.png);
  249. .search {
  250. width: 100%;
  251. position: absolute;
  252. z-index: 10;
  253. .uni-searchbar {
  254. background-color: transparent;
  255. }
  256. }
  257. .swiper {
  258. height: 175px;
  259. background-color: #6CA63A;
  260. }
  261. .entrance {
  262. width: calc(100% - 24px);
  263. height: 100px;
  264. margin-top: -16px;
  265. margin-left: 12px;
  266. display: flex;
  267. justify-content: space-between;
  268. background-color: #FFFFFF;
  269. border-radius: 15px;
  270. box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.35);
  271. .entrance-col {
  272. width: 96px;
  273. height: 72px;
  274. margin-top: 15px;
  275. background-size: 96px 56px;
  276. background-position: center 10px;
  277. background-repeat: no-repeat;
  278. background-image: url(@/static/images/entrance.png);
  279. .entrance-button {
  280. width: 96px;
  281. height: 72px;
  282. padding-top: 60px;
  283. box-sizing: border-box;
  284. text-align: center;
  285. font-size: 15px;
  286. font-family: PingFang SC;
  287. color: #52A63A;
  288. line-height: 12px;
  289. background-size: 50px;
  290. background-position: center top;
  291. background-repeat: no-repeat;
  292. }
  293. .caizhai {
  294. background-image: url(@/static/images/caizhai.png);
  295. }
  296. .zhongzhi {
  297. background-image: url(@/static/images/zhongzhi.png);
  298. }
  299. .paimai {
  300. background-image: url(@/static/images/paimai.png);
  301. }
  302. }
  303. }
  304. .index-title {
  305. width: calc(100% - 24px);
  306. border-left: 1px solid #6CA63A;
  307. padding: 2px 0 2px 5px;
  308. margin: 15px 12px 8px 12px;
  309. .title-text {
  310. height: 16px;
  311. line-height: 16px;
  312. font-size: 15px;
  313. font-family: PingFang SC;
  314. color: #6CA63A;
  315. }
  316. .title-tip {
  317. height: 12px;
  318. line-height: 12px;
  319. font-size: 12px;
  320. font-family: PingFang SC;
  321. color: #666666;
  322. }
  323. }
  324. .content-box {
  325. width: calc(100% - 24px);
  326. margin: 0 12px;
  327. .discount-col {
  328. width: calc(50% - 6px);
  329. background: #FFFFFF;
  330. box-shadow: 1px 2px 19px 0px rgba(0, 0, 0, 0.09);
  331. border-radius: 5px;
  332. padding-bottom: 10px;
  333. overflow: hidden;
  334. .discount-img {
  335. height: 170px;
  336. object-fit: co;
  337. }
  338. .discount-name {
  339. height: 12px;
  340. margin: 7px 6px 10px 6px;
  341. font-size: 12px;
  342. font-family: PingFang SC;
  343. font-weight: 400;
  344. color: #343434;
  345. line-height: 14px;
  346. }
  347. .discount-price {
  348. width: calc(100% - 12px);
  349. margin-left: 6px;
  350. height: 18px;
  351. line-height: 18px;
  352. font-family: PingFang SC;
  353. white-space: nowrap;
  354. text-overflow: ellipsis;
  355. overflow: hidden;
  356. .sale-icon {
  357. font-size: 12px;
  358. color: #6CA63A;
  359. }
  360. .sale-price {
  361. font-size: 18px;
  362. color: #6CA63A;
  363. margin-right: 5px;
  364. }
  365. .price {
  366. font-size: 10px;
  367. text-decoration: line-through;
  368. color: #A67954;
  369. }
  370. }
  371. }
  372. .goods-row {
  373. height: 104px;
  374. margin-bottom: 12px;
  375. background: #FFFFFF;
  376. box-shadow: 0px 2px 19px 0px rgba(0, 0, 0, 0.09);
  377. border-radius: 5px;
  378. overflow: hidden;
  379. display: flex;
  380. .goods-img {
  381. width: 104px;
  382. height: 104px;
  383. object-fit: cover;
  384. }
  385. .goods-info {
  386. width: calc(100% - 104px);
  387. padding: 10px 10px 10px 16px;
  388. box-sizing: border-box;
  389. .goods-name {
  390. height: 30px;
  391. font-size: 15px;
  392. font-family: PingFang SC;
  393. color: #333333;
  394. line-height: 15px;
  395. overflow: hidden;
  396. text-overflow: ellipsis;
  397. display: -webkit-box;
  398. -webkit-line-clamp: 2;
  399. -webkit-box-orient: vertical;
  400. word-wrap: break-word;
  401. }
  402. .goods-number {
  403. height: 16px;
  404. font-size: 12px;
  405. font-family: PingFang SC;
  406. color: #666666;
  407. line-height: 16px;
  408. margin: 8px 0;
  409. }
  410. .goods-price {
  411. height: 24px;
  412. line-height: 24px;
  413. font-family: PingFang SC;
  414. .sale-icon {
  415. font-size: 12px;
  416. color: #6CA63A;
  417. }
  418. .sale-price {
  419. font-size: 24px;
  420. color: #6CA63A;
  421. margin-right: 6px;
  422. }
  423. .price {
  424. font-size: 12px;
  425. text-decoration: line-through;
  426. color: #A67954;
  427. }
  428. }
  429. }
  430. }
  431. }
  432. .video-box {
  433. box-sizing: border-box;
  434. background: #FFFFFF;
  435. box-shadow: 1px 2px 19px 0px rgba(0, 0, 0, 0.09);
  436. border-radius: 5px;
  437. padding: 15px 15px 12px 15px;
  438. display: flex;
  439. .video-col {
  440. width: calc(50% - 11px);
  441. .video-title {
  442. height: 16px;
  443. line-height: 16px;
  444. margin-bottom: 8px;
  445. font-size: 15px;
  446. font-family: PingFang SC;
  447. color: #343434;
  448. white-space: nowrap;
  449. .circular {
  450. width: 16px;
  451. height: 16px;
  452. background-color: #6BA539;
  453. border-radius: 50%;
  454. margin-left: 6px;
  455. text-align: right;
  456. display: inline-grid;
  457. .iconfont {
  458. font-size: 14px;
  459. color: #FFFFFF;
  460. font-weight: bold;
  461. }
  462. }
  463. }
  464. .video-img {
  465. width: 100%;
  466. height: 145px;
  467. object-fit: cover;
  468. }
  469. .video-name {
  470. height: 16px;
  471. margin-top: 10px;
  472. line-height: 16px;
  473. text-align: center;
  474. font-size: 15px;
  475. font-family: PingFang SC;
  476. color: #343434;
  477. }
  478. }
  479. }
  480. }
  481. </style>