index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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',{customer: user._id,status:'0'});
  157. if (res.errcode == '0') that.$set(that, `notice_total`,res.total);
  158. }
  159. }
  160. })
  161. },
  162. async search() {
  163. const that = this;
  164. let res;
  165. // 轮播图
  166. res = await that.$api(`/banner`, 'GET', {
  167. status: '0'
  168. });
  169. if (res.errcode == '0') {
  170. let data = res.data.sort(function(a, b) {
  171. return a.sort - b.sort
  172. });
  173. that.$set(that, `bannerList`, data);
  174. }
  175. // 首页模块管理
  176. res = await that.$api(`/indexModule`, 'GET', {});
  177. if (res.errcode == '0') {
  178. let data = res.data.sort(function(a, b) {
  179. return a.sort - b.sort
  180. });
  181. that.$set(that, `btnList`, data);
  182. }
  183. // 推荐好货
  184. res = await that.$api(`/viewGoods/iatg`, 'GET', {});
  185. if (res.errcode == '0') that.$set(that, `recomList`, res.data);
  186. // 平台活动
  187. res = await that.$api(`/platformAct`, 'GET', {
  188. show_index: 0
  189. });
  190. if (res.errcode == '0') that.$set(that, `platformactList`, res.data);
  191. // 首页产品查询
  192. that.searchMarket()
  193. },
  194. // 首页产品查询
  195. async searchMarket() {
  196. const that = this;
  197. let res;
  198. let info = {
  199. skip: that.skip,
  200. limit: that.limit
  201. };
  202. // 首页产品列表
  203. res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  204. ...info
  205. });
  206. if (res.errcode == '0') {
  207. let list = [...that.marketList, ...res.data];
  208. that.$set(that, `marketList`, list);
  209. that.$set(that, `total`, res.total)
  210. }
  211. },
  212. // 系统消息页
  213. toNotice(){
  214. uni.navigateTo({
  215. url: `/pagesHome/notice/index`
  216. })
  217. },
  218. // 公共跳转
  219. toCommon(e) {
  220. uni.navigateTo({
  221. url: `/${e}`
  222. })
  223. },
  224. // 轮播图跳转
  225. toBanner(e) {
  226. uni.navigateTo({
  227. url: `/${e.to}?id=${e._id}`
  228. })
  229. },
  230. // 首页模块菜单跳转
  231. toIndexModel(data) {
  232. if (data && data.status == '1') {
  233. uni.showToast({
  234. title: '升级中敬请期待!',
  235. icon: 'none'
  236. })
  237. } else {
  238. uni.navigateTo({
  239. url: `/${data.to}`
  240. })
  241. }
  242. },
  243. // 推荐好物更多
  244. toMore(e) {
  245. const that = this;
  246. uni.navigateTo({
  247. url: `/pagesRest/recom/index?act_tags=${e.value}`
  248. })
  249. },
  250. // 平台活动
  251. toAct(e) {
  252. const that = this;
  253. uni.navigateTo({
  254. url: `/pagesRest/activity/info?id=${e._id}`
  255. })
  256. },
  257. // 购买
  258. toBuy(e) {
  259. const that = this;
  260. let id = e._id || e.id;
  261. uni.navigateTo({
  262. url: `/pagesHome/order/detail?id=${id}`
  263. })
  264. },
  265. // 分页
  266. toPage(e) {
  267. const that = this;
  268. let list = that.marketList;
  269. let limit = that.limit;
  270. if (that.total > list.length) {
  271. uni.showLoading({
  272. title: '加载中',
  273. mask: true
  274. })
  275. let page = that.page + 1;
  276. that.$set(that, `page`, page)
  277. let skip = page * limit;
  278. that.$set(that, `skip`, skip)
  279. that.searchMarket();
  280. uni.hideLoading();
  281. }
  282. },
  283. // 计算高度
  284. scroll: function(e) {
  285. const that = this;
  286. that.old_scrollTop = e.detail.scrollTop
  287. },
  288. // 返回顶部
  289. goTop: function(e) {
  290. const that = this;
  291. that.scrollTop = that.old_scrollTop;
  292. that.$nextTick(function() {
  293. that.scrollTop = 0
  294. });
  295. },
  296. clearPage() {
  297. const that = this;
  298. that.$set(that, `bannerList`, [])
  299. that.$set(that, `btnList`, [])
  300. that.$set(that, `recomList`, [])
  301. that.$set(that, `platformactList`, [])
  302. that.$set(that, `marketList`, [])
  303. that.$set(that, `skip`, 0)
  304. that.$set(that, `limit`, 6)
  305. that.$set(that, `page`, 0)
  306. },
  307. // 菜单跳转
  308. toPath(e) {
  309. let url = `/${e.route}`;
  310. if (e.type == '0') uni.redirectTo({
  311. url
  312. })
  313. else {
  314. uni.navigateTo({
  315. url
  316. })
  317. }
  318. },
  319. }
  320. }
  321. </script>
  322. <style lang="scss">
  323. .main {
  324. padding: 2vw;
  325. .zero {
  326. margin: 0 0 2vw 0;
  327. }
  328. .zero:last-child {
  329. margin: 0
  330. }
  331. .one {
  332. display: flex;
  333. justify-content: center;
  334. align-items: center;
  335. .one_1{
  336. width: 88vw;
  337. background-color: var(--fFB1Color);
  338. border-radius: 20px;
  339. padding: 0 2vw;
  340. input {
  341. font-size: var(--font15Size);
  342. color: var(--fffColor);
  343. border-radius: 14px;
  344. width: 100%;
  345. padding: 1.5vw 0;
  346. }
  347. .placss {
  348. color: var(--fffColor);
  349. }
  350. }
  351. .one_2{
  352. width: 12vw;
  353. text-align: center;
  354. .iconfont{
  355. font-size: 24px;
  356. }
  357. }
  358. }
  359. .two {
  360. swiper {
  361. height: 50vw;
  362. border-radius: 5px;
  363. }
  364. .list {
  365. border-radius: 5px;
  366. .image {
  367. width: 100%;
  368. height: 100%;
  369. border-radius: 5px;
  370. }
  371. }
  372. }
  373. .thr {
  374. display: flex;
  375. flex-direction: row;
  376. justify-content: space-around;
  377. flex-wrap: wrap;
  378. .list {
  379. width: 17vw;
  380. text-align: center;
  381. margin: 0 0 2vw 0;
  382. .image {
  383. width: 80%;
  384. height: 13vw;
  385. margin: 1.5vw 0 1.5vw 0;
  386. }
  387. .name {
  388. font-size: var(--font13Size);
  389. }
  390. }
  391. }
  392. .four {
  393. display: flex;
  394. flex-direction: row;
  395. justify-content: space-around;
  396. flex-wrap: wrap;
  397. background-color: var(--f2Color);
  398. padding: 2vw 0 0 0;
  399. .recomList {
  400. width: 41vw;
  401. display: flex;
  402. justify-content: space-around;
  403. background-image: linear-gradient(to bottom, rgba(250, 216, 213, 1) 5%, rgba(255, 255, 255, 1) 22%);
  404. margin: 0 0 2vw 0;
  405. border-radius: 5px;
  406. padding: 2vw;
  407. .list {
  408. width: 20vw;
  409. text-align: center;
  410. .list_1 {
  411. display: flex;
  412. justify-content: space-between;
  413. margin: 0 0 1vw 0;
  414. .txt {
  415. font-size: 15px;
  416. }
  417. .more {
  418. font-size: 12px;
  419. margin: 0 0 4px 0;
  420. }
  421. }
  422. .list_2 {
  423. margin: 0 0 1vw 0;
  424. .image {
  425. width: 96%;
  426. height: 18vw;
  427. }
  428. }
  429. .list_3 {
  430. width: 17vw;
  431. font-size: var(--font12Size);
  432. border: 1px solid var(--fFB1Color);
  433. border-radius: 25px;
  434. padding: 0 1vw;
  435. text-align: center;
  436. }
  437. }
  438. }
  439. }
  440. .act {
  441. background-color: var(--f2Color);
  442. padding: 2vw 2vw 0 2vw;
  443. display: flex;
  444. flex-direction: column;
  445. .act_1 {
  446. text-align: center;
  447. margin: 0 0 2vw 0;
  448. font-family: cursive;
  449. color: #ff0000;
  450. font-size: 20px;
  451. }
  452. .list {
  453. border-radius: 10px;
  454. position: relative;
  455. .img {
  456. .image {
  457. width: 100%;
  458. height: 14vh;
  459. box-shadow: 0 0 5px #f1f1f1;
  460. border-radius: 10px;
  461. }
  462. }
  463. .title {
  464. position: absolute;
  465. top: 5vw;
  466. text-align: center;
  467. width: 95%;
  468. left: 2vw;
  469. text {
  470. font-size: 20px;
  471. font-family: cursive;
  472. color: #000000;
  473. font-weight: bold;
  474. overflow: hidden;
  475. text-overflow: ellipsis;
  476. -webkit-line-clamp: 2;
  477. word-break: break-all;
  478. display: -webkit-box;
  479. -webkit-box-orient: vertical;
  480. }
  481. }
  482. .time {
  483. position: absolute;
  484. bottom: 2vw;
  485. right: 2vw;
  486. font-size: 12px;
  487. width: 100%;
  488. text-align: right;
  489. }
  490. }
  491. }
  492. .five {
  493. display: flex;
  494. flex-direction: column;
  495. background-color: var(--f2Color);
  496. padding: 2vw 0;
  497. .five_pubu {
  498. // column-count: 2;
  499. // column-gap: 2vw;
  500. display: flex;
  501. justify-content: space-between;
  502. flex-wrap: wrap;
  503. padding: 0 2vw;
  504. .list {
  505. // break-inside: avoid;
  506. position: relative;
  507. width: 41vw;
  508. background-color: var(--fffColor);
  509. padding: 2vw;
  510. margin: 0 0 2vw 0;
  511. border-radius: 10px;
  512. .image {
  513. width: 100%;
  514. height: 40vw;
  515. }
  516. .name {
  517. font-size: var(--font14Size);
  518. }
  519. .other {
  520. display: flex;
  521. flex-direction: row;
  522. padding: 1vw 0 0 0;
  523. .money {
  524. display: flex;
  525. .money_1 {
  526. color: var(--fFB1Color);
  527. font-size: 12px;
  528. text:last-child {
  529. font-size: 16px;
  530. padding: 0 0 0 1vw;
  531. }
  532. }
  533. .money_2 {
  534. font-size: 12px;
  535. margin: 0 0 0 2vw;
  536. color: var(--f99Color);
  537. text {
  538. text-decoration: line-through;
  539. }
  540. text:last-child {
  541. font-size: 16px;
  542. padding: 0 0 0 1vw;
  543. }
  544. }
  545. }
  546. .label {
  547. font-size: 12px;
  548. color: #FFA500;
  549. border: 1px solid #FFA500;
  550. border-radius: 5px;
  551. padding: 0 1vw;
  552. margin: 0 1vw 0 0;
  553. }
  554. }
  555. .acttags {
  556. position: absolute;
  557. top: 2vw;
  558. width: 93%;
  559. text {
  560. display: inline-block;
  561. background-color: #ff0000;
  562. color: #fff;
  563. border-radius: 1vw;
  564. padding: 0.5vw;
  565. font-size: 12px;
  566. margin: 0 1vw 0 0;
  567. }
  568. }
  569. }
  570. }
  571. }
  572. }
  573. .scroll-view {
  574. position: absolute;
  575. top: 0;
  576. left: 0;
  577. right: 0;
  578. bottom: 0;
  579. .list-scroll-view {
  580. display: flex;
  581. flex-direction: column;
  582. }
  583. }
  584. .backTop {
  585. position: fixed;
  586. bottom: 20vw;
  587. right: 5vw;
  588. text {
  589. font-size: 30px;
  590. background-color: #0000005f;
  591. border-radius: 90px;
  592. }
  593. }
  594. </style>