index.vue 12 KB

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