index.vue 14 KB

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