index.vue 12 KB

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