﻿<template>
    <div class="flow-form" >
    <div class="com-title">
      <h2>工作报告</h2>
      <span class="number"></span>
    </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_Code')">
					<el-form-item label="报告编码" prop="code">
						<el-input v-model="dataForm.code" placeholder="系统自动生成" readonly :disabled="JudgeWrite('F_Code')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('F_Title')">
					<el-form-item label="标题" prop="title">
						<el-input v-model="dataForm.title" placeholder="请输入" clearable required :disabled="JudgeWrite('F_Title')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('F_ToUserIds')">
					<el-form-item label="汇报给" prop="F_ToUserIds">
						<user-select v-model="dataForm.F_ToUserIds" placeholder="请选择" required :disabled="JudgeWrite('F_ToUserIds')" multiple >
						</user-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('F_WorkText')">
					<el-form-item label="工作内容" prop="workText">
						<el-input v-model="dataForm.workText" placeholder="请输入" required :disabled="JudgeWrite('F_WorkText')" 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('F_PlanText')">
					<el-form-item label="计划内容" prop="planText">
						<el-input v-model="dataForm.planText" placeholder="请输入" :disabled="JudgeWrite('F_PlanText')" 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('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="24" v-if="JudgeShow('F_Appendix')">
					<el-form-item label="附件" prop="appendix">
						<NCC-UploadFz v-model="dataForm.appendix" :disabled="JudgeWrite('F_Appendix')" :fileSize="1" sizeUnit="GB" :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 :disabled="JudgeWrite('F_CreatorUserId')" >
						</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 :disabled="JudgeWrite('F_CreatorTime')" >
						</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 :disabled="JudgeWrite('F_LastModifyUserId')" >
						</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 :disabled="JudgeWrite('F_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:'',
					code:undefined,
					title:undefined,
					F_ToUserIds:undefined,
					workText:undefined,
					planText:undefined,
					description:undefined,
					appendix:[],
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					title:[
						{
							required:true,
							message:'请输入标题',
							trigger:'blur'
						},
					],
					F_ToUserIds:[
						{
							required:true,
							message:'请输入汇报给',
							trigger:'change'
						},
					],
					workText:[
						{
							required:true,
							message:'请输入工作内容',
							trigger:'blur'
						},
					],
				},
			}
		},
		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/SubDev/ZyOaWfReports/' + 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/ZyOaWfReports',
						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/ZyOaWfReports/' + 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>

