index.vue 7.4 KB

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