index.vue 9.2 KB

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