index.vue 8.3 KB

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