﻿<template>
	<transition name="el-zoom-in-center">
		<div class="NCC-preview-main">
			<div class="NCC-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="medium" label-width="115px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="24" >
						<el-form-item label="流水编号" prop="spare1">
							<el-input v-model="dataForm.spare1" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="费用归口" prop="proName">
							<el-select v-model="dataForm.proName" placeholder="请选择" clearable required :style='{"width":"100%"}' filterable >
								<el-option v-for="(item, index) in proNameOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="发生时间" prop="happenDate">
							<el-date-picker v-model="dataForm.happenDate" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="费用类型" prop="finType">
							<el-select v-model="dataForm.finType" placeholder="请选择" clearable required :style='{"width":"100%"}' >
								<el-option v-for="(item, index) in finTypeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="总额" prop="bankAmount">
							<el-input-number v-model="dataForm.bankAmount" placeholder="数字文本" :precision="2" required :step="1" >
							</el-input-number>元
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="入账金额" prop="inAmount">
							<el-input-number v-model="dataForm.inAmount" placeholder="数字文本" :precision="2" required :step="100" >
							</el-input-number>元
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="出账金额" prop="outAmount">
							<el-input-number v-model="dataForm.outAmount" placeholder="数字文本" :precision="2" required :step="100" >
							</el-input-number>元
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="经办人" prop="desPerson">
							<user-select v-model="dataForm.desPerson" placeholder="请选择" required >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="协办成员" prop="desPersonName">
							<user-select v-model="dataForm.desPersonName" placeholder="请选择" required multiple >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="费用事由" prop="reason">
							<el-input v-model="dataForm.reason" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="备注" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建人" prop="creater">
							<el-input v-model="dataForm.creater" placeholder="系统自动生成" readonly >
							</el-input>
						</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 >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="最后修改人" prop="modifyer">
							<el-input v-model="dataForm.modifyer" placeholder="系统自动生成" readonly >
							</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 >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					spare1:undefined,
					proName:undefined,
					happenDate:undefined,
					finType:undefined,
					bankAmount:0,
					inAmount:0,
					outAmount:0,
					desPerson:undefined,
					desPersonName:undefined,
					reason:undefined,
					remark:undefined,
					creater:undefined,
					createTime:undefined,
					modifyer:undefined,
					modifyTime:undefined,
				},
				rules: {
					proName:[
						{
							required:true,
							message:'请输入费用归口',
							trigger:'change'
						},
					],
					happenDate:[
						{
							required:true,
							message:'请输入发生时间',
							trigger:'change'
						},
					],
					finType:[
						{
							required:true,
							message:'请输入费用类型',
							trigger:'change'
						},
					],
					bankAmount:[
						{
							required:true,
							message:'请输入总额(元)',
							trigger:["blur","change"]
						},
					],
					inAmount:[
						{
							required:true,
							message:'请输入入账金额(元)',
							trigger:["blur","change"]
						},
					],
					outAmount:[
						{
							required:true,
							message:'请输入出账金额(元)',
							trigger:["blur","change"]
						},
					],
					desPerson:[
						{
							required:true,
							message:'请输入经办人',
							trigger:'change'
						},
					],
					desPersonName:[
						{
							required:true,
							message:'请输入协办成员',
							trigger:'change'
						},
					],
					reason:[
						{
							required:true,
							message:'请输入费用事由',
							trigger:'blur'
						},
					],
				},
				proNameOptions : [],
				finTypeOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getproNameOptions();
			this.getfinTypeOptions();
		},
		mounted() {
        },
		methods: {
			getproNameOptions(){
				previewDataInterface('210191934059185413').then(res => {
					this.proNameOptions = res.data
				});
			},
			getfinTypeOptions(){
				getDictionaryDataSelector('193257366517449989').then(res => {
					this.finTypeOptions = res.data.list
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
                   this.$refs['elForm'].resetFields();
                   if (this.dataForm.id) {
                    if (this.dataForm.id==-1) {
                        request({
                        url: '/api/SubDev/ZyOaFinwater/Actions/BankAmount',
                        method: 'get'
                     }).then(res =>{
                       this.dataForm.bankAmount = res.data.balanceAmount;
                    })
                 }else{
                       request({
                       url: '/api/SubDev/ZyOaFinwater/' + this.dataForm.id,
                       method: 'get'
                    }).then(res =>{
                       this.dataForm = res.data;
                   })
                 }
		       }
             })
          },
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id||this.dataForm.id==-1) {
                            request({
                                url: `/api/SubDev/ZyOaFinwater`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/SubDev/ZyOaFinwater/' + 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('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>
