index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. console.log(data.to);
  200. uni.navigateTo({
  201. url: `/${data.to}`
  202. })
  203. }
  204. },
  205. // 推荐好物更多
  206. toMore(e) {
  207. const that = this;
  208. uni.navigateTo({
  209. url: `/pagesRest/recom/index?act_tags=${e.value}`
  210. })
  211. },
  212. // 平台活动
  213. toAct(e) {
  214. const that = this;
  215. uni.navigateTo({
  216. url: `/pagesRest/activity/info?id=${e._id}`
  217. })
  218. },
  219. // 购买
  220. toBuy(e) {
  221. const that = this;
  222. let id = e._id || e.id;
  223. uni.navigateTo({
  224. url: `/pagesHome/order/detail?id=${id}`
  225. })
  226. },
  227. // 分页
  228. toPage(e) {
  229. const that = this;
  230. let list = that.marketList;
  231. let limit = that.limit;
  232. if (that.total > list.length) {
  233. uni.showLoading({
  234. title: '加载中',
  235. mask: true
  236. })
  237. let page = that.page + 1;
  238. that.$set(that, `page`, page)
  239. let skip = page * limit;
  240. that.$set(that, `skip`, skip)
  241. that.searchMarket();
  242. uni.hideLoading();
  243. }
  244. },
  245. // 计算高度
  246. scroll: function(e) {
  247. const that = this;
  248. that.old_scrollTop = e.detail.scrollTop
  249. },
  250. // 返回顶部
  251. goTop: function(e) {
  252. const that = this;
  253. that.scrollTop = that.old_scrollTop;
  254. that.$nextTick(function() {
  255. that.scrollTop = 0
  256. });
  257. },
  258. clearPage() {
  259. const that = this;
  260. that.$set(that, `bannerList`, [])
  261. that.$set(that, `btnList`, [])
  262. that.$set(that, `recomList`, [])
  263. that.$set(that, `platformactList`, [])
  264. that.$set(that, `marketList`, [])
  265. that.$set(that, `skip`, 0)
  266. that.$set(that, `limit`, 6)
  267. that.$set(that, `page`, 0)
  268. },
  269. // 菜单跳转
  270. toPath(e) {
  271. let url = `/${e.route}`;
  272. if (e.type == '0') uni.redirectTo({
  273. url
  274. })
  275. else {
  276. uni.navigateTo({
  277. url
  278. })
  279. }
  280. },
  281. }
  282. }
  283. </script>
  284. <style lang="scss">
  285. .main {
  286. padding: 2vw;
  287. .zero {
  288. margin: 0 0 2vw 0;
  289. }
  290. .zero:last-child {
  291. margin: 0
  292. }
  293. .one {
  294. background-color: var(--fFB1Color);
  295. border-radius: 20px;
  296. padding: 0 2vw;
  297. input {
  298. font-size: var(--font15Size);
  299. color: var(--fffColor);
  300. border-radius: 14px;
  301. width: 100%;
  302. padding: 1.5vw 0;
  303. }
  304. .placss {
  305. color: var(--fffColor);
  306. }
  307. }
  308. .two {
  309. swiper {
  310. height: 50vw;
  311. border-radius: 5px;
  312. }
  313. .list {
  314. border-radius: 5px;
  315. .image {
  316. width: 100%;
  317. height: 100%;
  318. border-radius: 5px;
  319. }
  320. }
  321. }
  322. .thr {
  323. display: flex;
  324. flex-direction: row;
  325. justify-content: space-around;
  326. flex-wrap: wrap;
  327. .list {
  328. width: 17vw;
  329. text-align: center;
  330. margin: 0 0 2vw 0;
  331. .image {
  332. width: 80%;
  333. height: 13vw;
  334. margin: 1.5vw 0 1.5vw 0;
  335. }
  336. .name {
  337. font-size: var(--font13Size);
  338. }
  339. }
  340. }
  341. .four {
  342. display: flex;
  343. flex-direction: row;
  344. justify-content: space-around;
  345. flex-wrap: wrap;
  346. background-color: var(--f2Color);
  347. padding: 2vw 0 0 0;
  348. .recomList {
  349. width: 41vw;
  350. display: flex;
  351. justify-content: space-around;
  352. background-image: linear-gradient(to bottom, rgba(250, 216, 213, 1) 5%, rgba(255, 255, 255, 1) 22%);
  353. margin: 0 0 2vw 0;
  354. border-radius: 5px;
  355. padding: 2vw;
  356. .list {
  357. width: 20vw;
  358. text-align: center;
  359. .list_1 {
  360. display: flex;
  361. justify-content: space-between;
  362. margin: 0 0 1vw 0;
  363. .txt {
  364. font-size: 15px;
  365. }
  366. .more {
  367. font-size: 12px;
  368. margin: 0 0 4px 0;
  369. }
  370. }
  371. .list_2 {
  372. margin: 0 0 1vw 0;
  373. .image {
  374. width: 96%;
  375. height: 18vw;
  376. }
  377. }
  378. .list_3 {
  379. width: 17vw;
  380. font-size: var(--font12Size);
  381. border: 1px solid var(--fFB1Color);
  382. border-radius: 25px;
  383. padding: 0 1vw;
  384. text-align: center;
  385. }
  386. }
  387. }
  388. }
  389. .act {
  390. background-color: var(--f2Color);
  391. padding: 2vw 2vw 0 2vw;
  392. display: flex;
  393. flex-direction: column;
  394. .act_1 {
  395. text-align: center;
  396. margin: 0 0 2vw 0;
  397. font-family: cursive;
  398. color: #ff0000;
  399. font-size: 20px;
  400. }
  401. .list {
  402. border-radius: 10px;
  403. position: relative;
  404. .img {
  405. .image {
  406. width: 100%;
  407. height: 14vh;
  408. box-shadow: 0 0 5px #f1f1f1;
  409. border-radius: 10px;
  410. }
  411. }
  412. .title {
  413. position: absolute;
  414. top: 5vw;
  415. text-align: center;
  416. width: 95%;
  417. left: 2vw;
  418. text {
  419. font-size: 20px;
  420. font-family: cursive;
  421. color: #000000;
  422. font-weight: bold;
  423. overflow: hidden;
  424. text-overflow: ellipsis;
  425. -webkit-line-clamp: 2;
  426. word-break: break-all;
  427. display: -webkit-box;
  428. -webkit-box-orient: vertical;
  429. }
  430. }
  431. .time {
  432. position: absolute;
  433. bottom: 2vw;
  434. right: 2vw;
  435. font-size: 12px;
  436. width: 100%;
  437. text-align: right;
  438. }
  439. }
  440. }
  441. .five {
  442. display: flex;
  443. flex-direction: column;
  444. background-color: var(--f2Color);
  445. padding: 2vw 0;
  446. .five_pubu {
  447. // column-count: 2;
  448. // column-gap: 2vw;
  449. display: flex;
  450. justify-content: space-between;
  451. flex-wrap: wrap;
  452. padding: 0 2vw;
  453. .list {
  454. // break-inside: avoid;
  455. position: relative;
  456. width: 41vw;
  457. background-color: var(--fffColor);
  458. padding: 2vw;
  459. margin: 0 0 2vw 0;
  460. border-radius: 10px;
  461. .image {
  462. width: 100%;
  463. height: 40vw;
  464. }
  465. .name {
  466. font-size: var(--font14Size);
  467. margin: 0 0 1vw 0;
  468. }
  469. .other {
  470. display: flex;
  471. flex-direction: row;
  472. justify-content: space-between;
  473. .money {
  474. display: flex;
  475. .money_1 {
  476. color: var(--fFB1Color);
  477. font-size: 12px;
  478. text:last-child {
  479. font-size: 16px;
  480. padding: 0 0 0 1vw;
  481. }
  482. }
  483. .money_2 {
  484. font-size: 12px;
  485. margin: 0 0 0 2vw;
  486. color: var(--f99Color);
  487. text {
  488. text-decoration: line-through;
  489. }
  490. text:last-child {
  491. font-size: 16px;
  492. padding: 0 0 0 1vw;
  493. }
  494. }
  495. }
  496. }
  497. .acttags {
  498. position: absolute;
  499. top: 2vw;
  500. width: 93%;
  501. text {
  502. display: inline-block;
  503. background-color: #ff0000;
  504. color: #fff;
  505. border-radius: 1vw;
  506. padding: 0.5vw;
  507. font-size: 12px;
  508. margin: 0 1vw 0 0;
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. .scroll-view {
  516. position: absolute;
  517. top: 0;
  518. left: 0;
  519. right: 0;
  520. bottom: 0;
  521. .list-scroll-view {
  522. display: flex;
  523. flex-direction: column;
  524. }
  525. }
  526. .backTop {
  527. position: fixed;
  528. bottom: 20vw;
  529. right: 5vw;
  530. text {
  531. font-size: 30px;
  532. background-color: #0000005f;
  533. border-radius: 90px;
  534. }
  535. }
  536. </style>