index.vue 8.6 KB

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