index.vue 13 KB

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