index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <v-header mode="" async ref="header" @fetch="fetch" :title="config.name">
  3. <refresh-view @refresh="refresh">
  4. <view class="container">
  5. <!-- 小程序头部兼容 -->
  6. <!-- #ifdef MP -->
  7. <!-- <view class="mp-search-box"><input class="ser-input" type="text" value="输入关键字搜索" disabled /></view> -->
  8. <!-- #endif -->
  9. <!-- 头部轮播 -->
  10. <view class="carousel-section">
  11. <!-- 标题栏和状态栏占位符 -->
  12. <view class="titleNview-placing"></view>
  13. <swiper class="carousel" circular @change="swiperChange">
  14. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item" @click="navToDetailPage({ product_id: item.product_id })">
  15. <v-image mode="aspectFill" class="screen_all" :src="item.image" />
  16. </swiper-item>
  17. </swiper>
  18. </view>
  19. <!-- 新人赠送优惠券 -->
  20. <view v-if="coupon && coupon.id" class="coupon-container center">
  21. <layout-coupon :item="coupon" @receive="receiveCoupon"></layout-coupon>
  22. </view>
  23. <!-- 新人赠送优惠券 -->
  24. <!-- 分类 -->
  25. <view class="cate-section">
  26. <view class="cate-item" v-for="(item, index) in menu" :key="index" @click="trigger(item)">
  27. <image :src="item.icon" ></image>
  28. <text>{{item.label}}</text>
  29. </view>
  30. </view>
  31. <!-- 精品推荐-->
  32. <view class="boutique row center">
  33. <image :src="require('./images/decorate-left.png')"></image>
  34. <view class="boutique-title">精品·推荐</view>
  35. <image :src="require('./images/decorate-right.png')"></image>
  36. </view>
  37. <!-- 商品 -->
  38. <view class="shop-container">
  39. <view class="shop-item overflow relative"
  40. v-for="(item,index) in goodsList"
  41. :key="index"
  42. >
  43. <v-image mode="aspectFill" class="screen_all" :src="item.index_bg"></v-image>
  44. <view class="shop-item-info absolute jEnd aCenter" :style="{color:item.font_color}">
  45. <view class="absolute shop-item-header row aCenter">
  46. <image src="/static/images/logo.jpg" class="shop-item-header-logo"></image>
  47. <view class="flex-all-1">
  48. <view class="shop-logo-header-title">{{ config.name }}</view>
  49. <view class="shop-logo-en-title">{{config.enName}}</view>
  50. </view>
  51. </view>
  52. <view class="shop-item-title">{{item.title}}</view>
  53. <text class="shop-item-price-group" v-if="item.id">
  54. <text class="shop-item-price-em">¥</text>
  55. <text class="shop-item-price">{{item.price}}</text>
  56. <text>/1瓶</text>
  57. </text>
  58. <view class="shop-item-buy-button relative center" @click="goShopDetail(item)" v-if="item.id">立即购买</view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 查看更多产品 -->
  63. <view class="center">
  64. <view @click="goShopMore" class="shop-button row center">
  65. <text>查看更多商品</text>
  66. <image mode="aspectFill" :src="require('./images/more.png')"></image>
  67. </view>
  68. </view>
  69. </view>
  70. </refresh-view>
  71. </v-header>
  72. </template>
  73. <script>
  74. import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
  75. import menu from './data/menu';
  76. import layoutCoupon from '@/layout/layout-coupon/index.vue';
  77. import vHeader from '@/components/v-header/main.vue';
  78. import refreshView from '@/components/refresh-view/main.vue';
  79. import vImage from '@/components/v-image/main.vue';
  80. import trigger from '@/mixins/trigger/index';
  81. import shop from '@/utils/controls/shop';
  82. import login from '@/mixins/login';
  83. import {
  84. mapState
  85. } from 'vuex';
  86. export default {
  87. components: {uniCountdown,layoutCoupon,vHeader,refreshView,vImage},
  88. mixins:[trigger,login],
  89. data() {
  90. return {
  91. titleNViewBackground: '',
  92. swiperCurrent: 0,
  93. swiperLength: 0,
  94. carouselList: [{}],
  95. goodsList: [{},{}],
  96. menu:menu,
  97. coupon:{}
  98. };
  99. },
  100. computed:{
  101. ...mapState(['config'])
  102. },
  103. methods: {
  104. fetch(obj){
  105. return Promise.all([
  106. this.$request({
  107. url: '/index/getAdsList',
  108. cache:true
  109. }),
  110. this.$request({
  111. url:'index/getNewCoupon',
  112. token:true
  113. }),
  114. this.$request({
  115. url:'product/getProductList',
  116. cache:true,
  117. data:{
  118. is_recommend:1
  119. }
  120. })
  121. ]).then((data)=>{
  122. // 执行设置
  123. ['setBanner','setCoupon','setProduct'].map((item,index)=>{
  124. return this[item] && this[item](data[index]);
  125. });
  126. this.refreshStop && this.refreshStop();
  127. return obj.success();
  128. }).catch(()=>{
  129. this.refreshStop && this.refreshStop();
  130. obj.fail();
  131. });
  132. },
  133. receiveCoupon(){
  134. if (this.receiveCouponStatus) return;
  135. this.routerLogin(()=>{
  136. this.$request({
  137. url:'product/receiveCoupon',
  138. data:{
  139. coupon_id: this.coupon.id
  140. },
  141. token:true,
  142. message:true,
  143. loading:'领取中',
  144. next:({status})=> this.receiveCouponStatus = status,
  145. failMessage:true
  146. }).then((data)=>{
  147. if (data.isSuccess) {
  148. this.coupon = undefined;
  149. }
  150. });
  151. })
  152. },
  153. refresh(stop){
  154. this.refreshStop = stop;
  155. if (this.$refs.header) {
  156. if (this.$refs.header._state!==1) {
  157. return this.$refs.header.reload();
  158. }
  159. } else {
  160. stop();
  161. }
  162. },
  163. setBanner(res){
  164. let carouselList = res.data;
  165. this.swiperLength = carouselList.length;
  166. this.carouselList = carouselList;
  167. },
  168. setCoupon(data){
  169. this.coupon = data.data;
  170. },
  171. setProduct(data){
  172. this.goodsList = data.data.map((item)=>{
  173. let price = parseFloat(item.sales_price);
  174. let intPrice = Math.floor(price);
  175. if (price === intPrice) price = intPrice;
  176. item.price = price;
  177. return item;
  178. });
  179. },
  180. goShopDetail(item){
  181. console.log(item);
  182. return shop.goShopDetail(item);
  183. },
  184. goShopMore(){
  185. return this.$router.switchTab('category');
  186. }
  187. },
  188. };
  189. </script>
  190. <style lang="scss">
  191. /* #ifdef MP */
  192. .mp-search-box {
  193. position: absolute;
  194. left: 0;
  195. top: 30upx;
  196. z-index: 9999;
  197. width: 100%;
  198. padding: 0 80upx;
  199. .ser-input {
  200. flex: 1;
  201. height: 56upx;
  202. line-height: 56upx;
  203. text-align: center;
  204. font-size: 28upx;
  205. color: $font-color-base;
  206. border-radius: 20px;
  207. background: rgba(255, 255, 255, 0.6);
  208. }
  209. }
  210. /* #endif */
  211. page {
  212. .carousel-section {
  213. padding: 0;
  214. .titleNview-placing {
  215. padding-top: 0;
  216. height: 0;
  217. }
  218. .carousel {
  219. .carousel-item {
  220. padding: 0;
  221. }
  222. }
  223. .swiper-dots {
  224. left: 45upx;
  225. bottom: 40upx;
  226. }
  227. }
  228. }
  229. page {
  230. background: #f5f5f5;
  231. }
  232. .m-t {
  233. margin-top: 16upx;
  234. }
  235. /* 头部 轮播图 */
  236. .carousel-section {
  237. position: relative;
  238. padding-top: 10px;
  239. .titleNview-placing {
  240. height: var(--status-bar-height);
  241. padding-top: 44px;
  242. box-sizing: content-box;
  243. }
  244. .titleNview-background {
  245. position: absolute;
  246. top: 0;
  247. left: 0;
  248. width: 100%;
  249. height: 426upx;
  250. transition: 0.4s;
  251. }
  252. }
  253. .carousel {
  254. width: 100%;
  255. height: 960upx;
  256. .carousel-item,image {
  257. width: 100%;
  258. height: 100%;
  259. }
  260. }
  261. .swiper-dots {
  262. display: flex;
  263. position: absolute;
  264. left: 60upx;
  265. bottom: 15upx;
  266. width: 72upx;
  267. height: 36upx;
  268. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzV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Nww5kqdsmm6/2MwtVCp8CosQtP9vg/2+/gY+DRAMBgqnjIp2PaCxCLLldpPARRIiFj1yBbMV+cHZh9PURRLQNhY8kgWyL/WDtwujjI8hoE8rKLqb5CDJaRMJHokC6yKgSCR9JAukmokIknCQJpLOIrJFwMsBJELFcKHwM9BFkLBMKFxNcBCHlQ+FhoocgpVwwnv0Xn30QBJGMC0QcaBVJiAMiec/dcwKuL4j1QMsVCXFAJE4s4NQA3K/8Y6DzO4g40P7UcmIBJxbEesCKWBDg8wWxHrAiFgT4fEGsB/CwIhYE+AeBAAdPLOcV8HRmWRDAiQVcO7GcV8CLM8uCAE4sQCDAlHcQ7x+ABQEEAggEEAggEEAggEAAgQACASAQQCCAQACBAAIBBAIIBBAIIBBAIABe4e9iAe/xd7EAJxYgEGDeO4j3EODp/cOCAE4sYMyJ5cwCHs4rCwI4sYBxJ5YzC84rCwKcXxArAuthQYDzC2JF0H49LAhwYUGsCFqvx5EF2T07dMaJBetx4cRyaqFtHJ8EIhK0i8OJBQxcECuCVutxJhCRoE0cZwMRyRcFefa/ffZBVPogePihhyCnbBhcfMFFEFM+DD4m+ghSlgmDkwlOgpAl4+BkkJMgZdk4+EgaSCcpVX7bmY9kgXQQU+1TgE0c+QJZUUz1b2T4SBbIKmJW+3iMj2SBVBWz+leVfCQLpIqYbp8b85EskIxyfIOfK5Sf+wiCRJEsllQ+oqEkQfBxmD8BBgA5hVjXyrBNUQAAAABJRU5ErkJggg==);
  269. background-size: 100% 100%;
  270. .num {
  271. width: 36upx;
  272. height: 36upx;
  273. border-radius: 50px;
  274. font-size: 24upx;
  275. color: #fff;
  276. text-align: center;
  277. line-height: 36upx;
  278. }
  279. .sign {
  280. position: absolute;
  281. top: 0;
  282. left: 50%;
  283. line-height: 36upx;
  284. font-size: 12upx;
  285. color: #fff;
  286. transform: translateX(-50%);
  287. }
  288. }
  289. /* 分类 */
  290. .cate-section {
  291. display: flex;
  292. justify-content: space-around;
  293. margin-top: 20upx;
  294. padding: 30upx 22upx;
  295. .cate-item {
  296. display: flex;
  297. flex: 1;
  298. justify-content: center;
  299. align-items: center;
  300. flex-direction: column;
  301. font-size: 26upx;
  302. color: $font-color-dark;
  303. }
  304. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  305. image {
  306. width: 47upx;
  307. height: 47upx;
  308. margin-bottom: 14upx;
  309. }
  310. }
  311. </style>
  312. <style src="./style.scss" lang="scss"></style>