﻿<template>
	<transition name="el-zoom-in-center">
		<div class="NCC-preview-main">
			<div class="NCC-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="small" label-width="114px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="24">
					<el-form-item label-width="0">
						<NCC-Text value="合作方信息" :textStyle='{"color":"#787777","text-align":"center","font-weight":"bold","font-style":"normal","text-decoration":"none","line-height":20,"font-size":18}' :style='{"width":"100%"}' ></NCC-Text>
					</el-form-item>
				</el-col>
					<el-col :span="12" >
						<el-form-item label="合作方名称" prop="name">
							<el-input v-model="dataForm.name" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="合作方类别" prop="supplierType">
							<el-select v-model="dataForm.supplierType" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in supplierTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="证件类型" prop="certificatesType">
							<el-select v-model="dataForm.certificatesType" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in certificatesTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="证件号码" prop="certificatesNumber">
							<el-input v-model="dataForm.certificatesNumber" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="联系人" prop="director">
							<el-input v-model="dataForm.director" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="联系电话" prop="directorPhone">
							<el-input v-model="dataForm.directorPhone" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="所在区域" prop="area">
							<NCC-Address v-model="dataForm.area" placeholder="请选择" :level="2" >
							</NCC-Address>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<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="12" >
						<el-form-item label="合作方来源" prop="source">
							<el-select v-model="dataForm.source" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in sourceOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="日常联系人" prop="desPerson">
							<user-select v-model="dataForm.desPerson" placeholder="请选择" multiple >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="附件" prop="appendix">
							<NCC-UploadFz v-model="dataForm.appendix" :fileSize="2" sizeUnit="MB" :limit="9" buttonText="点击上传" >
							</NCC-UploadFz>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="备注" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建人" prop="creatorUserId">
							<el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建时间" prop="creatorTime">
							<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改人" prop="lastModifyUserId">
							<el-input v-model="dataForm.lastModifyUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改时间" prop="lastModifyTime">
							<el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</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:'',
					name:undefined,
					supplierType:undefined,
					certificatesType:undefined,
					certificatesNumber:undefined,
					director:undefined,
					directorPhone:undefined,
					area:[],
					address:undefined,
					source:undefined,
					desPerson:undefined,
					appendix:[],
					remark:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					name:[
						{
							required:true,
							message:'请输入合作方名称',
							trigger:'blur'
						},
					],
					supplierType:[
						{
							required:true,
							message:'请输入合作方类别',
							trigger:'change'
						},
					],
					source:[
						{
							required:true,
							message:'请输入合作方来源',
							trigger:'change'
						},
					],
				},
				supplierTypeOptions : [],
				certificatesTypeOptions : [],
				sourceOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getsupplierTypeOptions();
			this.getcertificatesTypeOptions();
			this.getsourceOptions();
		},
		mounted() {
        },
		methods: {
			getsupplierTypeOptions(){
				getDictionaryDataSelector('206940643107276037').then(res => {
					this.supplierTypeOptions = res.data.list
				});
			},
			getcertificatesTypeOptions(){
				getDictionaryDataSelector('7866376d5f694d4d851c7164bd00ebfc').then(res => {
					this.certificatesTypeOptions = res.data.list
				});
			},
			getsourceOptions(){
				getDictionaryDataSelector('4ce486ec911e46cb914ea53f685ead75').then(res => {
					this.sourceOptions = res.data.list
				});
			},
			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) {
						request({
							url: '/api/SubDev/ZyZbPartner/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
							if(!this.dataForm.area)this.dataForm.area=[];
							if(!this.dataForm.appendix)this.dataForm.appendix=[];
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/SubDev/ZyZbPartner`,
                                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: '/api/SubDev/ZyZbPartner/' + 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>
