index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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" @tap="toBuy(item)">
  41. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
  42. <view class="name">
  43. {{item.name}}
  44. </view>
  45. <view class="other">
  46. <view class="money">
  47. <text>¥</text><text>{{item.money||'暂无'}}</text>
  48. </view>
  49. <view class="btn">
  50. <button type="default" size="mini">购买</button>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </scroll-view>
  57. <view class="backTop" v-if="isShow==true">
  58. <text @click="backTop" class="iconfont icon-fanhuidingbu"></text>
  59. </view>
  60. </mobile-frame>
  61. </template>
  62. <script>
  63. export default {
  64. data() {
  65. return {
  66. frameStyle: {
  67. useBar: true
  68. },
  69. bannerList: [ // 轮播图
  70. ],
  71. btnList: [ //功能按钮
  72. ],
  73. recomList: [ //推荐好物
  74. {
  75. list: [ //商品
  76. {
  77. title: '新品上架',
  78. url: require('@/static/test.png'),
  79. name: '商品名称'
  80. },
  81. {
  82. title: '',
  83. url: require('@/static/test.png'),
  84. name: '商品名称'
  85. },
  86. ]
  87. },
  88. {
  89. list: [ //商品
  90. {
  91. title: '发现好货',
  92. url: require('@/static/test.png'),
  93. name: '商品名称'
  94. },
  95. {
  96. title: '热销爆款',
  97. url: require('@/static/test.png'),
  98. name: '商品名称'
  99. },
  100. ]
  101. },
  102. {
  103. list: [ //商品
  104. {
  105. title: '首农精选',
  106. url: require('@/static/test.png'),
  107. name: '商品名称'
  108. },
  109. {
  110. title: '居家常备',
  111. url: require('@/static/test.png'),
  112. name: '商品名称'
  113. },
  114. ]
  115. },
  116. {
  117. list: [ //商品
  118. {
  119. title: '人气单品',
  120. url: require('@/static/test.png'),
  121. name: '商品名称'
  122. },
  123. {
  124. title: '夏季畅销',
  125. url: require('@/static/test.png'),
  126. name: '商品名称'
  127. },
  128. ]
  129. }
  130. ],
  131. marketList: [ //商品列表
  132. {
  133. url: require('@/static/test.png'),
  134. name: '商品名称',
  135. money: 10
  136. },
  137. {
  138. url: require('@/static/test.png'),
  139. name: '商品名称',
  140. money: 10
  141. },
  142. {
  143. url: require('@/static/test.png'),
  144. name: '商品名称',
  145. money: 10
  146. },
  147. {
  148. url: require('@/static/test.png'),
  149. name: '商品名称',
  150. money: 10
  151. },
  152. {
  153. url: require('@/static/test.png'),
  154. name: '商品名称',
  155. money: 10
  156. },
  157. ],
  158. // 是否显示返回顶部
  159. isShow: false,
  160. topItem: ''
  161. };
  162. },
  163. onShow: function() {
  164. const that = this;
  165. that.search();
  166. },
  167. methods: {
  168. async search() {
  169. const that = this;
  170. let res;
  171. // 轮播图
  172. res = await that.$api(`/banner`, 'GET', {
  173. status: '0'
  174. });
  175. if (res.errcode == '0') that.$set(that, `bannerList`, res.data);
  176. // 首页模块管理
  177. res = await that.$api(`/indexModule`, 'GET', {
  178. status: '0'
  179. });
  180. if (res.errcode == '0') {
  181. let data = res.data.sort(function(a, b) {
  182. return a.sort - b.sort
  183. });
  184. that.$set(that, `btnList`, data);
  185. }
  186. res = await that.$api(`/goods`, `GET`, {});
  187. if (res.errcode == '0') {
  188. that.$set(that, `marketList`, res.data)
  189. }
  190. },
  191. // 公共跳转
  192. toCommon(e) {
  193. uni.navigateTo({
  194. url: `/${e}`
  195. })
  196. },
  197. toBuy(e) {
  198. uni.navigateTo({
  199. url: `/pagesHome/order/detail?id=${e.id}`
  200. })
  201. },
  202. // 计算高度
  203. handleScroll(e) {
  204. const that = this;
  205. let scrollTop = e.detail.scrollTop;
  206. that.isShow = scrollTop > 500;
  207. that.topItem = '';
  208. },
  209. // 返回顶部
  210. backTop() {
  211. const that = this;
  212. that.topItem = 'top'
  213. },
  214. toPath(e) {
  215. if (e && e.route) uni.redirectTo({
  216. url: `/${e.route}`
  217. })
  218. },
  219. }
  220. }
  221. </script>
  222. <style lang="scss">
  223. .scrollView {
  224. height: 100vh;
  225. }
  226. .main {
  227. padding: 2vw;
  228. .zero {
  229. margin: 0 0 2vw 0;
  230. }
  231. .one {
  232. background-color: var(--fFB1Color);
  233. border-radius: 20px;
  234. padding: 0 2vw;
  235. input {
  236. font-size: var(--font15Size);
  237. color: var(--fffColor);
  238. border-radius: 14px;
  239. width: 100%;
  240. padding: 1.5vw 0;
  241. }
  242. .placss {
  243. color: var(--fffColor);
  244. }
  245. }
  246. .two {
  247. swiper {
  248. height: 50vw;
  249. border-radius: 5px;
  250. }
  251. .list {
  252. border-radius: 5px;
  253. .image {
  254. width: 100%;
  255. height: 100%;
  256. border-radius: 5px;
  257. }
  258. }
  259. }
  260. .thr {
  261. display: flex;
  262. flex-direction: row;
  263. justify-content: space-around;
  264. flex-wrap: wrap;
  265. .list {
  266. width: 17vw;
  267. text-align: center;
  268. margin: 0 0 2vw 0;
  269. .image {
  270. width: 80%;
  271. height: 13vw;
  272. margin: 1.5vw 0 1.5vw 0;
  273. }
  274. .name {
  275. font-size: var(--font13Size);
  276. }
  277. }
  278. }
  279. .four {
  280. display: flex;
  281. flex-direction: row;
  282. justify-content: space-around;
  283. flex-wrap: wrap;
  284. background-color: var(--f2Color);
  285. padding: 2vw 0 0 0;
  286. .recomList {
  287. display: flex;
  288. flex-direction: row;
  289. justify-content: space-around;
  290. width: 41vw;
  291. margin: 0 0 2vw 0;
  292. padding: 2vw;
  293. border-radius: 10px;
  294. background-image: linear-gradient(to bottom, rgba(250, 216, 213, 1) 5%, rgba(255, 255, 255, 1) 22%);
  295. .list {
  296. width: 20vw;
  297. text-align: center;
  298. .title {
  299. text-align: center;
  300. font-weight: bold;
  301. font-size: var(--font15Size);
  302. ;
  303. margin: 0 0 1vw 0;
  304. }
  305. .image {
  306. width: 18vw;
  307. height: 20vw;
  308. margin: 0 0 1vw 0;
  309. }
  310. .name {
  311. width: 17vw;
  312. font-size: var(--font12Size);
  313. ;
  314. border: 1px solid var(--fFB1Color);
  315. border-radius: 25px;
  316. padding: 0 1vw;
  317. text-align: center;
  318. }
  319. }
  320. }
  321. }
  322. .five {
  323. display: flex;
  324. flex-direction: row;
  325. flex-wrap: wrap;
  326. background-color: var(--f2Color);
  327. padding: 2vw 0 0 0;
  328. .list {
  329. width: 40vw;
  330. background-color: var(--fffColor);
  331. padding: 2vw;
  332. margin: 0 2vw 2vw 2vw;
  333. border-radius: 10px;
  334. .image {
  335. width: 100%;
  336. height: 35vw;
  337. }
  338. .name {
  339. font-size: var(--font14Size);
  340. margin: 0 0 1vw 0;
  341. }
  342. .other {
  343. display: flex;
  344. flex-direction: row;
  345. justify-content: space-between;
  346. .money {
  347. color: var(--fFB1Color);
  348. text:nth-child(1) {
  349. font-size: var(--font12Size);
  350. }
  351. }
  352. .btn {
  353. button {
  354. color: var(--fffColor);
  355. background-color: var(--fFB1Color);
  356. padding: 5px 2vw;
  357. font-size: var(--font14Size);
  358. line-height: 1;
  359. border-radius: 90px;
  360. }
  361. }
  362. }
  363. }
  364. .list:nth-child(2n) {
  365. margin: 0 0 2vw 2vw;
  366. }
  367. }
  368. }
  369. .backTop {
  370. position: fixed;
  371. bottom: 20vw;
  372. right: 5vw;
  373. text {
  374. font-size: 30px;
  375. background-color: #0000005f;
  376. border-radius: 90px;
  377. }
  378. }
  379. </style>