<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="450" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="60px">
			<el-form-item label="厂商" prop="company_id">
				<el-select style="width: 100%;" v-model="form.company_id" placeholder="请选择厂商" clearable>
					<el-option v-for="(item,index) in setMap.companyList" :key="index" :label="item.name" :value="item.id"></el-option>
				</el-select>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSave" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	name: "manufacturer",
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "show",
			titleMap: {
				show: '维保厂商',
				review:'维保厂商',
			},
			visible: false,
			isSave: false,
			setMap:{
				companyList:[]
			},
			//表单数据
			form: {
				company_id: "",
			},
			//验证规则
			rules: {
				company_id: [
					{required: true, message: '请选择厂商'}
				],
			},
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(mode='show'){
			this.mode = mode;
			this.visible = true;
			this.getDataCompany();
			return this
		},
		async getDataCompany() {
			let params = {
				field:"name",
				name:{
					operator:"like",
					value:""
				}
			}
			const res = await this.$API.orders.order.maintenance.wbCompanyField.post(params);
			if (res.code == 200) {
				this.setMap.companyList = res.data;
			}
		},
		//表单提交方法
		submit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSave = true;
					this.$emit('success', this.form, this.mode);
				}
			})
		},
		hideVisible(){
			this.isSave = false;
			this.visible = false;
		},
		//表单注入数据
		async setData() {

		}
	}
}
</script>

<style scoped>

</style>
