﻿<template>
    <div>
        <el-row :gutter="15">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="125px" label-position="right" :disabled="setting.readonly">
				<el-col :span="24" v-if="false" >
					<el-form-item label="主键" prop="id">
						<el-input v-model="dataForm.id" placeholder="请输入" clearable :disabled="judgeWrite('id')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('registrationTime')">
					<el-form-item label="登记时间" prop="registrationTime">
						<el-date-picker v-model="dataForm.registrationTime" placeholder="请选择" clearable :disabled="judgeWrite('registrationTime')" :style='{"width":"100%"}' type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('number')">
					<el-form-item label="文号" prop="number">
						<el-input v-model="dataForm.number" placeholder="请输入" clearable :disabled="judgeWrite('number')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('systemName')">
					<el-form-item label="网站/APP名称" prop="systemName">
						<el-input v-model="dataForm.systemName" placeholder="请输入" clearable :disabled="judgeWrite('systemName')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('registeredEntity')">
					<el-form-item label="注册主体" prop="registeredEntity">
						<el-input v-model="dataForm.registeredEntity" placeholder="请输入" clearable :disabled="judgeWrite('registeredEntity')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('category')">
					<el-form-item label="类别" prop="category">
						<el-select v-model="dataForm.category" placeholder="请选择" clearable :disabled="judgeWrite('category')" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in categoryOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('recordNumber')">
					<el-form-item label="备案号" prop="recordNumber">
						<el-input v-model="dataForm.recordNumber" placeholder="请输入" clearable :disabled="judgeWrite('recordNumber')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('districtCounty')">
					<el-form-item label="所属区（市）县" prop="districtCounty">
						<NCC-Address v-model="dataForm.districtCounty" placeholder="请选择" clearable :disabled="judgeWrite('districtCounty')" :level="2" >
						</NCC-Address>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('illegalReasons')">
					<el-form-item label="违法原因" prop="illegalReasons">
						<el-input v-model="dataForm.illegalReasons" placeholder="请输入" clearable :disabled="judgeWrite('illegalReasons')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('punishmentRequirements')">
					<el-form-item label="处罚要求" prop="punishmentRequirements">
						<el-input v-model="dataForm.punishmentRequirements" placeholder="请输入" clearable :disabled="judgeWrite('punishmentRequirements')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('punishmentContent')">
					<el-form-item label="处罚内容" prop="punishmentContent">
						<el-input v-model="dataForm.punishmentContent" placeholder="请输入" :disabled="judgeWrite('punishmentContent')" 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="judgeShow('state')">
					<el-form-item label="状态" prop="state">
						<el-select v-model="dataForm.state" placeholder="请选择" clearable :disabled="judgeWrite('state')" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in stateOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('record')">
					<el-form-item label="笔录" prop="record">
						<NCC-UploadFz v-model="dataForm.record" :disabled="judgeWrite('record')" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('caseHandlingOpinions')">
					<el-form-item label="案件处理意见" prop="caseHandlingOpinions">
						<NCC-UploadFz v-model="dataForm.caseHandlingOpinions" :disabled="judgeWrite('caseHandlingOpinions')" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('enforcementRecords')">
					<el-form-item label="执法记录" prop="enforcementRecords">
						<NCC-UploadFz v-model="dataForm.enforcementRecords" :disabled="judgeWrite('enforcementRecords')" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('noticeLetter')">
					<el-form-item label="行政处罚意见告知" prop="noticeLetter">
						<NCC-UploadFz v-model="dataForm.noticeLetter" :disabled="judgeWrite('noticeLetter')" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('punishmentDecision')">
					<el-form-item label="行政处罚决定" prop="punishmentDecision">
						<NCC-UploadFz v-model="dataForm.punishmentDecision" :disabled="judgeWrite('punishmentDecision')" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('closingReport')">
					<el-form-item label="行政处罚结案报告" prop="closingReport">
						<NCC-UploadFz v-model="dataForm.closingReport" :disabled="judgeWrite('closingReport')" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false" >
					<el-form-item label="工作流ID" prop="taskId">
						<el-input v-model="dataForm.taskId" placeholder="请输入" clearable :disabled="judgeWrite('taskId')" :style='{"width":"100%"}' >
						</el-input>
					</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 :disabled="judgeWrite('creatorUserId')" >
						</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 :disabled="judgeWrite('creatorTime')" >
						</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 :disabled="judgeWrite('lastModifyUserId')" >
						</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 :disabled="judgeWrite('lastModifyTime')" >
						</el-input>
					</el-form-item>
				</el-col>
            </el-form>
        </el-row>
        <UserBox v-if="userBoxVisible" ref="userBox" @submit="submit" />
    </div>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		data(){
			return {
				visible: false,
				setting:{},
				eventType: '',
				userBoxVisible:false,
				dataForm: {
					id:'',
					id:undefined,
					registrationTime:undefined,
					number:undefined,
					systemName:undefined,
					registeredEntity:undefined,
					category:undefined,
					recordNumber:undefined,
					districtCounty:[],
					illegalReasons:undefined,
					punishmentRequirements:undefined,
					punishmentContent:undefined,
					state:undefined,
					record:[],
					caseHandlingOpinions:[],
					enforcementRecords:[],
					noticeLetter:[],
					punishmentDecision:[],
					closingReport:[],
					taskId:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
				},
				categoryOptions:[{"fullName":"选项一","id":"选项一"},{"fullName":"","id":"选项二"}],
				stateOptions:[{"fullName":"选项一","id":"1"},{"fullName":"选项二","id":"2"}],
			}
		},
		computed: {},
        watch: {},
        created() {
		},
		mounted() {},
		methods: {
			goBack() {
                this.$emit('refresh')
            },
			init(data) {
				this.dataForm.id = data.id || 0;
                this.loading = true
				this.setting = data
				this.visible = true;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/Extend/BaseCaseHandling/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						  if(!this.dataForm.districtCounty)this.dataForm.districtCounty=[];
						  if(!this.dataForm.record)this.dataForm.record=[];
						  if(!this.dataForm.caseHandlingOpinions)this.dataForm.caseHandlingOpinions=[];
						  if(!this.dataForm.enforcementRecords)this.dataForm.enforcementRecords=[];
						  if(!this.dataForm.noticeLetter)this.dataForm.noticeLetter=[];
						  if(!this.dataForm.punishmentDecision)this.dataForm.punishmentDecision=[];
						  if(!this.dataForm.closingReport)this.dataForm.closingReport=[];
						})
					}
					else{
						this.dataForm.flowId = data.flowId
					}
					this.loading = false
					this.$emit('setPageLoad')
				})
			},
			dataFormSubmit(eventType) {				
				this.$refs['elForm'].validate((valid) => {
					if (valid) {
						if (eventType === 'audit' || eventType === 'reject') {
            				this.$emit('eventReciver', this.dataForm, eventType)
            				return
          				}
						this.dataForm.flowState = eventType === 'submit' ? 0 : 1
						this.eventType = eventType
						if (this.eventType === 'submit') {
							this.$confirm('您确定要提交当前流程吗, 是否继续?', '提示', {
								type: 'warning'
							}).then(() => {
								this.request()
							}).catch(() => { });
						} else {
							this.request()
						}
					}
				})
			},
			request() {
				if (!this.dataForm.id) {
					delete (this.dataForm.id)
					request({
						url: '/api/Extend/BaseCaseHandling',
						method: 'post',
						data: this.dataForm
					}).then((res) => {
						this.$message({
							message: res.msg,
							type: 'success',
							duration: 1000,
							onClose: () => {
								this.visible = false
								this.$emit('close', true)
							}
						})
					})
				}else{
					request({
						url: '/api/Extend/BaseCaseHandling/' + 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('close', true)
							}
						})
					})
				}
			},
			judgeShow(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length) return true
				let arr = this.setting.formOperates.filter(o => o.id === id) || []
				if (!arr.length) return true
				let item = arr[0]
				return item.read
			},
			judgeWrite(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length) return false
				let arr = this.setting.formOperates.filter(o => o.id === id) || []
				if (!arr.length) return true
				let item = arr[0]
				return !item.write
			},
		}
	}
</script>

