﻿<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%">
		<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" v-if="ncc.hasFormP('companyId')">
						<el-form-item label="所属公司" prop="companyId">
							<el-select v-model="dataForm.companyId" placeholder="请选择" clearable required :style='{"width":"100%"}' filterable >
								<el-option v-for="(item, index) in companyIdOptions" :key="index" :label="item.F_CompanyName" :value="item.F_id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="ncc.hasFormP('systemClass')">
						<el-form-item label="系统分类" prop="systemClass">
							<el-select v-model="dataForm.systemClass" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in systemClassOptions" :key="index" :label="item.F_ClassName" :value="item.F_Id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="ncc.hasFormP('systemType')">
						<el-form-item label="系统类型" prop="systemType">
							<el-select v-model="dataForm.systemType" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in systemTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="ncc.hasFormP('systemName')">
						<el-form-item label="系统名称" prop="systemName">
							<el-input v-model="dataForm.systemName" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="ncc.hasFormP('systemState')">
						<el-form-item label="状态" prop="systemState">
							<el-radio-group v-model="dataForm.systemState" required :style='{}' >
								<el-radio v-for="(item, index) in systemStateOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="ncc.hasFormP('systemChangeSituation')">
						<el-form-item label="变更情况" prop="systemChangeSituation">
							<el-radio-group v-model="dataForm.systemChangeSituation" required :style='{}' >
								<el-radio v-for="(item, index) in systemChangeSituationOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="ncc.hasFormP('systemIcon')">
						<el-form-item label="系统图标" prop="systemIcon">
							<NCC-UploadImg v-model="dataForm.systemIcon" :fileSize="5" sizeUnit="MB" :limit="9" >
							</NCC-UploadImg>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="ncc.hasFormP('systemRecordNumber')">
						<el-form-item label="备案号" prop="systemRecordNumber">
							<el-input v-model="dataForm.systemRecordNumber" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="ncc.hasFormP('systemLocation')">
						<el-form-item label="所在区县" prop="systemLocation">
							<NCC-Address v-model="dataForm.systemLocation" placeholder="请选择" clearable :level="2" >
							</NCC-Address>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="ncc.hasFormP('systemIntroduce')">
						<el-form-item label="简介" prop="systemIntroduce">
							<el-input v-model="dataForm.systemIntroduce" 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" v-if="ncc.hasFormP('systemDownloadVolume')">
						<el-form-item label="下载量" prop="systemDownloadVolume">
							<el-input-number v-model="dataForm.systemDownloadVolume" placeholder="数字文本" :step="1" >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="24" 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="24" 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="24" 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="24" 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>
		<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,
					companyId:undefined,
					systemClass:undefined,
					systemType:undefined,
					systemName:undefined,
					systemState:undefined,
					systemChangeSituation:undefined,
					systemIcon:[],
					systemRecordNumber:undefined,
					systemLocation:[],
					systemIntroduce:undefined,
					systemDownloadVolume:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					companyId:[
						{
							required:true,
							message:'请输入所属公司',
							trigger:'change'
						},
					],
					systemClass:[
						{
							required:true,
							message:'请输入系统分类',
							trigger:'change'
						},
					],
					systemType:[
						{
							required:true,
							message:'请输入系统类型',
							trigger:'change'
						},
					],
					systemName:[
						{
							required:true,
							message:'请输入系统名称',
							trigger:'blur'
						},
					],
					systemState:[
						{
							required:true,
							message:'请输入状态',
							trigger:'change'
						},
					],
					systemChangeSituation:[
						{
							required:true,
							message:'请输入变更情况',
							trigger:'change'
						},
					],
				},
				companyIdOptions : [],
				systemClassOptions : [],
				systemTypeOptions : [],
				systemStateOptions : [],
				systemChangeSituationOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getcompanyIdOptions();
			this.getsystemClassOptions();
			this.getsystemTypeOptions();
			this.getsystemStateOptions();
			this.getsystemChangeSituationOptions();
		},
		mounted() {
        },
		methods: {
			getcompanyIdOptions(){
				previewDataInterface('576296400682222853').then(res => {
					this.companyIdOptions = res.data
				});
			},
			getsystemClassOptions(){
				previewDataInterface('576295179435115781').then(res => {
					this.systemClassOptions = res.data
				});
			},
			getsystemTypeOptions(){
				getDictionaryDataSelector('576279943168656645').then(res => {
					this.systemTypeOptions = res.data.list
				});
			},
			getsystemStateOptions(){
				getDictionaryDataSelector('576291549546022149').then(res => {
					this.systemStateOptions = res.data.list
				});
			},
			getsystemChangeSituationOptions(){
				getDictionaryDataSelector('576291912521090309').then(res => {
					this.systemChangeSituationOptions = 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/Extend/BaseSysteminfo/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
							if(!this.dataForm.systemIcon)this.dataForm.systemIcon=[];
							if(!this.dataForm.systemLocation)this.dataForm.systemLocation=[];
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/Extend/BaseSysteminfo`,
                                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/Extend/BaseSysteminfo/' + 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>
