index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  3. <scroll-view scroll-y="true" class="scroll-view" scroll-with-animation :scroll-top="scrollTop" @scroll="scroll" @scrolltolower="toPage">
  4. <view class="list-scroll-view">
  5. <view class="main">
  6. <view class="zero one">
  7. <input type="text" placeholder="搜索商品" @tap="toCommon('pagesHome/market/search')" placeholder-class="placss">
  8. </view>
  9. <view class="zero two">
  10. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#ffffff" indicator-active-color="#FB1438" :autoplay="true" :interval="3000" :duration="1000">
  11. <swiper-item class="list" v-for="(item,index) in bannerList" :key="index" @tap="toBanner(item)">
  12. <image class="image" :src="item.url&&item.url.length>0?item.url[0].url:''" mode="">
  13. </image>
  14. </swiper-item>
  15. </swiper>
  16. </view>
  17. <view class="zero thr">
  18. <view class="list" v-for="(item,index) in btnList" :key="index" @tap="toIndexModel(item)">
  19. <image class="image" :src="item.url&&item.url.length>0?item.url[0].url:''" mode=""></image>
  20. <view class="textOver name">
  21. {{item.name}}
  22. </view>
  23. </view>
  24. </view>
  25. <view class="zero four" v-if="recomList&&recomList.length>0">
  26. <view class="recomList" v-for="(item,index) in recomList" :key="index" v-if="item.list&&item.list.length>0">
  27. <view class="list" v-for="(tag,indexs) in item.list" :key="indexs" @tap="toBuy(tag)">
  28. <view class="list_1">
  29. <view class="txt">
  30. <text>{{tag.title}}</text>
  31. </view>
  32. <view class="more" v-if="indexs==1" @tap.stop="toMore(tag)">
  33. <text>更多</text>
  34. </view>
  35. </view>
  36. <view class="list_2">
  37. <image class="image" :src="tag.url&&tag.url.length>0?tag.url[0].url:''" mode="">
  38. </image>
  39. </view>
  40. <view class="list_3 textOver">
  41. {{tag.name}}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="zero act">
  47. <view class="list" v-for="(item,index) in platformactList" :key="index" @tap="toAct(item)">
  48. <view class="img">
  49. <image class="image" :src="item.cover&&item.cover.length>0?item.cover[0].url:''" mode="">
  50. </image>
  51. </view>
  52. <view class="title" v-if="item.act_time.is_use=='0'">
  53. <text>{{item.act_time.title}}</text>
  54. </view>
  55. <view class="time" v-if="item.act_time.is_use=='0'">
  56. <text>{{item.act_time.value}}</text>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="zero five">
  61. <view class="five_pubu">
  62. <view class="list" v-for="(item,index) in marketList" :key="index" @tap="toBuy(item)">
  63. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="">
  64. </image>
  65. <view class="name textOver">
  66. {{item.name}}
  67. </view>
  68. <view class="other">
  69. <view class="money">
  70. <view class="money_1">
  71. <text>¥</text><text>{{item.sell_money||0}}</text>
  72. </view>
  73. <view class="money_2">
  74. <text>¥</text><text>{{item.flow_money||0}}</text>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="acttags">
  79. <text v-for="i in item.actTagsShow" :key="i">{{i.label}}</text>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </scroll-view>
  87. <view class="backTop" v-if="old_scrollTop>500">
  88. <text @tap="goTop" class="iconfont icon-fanhuidingbu"></text>
  89. </view>
  90. </mobile-frame>
  91. </template>
  92. <script>
  93. export default {
  94. data() {
  95. return {
  96. frameStyle: {
  97. useBar: true
  98. },
  99. bannerList: [ // 轮播图
  100. ],
  101. btnList: [ //功能按钮
  102. ],
  103. recomList: [ //推荐好物
  104. ],
  105. platformactList: [ //平台活动
  106. ],
  107. marketList: [ //商品列表
  108. ],
  109. total: 0,
  110. skip: 0,
  111. limit: 10,
  112. page: 0,
  113. // 返回顶部
  114. scrollTop: 0,
  115. old_scrollTop: 0
  116. };
  117. },
  118. onLoad: function() {
  119. const that = this;
  120. that.search();
  121. },
  122. onPullDownRefresh: async function() {
  123. const that = this;
  124. that.clearPage();
  125. await that.search();
  126. uni.stopPullDownRefresh();
  127. },
  128. methods: {
  129. async search() {
  130. const that = this;
  131. let res;
  132. // 轮播图
  133. res = await that.$api(`/banner`, 'GET', {
  134. status: '0'
  135. });
  136. if (res.errcode == '0') {
  137. let data = res.data.sort(function(a, b) {
  138. return a.sort - b.sort
  139. });
  140. that.$set(that, `bannerList`, data);
  141. }
  142. // 首页模块管理
  143. res = await that.$api(`/indexModule`, 'GET', {});
  144. if (res.errcode == '0') {
  145. let data = res.data.sort(function(a, b) {
  146. return a.sort - b.sort
  147. });
  148. that.$set(that, `btnList`, data);
  149. }
  150. // 推荐好货
  151. res = await that.$api(`/viewGoods/iatg`, 'GET', {});
  152. if (res.errcode == '0') that.$set(that, `recomList`, res.data);
  153. // 平台活动
  154. res = await that.$api(`/platformAct`, 'GET', {
  155. show_index: 0
  156. });
  157. if (res.errcode == '0') that.$set(that, `platformactList`, res.data);
  158. // 首页产品查询
  159. that.searchMarket()
  160. },
  161. // 首页产品查询
  162. async searchMarket() {
  163. const that = this;
  164. let res;
  165. let info = {
  166. skip: that.skip,
  167. limit: that.limit
  168. };
  169. // 首页产品列表
  170. res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  171. ...info
  172. });
  173. if (res.errcode == '0') {
  174. let list = [...that.marketList, ...res.data];
  175. that.$set(that, `marketList`, list);
  176. that.$set(that, `total`, res.total)
  177. }
  178. },
  179. // 公共跳转
  180. toCommon(e) {
  181. uni.navigateTo({
  182. url: `/${e}`
  183. })
  184. },
  185. // 轮播图跳转
  186. toBanner(e) {
  187. uni.navigateTo({
  188. url: `/${e.to}?id=${e._id}`
  189. })
  190. },
  191. // 首页模块菜单跳转
  192. toIndexModel(data) {
  193. if (data && data.status == '1') {
  194. uni.showToast({
  195. title: '升级中敬请期待!',
  196. icon: 'none'
  197. })
  198. } else {
  199. uni.navigateTo({
  200. url: `/${data.to}`
  201. })
  202. }
  203. },
  204. // 推荐好物更多
  205. toMore(e) {
  206. const that = this;
  207. uni.navigateTo({
  208. url: `/pagesRest/recom/index?act_tags=${e.value}`
  209. })
  210. },
  211. // 平台活动
  212. toAct(e) {
  213. const that = this;
  214. uni.navigateTo({
  215. url: `/pagesRest/activity/info?id=${e._id}`
  216. })
  217. },
  218. // 购买
  219. toBuy(e) {
  220. const that = this;
  221. let id = e._id || e.id;
  222. uni.navigateTo({
  223. url: `/pagesHome/order/detail?id=${id}`
  224. })
  225. },
  226. // 分页
  227. toPage(e) {
  228. const that = this;
  229. let list = that.marketList;
  230. let limit = that.limit;
  231. if (that.total > list.length) {
  232. uni.showLoading({
  233. title: '加载中',
  234. mask: true
  235. })
  236. let page = that.page + 1;
  237. that.$set(that, `page`, page)
  238. let skip = page * limit;
  239. that.$set(that, `skip`, skip)
  240. that.searchMarket();
  241. uni.hideLoading();
  242. }
  243. },
  244. // 计算高度
  245. scroll: function(e) {
  246. const that = this;
  247. that.old_scrollTop = e.detail.scrollTop
  248. },
  249. // 返回顶部
  250. goTop: function(e) {
  251. const that = this;
  252. that.scrollTop = that.old_scrollTop;
  253. that.$nextTick(function() {
  254. that.scrollTop = 0
  255. });
  256. },
  257. clearPage() {
  258. const that = this;
  259. that.$set(that, `bannerList`, [])
  260. that.$set(that, `btnList`, [])
  261. that.$set(that, `recomList`, [])
  262. that.$set(that, `platformactList`, [])
  263. that.$set(that, `marketList`, [])
  264. that.$set(that, `skip`, 0)
  265. that.$set(that, `limit`, 6)
  266. that.$set(that, `page`, 0)
  267. },
  268. // 菜单跳转
  269. toPath(e) {
  270. let url = `/${e.route}`;
  271. if (e.type == '0') uni.redirectTo({
  272. url
  273. })
  274. else {
  275. uni.navigateTo({
  276. url
  277. })
  278. }
  279. },
  280. }
  281. }
  282. </script>
  283. <style lang="scss">
  284. .main {
  285. padding: 2vw;
  286. .zero {
  287. margin: 0 0 2vw 0;
  288. }
  289. .zero:last-child {
  290. margin: 0
  291. }
  292. .one {
  293. background-color: var(--fFB1Color);
  294. border-radius: 20px;
  295. padding: 0 2vw;
  296. input {
  297. font-size: var(--font15Size);
  298. color: var(--fffColor);
  299. border-radius: 14px;
  300. width: 100%;
  301. padding: 1.5vw 0;
  302. }
  303. .placss {
  304. color: var(--fffColor);
  305. }
  306. }
  307. .two {
  308. swiper {
  309. height: 50vw;
  310. border-radius: 5px;
  311. }
  312. .list {
  313. border-radius: 5px;
  314. .image {
  315. width: 100%;
  316. height: 100%;
  317. border-radius: 5px;
  318. }
  319. }
  320. }
  321. .thr {
  322. display: flex;
  323. flex-direction: row;
  324. justify-content: space-around;
  325. flex-wrap: wrap;
  326. .list {
  327. width: 17vw;
  328. text-align: center;
  329. margin: 0 0 2vw 0;
  330. .image {
  331. width: 80%;
  332. height: 13vw;
  333. margin: 1.5vw 0 1.5vw 0;
  334. }
  335. .name {
  336. font-size: var(--font13Size);
  337. }
  338. }
  339. }
  340. .four {
  341. display: flex;
  342. flex-direction: row;
  343. justify-content: space-around;
  344. flex-wrap: wrap;
  345. background-color: var(--f2Color);
  346. padding: 2vw 0 0 0;
  347. .recomList {
  348. width: 41vw;
  349. display: flex;
  350. justify-content: space-around;
  351. background-image: linear-gradient(to bottom, rgba(250, 216, 213, 1) 5%, rgba(255, 255, 255, 1) 22%);
  352. margin: 0 0 2vw 0;
  353. border-radius: 5px;
  354. padding: 2vw;
  355. .list {
  356. width: 20vw;
  357. text-align: center;
  358. .list_1 {
  359. display: flex;
  360. justify-content: space-between;
  361. margin: 0 0 1vw 0;
  362. .txt {
  363. font-size: 15px;
  364. }
  365. .more {
  366. font-size: 12px;
  367. margin: 0 0 4px 0;
  368. }
  369. }
  370. .list_2 {
  371. margin: 0 0 1vw 0;
  372. .image {
  373. width: 96%;
  374. height: 18vw;
  375. }
  376. }
  377. .list_3 {
  378. width: 17vw;
  379. font-size: var(--font12Size);
  380. border: 1px solid var(--fFB1Color);
  381. border-radius: 25px;
  382. padding: 0 1vw;
  383. text-align: center;
  384. }
  385. }
  386. }
  387. }
  388. .act {
  389. background-color: var(--f2Color);
  390. padding: 2vw 2vw 0 2vw;
  391. display: flex;
  392. flex-direction: column;
  393. .act_1 {
  394. text-align: center;
  395. margin: 0 0 2vw 0;
  396. font-family: cursive;
  397. color: #ff0000;
  398. font-size: 20px;
  399. }
  400. .list {
  401. border-radius: 10px;
  402. position: relative;
  403. .img {
  404. .image {
  405. width: 100%;
  406. height: 14vh;
  407. box-shadow: 0 0 5px #f1f1f1;
  408. border-radius: 10px;
  409. }
  410. }
  411. .title {
  412. position: absolute;
  413. top: 5vw;
  414. text-align: center;
  415. width: 95%;
  416. left: 2vw;
  417. text {
  418. font-size: 20px;
  419. font-family: cursive;
  420. color: #000000;
  421. font-weight: bold;
  422. overflow: hidden;
  423. text-overflow: ellipsis;
  424. -webkit-line-clamp: 2;
  425. word-break: break-all;
  426. display: -webkit-box;
  427. -webkit-box-orient: vertical;
  428. }
  429. }
  430. .time {
  431. position: absolute;
  432. bottom: 2vw;
  433. right: 2vw;
  434. font-size: 12px;
  435. width: 100%;
  436. text-align: right;
  437. }
  438. }
  439. }
  440. .five {
  441. display: flex;
  442. flex-direction: column;
  443. background-color: var(--f2Color);
  444. padding: 2vw 0;
  445. .five_pubu {
  446. // column-count: 2;
  447. // column-gap: 2vw;
  448. display: flex;
  449. justify-content: space-between;
  450. flex-wrap: wrap;
  451. padding: 0 2vw;
  452. .list {
  453. // break-inside: avoid;
  454. position: relative;
  455. width: 41vw;
  456. background-color: var(--fffColor);
  457. padding: 2vw;
  458. margin: 0 0 2vw 0;
  459. border-radius: 10px;
  460. .image {
  461. width: 100%;
  462. height: 40vw;
  463. }
  464. .name {
  465. font-size: var(--font14Size);
  466. margin: 0 0 1vw 0;
  467. }
  468. .other {
  469. display: flex;
  470. flex-direction: row;
  471. justify-content: space-between;
  472. .money {
  473. display: flex;
  474. .money_1 {
  475. color: var(--fFB1Color);
  476. font-size: 12px;
  477. text:last-child {
  478. font-size: 16px;
  479. padding: 0 0 0 1vw;
  480. }
  481. }
  482. .money_2 {
  483. font-size: 12px;
  484. margin: 0 0 0 2vw;
  485. color: var(--f99Color);
  486. text {
  487. text-decoration: line-through;
  488. }
  489. text:last-child {
  490. font-size: 16px;
  491. padding: 0 0 0 1vw;
  492. }
  493. }
  494. }
  495. }
  496. .acttags {
  497. position: absolute;
  498. top: 2vw;
  499. width: 93%;
  500. text {
  501. display: inline-block;
  502. background-color: #ff0000;
  503. color: #fff;
  504. border-radius: 1vw;
  505. padding: 0.5vw;
  506. font-size: 12px;
  507. margin: 0 1vw 0 0;
  508. }
  509. }
  510. }
  511. }
  512. }
  513. }
  514. .scroll-view {
  515. position: absolute;
  516. top: 0;
  517. left: 0;
  518. right: 0;
  519. bottom: 0;
  520. .list-scroll-view {
  521. display: flex;
  522. flex-direction: column;
  523. }
  524. }
  525. .backTop {
  526. position: fixed;
  527. bottom: 20vw;
  528. right: 5vw;
  529. text {
  530. font-size: 30px;
  531. background-color: #0000005f;
  532. border-radius: 90px;
  533. }
  534. }
  535. </style>