index.vue 8.7 KB

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