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