﻿<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('Assignment_Code')">
					<el-form-item label="任务编码" prop="assignmentCode">
						<el-input v-model="dataForm.assignmentCode" placeholder="系统自动生成" readonly :disabled="JudgeWrite('Assignment_Code')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('Assignment_User')">
					<el-form-item label="参与人员" prop="Assignment_User">
						<user-select v-model="dataForm.Assignment_User" placeholder="请选择" required :disabled="JudgeWrite('Assignment_User')" multiple >
						</user-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('Assignment_Name')">
					<el-form-item label="任务名称" prop="assignmentName">
						<el-input v-model="dataForm.assignmentName" placeholder="请输入" clearable required :disabled="JudgeWrite('Assignment_Name')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('Assignment_Type')">
					<el-form-item label="任务类型" prop="assignmentType">
						<el-select v-model="dataForm.assignmentType" placeholder="请选择" clearable required :disabled="JudgeWrite('Assignment_Type')" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in assignmentTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('F_ProjectId')">
					<el-form-item label="关联项目" prop="projectId" v-if="dataForm.assignmentType=='204034329662194949'">
						<el-select v-model="dataForm.projectId" placeholder="请选择" clearable required :disabled="JudgeWrite('F_ProjectId')" :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in projectIdOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('F_StartTime')">
					<el-form-item label="开始时间" prop="startTime">
						<el-date-picker v-model="dataForm.startTime" placeholder="请选择" clearable required :disabled="JudgeWrite('F_StartTime')" :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="12" v-if="JudgeShow('F_EndTime')">
					<el-form-item label="结束时间" prop="endTime">
						<el-date-picker v-model="dataForm.endTime" placeholder="请选择" clearable required :disabled="JudgeWrite('F_EndTime')" :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="12" v-if="JudgeShow('F_TimeLimit')">
					<el-form-item label="任务工期" prop="timeLimit">
						<el-input-number v-model="dataForm.timeLimit" placeholder="数字文本" required :disabled="JudgeWrite('F_TimeLimit')" :step="1" >
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('F_SignColor')">
					<el-form-item label="任务标记" prop="signColor">
						<el-color-picker v-model="dataForm.signColor" required :disabled="JudgeWrite('F_SignColor')" color-format="hex" >
						</el-color-picker>
					</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="请输入" required :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('Appendix')">
					<el-form-item label="附件" prop="appendix">
						<NCC-UploadFz v-model="dataForm.appendix" :disabled="JudgeWrite('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 :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:'',
					assignmentCode:undefined,
					Assignment_User:undefined,
					assignmentName:undefined,
					assignmentType:undefined,
					projectId:undefined,
					startTime:undefined,
					endTime:undefined,
					timeLimit:0,
					signColor:"#10BDE0",
					description:undefined,
					appendix:[],
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					Assignment_User:[
						{
							required:true,
							message:'请输入参与人员',
							trigger:'change'
						},
					],
					assignmentName:[
						{
							required:true,
							message:'请输入任务名称',
							trigger:'blur'
						},
					],
					assignmentType:[
						{
							required:true,
							message:'请输入任务类型',
							trigger:'change'
						},
					],
					projectId:[
						{
							required:true,
							message:'请输入关联项目',
							trigger:'blur'
						},
					],
					startTime:[
						{
							required:true,
							message:'请输入开始时间',
							trigger:'change'
						},
					],
					endTime:[
						{
							required:true,
							message:'请输入结束时间',
							trigger:'change'
						},
					],
					timeLimit:[
						{
							required:true,
							message:'请输入任务工期',
							trigger:["blur","change"]
						},
					],
					signColor:[
						{
							required:true,
							message:'请输入任务标记',
							trigger:'change'
						},
					],
					description:[
						{
							required:true,
							message:'请输入任务描述',
							trigger:'blur'
						},
					],
				},
				assignmentTypeOptions : [],
				projectIdOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getassignmentTypeOptions();
			this.getprojectIdOptions();
		},
		mounted() {},
		methods: {
			getassignmentTypeOptions(){
				getDictionaryDataSelector('204018991591589125').then(res => {
					this.assignmentTypeOptions = res.data.list
				});
			},
			getprojectIdOptions(){
				previewDataInterface('195045591036724485').then(res => {
					this.projectIdOptions = res.data
				});
			},
			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/ZyOaWfAssignment/' + 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/ZyOaWfAssignment',
						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/ZyOaWfAssignment/' + 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>

