﻿<template>
	<el-dialog :title="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'" :close-on-click-modal="false"
		:visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll width="70%" v-loading="loading">
		<el-row :gutter="15" class="NCC-dialog-content">
			<el-form ref="elForm" :model="dataForm" size="small" label-width="120px" label-position="right"
				:disabled="!!isDetail" :rules="rules">
				<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="qualificationCertificate">
						<NCC-UploadFz v-model="dataForm.qualificationCertificate" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="联系人" prop="contactUser">
						<el-input v-model="dataForm.contactUser" placeholder="请输入联系人" clearable
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="联系电话" prop="contactPhone">
						<el-input v-model="dataForm.contactPhone" placeholder="请输入联系电话" clearable
							:style='{ "width": "100%" }'>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
         		  <el-form-item label="所属区县" prop="areaId">
         		    <el-radio-group v-model="dataForm.areaId" placeholder="请选择所属区县" style="line-height: 22px">
         		      <el-radio v-for="v in areaOptions" :key="v.id" :label="v.id">{{ v.fullName }}</el-radio>
         		    </el-radio-group>
         		  </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>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail" :loading="btnLoading">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import request from '@/utils/request'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { previewDataInterface } from '@/api/systemData/dataInterface'
import infoMixin from "@/mixins/info";

export default {
	components: {},
	props: [],
	mixins: [infoMixin],
	data() {
		return {
			loading: false,
			visible: false,
			isDetail: false,
			areaOptions: [],
			dataForm: {
				id: '',
				id: undefined,
				companyName: undefined,
				socialCreditAgency: undefined,
				legalPerson: undefined,
				address: undefined,
				contactInformation: undefined,
				qualificationCertificate: [],
				otherInfo: undefined,
				areaId: undefined,
				contactUser: undefined,
				contactPhone: undefined
			},
			rules: {
				companyName: [
					{
						required: true,
						message: '请输入公司名称',
						trigger: 'blur'
					},
				],
				contactPhone: [
					{
						pattern: /^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
						message: '请输入正确的联系段话',
						trigger: 'blur'
					},
				],
			},
			btnLoading: false,
		}
	},
	computed: {},
	watch: {},
	created() {
		this.initAreaTypeList();
	},
	mounted() {
	},
	methods: {
		goBack() {
			this.$emit('refresh')
		},
		init(id, isDetail) {
			this.dataForm.id = id || 0;
			this.visible = true;
			this.isDetail = isDetail || false;
			this.$nextTick(() => {
				this.$refs['elForm'].resetFields();
				if (this.dataForm.id) {
					this.loading = true;
					request({
						url: '/Extend/BaseComapnyInfo/' + this.dataForm.id,
						method: 'get'
					}).then(res => {
						this.dataForm = res.data;
						this.loading = false;
						if (!this.dataForm.qualificationCertificate) this.dataForm.qualificationCertificate = [];
					})
				}
			})
		},
		dataFormSubmit() {
			this.$refs['elForm'].validate((valid) => {
				if (valid) {
					this.btnLoading = true;
					if (!this.dataForm.id) {
						request({
							url: `/Extend/BaseComapnyInfo`,
							method: 'post',
							data: this.dataForm,
						}).then((res) => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.visible = false,
										this.$emit('refresh', true);
									}
								});
								this.btnLoading = false;
						}).catch(() => this.btnLoading = false);
					} else {
						request({
							url: '/Extend/BaseComapnyInfo/' + this.dataForm.id,
							method: 'PUT',
							data: this.dataForm
						}).then((res) => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.visible = false
									this.$emit('refresh', true);
								}
							});
							this.btnLoading = false;
						}).catch(() => this.btnLoading = false);
					}
				}
			})
		},
	}
}
</script>
