<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.modelName" placeholder="请输入车型"/></u-form-item>
				<u-form-item label="空调滤清器" label-position="top">
					<u-radio-group v-model="form.airConditionerFilterFlag" :size="28">
						<u-radio 
							v-for="(item, index) in list" :key="index" 
							:name="item.val" :disabled="item.disabled"
						>
							{{item.name}}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="空气滤清器" label-position="top">
					<u-radio-group v-model="form.airFilterFlag" :size="28">
						<u-radio 
							v-for="(item, index) in list" :key="index" 
							:name="item.val" :disabled="item.disabled"
						>
							{{item.name}}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="机油滤清器" label-position="top">
					<u-radio-group v-model="form.engineOilFilterFlag" :size="28">
						<u-radio 
							v-for="(item, index) in list" :key="index" 
							:name="item.val" :disabled="item.disabled"
						>
							{{item.name}}
						</u-radio>
					</u-radio-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,//车辆品牌
					modelName: undefined//车型
				},
				customBtnStyle: {  //  自定义按钮样式
					borderColor: this.$config('primaryColor'),
					backgroundColor: this.$config('primaryColor'),
					color: '#fff'
				},
				list: [
					{
						name: '有适配',
						val:1,
						disabled: false
					},
					{
						name: '无适配',
						val:2,
						disabled: false
					},
					{
						name: '空(--)',
						val:0,
						disabled: false
					}
				],
				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 = ''
			},
			// 表单清空
			handleClean(){
				this.form={
					date: '',
					beginDate: '',
					endDate: '',
					airConditionerFilterFlag:undefined,
					airFilterFlag:undefined,
					engineOilFilterFlag:undefined,
					vinCode: undefined, 
					brandName: undefined,//车辆品牌
					modelName: undefined//车型
				}
				setTimeout(()=>{
					this.handleSearch()
				},300)
			},
			handleSearch(){
				let data = JSON.parse(JSON.stringify(this.form))
				this.$emit('refresh', data)
				this.isShow=false
			},
		},
		watch:{
			//  父页面传过来的弹框状态
			showModal (newValue, oldValue) {
				this.isShow = newValue
			},
			//  重定义的弹框状态
			isShow (newValue, oldValue) {
				if (!newValue) {
					this.$emit('close')
				}
			}
		}
	}
</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>
