index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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">
  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: 5,
  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. toIndexModel(data) {
  138. if (data && data.status == '1') {
  139. uni.showToast({
  140. title: '模块禁用',
  141. icon: 'none'
  142. })
  143. } else {
  144. uni.navigateTo({
  145. url: `/${data.to}`
  146. })
  147. }
  148. },
  149. // 购买
  150. toBuy(e) {
  151. uni.navigateTo({
  152. url: `/pagesHome/order/detail?id=${e.id||e._id}`
  153. })
  154. },
  155. toPath(e) {
  156. if (e && e.route && e.type == '0') {
  157. uni.redirectTo({
  158. url: `/${e.route}`
  159. })
  160. } else {
  161. uni.navigateTo({
  162. url: `/${e.route}`
  163. })
  164. }
  165. },
  166. // 分页
  167. toPage(e) {
  168. const that = this;
  169. let list = that.marketList;
  170. let limit = that.limit;
  171. if (that.total > list.length) {
  172. uni.showLoading({
  173. title: '加载中',
  174. mask: true
  175. })
  176. let page = that.page + 1;
  177. that.$set(that, `page`, page)
  178. let skip = page * limit;
  179. that.$set(that, `skip`, skip)
  180. that.search();
  181. uni.hideLoading();
  182. } else uni.showToast({
  183. title: '没有更多数据了'
  184. });
  185. },
  186. // 计算高度
  187. scroll: function(e) {
  188. this.old.scrollTop = e.detail.scrollTop
  189. },
  190. // 返回顶部
  191. goTop: function(e) {
  192. this.scrollTop = this.old.scrollTop
  193. this.$nextTick(function() {
  194. this.scrollTop = 0
  195. });
  196. },
  197. }
  198. }
  199. </script>
  200. <style lang="scss">
  201. .main {
  202. padding: 2vw;
  203. .zero {
  204. margin: 0 0 2vw 0;
  205. }
  206. .zero:last-child {
  207. margin: 0
  208. }
  209. .one {
  210. background-color: var(--fFB1Color);
  211. border-radius: 20px;
  212. padding: 0 2vw;
  213. input {
  214. font-size: var(--font15Size);
  215. color: var(--fffColor);
  216. border-radius: 14px;
  217. width: 100%;
  218. padding: 1.5vw 0;
  219. }
  220. .placss {
  221. color: var(--fffColor);
  222. }
  223. }
  224. .two {
  225. swiper {
  226. height: 50vw;
  227. border-radius: 5px;
  228. }
  229. .list {
  230. border-radius: 5px;
  231. .image {
  232. width: 100%;
  233. height: 100%;
  234. border-radius: 5px;
  235. }
  236. }
  237. }
  238. .thr {
  239. display: flex;
  240. flex-direction: row;
  241. justify-content: space-around;
  242. flex-wrap: wrap;
  243. .list {
  244. width: 17vw;
  245. text-align: center;
  246. margin: 0 0 2vw 0;
  247. .image {
  248. width: 80%;
  249. height: 13vw;
  250. margin: 1.5vw 0 1.5vw 0;
  251. }
  252. .name {
  253. font-size: var(--font13Size);
  254. }
  255. }
  256. }
  257. .four {
  258. display: flex;
  259. flex-direction: row;
  260. justify-content: space-around;
  261. flex-wrap: wrap;
  262. background-color: var(--f2Color);
  263. padding: 2vw 0 0 0;
  264. .recomList {
  265. display: flex;
  266. flex-direction: row;
  267. justify-content: space-around;
  268. width: 41vw;
  269. margin: 0 0 2vw 0;
  270. padding: 2vw;
  271. border-radius: 10px;
  272. background-image: linear-gradient(to bottom, rgba(250, 216, 213, 1) 5%, rgba(255, 255, 255, 1) 22%);
  273. .list {
  274. width: 20vw;
  275. text-align: center;
  276. .title {
  277. text-align: center;
  278. font-weight: bold;
  279. font-size: var(--font15Size);
  280. ;
  281. margin: 0 0 1vw 0;
  282. }
  283. .image {
  284. width: 18vw;
  285. height: 20vw;
  286. margin: 0 0 1vw 0;
  287. }
  288. .name {
  289. width: 17vw;
  290. font-size: var(--font12Size);
  291. ;
  292. border: 1px solid var(--fFB1Color);
  293. border-radius: 25px;
  294. padding: 0 1vw;
  295. text-align: center;
  296. }
  297. }
  298. }
  299. }
  300. .five {
  301. display: flex;
  302. flex-direction: row;
  303. flex-wrap: wrap;
  304. background-color: var(--f2Color);
  305. padding: 2vw 0 0 0;
  306. .list {
  307. width: 40vw;
  308. background-color: var(--fffColor);
  309. padding: 2vw;
  310. margin: 0 2vw 2vw 2vw;
  311. border-radius: 10px;
  312. .image {
  313. width: 100%;
  314. height: 35vw;
  315. }
  316. .name {
  317. font-size: var(--font14Size);
  318. margin: 0 0 1vw 0;
  319. }
  320. .other {
  321. display: flex;
  322. flex-direction: row;
  323. justify-content: space-between;
  324. .money {
  325. color: var(--fFB1Color);
  326. text:nth-child(1) {
  327. font-size: var(--font12Size);
  328. }
  329. }
  330. .btn {
  331. button {
  332. color: var(--fffColor);
  333. background-color: var(--fFB1Color);
  334. padding: 5px 2vw;
  335. font-size: var(--font14Size);
  336. line-height: 1;
  337. border-radius: 90px;
  338. }
  339. }
  340. }
  341. }
  342. .list:nth-child(2n) {
  343. margin: 0 0 2vw 2vw;
  344. }
  345. }
  346. }
  347. .scroll-view {
  348. position: absolute;
  349. top: 0;
  350. left: 0;
  351. right: 0;
  352. bottom: 0;
  353. .list-scroll-view {
  354. display: flex;
  355. flex-direction: column;
  356. }
  357. }
  358. .backTop {
  359. position: fixed;
  360. bottom: 20vw;
  361. right: 5vw;
  362. text {
  363. font-size: 30px;
  364. background-color: #0000005f;
  365. border-radius: 90px;
  366. }
  367. }
  368. </style>