index.vue 8.5 KB

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