<template>
	<view class="modal-box">
		<u-popup v-model="isShow"  @close="isShow=false" mode="right" length="85%" >
			<u-form :model="form" ref="uForm" label-width="150" class="form-content">
				<u-form-item label="扫描时间" prop="date" class="form-item">
					<u-input clearable v-model="form.date" disabled placeholder="请选择扫描时间区间" class="form-item-inp" @click="showDate=true" />
					<u-icon v-show="form.date.length != 0" name="close-circle-fill" color="#c8c0cc" size="32" class="close-circle" @click="clearTime"></u-icon>
				</u-form-item>
				<u-form-item label="VIN"><u-input v-model.trim="form.vinCode" placeholder="请输入VIN"/></u-form-item>
				<u-form-item label="车辆品牌"><u-input v-model.trim="form.brandName" placeholder="请输入车辆品牌"/></u-form-item>
				<u-form-item label="车型"><u-input v-model.trim="form.modelInfo" placeholder="请输入车型"/></u-form-item>
				<u-form-item label="空调滤清器" label-position="top">
					<u-checkbox-group :size="28">
						<u-checkbox 
							v-for="(item, index) in list0" 
							:key="index" 
							:name="item.val" 
							v-model="item.checked"
							:disabled="item.disabled"
							@change="(e)=>{checkboxChange(e,'airConditionerFilterFlag',list0)}"
						>
							{{item.name}}
						</u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<u-form-item label="空气滤清器" label-position="top">
					<u-checkbox-group :size="28">
						<u-checkbox 
							v-for="(item, index) in list1" 
							:key="index" 
							:name="item.val" 
							:disabled="item.disabled"
							v-model="item.checked"
							@change="(e)=>{checkboxChange(e,'airFilterFlag',list1)}"
						>
							{{item.name}}
						</u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<u-form-item label="机油滤清器" label-position="top">
					<u-checkbox-group :size="28">
						<u-checkbox 
							v-for="(item, index) in list2" 
							:key="index" 
							:name="item.val" 
							:disabled="item.disabled"
							v-model="item.checked"
							@change="(e)=>{checkboxChange(e,'engineOilFilterFlag',list2)}"
						>
							{{item.name}}
						</u-checkbox>
					</u-checkbox-group>
				</u-form-item>
			</u-form>
			<view class="form-footer-btn">
				<u-button class="handle-btn" shape="circle" size="medium" hover-class="none" @click="handleClean">重置</u-button>
				<u-button class="handle-btn" shape="circle" size="medium" hover-class="none" :custom-style="customBtnStyle" @click="handleSearch">查询</u-button>
			</view>
		</u-popup>
		<!-- 选择日期范围 -->
		<u-calendar v-model="showDate" @change="dateChange" mode="range"></u-calendar>
	</view>
</template>

<script>
	export default{
		components: { },
		props:{
			showModal:{
				type: Boolean,
				default: false
			}
		},
		data(){
			return{
				form: {
					date: '',
					beginDate: '',
					endDate: '',
					airConditionerFilterFlag:null,
					airFilterFlag:null,
					engineOilFilterFlag:null,
					vinCode: undefined, 
					brandName: undefined,//车辆品牌
					modelInfo: undefined//车型
				},
				customBtnStyle: {  //  自定义按钮样式
					borderColor: this.$config('primaryColor'),
					backgroundColor: this.$config('primaryColor'),
					color: '#fff'
				},
				list: [
					{
						name: '有适配',
						val:1,
						disabled: false,
						checked: false
					},
					{
						name: '无适配',
						val:2,
						disabled: false,
						checked: false
					},
					{
						name: '空(--)',
						val:0,
						disabled: false,
						checked: false
					}
				],
				list0:[],
				list1:[],
				list2:[],
				showDate: false, // 是否显示时间弹窗
				isShow:this.showModal,
				showTypeModal: false,
				brandModal:false
			}
		},
		methods:{
			// 时间  change
			dateChange(date){
				this.form.date = date.startDate + ' ~ ' + date.endDate
				this.form.beginDate = date.startDate + ' 00:00:00'
				this.form.endDate = date.endDate + ' 23:59:59'
			},
			//  清空创建时间
			clearTime(){
				this.form.date = ''
				this.form.beginDate = ''
				this.form.endDate = ''
			},
			checkboxChange(e,key,list){
				console.log(e,key)
				list.map(item => {
					item.checked = item.val == e.name
				})
				this.form[key] = e.value ? e.name : ''
			},
			// 表单清空
			handleClean(){
				this.form={
					date: '',
					beginDate: '',
					endDate: '',
					airConditionerFilterFlag:null,
					airFilterFlag:null,
					engineOilFilterFlag:null,
					vinCode: undefined, 
					brandName: undefined,//车辆品牌
					modelInfo: undefined//车型
				}
				setTimeout(()=>{
					this.handleSearch()
				},300)
			},
			handleSearch(){
				let data = JSON.parse(JSON.stringify(this.form))
				this.$emit('refresh', data)
				this.isShow=false
			},
			setOptionVal(list,key){
				list.map(item => {
					item.checked = item.val === this.form[key]
				})
			}
		},
		watch:{
			//  父页面传过来的弹框状态
			showModal (newValue, oldValue) {
				this.isShow = newValue
			},
			//  重定义的弹框状态
			isShow (newValue, oldValue) {
				if (!newValue) {
					this.$emit('close')
				}else{
					this.list0 = JSON.parse(JSON.stringify(this.list))
					this.list1 = JSON.parse(JSON.stringify(this.list))
					this.list2 = JSON.parse(JSON.stringify(this.list))
					this.setOptionVal(this.list0,'airConditionerFilterFlag')
					this.setOptionVal(this.list1,'airFilterFlag')
					this.setOptionVal(this.list2,'engineOilFilterFlag')
				}
			}
		}
	}
</script>

<style lang="scss">
	.modal-box{
		width: 100%;
		.form-content{
			display: block;
			padding: 0 20upx;
			box-sizing: content-box;
		}
		.u-form-item{
			padding: 10upx;
		}
		.form-footer-btn{
			margin: 30upx;
			display: flex;
			justify-content: space-between;
		}
		.form-footer-btn {
			display: flex;
			padding: 20upx;
			.handle-btn {
				font-size: 28upx;
				margin: 0 30upx;
				width: 100%;
				flex: 1;
			}
		}
	}
</style>
