index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view class="container">
  3. <!--搜索栏-->
  4. <u-sticky style="top: 0" offset-top="0">
  5. <view class="search-wrap">
  6. <u-search placeholder="搜索" disabled height="32" :show-action="false" @click="handleSearchClick"></u-search>
  7. </view>
  8. </u-sticky>
  9. <!--轮播图-->
  10. <u-swiper :list="swiperList" previousMargin="20" nextMargin="20" circular height="200" @change="e => (current = e.current)" :autoplay="true" @click="handleSwiperClick">
  11. <view slot="indicator" class="indicator">
  12. <view class="indicator__dot" v-for="(item, index) in swiperList" :key="index" :class="[index === current && 'indicator__dot--active']"> </view>
  13. </view>
  14. </u-swiper>
  15. <u-gap height="20px"></u-gap>
  16. <!--宫格菜单按钮-->
  17. <u-grid :border="false" col="4"
  18. ><u-grid-item v-for="(item, index) in menuList" :key="index">
  19. <u-icon :name="item.icon" :size="40"></u-icon>
  20. <text class="grid-title">{{ item.title }}</text>
  21. </u-grid-item>
  22. </u-grid>
  23. <u-gap height="15px"></u-gap>
  24. <!--消息滚动栏-->
  25. <u-notice-bar style="padding: 13px 12px" :text="noticeList" mode="link" direction="column" @click="click"></u-notice-bar>
  26. <!--商品展示栏-->
  27. <view>
  28. <u-gap height="180" bgColor="#398ade"></u-gap>
  29. <view class="prod-block">
  30. <view class="bloc-header">
  31. <text class="bloc-title">每日上新</text>
  32. <text class="see-more">查看更多</text>
  33. </view>
  34. <view class="prod-grid">
  35. <view class="prod-item" v-for="(item, index) in productList" :key="item.id" @click="handleProdItemClick(item.id)">
  36. <image class="prod-image" :src="item.image"></image>
  37. <view class="item-info">
  38. <view class="info-text">
  39. <u--text :lines="2" size="14px" color="#333333" :text="item.title"></u--text>
  40. </view>
  41. <view class="price-and-cart">
  42. <custom-text-price color="red" size="12" intSize="18" :price="item.price"></custom-text-price>
  43. <u-icon name="shopping-cart" color="#2979ff" size="28"></u-icon>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view>
  51. <view class="prod-block half">
  52. <view class="bloc-header">
  53. <text class="bloc-title">商品热卖</text>
  54. <text class="more">更多 &gt;</text>
  55. </view>
  56. <view class="prod-grid half">
  57. <view class="prod-item" v-for="(item, index) in productList" :key="item.id" @click="handleProdItemClick(item.id)">
  58. <image class="prod-image" :src="item.image"></image>
  59. <view class="item-info">
  60. <view class="info-text">
  61. <u--text :lines="1" size="14px" color="#333333" :text="item.title"></u--text>
  62. <u--text :lines="1" size="12px" color="#939393" :text="item.desc"></u--text>
  63. </view>
  64. <view class="price-and-cart">
  65. <custom-text-price color="red" size="12" intSize="18" :price="item.price"></custom-text-price>
  66. <u-icon name="shopping-cart" color="#2979ff" size="28"></u-icon>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view>
  74. <view class="prod-block list">
  75. <view class="bloc-header">
  76. <text class="bloc-title">更多宝贝</text>
  77. <text></text>
  78. </view>
  79. <view class="prod-list" v-for="(item, index) in productList" :key="item.id">
  80. <view class="prod-item" @click="handleProdItemClick(item.id)">
  81. <image class="prod-image" :src="item.image"></image>
  82. <view class="item-info">
  83. <view class="info-text">
  84. <u--text :lines="1" size="14px" color="#333333" :text="item.title"></u--text>
  85. <u-gap height="2px"></u-gap>
  86. <u--text class="info-desc" :lines="2" size="12px" color="#939393" :text="item.desc"></u--text>
  87. </view>
  88. <view class="price-and-cart">
  89. <custom-text-price color="red" size="12" intSize="18" :price="item.price"></custom-text-price>
  90. <u-icon name="shopping-cart" color="#2979ff" size="28"></u-icon>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. <!--加载更多-->
  98. <u-loadmore fontSize="28rpx" :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
  99. </view>
  100. </template>
  101. <script>
  102. import { getBannerData, getNoticeData } from '../../api/index'
  103. export default {
  104. components: {},
  105. data() {
  106. return {
  107. current: 0,
  108. currentNum: 0,
  109. bannerList: ['https://cdn.uviewui.com/uview/swiper/swiper3.png', 'https://cdn.uviewui.com/uview/swiper/swiper2.png', 'https://cdn.uviewui.com/uview/swiper/swiper1.png'],
  110. menuList: [
  111. { icon: 'gift', title: '热门推荐' },
  112. { icon: 'star', title: '收藏转发' },
  113. { icon: 'thumb-up', title: '点赞投币' },
  114. { icon: 'heart', title: '感谢支持' }
  115. ],
  116. noticeList: ['寒雨连江夜入吴', '平明送客楚山孤', '洛阳亲友如相问', '一片冰心在玉壶'],
  117. productList: [
  118. {
  119. id: 1,
  120. image: 'https://cdn.uviewui.com/uview/album/1.jpg',
  121. title: '山不在高,有仙则名。水不在深,有龙则灵。斯是陋室,惟吾德馨。',
  122. desc: '山不在于高,有了神仙就会有名气。水不在于深,有了龙就会有灵气。这是简陋的房子,只是我品德好就感觉不到简陋了。',
  123. price: '13.00'
  124. },
  125. {
  126. id: 2,
  127. image: 'https://cdn.uviewui.com/uview/album/2.jpg',
  128. title: '商品222',
  129. desc: '',
  130. price: '23.00'
  131. },
  132. {
  133. id: 3,
  134. image: 'https://cdn.uviewui.com/uview/album/3.jpg',
  135. title: '商品333',
  136. desc: '商品描述信息2',
  137. price: '33.00'
  138. },
  139. {
  140. id: 4,
  141. image: 'https://cdn.uviewui.com/uview/album/4.jpg',
  142. title: '商品444',
  143. desc: '商品描述信息4',
  144. price: '43.00'
  145. },
  146. {
  147. id: 5,
  148. image: 'https://cdn.uviewui.com/uview/album/5.jpg',
  149. title: '商品555',
  150. desc: '商品描述信息5',
  151. price: '53.00'
  152. }
  153. ],
  154. status: 'nomore',
  155. loadingText: '努力加载中...',
  156. loadmoreText: '轻轻上拉',
  157. nomoreText: '实在没有了...'
  158. }
  159. },
  160. onLoad() {
  161. //this.loadBannerData();
  162. //this.loadNoticeData();
  163. },
  164. methods: {
  165. loadBannerData() {
  166. getBannerData().then(res => {
  167. this.bannerList = res.data
  168. })
  169. },
  170. loadNoticeData() {
  171. getNoticeData().then(res => {
  172. this.noticeList = res.data
  173. })
  174. },
  175. handleSearchClick(e) {
  176. uni.$u.route('/pages/search/search')
  177. },
  178. handleSwiperClick(index) {
  179. console.log('点击了图片索引值:', index)
  180. },
  181. handleProdItemClick(productId) {
  182. uni.$u.route('/pages/product/product', {
  183. productId: productId
  184. })
  185. }
  186. },
  187. computed: {
  188. swiperList() {
  189. return this.bannerList.map(item => {
  190. if (item) {
  191. return item
  192. }
  193. })
  194. },
  195. noticeTextList() {
  196. return this.noticeList.map(item => {
  197. if (item.title) {
  198. return item.title
  199. }
  200. })
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. .search-wrap {
  207. background: $custom-bg-color;
  208. padding: 20rpx;
  209. }
  210. .indicator {
  211. @include flex(row);
  212. justify-content: center;
  213. &__dot {
  214. height: 15rpx;
  215. width: 15rpx;
  216. border-radius: 100rpx;
  217. background-color: rgba(255, 255, 255, 0.35);
  218. margin: 0 10rpx;
  219. transition: background-color 0.3s;
  220. &--active {
  221. background-color: $custom-bg-color;
  222. }
  223. }
  224. }
  225. .grid-title {
  226. line-height: 50rpx;
  227. font-size: 26rpx;
  228. }
  229. .prod-block {
  230. margin-top: -160px;
  231. .bloc-header {
  232. @include flex-space-between;
  233. padding: 10rpx 20rpx;
  234. .bloc-title {
  235. color: $custom-bg-color;
  236. font-size: 34rpx;
  237. }
  238. .see-more {
  239. color: $custom-bg-color;
  240. background: $u-primary;
  241. padding: 0 30rpx;
  242. height: 50rpx;
  243. line-height: 50rpx;
  244. border-radius: 50rpx;
  245. font-size: 24rpx;
  246. }
  247. }
  248. &.half,
  249. &.list {
  250. margin-top: 0;
  251. .bloc-header {
  252. margin-top: 50rpx;
  253. margin-bottom: 20rpx;
  254. .bloc-title {
  255. color: #333333;
  256. }
  257. .more {
  258. font-size: 24rpx;
  259. }
  260. }
  261. }
  262. .prod-grid {
  263. width: 730rpx;
  264. margin: 0 auto;
  265. @include flex;
  266. flex-wrap: wrap;
  267. justify-content: left;
  268. &.half {
  269. .prod-item {
  270. width: 346rpx;
  271. margin: 10rpx;
  272. .prod-image {
  273. width: 346rpx;
  274. height: 346rpx;
  275. }
  276. }
  277. }
  278. .prod-item {
  279. width: 224rpx;
  280. margin: 10rpx;
  281. background: #ffffff;
  282. border-radius: 10rpx;
  283. box-shadow: -1rpx 1rpx 2rpx #afd3f5, 1rpx 1rpx 0rpx #afd3f5;
  284. .prod-image {
  285. width: 224rpx;
  286. height: 224rpx;
  287. border-radius: 10rpx 10rpx 0 0;
  288. }
  289. .item-info {
  290. padding: 15rpx;
  291. .info-text {
  292. height: 70rpx;
  293. padding-bottom: 10rpx;
  294. }
  295. .price-and-cart {
  296. @include flex-space-between;
  297. }
  298. }
  299. }
  300. }
  301. }
  302. .prod-list {
  303. .prod-item {
  304. background: #ffffff;
  305. @include flex-space-between;
  306. border-bottom: $custom-border-style;
  307. padding: 20rpx;
  308. .prod-image {
  309. width: 200rpx;
  310. height: 200rpx;
  311. border-radius: 10rpx;
  312. }
  313. .item-info {
  314. flex: 1;
  315. padding: 20rpx 20rpx 0;
  316. .info-text {
  317. height: 100rpx;
  318. padding-bottom: 10rpx;
  319. }
  320. .price-and-cart {
  321. @include flex-space-between;
  322. }
  323. }
  324. }
  325. }
  326. </style>