index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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']">
  13. </view>
  14. </view>
  15. </u-swiper>
  16. <u-gap height="20px"></u-gap>
  17. <!--宫格菜单按钮-->
  18. <u-grid :border="false" col="4"><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="index">
  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. <u--text-price color="red" size="12" intSize="18" :text="item.price"></u--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="index">
  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. <u--text-price color="red" size="12" intSize="18" :text="item.price"></u--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="index">
  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. <u--text-price color="red" size="12" intSize="18" :text="item.price"></u--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. },
  114. data() {
  115. return {
  116. current: 0,
  117. currentNum: 0,
  118. bannerList: [
  119. 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  120. 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  121. 'https://cdn.uviewui.com/uview/swiper/swiper1.png',],
  122. menuList: [{icon: 'gift', title: '热门推荐'}, {icon: 'star', title: '收藏转发'}, {icon: 'thumb-up', title: '点赞投币'}, {icon: 'heart', title: '感谢支持'}],
  123. noticeList:[
  124. '寒雨连江夜入吴',
  125. '平明送客楚山孤',
  126. '洛阳亲友如相问',
  127. '一片冰心在玉壶'
  128. ],
  129. productList: [
  130. {
  131. id: 1,
  132. image: 'https://cdn.uviewui.com/uview/album/1.jpg',
  133. title: '山不在高,有仙则名。水不在深,有龙则灵。斯是陋室,惟吾德馨。',
  134. desc: '山不在于高,有了神仙就会有名气。水不在于深,有了龙就会有灵气。这是简陋的房子,只是我品德好就感觉不到简陋了。',
  135. price: '13.00'
  136. },
  137. {
  138. id: 2,
  139. image: 'https://cdn.uviewui.com/uview/album/2.jpg',
  140. title: '商品222',
  141. desc: '',
  142. price: '23.00'
  143. },
  144. {
  145. id: 3,
  146. image: 'https://cdn.uviewui.com/uview/album/3.jpg',
  147. title: '商品333',
  148. desc: '商品描述信息2',
  149. price: '33.00'
  150. },
  151. {
  152. id: 4,
  153. image: 'https://cdn.uviewui.com/uview/album/4.jpg',
  154. title: '商品444',
  155. desc: '商品描述信息4',
  156. price: '43.00'
  157. },
  158. {
  159. id: 5,
  160. image: 'https://cdn.uviewui.com/uview/album/5.jpg',
  161. title: '商品555',
  162. desc: '商品描述信息5',
  163. price: '53.00'
  164. }
  165. ],
  166. status: 'nomore',
  167. loadingText: '努力加载中...',
  168. loadmoreText: '轻轻上拉',
  169. nomoreText: '实在没有了...'
  170. }
  171. },
  172. onLoad() {
  173. //this.loadBannerData();
  174. //this.loadNoticeData();
  175. },
  176. methods: {
  177. loadBannerData() {
  178. getBannerData().then(res => {
  179. this.bannerList = res.data;
  180. }).catch(err => {
  181. //console.log(err)
  182. })
  183. },
  184. loadNoticeData() {
  185. getNoticeData().then(res => {
  186. this.noticeList = res.data;
  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. display: flex;
  249. flex-direction: row;
  250. align-items: center;
  251. justify-content: space-between;
  252. padding: 10rpx 30rpx;
  253. .bloc-title {
  254. color: $custom-bg-color;
  255. font-size: 34rpx;
  256. }
  257. .see-more {
  258. color: $custom-bg-color;
  259. background: $u-primary;
  260. padding: 0 30rpx;
  261. height: 50rpx;
  262. line-height: 50rpx;
  263. border-radius: 50rpx;
  264. font-size: 24rpx;
  265. }
  266. }
  267. &.half, &.list {
  268. margin-top: 0;
  269. .bloc-header {
  270. margin-top: 50rpx;
  271. margin-bottom: 20rpx;
  272. .bloc-title {
  273. color: #333333;
  274. }
  275. .more {
  276. font-size: 24rpx;
  277. }
  278. }
  279. }
  280. .prod-grid {
  281. width: 730rpx;
  282. margin: 0 auto;
  283. .prod-item-box {
  284. padding: 10rpx;
  285. .prod-item {
  286. background: #fff;
  287. border-radius: 10rpx;
  288. box-shadow: -1rpx 1rpx 2rpx #afd3f5, 1rpx 1rpx 0rpx #afd3f5;
  289. justify-content: left;
  290. /deep/ * {
  291. border-radius: 10rpx 10rpx 0 0;
  292. }
  293. .item-info {
  294. padding: 15rpx;
  295. .info-text {
  296. height: 70rpx;
  297. padding-bottom: 10rpx;
  298. }
  299. .price-and-cart {
  300. display: flex;
  301. justify-content: space-between;
  302. }
  303. }
  304. }
  305. }
  306. }
  307. }
  308. .prod-list {
  309. height: auto !important;
  310. .prod-item {
  311. padding: 20rpx;
  312. background: #fff;
  313. display: flex;
  314. flex-direction: row;
  315. justify-content: space-between;
  316. border-bottom: $custom-border-style;
  317. .prod-image {
  318. border-radius: 10rpx;
  319. /deep/ * {
  320. border-radius: 10rpx;
  321. }
  322. }
  323. .item-info {
  324. width: 450rpx;
  325. padding: 20rpx 30rpx 0 30rpx;
  326. .info-text {
  327. height: 100rpx;
  328. padding-bottom: 10rpx;
  329. }
  330. .price-and-cart {
  331. display: flex;
  332. justify-content: space-between;
  333. }
  334. }
  335. }
  336. }
  337. </style>