﻿<template>
    <div>
        <el-row :gutter="15">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="134px" label-position="right" :disabled="setting.readonly">
				<el-col :span="24">
					<el-form-item label-width="0">
						<NCC-Text value="可行性研究报告审批单" :textStyle='{"color":"#767575","text-align":"center","font-weight":"bold","font-style":"normal","text-decoration":"none","line-height":32,"font-size":24}' :style='{"width":"100%"}' ></NCC-Text>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false" >
					<el-form-item label="自动编号" prop="autoCode">
						<el-input v-model="dataForm.autoCode" placeholder="系统自动生成" readonly :disabled="JudgeWrite('autoCode')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('projectId')">
					<el-form-item label="项目名称" prop="projectId">
						<el-select v-model="dataForm.projectId" placeholder="请选择" clearable required :disabled="JudgeWrite('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('enCode')">
					<el-form-item label="项目编号" prop="enCode">
						<el-input v-model="dataForm.enCode" placeholder="请输入" clearable :disabled="JudgeWrite('enCode')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('organizationId')">
					<el-form-item label="甲方单位" prop="organizationId">
						<el-select v-model="dataForm.organizationId" placeholder="请选择" clearable required :disabled="JudgeWrite('organizationId')" :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in organizationIdOptions" :key="index" :label="item.F_Name" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('lastHander')">
					<el-form-item label="主要负责人" prop="lastHander">
						<user-select v-model="dataForm.lastHander" placeholder="请选择" required :disabled="JudgeWrite('lastHander')" >
						</user-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('objective')">
					<el-form-item label="项目概要" prop="objective">
						<el-input v-model="dataForm.objective" placeholder="请输入" required :disabled="JudgeWrite('objective')" 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" required :disabled="JudgeWrite('appendix')" accept=".doc,.docx" showTip :fileSize="50" 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('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('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('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('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:'',
					autoCode:undefined,
					projectId:undefined,
					enCode:undefined,
					organizationId:undefined,
					lastHander:undefined,
					objective:undefined,
					appendix:[],
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					projectId:[
						{
							required:true,
							message:'请输入项目名称',
							trigger:'change'
						},
					],
					organizationId:[
						{
							required:true,
							message:'请输入甲方单位',
							trigger:'change'
						},
					],
					lastHander:[
						{
							required:true,
							message:'请输入主要负责人',
							trigger:'change'
						},
					],
					objective:[
						{
							required:true,
							message:'请输入项目概要',
							trigger:'blur'
						},
					],
					appendix:[
						{
							required:true,
							message:'请输入可研报告',
							trigger:'click'
						},
					],
				},
				projectIdOptions : [],
				organizationIdOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getprojectIdOptions();
			this.getorganizationIdOptions();
		},
		mounted() {},
		methods: {
			getprojectIdOptions(){
				previewDataInterface('210191934059185413').then(res => {
					this.projectIdOptions = res.data
				});
			},
			getorganizationIdOptions(){
				previewDataInterface('208733616207824133').then(res => {
					this.organizationIdOptions = 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/ZyZbwfProjectfsr/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						  if(!this.dataForm.appendix)this.dataForm.appendix=[];
						})
					}
					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/ZyZbwfProjectfsr',
						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/ZyZbwfProjectfsr/' + 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>

