<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
	<div>
		<el-dialog :title="title" :close-on-click-modal="false" draggable width="1200px" height="500px" @close="close"
			append-to-body v-model="visible">
			<el-form :model="inputForm" ref="inputForm" v-loading="loading" :rules="rules"
				:class="method === 'view' ? 'readonly' : ''"
				:disabled="status === 'audit' || status === 'taskFormDetail' || method === 'view'" label-width="100px"
				@submit.native.prevent>
				<el-row :gutter="26">
					<el-col :span="12">
						<el-form-item label="成员姓名" prop="name">
							<el-input v-model="inputForm.name" placeholder="请输入成员姓名"></el-input>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="出生日期" prop="birthDate">
							<el-date-picker v-model="inputForm.birthDate" type="date" placeholder="请选择出生日期"
								style="width: 100%;"></el-date-picker>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="与本人关系" prop="relation">
							<el-input v-model="inputForm.relation" placeholder="请输入与本人关系"></el-input>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="性别" prop="gender">
							<el-radio-group v-model="inputForm.gender">
								<el-radio v-for="item in $dictUtils.getDictList('sex')" :label="item.value + ''">{{
									item.label }}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="手机号码" prop="mobile">
							<el-input v-model="inputForm.mobile" placeholder="请输入手机号码"></el-input>
						</el-form-item>
					</el-col>

					<!-- <el-col :span="12">
						<el-form-item label="工作单位" prop="workUnit">
							<el-input v-model="inputForm.workUnit" placeholder="请输入工作单位"></el-input>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="联系电话" prop="contactNumber">
							<el-input v-model="inputForm.contactNumber" placeholder="请输入联系电话"></el-input>
						</el-form-item>
					</el-col> -->


				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
					<el-button v-if="method === 'edit' || method == 'add'" type="primary" icon="el-icon-circle-check"
						@click="doSubmit()">确定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script>
import enrollmentRegistrationService from '@/api/human/enrollment/EnrollmentRegistrationService'
export default {
	props: {
		businessId: {
			type: String,
			default: ''
		},
		formReadOnly: {
			type: Boolean,
			default: false
		},
		status: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			disabled: false,
			title: '',
			method: '',
			visible: false,
			loading: false,
			inputForm: {
				enrollmentRegistrationId: '',
				name: '',            // 成员姓名
				birthDate: '',       // 出生日期
				relation: '',        // 与本人关系名称
				gender: '1',          // 性别
				mobile: '',          // 手机号码
				workUnit: '',        // 工作单位
				contactNumber: ''    // 联系电话
			},
			keyWatch: '',
			rules: {
				name: [
					{ required: true, message: '请输入成员姓名', trigger: 'blur' },
				],
				relation: [
					{ required: true, message: '请输入与本人关系', trigger: 'blur' },
				],
				// contactNumber: [
				// 	{ required: true, message: '请输入联系电话', trigger: 'blur' },
				// ]
			}
		}
	},
	created() {
	},
	components: {
	},
	computed: {
		bus: {
			get() {
				return this.businessId
			},
			set(val) {
				this.businessId = val
			}
		},
		name() {
			return this.$store.state.user.name
		},
		userId() {
			return this.$store.state.user.id
		}
	},
	watch: {
		'keyWatch': {
			handler(newVal) {
				if (this.commonJS.isNotEmpty(this.bus)) {
					this.init('', this.bus)
				} else {
					this.$nextTick(() => {
						this.$refs.inputForm.resetFields()
					})
				}
			}
		},
		'loading': {
			handler(newVal) {
				this.$emit('changeLoading', newVal)
			}
		}
	},
	methods: {
		getKeyWatch(keyWatch) {
			this.keyWatch = keyWatch
		},
		init(method, id, reId) {
			this.method = method
			this.inputForm = {
				enrollmentRegistrationId: '',
				name: '',            // 成员姓名
				birthDate: '',       // 出生日期（格式：YYYY-MM-DD）
				relation: '',        // 与本人关系名称
				gender: '1',          // 性别（如：男、女）
				mobile: '',          // 手机号码
				workUnit: '',        // 工作单位
				contactNumber: ''    // 联系电话
			}
			if (method === 'add') {
				this.title = `新增家庭情况`
			} else if (method === 'edit') {
				this.title = '修改家庭情况'
			} else if (method === 'view') {
				this.title = '查看家庭情况'
			}
			this.inputForm.id = id
			this.inputForm.userId = reId
			this.visible = true
			this.loading = true
			this.$nextTick(() => {
				if (id) {
					enrollmentRegistrationService.findFamilyInfoById({
						id: this.inputForm.id
					}).then(res => {
						this.inputForm = this.recover(this.inputForm, res)
						this.inputForm = JSON.parse(JSON.stringify(this.inputForm))
						this.loading = false
					})
				} else {
					this.inputForm.id = id
					this.loading = false
				}
			})
		},
		// 表单提交
		doSubmit() {
			this.$refs['inputForm'].validate((valid) => {
				if (valid) {
					this.inputForm.birthDate = new Date(this.inputForm.birthDate).getTime(); // 转为时间戳
					this.inputForm.status = "5"
					enrollmentRegistrationService.saveFamilyInfo(this.inputForm).then(res => {
						this.close()
						this.$message.success(res)
						this.$emit("addFamilyInfo", this.inputForm.enrollmentRegistrationId)
						this.loading = false
					})
				}
			})
		},
		close() {
			this.$refs.inputForm.resetFields()
			this.visible = false
		},
	}
}
</script>


<style lang="less">
.fileUpload {
	.el-form-item__content {
		width: 100%;
	}
}
</style>
