﻿<template>
    <div>
        <el-row :gutter="15">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="120px" label-position="right" :disabled="setting.readonly">
				<el-col :span="24">
					<el-form-item label-width="0">
						<groupTitle content-position="center" content="造价咨询成果审批单"></groupTitle>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false" >
					<el-form-item label="咨询编号" prop="enCode">
						<el-input v-model="dataForm.enCode" placeholder="系统自动生成" readonly :disabled="JudgeWrite('enCode')" >
						</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('projectCode')">
					<el-form-item label="项目编号" prop="projectCode">
						<el-input v-model="dataForm.projectCode" placeholder="请输入" clearable :disabled="JudgeWrite('projectCode')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('organizationId')">
					<el-form-item label="甲方单位" prop="organizationId">
					<el-select v-model="dataForm.organizationId" placeholder="请选择" clearable required @visible-change="handleChange" :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">
						<el-input v-model="dataForm.lastHander" placeholder="请输入" clearable :disabled="JudgeWrite('lastHander')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('lastHanderPhone')">
					<el-form-item label="联系电话" prop="lastHanderPhone">
						<el-input v-model="dataForm.lastHanderPhone" placeholder="请输入" clearable :disabled="JudgeWrite('lastHanderPhone')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('consultType')">
					<el-form-item label="咨询类别" prop="consultType">
						<el-checkbox-group v-model="dataForm.consultType" required :disabled="JudgeWrite('consultType')" :style='{}' >
							<el-checkbox v-for="(item, index) in consultTypeOptions" :key="index" :label="item.id" >{{item.fullName}}</el-checkbox>
						</el-checkbox-group>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('sealState')">
					<el-form-item label="是否盖章" prop="sealState">
						<el-radio-group v-model="dataForm.sealState" required :disabled="JudgeWrite('sealState')" :style='{}' >
							<el-radio v-for="(item, index) in sealStateOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('sealType')">
					<el-form-item label="盖章类型" prop="sealType" v-if="dataForm.sealState==1">
						<el-checkbox-group v-model="dataForm.sealType" required :disabled="JudgeWrite('sealType')" :style='{}' >
							<el-checkbox v-for="(item, index) in sealTypeOptions" :key="index" :label="item.id" >{{item.fullName}}</el-checkbox>
						</el-checkbox-group>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('content')">
					<el-form-item label="内容概要" prop="content">
						<el-input v-model="dataForm.content" placeholder="请输入" required :disabled="JudgeWrite('content')" 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')" showTip :fileSize="100" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('gldAppendix')">
					<el-form-item label="广联达格式文件" prop="gldAppendix">
						<NCC-UploadFz v-model="dataForm.gldAppendix" :disabled="JudgeWrite('gldAppendix')" :fileSize="100" 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:'',
					enCode:undefined,
					projectId:undefined,
					projectCode:undefined,
					organizationId:undefined,
					lastHander:undefined,
					lastHanderPhone:undefined,
					consultType:[],
					sealState:undefined,
					sealType:[],
					content:undefined,
					appendix:[],
					gldAppendix:[],
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					projectId:[
						{
							required:true,
							message:'请输入项目名称',
							trigger:'change'
						},
					],
					organizationId:[
						{
							required:true,
							message:'请选择甲方单位',
							trigger:'change'
						},
					],
					lastHanderPhone:[
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
					consultType:[
						{
							required:true,
							message:'请输入咨询类别',
							trigger:'change'
						},
					],
					sealState:[
						{
							required:true,
							message:'请输入是否盖章',
							trigger:'change'
						},
					],
					sealType:[
						{
							required:true,
							message:'请输入盖章类型',
							trigger:'change'
						},
					],
					content:[
						{
							required:true,
							message:'请输入内容概要',
							trigger:'blur'
						},
					],
					appendix:[
						{
							required:true,
							message:'请上传附件',
							trigger:'click'
						},
					],
				},
				projectIdOptions : [],
				organizationIdOptions : [],
				consultTypeOptions : [],
				sealStateOptions:[{"fullName":"否","id":"0"},{"fullName":"是","id":"1"}],
				sealTypeOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getprojectIdOptions();
			this.getorganizationIdOptions();
			this.getconsultTypeOptions();
			this.getsealTypeOptions();
		},
		mounted() {},
		methods: {
			getprojectIdOptions(){
				previewDataInterface('210191934059185413').then(res => {
					this.projectIdOptions = res.data
				});
			},
			getorganizationIdOptions(){
				previewDataInterface('208733616207824133').then(res => {
					this.organizationIdOptions = res.data
				});
			},
			getconsultTypeOptions(){
				getDictionaryDataSelector('214323576004674821').then(res => {
					this.consultTypeOptions = res.data.list
				});
			},
			getsealTypeOptions(){
				getDictionaryDataSelector('214323207396656389').then(res => {
					this.sealTypeOptions = res.data.list
				});
			},
			handleChange() {
                // 项目Id
                if (this.dataForm.organizationId) {
					request({
						url: '/api/SubDev/ZyZbPartner/Actions/GetPartner/' + this.dataForm.organizationId,
						method: 'get'
					}).then(res =>{
						this.dataForm.lastHander=res.data.director;
						this.dataForm.lastHanderPhone = res.data.directorPhone;
					})
				}
            },
			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/ZyZbwfConsult/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						  if(!this.dataForm.consultType)this.dataForm.consultType=[];
						  if(!this.dataForm.sealType)this.dataForm.sealType=[];
						  if(!this.dataForm.appendix)this.dataForm.appendix=[];
						  if(!this.dataForm.gldAppendix)this.dataForm.gldAppendix=[];
						})
					}
					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/ZyZbwfConsult',
						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/ZyZbwfConsult/' + 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>

