index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <v-header mode="" service 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="triggerBannerHandle(item)">
  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 menu from './data/menu';
  75. import layoutCoupon from '@/layout/layout-coupon/index.vue';
  76. import vHeader from '@/components/v-header/main.vue';
  77. import refreshView from '@/components/refresh-view/main.vue';
  78. import vImage from '@/components/v-image/main.vue';
  79. import trigger from '@/mixins/trigger/index';
  80. import shop from '@/utils/controls/shop';
  81. import login from '@/mixins/login';
  82. import globalMixins from '@/mixins/global';
  83. import {
  84. mapState
  85. } from 'vuex';
  86. export default {
  87. components: {layoutCoupon,vHeader,refreshView,vImage},
  88. mixins:[globalMixins,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. //
  105. triggerBannerHandle(item){
  106. if (item.product_id) {
  107. shop.goShopDetail({
  108. id:item.product_id
  109. })
  110. }
  111. },
  112. fetch(obj){
  113. return Promise.all([
  114. this.$request({
  115. url: '/index/getAdsList',
  116. cache:true
  117. }),
  118. this.$request({
  119. url:'index/getNewCoupon',
  120. token:true
  121. }),
  122. this.$request({
  123. url:'product/getProductList',
  124. cache:true,
  125. data:{
  126. is_recommend:1
  127. }
  128. })
  129. ]).then((data)=>{
  130. // 执行设置
  131. ['setBanner','setCoupon','setProduct'].map((item,index)=>{
  132. return this[item] && this[item](data[index]);
  133. });
  134. this.refreshStop && this.refreshStop();
  135. return obj.success();
  136. }).catch(()=>{
  137. this.refreshStop && this.refreshStop();
  138. obj.fail();
  139. });
  140. },
  141. receiveCoupon(){
  142. if (this.receiveCouponStatus) return;
  143. this.routerLogin(()=>{
  144. this.$request({
  145. url:'product/receiveCoupon',
  146. data:{
  147. coupon_id: this.coupon.id
  148. },
  149. token:true,
  150. message:true,
  151. loading:'领取中',
  152. next:({status})=> this.receiveCouponStatus = status,
  153. failMessage:true
  154. }).then((data)=>{
  155. this.coupon = {};
  156. });
  157. })
  158. },
  159. refresh(stop){
  160. this.refreshStop = stop;
  161. if (this.$refs.header) {
  162. if (this.$refs.header._state!==1) {
  163. return this.$refs.header.reload(2);
  164. }
  165. } else {
  166. stop();
  167. }
  168. },
  169. setBanner(res){
  170. let carouselList = res.data;
  171. this.swiperLength = carouselList.length;
  172. this.carouselList = carouselList;
  173. },
  174. setCoupon(data){
  175. this.coupon = data.data;
  176. },
  177. setProduct(data){
  178. this.goodsList = data.data.map((item)=>{
  179. let price = parseFloat(item.sales_price);
  180. let intPrice = Math.floor(price);
  181. if (price === intPrice) price = intPrice;
  182. item.price = price;
  183. return item;
  184. });
  185. },
  186. goShopDetail(item){
  187. return shop.goShopDetail(item);
  188. },
  189. goShopMore(){
  190. return this.$router.switchTab('category');
  191. }
  192. },
  193. };
  194. </script>
  195. <style lang="scss">
  196. /* #ifdef MP */
  197. .mp-search-box {
  198. position: absolute;
  199. left: 0;
  200. top: 30upx;
  201. z-index: 9999;
  202. width: 100%;
  203. padding: 0 80upx;
  204. .ser-input {
  205. flex: 1;
  206. height: 56upx;
  207. line-height: 56upx;
  208. text-align: center;
  209. font-size: 28upx;
  210. color: $font-color-base;
  211. border-radius: 20px;
  212. background: rgba(255, 255, 255, 0.6);
  213. }
  214. }
  215. /* #endif */
  216. page {
  217. .carousel-section {
  218. padding: 0;
  219. .titleNview-placing {
  220. padding-top: 0;
  221. height: 0;
  222. }
  223. .carousel {
  224. .carousel-item {
  225. padding: 0;
  226. }
  227. }
  228. .swiper-dots {
  229. left: 45upx;
  230. bottom: 40upx;
  231. }
  232. }
  233. }
  234. page {
  235. background: #f5f5f5;
  236. }
  237. .m-t {
  238. margin-top: 16upx;
  239. }
  240. /* 头部 轮播图 */
  241. .carousel-section {
  242. position: relative;
  243. padding-top: 10px;
  244. .titleNview-placing {
  245. height: var(--status-bar-height);
  246. padding-top: 44px;
  247. box-sizing: content-box;
  248. }
  249. .titleNview-background {
  250. position: absolute;
  251. top: 0;
  252. left: 0;
  253. width: 100%;
  254. height: 426upx;
  255. transition: 0.4s;
  256. }
  257. }
  258. .carousel {
  259. width: 100%;
  260. height: 960upx;
  261. .carousel-item,image {
  262. width: 100%;
  263. height: 100%;
  264. }
  265. }
  266. .swiper-dots {
  267. display: flex;
  268. position: absolute;
  269. left: 60upx;
  270. bottom: 15upx;
  271. width: 72upx;
  272. height: 36upx;
  273. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAYAAADDhn8LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBh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ACTUlEQVR42uzcQW7jQAwFUdN306l1uWwNww5kqdsmm6/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==);
  274. background-size: 100% 100%;
  275. .num {
  276. width: 36upx;
  277. height: 36upx;
  278. border-radius: 50px;
  279. font-size: 24upx;
  280. color: #fff;
  281. text-align: center;
  282. line-height: 36upx;
  283. }
  284. .sign {
  285. position: absolute;
  286. top: 0;
  287. left: 50%;
  288. line-height: 36upx;
  289. font-size: 12upx;
  290. color: #fff;
  291. transform: translateX(-50%);
  292. }
  293. }
  294. /* 分类 */
  295. .cate-section {
  296. display: flex;
  297. justify-content: space-around;
  298. margin-top: 20upx;
  299. padding: 30upx 22upx;
  300. .cate-item {
  301. display: flex;
  302. flex: 1;
  303. justify-content: center;
  304. align-items: center;
  305. flex-direction: column;
  306. font-size: 26upx;
  307. color: $font-color-dark;
  308. }
  309. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  310. image {
  311. width: 47upx;
  312. height: 47upx;
  313. margin-bottom: 14upx;
  314. }
  315. }
  316. </style>
  317. <style src="./style.scss" lang="scss"></style>