<template>
  <div class="companyForm">
    <div class="userSelect-input" @click="openDialog">
      <el-button type="text" icon="el-icon-circle-plus-outline" size="small"
        >点击新增企业</el-button
      >
    </div>
    <el-dialog
      title="新增企业"
      :close-on-click-modal="false"
      :visible.sync="visible"
      lock-scroll
      append-to-body
      width="60%"
      top="15vh"
      :modal-append-to-body="false"
      class="NCC-dialog NCC-dialog_center company-dialog"
    >
      <el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right"
				 :rules="rules" v-lodding="loading">
				<el-col :span="24" v-if="false">
					<el-form-item label="主键" prop="id">
						<el-input v-model="dataForm.id" placeholder="请输入" clearable :style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="公司名称" prop="companyName">
						<el-input v-model="dataForm.companyName" placeholder="请输入" clearable required
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="社会信用代" prop="socialCreditAgency">
						<el-input v-model="dataForm.socialCreditAgency" placeholder="请输入" clearable
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="公司法人" prop="legalPerson">
						<el-input v-model="dataForm.legalPerson" placeholder="请输入" clearable :style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="公司地址" prop="address">
						<el-input v-model="dataForm.address" placeholder="请输入" clearable :style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="联系方式" prop="contactInformation">
						<el-input v-model="dataForm.contactInformation" placeholder="请输入" clearable
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="其他信息" prop="otherInfo">
						<NCC-Quill v-model="dataForm.otherInfo" placeholder="请输入内容...">
						</NCC-Quill>
					</el-form-item>
				</el-col>
			</el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="confirm" :loading="btnLoading">确认</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  name: "companyForm",
  props: {},
  data() {
    return {
     	visible: false,
     	loading: false,
     	dataForm: {
			id: '',
			id: undefined,
			companyName: undefined,
			socialCreditAgency: undefined,
			legalPerson: undefined,
			address: undefined,
			contactInformation: undefined,
			qualificationCertificate: [],
			otherInfo: undefined,
		},
		rules: {
			companyName: [
				{
					required: true,
					message: '请输入公司名称',
					trigger: 'blur'
				},
			],
			contactInformation: [
				{
					pattern: /^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
					message: '请输入正确的联系方式',
					trigger: 'blur'
				},
			],
		},
		btnLoading: false
    };
  },
  watch: {},
  mounted() {},
  created() {},
  methods: {
    close() {
      this.visible = false;
    },
    openDialog() {
      this.visible = true;
			this.$refs['elForm'].resetFields();
    },
    async confirm() {
      	this.$refs['elForm'].validate((valid) => {
			if (valid) {
				this.btnLoading = true;
          		request({
					url: `/Extend/BaseComapnyInfo`,
					method: 'post',
					data: this.dataForm,
				}).then((res) => {
					this.btnLoading = false;
					this.$message({
						message: res.msg,
						type: 'success',
						duration: 1000,
						onClose: () => {
							this.visible = false,
								this.$emit('refresh', true)
						}
					})
				}).catch(() => {this.btnLoading = false})
    	    }
		})
    },
  },
};
</script>
<style lang="scss" scoped>
</style>