﻿<template>
    <div style="background-color: #FFF;padding-top: 10px;">
        <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="false">
					<el-form-item label="主键" prop="id">
						<el-input v-model="dataForm.id" placeholder="请输入" clearable :disabled="judgeWrite('id')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="judgeShow('instructClass')">
					<el-form-item label="指令分类" prop="instructClass">
						<el-select v-model="dataForm.instructClass" placeholder="请选择" clearable :disabled="judgeWrite('instructClass')" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in instructClassOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="judgeShow('instructType')">
					<el-form-item label="指令类型" prop="instructType">
						<el-select v-model="dataForm.instructType" placeholder="请选择" clearable :disabled="judgeWrite('instructType')" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in instructTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('title')">
					<el-form-item label="标题" prop="title">
						<el-input v-model="dataForm.title" placeholder="请输入" clearable :disabled="judgeWrite('title')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('originalLink')">
					<el-form-item label="原文链接" prop="originalLink">
						<el-input v-model="dataForm.originalLink" placeholder="请输入" clearable :disabled="judgeWrite('originalLink')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('releaseTime')">
					<el-form-item label="发布时间" prop="releaseTime">
						<el-date-picker v-model="dataForm.releaseTime" placeholder="请选择" clearable :disabled="judgeWrite('releaseTime')" :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="24" v-if="judgeShow('content')">
					<el-form-item label="内容" prop="content">
						<el-input v-model="dataForm.content" placeholder="请输入" :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('annex')">
					<el-form-item label="附件" prop="annex">
						<NCC-UploadFz v-model="dataForm.annex" :disabled="judgeWrite('annex')" :fileSize="5" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('taskDep')">
					<el-form-item label="任务部门" prop="taskDep">
						<dep-select v-model="dataForm.taskDep" placeholder="请选择" clearable :disabled="judgeWrite('taskDep')" >
						</dep-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('assigner')">
					<el-form-item label="指定人" prop="assigner">
						<user-select v-model="dataForm.assigner" placeholder="请选择" clearable :disabled="judgeWrite('assigner')" >
						</user-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('keyword')">
					<el-form-item label="标签关键词" prop="keyword">
						<el-input v-model="dataForm.keyword" placeholder="请输入" clearable :disabled="judgeWrite('keyword')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('districtAndCounty')">
					<el-form-item label="区县" prop="districtAndCounty">
						<NCC-Address v-model="dataForm.districtAndCounty" placeholder="请选择" clearable :disabled="judgeWrite('districtAndCounty')" :level="2" >
						</NCC-Address>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="judgeShow('executionFeedback')">
					<el-form-item label="执行反馈" prop="executionFeedback">
						<NCC-Quill v-model="dataForm.executionFeedback" placeholder="请输入内容..." :disabled="judgeWrite('executionFeedback')" >
						</NCC-Quill>
					</el-form-item>
				</el-col>
				<el-col :span="24" 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="24" 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="24" 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="24" 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-col :span="24" v-if="false" >
					<el-form-item label="状态" prop="state">
						<el-input v-model="dataForm.state" placeholder="请输入" clearable :disabled="judgeWrite('state')" :style='{"width":"100%"}' >
						</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:'',
					id:undefined,
					instructClass:undefined,
					instructType:undefined,
					title:undefined,
					originalLink:undefined,
					releaseTime:undefined,
					content:undefined,
					annex:[],
					taskDep:undefined,
					assigner:undefined,
					keyword:undefined,
					districtAndCounty:[],
					executionFeedback:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
					state:undefined,
				},
				rules: {
				},
				instructClassOptions : [],
				instructTypeOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getinstructClassOptions();
			this.getinstructTypeOptions();
		},
		mounted() {},
		methods: {
			getinstructClassOptions(){
				getDictionaryDataSelector('576299676240708869').then(res => {
					this.instructClassOptions = res.data.list
				});
			},
			getinstructTypeOptions(){
				getDictionaryDataSelector('576299511719134469').then(res => {
					this.instructTypeOptions = 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/Extend/BaseWorkOrder/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						  if(!this.dataForm.annex)this.dataForm.annex=[];
						  if(!this.dataForm.districtAndCounty)this.dataForm.districtAndCounty=[];
						})
					}
					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/Extend/BaseWorkOrder',
						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/Extend/BaseWorkOrder/' + 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>

