﻿<template>
    <div>
        <el-row :gutter="15">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="100px" label-position="right" :disabled="setting.readonly">
				<el-col :span="24" v-if="JudgeShow('F_EnCode')">
					<el-form-item label="用章编码" prop="enCode">
						<el-input v-model="dataForm.enCode" placeholder="系统自动生成" readonly :disabled="JudgeWrite('F_EnCode')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('F_SealName')">
					<el-form-item label="文件名称" prop="sealName">
						<el-input v-model="dataForm.sealName" placeholder="请输入" clearable required :disabled="JudgeWrite('F_SealName')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('F_SealType')">
					<el-form-item label="盖章类型" prop="sealType">
						<el-select v-model="dataForm.sealType" placeholder="请选择" clearable required :disabled="JudgeWrite('F_SealType')" :style='{"width":"100%"}' multiple >
							<el-option v-for="(item, index) in sealTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('F_SealDate')">
					<el-form-item label="用章日期" prop="sealDate">
						<el-date-picker v-model="dataForm.sealDate" placeholder="请选择" clearable required :disabled="JudgeWrite('F_SealDate')" :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('F_SealCount')">
					<el-form-item label="文件份数" prop="sealCount">
						<el-input-number v-model="dataForm.sealCount" placeholder="数字文本" required :disabled="JudgeWrite('F_SealCount')" :step="1" >
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('F_SealFile')">
					<el-form-item label="用印文件" prop="sealFile">
						<NCC-UploadFz v-model="dataForm.sealFile" required :disabled="JudgeWrite('F_SealFile')" :fileSize="2" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('F_Description')">
					<el-form-item label="其他说明" prop="description">
						<el-input v-model="dataForm.description" placeholder="请输入" :disabled="JudgeWrite('F_Description')" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="false" >
					<el-form-item label="申请人" prop="creatorUserId">
						<el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly :disabled="JudgeWrite('F_CreatorUserId')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="false" >
					<el-form-item label="创建时间" prop="creatorTime">
						<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly :disabled="JudgeWrite('F_CreatorTime')" >
						</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:'',
					enCode:undefined,
					sealName:undefined,
					sealType:[],
					sealDate:undefined,
					sealCount:1,
					sealFile:[],
					description:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
				},
				rules: {
					sealName:[
						{
							required:true,
							message:'请输入文件名称',
							trigger:'blur'
						},
					],
					sealType:[
						{
							required:true,
							message:'请输入盖章类型',
							trigger:'change'
						},
					],
					sealDate:[
						{
							required:true,
							message:'请输入用章日期',
							trigger:'change'
						},
					],
					sealCount:[
						{
							required:true,
							message:'请输入文件份数',
							trigger:["blur","change"]
						},
					],
					sealFile:[
						{
							required:true,
							message:'请输入用印文件',
							trigger:'click'
						},
					],
				},
				sealTypeOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getsealTypeOptions();
		},
		mounted() {},
		methods: {
			getsealTypeOptions(){
				getDictionaryDataSelector('200800482640266501').then(res => {
					this.sealTypeOptions = res.data.list
				});
			},
			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/SubDev/ZyOaWfSeal/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						})
					}
					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/SubDev/ZyOaWfSeal',
						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/SubDev/ZyOaWfSeal/' + 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>

