﻿<template>
    <div>
        <el-row :gutter="15">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="medium" label-width="113px" label-position="right" :disabled="setting.readonly">
				<el-col :span="24">
					<el-form-item label-width="0">
						<NCC-Text value="费用报销单" :textStyle='{"color":"#636262","text-align":"center","font-weight":"bold","font-style":"normal","text-decoration":"none","line-height":26,"font-size":22}' :style='{"width":"100%"}' ></NCC-Text>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="false" >
					<el-form-item label="报销单号" prop="reimbursement">
						<el-input v-model="dataForm.reimbursement" placeholder="系统自动生成" readonly :disabled="JudgeWrite('reimbursement')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="false" >
					<el-form-item label="报销人" prop="handler">
						<el-input v-model="dataForm.handler" placeholder="系统自动生成" readonly :disabled="JudgeWrite('handler')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('state')">
					<el-form-item label="是否关联项目" prop="state">
						<el-radio-group v-model="dataForm.state" required :disabled="JudgeWrite('state')" :style='{}' >
							<el-radio v-for="(item, index) in stateOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('proId')">
					<el-form-item label="关联项目" prop="proId" v-if="dataForm.state==1">
						<el-select v-model="dataForm.proId" placeholder="请选择" clearable required :disabled="JudgeWrite('proId')" :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in proIdOptions" :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('happedTime')">
					<el-form-item label="发生时间" prop="happedTime">
						<el-date-picker v-model="dataForm.happedTime" placeholder="请选择" clearable required :disabled="JudgeWrite('happedTime')" :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('totalAmount')">
					<el-form-item label="报销总额" prop="totalAmount">
						<el-input-number v-model="dataForm.totalAmount" placeholder="数字文本" :precision="2"    required :disabled="JudgeWrite('totalAmount')" :step="100" >
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('remark')">
					<el-form-item label="报销事由" prop="remark">
						<el-input v-model="dataForm.remark" placeholder="请输入" clearable required :disabled="JudgeWrite('remark')" :style='{"width":"100%"}' >
						</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="1" sizeUnit="GB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
                <el-col :span="24" v-if="JudgeShow('zyOaWfFinrmbtDetails')">
                    <el-form-item label-width="0">
                        <el-table :data="dataForm.zyOaWfFinrmbtDetailsList" size='mini'>
                            <el-table-column type="index" width="50" label="序号" align="center" />
                            <el-table-column prop="costType" label="费用类别">
                                <template slot-scope="scope">
                                    <el-select v-model="scope.row.costType" placeholder="请选择" clearable :disabled="JudgeWrite('zyOaWfFinrmbtDetails')" >
										<el-option v-for="(item, index) in costTypeOptions" :key="index" :label="item.fullName" :value="item.id" :disabled="item.disabled"></el-option>
									</el-select>
                                </template>
                            </el-table-column>
                            <el-table-column prop="costItem" label="费用项目">
                                <template slot-scope="scope">
									<el-input v-model="scope.row.costItem"  placeholder="请输入" clearable :disabled="JudgeWrite('zyOaWfFinrmbtDetails')" ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column prop="costAmount" label="报销金额">
                                <template slot-scope="scope">
									<el-input-number v-model="scope.row.costAmount"  placeholder="数字文本" :precision="2"  :step="100"  :disabled="JudgeWrite('zyOaWfFinrmbtDetails')" ></el-input-number>
                                </template>
                            </el-table-column>
                            <el-table-column prop="remarks" label="备注说明">
                                <template slot-scope="scope">
									<el-input v-model="scope.row.remarks"  placeholder="请输入" clearable :disabled="JudgeWrite('zyOaWfFinrmbtDetails')" ></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" width="50" v-if="!setting.readonly && !JudgeWrite('zyOaWfFinrmbtDetails')">
								<template slot-scope="scope">
									<el-button size="mini" type="text" class="NCC-table-delBtn" @click="handleDelZyOaWfFinrmbtDetailsEntityList(scope.$index)">删除</el-button>
								</template>
							</el-table-column>
						</el-table>
						<div class="table-actions" @click="addHandleZyOaWfFinrmbtDetailsEntityList()" v-if="!setting.readonly && !JudgeWrite('zyOaWfFinrmbtDetails')">
							<el-button type="text" icon="el-icon-plus">新增</el-button>
						</div>
					</el-form-item>
				</el-col>
				<el-col :span="6" v-if="false" >
					<el-form-item label="创建时间" prop="createTime">
						<el-input v-model="dataForm.createTime" placeholder="系统自动生成" readonly :disabled="JudgeWrite('createTime')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" v-if="false" >
					<el-form-item label="修改人" prop="modifyPerson">
						<el-input v-model="dataForm.modifyPerson" placeholder="系统自动生成" readonly :disabled="JudgeWrite('modifyPerson')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" v-if="false" >
					<el-form-item label="修改时间" prop="modifyTime">
						<el-input v-model="dataForm.modifyTime" placeholder="系统自动生成" readonly :disabled="JudgeWrite('modifyTime')" >
						</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:'',
					reimbursement:undefined,
					handler:undefined,
					state:"1",
					proId:undefined,
					happedTime:undefined,
					totalAmount:0,
					remark:undefined,
					appendix:[],
					zyOaWfFinrmbtDetailsList:[],
					createTime:undefined,
					modifyPerson:undefined,
					modifyTime:undefined,
				},
				rules: {
					state:[
						{
							required:true,
							message:'请输入是否关联项目',
							trigger:'change'
						},
					],
					proId:[
						{
							required:true,
							message:'请输入关联项目',
							trigger:'change'
						},
					],
					happedTime:[
						{
							required:true,
							message:'请输入发生时间',
							trigger:'change'
						},
					],
					totalAmount:[
						{
							required:true,
							message:'请输入报销总额',
							trigger:["blur","change"]
						},
					],
					remark:[
						{
							required:true,
							message:'请输入报销事由',
							trigger:'blur'
						},
					],
				},
				stateOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"0"}],
				proIdOptions : [],
				costTypeOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getproIdOptions();
			this.getcostTypeOptions();
		},
		mounted() {},
		methods: {
			getproIdOptions(){
				previewDataInterface('210191934059185413').then(res => {
					this.proIdOptions = res.data
				});
			},
			getcostTypeOptions(){
				getDictionaryDataSelector('3e2d33e54d554b4b8a33fc41b93f8a2d').then(res => {
					this.costTypeOptions = 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/system/ZyOaWfFinrmbt/' + 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/system/ZyOaWfFinrmbt',
						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/system/ZyOaWfFinrmbt/' + 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
			},
			addHandleZyOaWfFinrmbtDetailsEntityList() {
				let item = {
					costType:undefined,
					costItem:undefined,
					costAmount:0.00,
					remarks:undefined,
				}
				this.dataForm.zyOaWfFinrmbtDetailsList.push(item)
			},
			handleDelZyOaWfFinrmbtDetailsEntityList(index) {
				this.dataForm.zyOaWfFinrmbtDetailsList.splice(index, 1);
			},
		}
	}
</script>

