Form.vue 4.73 KB
<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="">
			<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" 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="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">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import request from '@/utils/request'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { previewDataInterface } from '@/api/systemData/dataInterface'
export default {
	components: {},
	props: [],
	data() {
		return {
			loading: false,
			visible: false,
			isDetail: 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'
					},
				],
			},
		}
	},
	computed: {},
	watch: {},
	created() {
	},
	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) {
					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)
								}
							})
						})
					} 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)
								}
							})
						})
					}
				}
			})
		},
	}
}
</script>