index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  3. <scroll-view class="scrollView" scroll-with-animation :scroll-into-view="topItem" scroll-y="true"
  4. @scroll="handleScroll">
  5. <view class="main" id="top">
  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=""></image>
  15. </swiper-item>
  16. </swiper>
  17. </view>
  18. <view class="zero thr">
  19. <view class="list" v-for="(item,index) in btnList" :key="index" @tap="toCommon(item.to)">
  20. <image class="image" :src="item.url&&item.url.length>0?item.url[0].url:''" mode=""></image>
  21. <view class="textOver name">
  22. {{item.name}}
  23. </view>
  24. </view>
  25. </view>
  26. <view class="zero four">
  27. <view class="recomList" v-for="(item,index) in recomList" :key="index">
  28. <view class="list" v-for="(tag,indexs) in item.list" :key="indexs">
  29. <view class="title">
  30. <text>{{tag.title||'&nbsp;'}}</text>
  31. </view>
  32. <image class="image" :src="tag.url" mode=""></image>
  33. <view class="textOver name">
  34. {{tag.name}}
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="zero five">
  40. <view class="list" v-for="(item,index) in marketList" :key="index"
  41. @tap="toCommon('pagesHome/order/detail')">
  42. <image class="image" :src="item.url" mode=""></image>
  43. <view class="name">
  44. {{item.name}}
  45. </view>
  46. <view class="other">
  47. <view class="money">
  48. <text>¥</text><text>{{item.money}}</text>
  49. </view>
  50. <view class="btn">
  51. <button type="default" size="mini">购买</button>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </scroll-view>
  58. <view class="backTop" v-if="isShow==true">
  59. <text @click="backTop" class="iconfont icon-fanhuidingbu"></text>
  60. </view>
  61. </mobile-frame>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. frameStyle: {
  68. useBar: true
  69. },
  70. bannerList: [ // 轮播图
  71. ],
  72. btnList: [ //功能按钮
  73. ],
  74. recomList: [ //推荐好物
  75. {
  76. list: [ //商品
  77. {
  78. title: '新品上架',
  79. url: require('@/static/test.png'),
  80. name: '商品名称'
  81. },
  82. {
  83. title: '',
  84. url: require('@/static/test.png'),
  85. name: '商品名称'
  86. },
  87. ]
  88. },
  89. {
  90. list: [ //商品
  91. {
  92. title: '发现好货',
  93. url: require('@/static/test.png'),
  94. name: '商品名称'
  95. },
  96. {
  97. title: '热销爆款',
  98. url: require('@/static/test.png'),
  99. name: '商品名称'
  100. },
  101. ]
  102. },
  103. {
  104. list: [ //商品
  105. {
  106. title: '首农精选',
  107. url: require('@/static/test.png'),
  108. name: '商品名称'
  109. },
  110. {
  111. title: '居家常备',
  112. url: require('@/static/test.png'),
  113. name: '商品名称'
  114. },
  115. ]
  116. },
  117. {
  118. list: [ //商品
  119. {
  120. title: '人气单品',
  121. url: require('@/static/test.png'),
  122. name: '商品名称'
  123. },
  124. {
  125. title: '夏季畅销',
  126. url: require('@/static/test.png'),
  127. name: '商品名称'
  128. },
  129. ]
  130. }
  131. ],
  132. marketList: [ //商品列表
  133. {
  134. url: require('@/static/test.png'),
  135. name: '商品名称',
  136. money: 10
  137. },
  138. {
  139. url: require('@/static/test.png'),
  140. name: '商品名称',
  141. money: 10
  142. },
  143. {
  144. url: require('@/static/test.png'),
  145. name: '商品名称',
  146. money: 10
  147. },
  148. {
  149. url: require('@/static/test.png'),
  150. name: '商品名称',
  151. money: 10
  152. },
  153. {
  154. url: require('@/static/test.png'),
  155. name: '商品名称',
  156. money: 10
  157. },
  158. ],
  159. // 是否显示返回顶部
  160. isShow: false,
  161. topItem: ''
  162. };
  163. },
  164. onShow: function() {
  165. const that = this;
  166. that.search();
  167. },
  168. methods: {
  169. async search() {
  170. const that = this;
  171. let res;
  172. // 轮播图
  173. res = await that.$api(`/banner`, 'GET', {
  174. status: '0'
  175. });
  176. if (res.errcode == '0') that.$set(that, `bannerList`, res.data);
  177. // 首页模块管理
  178. res = await that.$api(`/indexModule`, 'GET', {
  179. status: '0'
  180. });
  181. if (res.errcode == '0') {
  182. let data = res.data.sort(function(a, b) {
  183. return a.sort - b.sort
  184. });
  185. that.$set(that, `btnList`, data);
  186. }
  187. },
  188. // 公共跳转
  189. toCommon(e) {
  190. uni.navigateTo({
  191. url: `/${e}`
  192. })
  193. },
  194. toPath(e) {
  195. if (e && e.route) uni.redirectTo({
  196. url: `/${e.route}`
  197. })
  198. },
  199. // 计算高度
  200. handleScroll(e) {
  201. const that = this;
  202. let scrollTop = e.detail.scrollTop;
  203. that.isShow = scrollTop > 500;
  204. that.topItem = '';
  205. },
  206. // 返回顶部
  207. backTop() {
  208. const that = this;
  209. that.topItem = 'top'
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang="scss">
  215. .scrollView {
  216. height: 100vh;
  217. }
  218. .main {
  219. padding: 2vw;
  220. .zero {
  221. margin: 0 0 2vw 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. .backTop {
  362. position: fixed;
  363. bottom: 20vw;
  364. right: 5vw;
  365. text {
  366. font-size: 30px;
  367. background-color: #0000005f;
  368. border-radius: 90px;
  369. }
  370. }
  371. </style>