index.vue 8.6 KB

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