<template>
	<movable-area class="page__view">
		<!-- <view class="bg">
			<image class="img" src="@/static/image/bg.png" mode="widthFix"></image>
		</view> -->
		<bgSwiperView></bgSwiperView>

		<view class="main">
			
			<!-- 搜索栏 -->
			<view :class="['flex', 'search', searchStyle.class]">
				<uv-search 
					v-model="keyword" 
					placeholder="输入关键词搜索" 
					:color="searchStyle.color"
					bgColor="transparent" 
					:showAction="searchStyle.showAction"
					@custom="search" 
					@search="search"
					@focus="isFocusSearch = true"
					@blur="isFocusSearch = false"
				>
          <template #prefix>
            <image class="search-icon" :src="searchStyle.icon" mode="widthFix"></image>
          </template>
        </uv-search>
				<view class="border">
					<view class="border-left"></view>
				</view>
			</view>

			<view class="section">
				<categoryView></categoryView>
			</view>

			<view class="section">
				<recommendView></recommendView>
			</view>
			
			<view class="section">
				<swiperView></swiperView>
			</view>

			<view class="section">
				<pictureLiveView></pictureLiveView>
			</view>

			<view class="section reason">
				<image class="img" src="@/static/image/temp-19.png" mode="widthFix"></image>
			</view>

			<view class="section">
				<productView :list="list"></productView>
			</view>

		</view>
		
		<movable-view v-if="showBtnService" class="movable-view" :x="273" :y="628" direction="all">
			<view class="movable-content">
				<button class="flex btn btn-service" open-type="contact">
					<view class="label">联系客服</view>
					<image class="icon" src="@/static/image/icon-service.png" mode="widthFix"></image>
				</button>
				<button class="flex btn btn-close" @click.stop="showBtnService = false">
					<image class="icon" src="@/static/image/icon-close.png" mode="widthFix"></image>
				</button>
			</view>
		</movable-view>

		<tabber select="home" />

	</movable-area>
</template>

<script>
	import mixinsList from '@/mixins/list.js'

	import tabber from '@/components/base/tabbar.vue'
	import bgSwiperView from '@/components/home/bgSwiperView.vue'
	import categoryView from '@/components/home/categoryView.vue'
	import recommendView from '@/components/home/recommendView.vue'
	import swiperView from '@/components/home/swiperView.vue'
	import pictureLiveView from '@/components/home/pictureLiveView.vue'
	import productView from '@/components/home/productView.vue'

	export default {
		mixins: [mixinsList],
		components: {
      tabber,
			bgSwiperView,
			categoryView,
			recommendView,
			swiperView,
			pictureLiveView,
			productView,
		},
		data() {
			return {
				keyword: '',
				isFocusSearch: false,
				mixinsListApi: 'queryActivityList',
				showBtnService: true,
			}
		},
		onLoad() {
			if(uni.getStorageSync('token')){
				this.$store.commit('getUserInfo')
			}
		},
		computed: {
			searchStyle() {
				let focusStyle = {
					class: 'focus',
					color: '#181818',
					icon: '/static/image/icon-search-dark.png',
					showAction: true,
				}
				let blurStyle = {
					class: 'blur',
					color: '#FFFFFF',
					icon: '/static/image/icon-search-light.png',
					showAction: false,
				}

				return this.isFocusSearch ? focusStyle : blurStyle
			},
		},
		methods: {
			search() {
				console.log('search', this.keyword)
        uni.navigateTo({
					url: '/pages_order/product/search?search=' + this.keyword
				})
				// this.keyword = ''
			},
		},
	}
</script>

<style scoped lang="scss">

	.bg {
		width: 100%;
		height: auto;
		border-bottom-left-radius: 40rpx;
		border-bottom-right-radius: 40rpx;
    font-size: 0;
    overflow: hidden;

		.img {
			width: 100%;
			height: auto;
		}
	}

	.main {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		padding: 100rpx 32rpx calc(120rpx + env(safe-area-inset-bottom) + 32rpx) 32rpx;
    box-sizing: border-box;
	}

	.search {
		$w: 474rpx;
		$h: 64rpx;
		$radius: 32rpx;
		$borderWidth: 4rpx;

		width: $w;
		height: $h;
		position: relative;
		border-radius: $radius;

		&-icon {
			margin: 0 13rpx 0 26rpx;
			width: 30rpx;
			height: auto;
		}

		/deep/ .uv-search__content {
			padding: 12rpx 0;
			border: 4rpx solid transparent;
		}

		&.blur {
			background: #FFFFFF66;

			&:before,
			&:after {
				width: calc(#{$w} - #{$radius});
				height: $borderWidth;
				position: absolute;
				left: $radius;
				content: ' ';
				background: linear-gradient(to right, #FFFFFF, #FFFFFF00);
			}
			&:before {
				top: 0;
			}
			&:after {
				bottom: 0;
			}

			.border {
				width: $radius;
				overflow: hidden;
				position: absolute;
				top: 0;
				left: 0;

				&-left {
					width: calc(#{$radius} * 2 - #{$borderWidth} * 2);
					height: calc(#{$h} - #{$borderWidth} * 2);
					border: $borderWidth solid #FFFFFF;
					border-radius: $radius;
				}
			}

		}

		&.focus {
			/deep/ .uv-search__content {
				background: #FFFFFF !important;
				border-color: #CFEFFF !important;
			}

			/deep/ .uv-search__action {
				padding: 19rpx 24rpx;
				font-size: 26rpx;
				font-weight: 500;
				line-height: 1;
				color: #FFFFFF;
				background: #00A9FF;
				border-radius: 32rpx;
			}
		}
	}

	.section {
		& + & {
			margin-top: 32rpx;
		}
	}

	.reason {
		width: 100%;
		font-size: 0;
		border-radius: 32rpx;
		overflow: hidden;
		
		.img {
			width: 100%;
			height: auto;
		}
	}

	.movable {

		&-view {
    	position: fixed;
			width: auto;
			height: auto;
		}

		&-content {
			position: relative;

			.btn {
				&-service {
					column-gap: 4rpx;
					padding: 6rpx 6rpx 6rpx 18rpx;
					background: linear-gradient(to right, #21FEEC, #019AF9);
					border: 2rpx solid #00A9FF;
					border-radius: 40rpx;

					.label {
						white-space: nowrap;
						font-size: 24rpx;
						font-weight: 500;
						color: #FFFFFF;
						text-shadow: 0 1px 2px #135A98;
					}

					.icon {
						width: 64rpx;
						height: auto;
					}
				}

				&-close {
					width: 32rpx;
					height: auto;
					position: absolute;
					top: 0;
					left: 0;
					transform: translate(-10rpx, -10rpx);
				}
			}
		}
	}

</style>