index.vue 7.7 KB

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