index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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 five">
  46. <view class="five_pubu">
  47. <view class="list" v-for="(item,index) in marketList" :key="index" @tap="toBuy(item)">
  48. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="">
  49. </image>
  50. <view class="name">
  51. {{item.name}}
  52. </view>
  53. <view class="other">
  54. <view class="money">
  55. <view class="money_1">
  56. <text>¥</text><text>{{item.sell_money||0}}</text>
  57. </view>
  58. <view class="money_2">
  59. <text>¥</text><text>{{item.flow_money||0}}</text>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <!-- <view class="is_bottom" v-if="is_bottom">
  67. <text>数据到底了!!</text>
  68. </view> -->
  69. </view>
  70. </view>
  71. </scroll-view>
  72. <view class="backTop" v-if="old.scrollTop>500">
  73. <text @tap="goTop" class="iconfont icon-fanhuidingbu"></text>
  74. </view>
  75. </mobile-frame>
  76. </template>
  77. <script>
  78. import {
  79. getAddress
  80. } from '@/common/tool.js'
  81. export default {
  82. data() {
  83. return {
  84. frameStyle: {
  85. useBar: true
  86. },
  87. bannerList: [ // 轮播图
  88. ],
  89. btnList: [ //功能按钮
  90. ],
  91. recomList: [ //推荐好物
  92. ],
  93. marketList: [ //商品列表
  94. ],
  95. total: 0,
  96. skip: 0,
  97. limit: 6,
  98. page: 0,
  99. // 返回顶部
  100. scrollTop: 0,
  101. old: {
  102. scrollTop: 0
  103. },
  104. // // 数据是否触底
  105. // is_bottom: false,
  106. };
  107. },
  108. onLoad: function() {},
  109. onShow: function() {
  110. const that = this;
  111. that.search();
  112. },
  113. methods: {
  114. async search() {
  115. const that = this;
  116. let res;
  117. // 轮播图
  118. res = await that.$api(`/banner`, 'GET', {
  119. status: '0'
  120. });
  121. if (res.errcode == '0') {
  122. let data = res.data.sort(function(a, b) {
  123. return a.sort - b.sort
  124. });
  125. that.$set(that, `bannerList`, data);
  126. }
  127. // 首页模块管理
  128. res = await that.$api(`/indexModule`, 'GET', {});
  129. if (res.errcode == '0') {
  130. let data = res.data.sort(function(a, b) {
  131. return a.sort - b.sort
  132. });
  133. that.$set(that, `btnList`, data);
  134. }
  135. // 推荐好货
  136. res = await that.$api(`/viewGoods/iatg`, 'GET', {});
  137. if (res.errcode == '0') that.$set(that, `recomList`, res.data);
  138. // 首页产品列表
  139. res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  140. skip: that.skip,
  141. limit: that.limit
  142. });
  143. if (res.errcode == '0') {
  144. let list = [...that.marketList, ...res.data];
  145. that.$set(that, `marketList`, list);
  146. that.$set(that, `total`, res.total)
  147. }
  148. },
  149. // 公共跳转
  150. toCommon(e) {
  151. uni.navigateTo({
  152. url: `/${e}`
  153. })
  154. },
  155. // 轮播图跳转
  156. toBanner(e) {
  157. uni.navigateTo({
  158. url: `/${e.to}?id=${e._id}`
  159. })
  160. },
  161. // 首页模块菜单跳转
  162. toIndexModel(data) {
  163. if (data && data.status == '1') {
  164. uni.showToast({
  165. title: '模块禁用',
  166. icon: 'none'
  167. })
  168. } else {
  169. uni.navigateTo({
  170. url: `/${data.to}`
  171. })
  172. }
  173. },
  174. // 推荐好物更多
  175. toMore(e) {
  176. const that = this;
  177. that.clearPage();
  178. uni.navigateTo({
  179. url: `/pagesRest/recom/index?act_tags=${e.value}&type=2`
  180. })
  181. },
  182. // 购买
  183. toBuy(e) {
  184. const that = this;
  185. that.clearPage();
  186. uni.navigateTo({
  187. url: `/pagesHome/order/detail?id=${e.id||e._id}`
  188. })
  189. },
  190. toPath(e) {
  191. if (e && e.route && e.type == '0') {
  192. uni.redirectTo({
  193. url: `/${e.route}`
  194. })
  195. } else {
  196. uni.navigateTo({
  197. url: `/${e.route}`
  198. })
  199. }
  200. },
  201. // 分页
  202. toPage(e) {
  203. const that = this;
  204. let list = that.marketList;
  205. let limit = that.limit;
  206. if (that.total > list.length) {
  207. uni.showLoading({
  208. title: '加载中',
  209. mask: true
  210. })
  211. let page = that.page + 1;
  212. that.$set(that, `page`, page)
  213. let skip = page * limit;
  214. that.$set(that, `skip`, skip)
  215. that.search();
  216. uni.hideLoading();
  217. } else {
  218. // that.$set(that, `is_bottom`, true)
  219. }
  220. },
  221. // 计算高度
  222. scroll: function(e) {
  223. this.old.scrollTop = e.detail.scrollTop
  224. },
  225. // 返回顶部
  226. goTop: function(e) {
  227. this.scrollTop = this.old.scrollTop
  228. this.$nextTick(function() {
  229. this.scrollTop = 0
  230. });
  231. },
  232. // 清空列表
  233. clearPage() {
  234. const that = this;
  235. that.$set(that, `marketList`, [])
  236. that.$set(that, `skip`, 0)
  237. that.$set(that, `limit`, 6)
  238. that.$set(that, `page`, 0)
  239. }
  240. }
  241. }
  242. </script>
  243. <style lang="scss">
  244. .main {
  245. padding: 2vw;
  246. .zero {
  247. margin: 0 0 2vw 0;
  248. }
  249. .zero:last-child {
  250. margin: 0
  251. }
  252. .one {
  253. background-color: var(--fFB1Color);
  254. border-radius: 20px;
  255. padding: 0 2vw;
  256. input {
  257. font-size: var(--font15Size);
  258. color: var(--fffColor);
  259. border-radius: 14px;
  260. width: 100%;
  261. padding: 1.5vw 0;
  262. }
  263. .placss {
  264. color: var(--fffColor);
  265. }
  266. }
  267. .two {
  268. swiper {
  269. height: 50vw;
  270. border-radius: 5px;
  271. }
  272. .list {
  273. border-radius: 5px;
  274. .image {
  275. width: 100%;
  276. height: 100%;
  277. border-radius: 5px;
  278. }
  279. }
  280. }
  281. .thr {
  282. display: flex;
  283. flex-direction: row;
  284. justify-content: space-around;
  285. flex-wrap: wrap;
  286. .list {
  287. width: 17vw;
  288. text-align: center;
  289. margin: 0 0 2vw 0;
  290. .image {
  291. width: 80%;
  292. height: 13vw;
  293. margin: 1.5vw 0 1.5vw 0;
  294. }
  295. .name {
  296. font-size: var(--font13Size);
  297. }
  298. }
  299. }
  300. .four {
  301. display: flex;
  302. flex-direction: row;
  303. justify-content: space-around;
  304. flex-wrap: wrap;
  305. background-color: var(--f2Color);
  306. padding: 2vw 0 0 0;
  307. .recomList {
  308. width: 41vw;
  309. display: flex;
  310. justify-content: space-around;
  311. background-image: linear-gradient(to bottom, rgba(250, 216, 213, 1) 5%, rgba(255, 255, 255, 1) 22%);
  312. margin: 0 0 2vw 0;
  313. border-radius: 5px;
  314. padding: 2vw;
  315. .list {
  316. width: 20vw;
  317. text-align: center;
  318. .list_1 {
  319. display: flex;
  320. justify-content: space-between;
  321. margin: 0 0 1vw 0;
  322. .txt {
  323. font-size: 15px;
  324. }
  325. .more {
  326. font-size: 12px;
  327. margin: 0 0 4px 0;
  328. }
  329. }
  330. .list_2 {
  331. margin: 0 0 1vw 0;
  332. .image {
  333. width: 96%;
  334. height: 18vw;
  335. }
  336. }
  337. .list_3 {
  338. width: 17vw;
  339. font-size: var(--font12Size);
  340. border: 1px solid var(--fFB1Color);
  341. border-radius: 25px;
  342. padding: 0 1vw;
  343. text-align: center;
  344. }
  345. }
  346. }
  347. }
  348. .five {
  349. display: flex;
  350. flex-direction: column;
  351. background-color: var(--f2Color);
  352. padding: 2vw 0;
  353. .five_pubu {
  354. column-count: 2;
  355. column-gap: 2vw;
  356. .list {
  357. background-color: var(--fffColor);
  358. padding: 2vw;
  359. margin: 0 0 2vw 0;
  360. break-inside: avoid;
  361. border-radius: 10px;
  362. .image {
  363. width: 100%;
  364. height: 35vw;
  365. }
  366. .name {
  367. font-size: var(--font14Size);
  368. margin: 0 0 1vw 0;
  369. }
  370. .other {
  371. display: flex;
  372. flex-direction: row;
  373. justify-content: space-between;
  374. .money {
  375. display: flex;
  376. .money_1 {
  377. color: var(--fFB1Color);
  378. font-size: 12px;
  379. text:last-child {
  380. font-size: 16px;
  381. padding: 0 0 0 1vw;
  382. }
  383. }
  384. .money_2 {
  385. font-size: 12px;
  386. margin: 0 0 0 2vw;
  387. text {
  388. text-decoration: line-through;
  389. }
  390. text:last-child {
  391. font-size: 16px;
  392. padding: 0 0 0 1vw;
  393. }
  394. }
  395. }
  396. }
  397. }
  398. }
  399. }
  400. }
  401. .scroll-view {
  402. position: absolute;
  403. top: 0;
  404. left: 0;
  405. right: 0;
  406. bottom: 0;
  407. .list-scroll-view {
  408. display: flex;
  409. flex-direction: column;
  410. }
  411. }
  412. .backTop {
  413. position: fixed;
  414. bottom: 20vw;
  415. right: 5vw;
  416. text {
  417. font-size: 30px;
  418. background-color: #0000005f;
  419. border-radius: 90px;
  420. }
  421. }
  422. .is_bottom {
  423. text-align: center;
  424. text {
  425. padding: 1vw 0;
  426. display: inline-block;
  427. }
  428. }
  429. </style>