index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <view class="container">
  3. <view class="search">
  4. <uni-search-bar radius="100" placeholder="搜索" clearButton="auto" cancelButton="none" bgColor="#ffffff" @confirm="search" />
  5. </view>
  6. <view>
  7. <swiper class="swiper" :indicator-dots="false" :autoplay="true" :interval="3000" :duration="500">
  8. <swiper-item>
  9. <view>A</view>
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. <view class="entrance">
  14. <view class="entrance-col">
  15. <view class="entrance-button caizhai">自助采摘</view>
  16. </view>
  17. <view class="entrance-col">
  18. <view class="entrance-button zhongzhi">共享种植</view>
  19. </view>
  20. <view class="entrance-col">
  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. <view class="content-box">
  67. <view class="goods-row" v-for="(item,index) in goodsList" :key="index" @click="goToGoodDetails(item)">
  68. <cover-image class="goods-img" :src="item.imgPath"></cover-image>
  69. <view class="goods-info">
  70. <view class="goods-name">{{item.productName}}</view>
  71. <view class="goods-number">{{item.sellCount}}人付款</view>
  72. <text class="goods-price">
  73. <text class="sale-icon">¥</text>
  74. <text class="sale-price">{{item.bizPrice}}</text>
  75. <text class="price">原价:{{item.originalPrice}}</text>
  76. </text>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. const NET = require('../../utils/request')
  84. const API = require('../../config/api')
  85. export default {
  86. data() {
  87. return {
  88. liveTelecast: null,
  89. shortVideo: null,
  90. discountList: [],
  91. goodsList: [],
  92. }
  93. },
  94. onLoad(options) {
  95. // this.appLoginWx()
  96. NET.request(API.getAdvert, {}, 'GET').then(res => {
  97. if (res.code == 0) {
  98. } else {
  99. uni.showToast({
  100. title: "获取广告列表失败",
  101. icon: "none"
  102. });
  103. }
  104. })
  105. NET.request(API.getLiveTelecast + '/1/1', {}, 'GET').then(res => {
  106. if (res.code == 0) {
  107. this.liveTelecast = res.data.list.length ? res.data.list[0] : null
  108. } else {
  109. uni.showToast({
  110. title: "获取直播列表失败",
  111. icon: "none"
  112. });
  113. }
  114. })
  115. NET.request(API.getShortVideo + '/1/1', {}, 'GET').then(res => {
  116. if (res.code == 0) {
  117. this.shortVideo = res.data.list.length ? res.data.list[0] : null
  118. } else {
  119. uni.showToast({
  120. title: "获取短视频列表失败",
  121. icon: "none"
  122. });
  123. }
  124. })
  125. NET.request(API.getPreferentialGoods, {}, 'GET').then(res => {
  126. if (res.code == 0) {
  127. this.discountList = res.data
  128. } else {
  129. uni.showToast({
  130. title: "获取今日特惠商品列表失败",
  131. icon: "none"
  132. });
  133. }
  134. })
  135. NET.request(API.getPreferGoods, {}, 'GET').then(res => {
  136. if (res.code == 0) {
  137. this.goodsList = res.data
  138. } else {
  139. uni.showToast({
  140. title: "获取猜你喜欢商品列表失败",
  141. icon: "none"
  142. });
  143. }
  144. })
  145. },
  146. methods: {
  147. appLoginWx() {
  148. uni.getProvider({
  149. service: 'oauth',
  150. success: function(res) {
  151. if (~res.provider.indexOf('weixin')) {
  152. uni.login({
  153. provider: 'weixin',
  154. success: (res2) => {
  155. uni.getUserInfo({
  156. provider: 'weixin',
  157. success: (info) => { //这里请求接口
  158. NET.request(API.WxLogin, {
  159. code: res2.code,
  160. encryptedData: info.encryptedData,
  161. iv: info.iv,
  162. rawData: info.rawData,
  163. signature: info.signature,
  164. }, 'POST').then(res3 => {
  165. if (res.code == 0) {
  166. uni.setStorage({
  167. key: 'token',
  168. data: res3.data.token
  169. });
  170. }
  171. }).catch(res3 => {
  172. uni.showToast({
  173. title: "微信登录授权失败",
  174. icon: "none"
  175. });
  176. })
  177. },
  178. fail: () => {
  179. uni.showToast({
  180. title: "微信登录授权失败",
  181. icon: "none"
  182. });
  183. }
  184. })
  185. },
  186. fail: () => {
  187. uni.showToast({
  188. title: "微信登录授权失败",
  189. icon: "none"
  190. });
  191. }
  192. })
  193. } else {
  194. uni.showToast({
  195. title: '请先安装微信或升级版本',
  196. icon: "none"
  197. });
  198. }
  199. }
  200. });
  201. },
  202. goToGoodDetails(item) {
  203. uni.navigateTo({
  204. url: '/pagesGood/goodDetails?goodId=' + item.productId
  205. });
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="less" scoped>
  211. .container {
  212. background-size: 128px 124px;
  213. background-position: center;
  214. background-repeat: no-repeat;
  215. background-image: url(@/static/images/indexBg.png);
  216. .search {
  217. width: 100%;
  218. position: absolute;
  219. z-index: 10;
  220. .uni-searchbar {
  221. background-color: transparent;
  222. }
  223. }
  224. .swiper {
  225. height: 175px;
  226. background-color: #6CA63A;
  227. }
  228. .entrance {
  229. width: calc(100% - 24px);
  230. height: 100px;
  231. margin-top: -16px;
  232. margin-left: 12px;
  233. display: flex;
  234. justify-content: space-between;
  235. background-color: #FFFFFF;
  236. border-radius: 15px;
  237. box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.35);
  238. .entrance-col {
  239. width: 96px;
  240. height: 72px;
  241. margin-top: 15px;
  242. background-size: 96px 56px;
  243. background-position: center 10px;
  244. background-repeat: no-repeat;
  245. background-image: url(@/static/images/entrance.png);
  246. .entrance-button {
  247. width: 96px;
  248. height: 72px;
  249. padding-top: 60px;
  250. box-sizing: border-box;
  251. text-align: center;
  252. font-size: 15px;
  253. font-family: PingFang SC;
  254. color: #52A63A;
  255. line-height: 12px;
  256. background-size: 50px;
  257. background-position: center top;
  258. background-repeat: no-repeat;
  259. }
  260. .caizhai {
  261. background-image: url(@/static/images/caizhai.png);
  262. }
  263. .zhongzhi {
  264. background-image: url(@/static/images/zhongzhi.png);
  265. }
  266. .paimai {
  267. background-image: url(@/static/images/paimai.png);
  268. }
  269. }
  270. }
  271. .index-title {
  272. width: calc(100% - 24px);
  273. border-left: 1px solid #6CA63A;
  274. padding: 2px 0 2px 5px;
  275. margin: 15px 12px 8px 12px;
  276. .title-text {
  277. height: 16px;
  278. line-height: 16px;
  279. font-size: 15px;
  280. font-family: PingFang SC;
  281. color: #6CA63A;
  282. }
  283. .title-tip {
  284. height: 12px;
  285. line-height: 12px;
  286. font-size: 12px;
  287. font-family: PingFang SC;
  288. color: #666666;
  289. }
  290. }
  291. .content-box {
  292. width: calc(100% - 24px);
  293. margin: 0 12px;
  294. .discount-col {
  295. width: calc(50% - 6px);
  296. background: #FFFFFF;
  297. box-shadow: 1px 2px 19px 0px rgba(0, 0, 0, 0.09);
  298. border-radius: 5px;
  299. padding-bottom: 10px;
  300. overflow: hidden;
  301. .discount-img {
  302. height: 170px;
  303. object-fit: co;
  304. }
  305. .discount-name {
  306. height: 12px;
  307. margin: 7px 6px 10px 6px;
  308. font-size: 12px;
  309. font-family: PingFang SC;
  310. font-weight: 400;
  311. color: #343434;
  312. line-height: 14px;
  313. }
  314. .discount-price {
  315. width: calc(100% - 12px);
  316. margin-left: 6px;
  317. height: 18px;
  318. line-height: 18px;
  319. font-family: PingFang SC;
  320. white-space: nowrap;
  321. text-overflow: ellipsis;
  322. overflow: hidden;
  323. .sale-icon {
  324. font-size: 12px;
  325. color: #6CA63A;
  326. }
  327. .sale-price {
  328. font-size: 18px;
  329. color: #6CA63A;
  330. margin-right: 5px;
  331. }
  332. .price {
  333. font-size: 10px;
  334. text-decoration: line-through;
  335. color: #A67954;
  336. }
  337. }
  338. }
  339. .goods-row {
  340. height: 104px;
  341. margin-bottom: 12px;
  342. background: #FFFFFF;
  343. box-shadow: 0px 2px 19px 0px rgba(0, 0, 0, 0.09);
  344. border-radius: 5px;
  345. overflow: hidden;
  346. display: flex;
  347. .goods-img {
  348. width: 104px;
  349. height: 104px;
  350. object-fit: cover;
  351. }
  352. .goods-info {
  353. width: calc(100% - 104px);
  354. padding: 10px 10px 10px 16px;
  355. box-sizing: border-box;
  356. .goods-name {
  357. height: 30px;
  358. font-size: 15px;
  359. font-family: PingFang SC;
  360. color: #333333;
  361. line-height: 15px;
  362. overflow: hidden;
  363. text-overflow: ellipsis;
  364. display: -webkit-box;
  365. -webkit-line-clamp: 2;
  366. -webkit-box-orient: vertical;
  367. word-wrap: break-word;
  368. }
  369. .goods-number {
  370. height: 16px;
  371. font-size: 12px;
  372. font-family: PingFang SC;
  373. color: #666666;
  374. line-height: 16px;
  375. margin: 8px 0;
  376. }
  377. .goods-price {
  378. height: 24px;
  379. line-height: 24px;
  380. font-family: PingFang SC;
  381. .sale-icon {
  382. font-size: 12px;
  383. color: #6CA63A;
  384. }
  385. .sale-price {
  386. font-size: 24px;
  387. color: #6CA63A;
  388. margin-right: 6px;
  389. }
  390. .price {
  391. font-size: 12px;
  392. text-decoration: line-through;
  393. color: #A67954;
  394. }
  395. }
  396. }
  397. }
  398. }
  399. .video-box {
  400. box-sizing: border-box;
  401. background: #FFFFFF;
  402. box-shadow: 1px 2px 19px 0px rgba(0, 0, 0, 0.09);
  403. border-radius: 5px;
  404. padding: 15px 15px 12px 15px;
  405. display: flex;
  406. .video-col {
  407. width: calc(50% - 11px);
  408. .video-title {
  409. height: 16px;
  410. line-height: 16px;
  411. margin-bottom: 8px;
  412. font-size: 15px;
  413. font-family: PingFang SC;
  414. color: #343434;
  415. white-space: nowrap;
  416. .circular {
  417. width: 16px;
  418. height: 16px;
  419. background-color: #6BA539;
  420. border-radius: 50%;
  421. margin-left: 6px;
  422. text-align: right;
  423. display: inline-grid;
  424. .iconfont {
  425. font-size: 14px;
  426. color: #FFFFFF;
  427. font-weight: bold;
  428. }
  429. }
  430. }
  431. .video-img {
  432. width: 100%;
  433. height: 145px;
  434. object-fit: cover;
  435. }
  436. .video-name {
  437. height: 16px;
  438. margin-top: 10px;
  439. line-height: 16px;
  440. text-align: center;
  441. font-size: 15px;
  442. font-family: PingFang SC;
  443. color: #343434;
  444. }
  445. }
  446. }
  447. }
  448. </style>