﻿<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":"#666666","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="24">
						<el-form-item label-width="0">
							<groupTitle content-position="left" content="基础信息"></groupTitle>
						</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="industry">
							<el-select v-model="dataForm.industry" placeholder="请选择" clearable :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in industryOptions" :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="mobile">
							<el-input v-model="dataForm.mobile" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="电子邮件" prop="email">
							<el-input v-model="dataForm.email" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</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="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="24">
						<el-form-item label-width="0">
							<groupTitle content-position="left" content="其他信息"></groupTitle>
						</el-form-item>
					</el-col>
					<el-col :span="8" >
						<el-form-item label="法定代表人" prop="corporation">
							<el-input v-model="dataForm.corporation" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8" >
						<el-form-item label="注册资本" prop="regCapital">
							<el-input-number v-model="dataForm.regCapital" placeholder="数字文本" :style='{"width":"40%"}' :step="10" :precision="2">
							</el-input-number>万元
						</el-form-item>
					</el-col>
					<el-col :span="8" >
						<el-form-item label="成立日期" prop="establishTime">
							<el-date-picker v-model="dataForm.establishTime" placeholder="请选择" clearable :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="8" >
						<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="8" >
						<el-form-item label="联系人职务" prop="directorJob">
							<el-input v-model="dataForm.directorJob" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8" >
						<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="24" >
						<el-form-item label="经营范围" prop="businessScope">
							<el-input v-model="dataForm.businessScope" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="主要产品" prop="product">
							<el-input v-model="dataForm.product" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</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="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,
					industry:undefined,
					certificatesType:undefined,
					certificatesNumber:undefined,
					mobile:undefined,
					email:undefined,
					desPerson:undefined,
					area:[],
					address:undefined,
					corporation:undefined,
					regCapital:0,
					establishTime:undefined,
					director:undefined,
					directorJob:undefined,
					directorPhone:undefined,
					businessScope:undefined,
					product:undefined,
					appendix:[],
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					name:[
						{
							required:true,
							message:'请输入供应商名称',
							trigger:'blur'
						},
					],
					supplierType:[
						{
							required:true,
							message:'请选择供应商类别',
							trigger:'change'
						},
					],
					mobile:[
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
					email:[
						{
							pattern:/^[a-z0-9]+([._\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/,
							message:'请输入正确的邮箱',
							trigger:'blur'
						},
					],
					directorPhone:[
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
				},
				supplierTypeOptions : [],
				industryOptions : [],
				certificatesTypeOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getsupplierTypeOptions();
			this.getindustryOptions();
			this.getcertificatesTypeOptions();
		},
		mounted() {
        },
		methods: {
			getsupplierTypeOptions(){
				getDictionaryDataSelector('206940643107276037').then(res => {
					this.supplierTypeOptions = res.data.list
				});
			},
			getindustryOptions(){
				getDictionaryDataSelector('d59a3cf65f9847dbb08be449e3feae16').then(res => {
					this.industryOptions = res.data.list
				});
			},
			getcertificatesTypeOptions(){
				getDictionaryDataSelector('7866376d5f694d4d851c7164bd00ebfc').then(res => {
					this.certificatesTypeOptions = 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/ZyZbSupplier/' + 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/ZyZbSupplier`,
                                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/ZyZbSupplier/' + 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>
