index.vue 10 KB

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