<!-- 离职申请 -->
<template>
	<view class="container">
		<scroll-view scroll-y style="padding-bottom: 180rpx;background-color: #fff;">
			<uni-forms v-model="form" label-width="180rpx"  ref="customForm" :rules="customRules">
				<ticketd :ticket_="form.ticket_"></ticketd>
				<uni-forms-item label="姓名">
					<uni-easyinput v-model="form.employee_name" placeholder="请输入姓名" :disabled="true"/>
				</uni-forms-item>
				<uni-forms-item label="部门">
					<uni-easyinput v-model="form.belong_dept_name" placeholder="请输入岗位" :disabled="true"/>
				</uni-forms-item>
				<uni-forms-item label="岗位">
					<uni-easyinput v-model="form.post_name" placeholder="请输入岗位" :disabled="true"/>
				</uni-forms-item>
				<uni-forms-item label="离职时间" required>
					<uni-datetime-picker type="date" :clear-icon="false" v-model="form.end_date" v-if="mode!='show'"/>
					<span v-else>{{form.end_date}}</span>
				</uni-forms-item>
				<uni-forms-item label="离职原因：" label-width="750" required>
				</uni-forms-item>
				<uni-forms-item label-width="100">
					<textarea placeholder-style="color:#efefef" v-model="form.reason"  placeholder="离职原因" style="width:100%; border: 2upx solid #e5e5e5;padding: 10upx;"/>
				</uni-forms-item>
				<uni-forms-item label="办理离职交接日期" required v-if="form.ticket_&&form.ticket_.state_">
					<uni-datetime-picker type="date" :clear-icon="false" v-model="ticket_data.handle_date" v-if="form.ticket_?.state_?.name=='部门负责人'"/>
					<span v-else>{{form.ticket_.ticket_data.handle_date}}</span>
				</uni-forms-item>
			</uni-forms>
		</scroll-view>
		<view class="footer_fixed">
			<button v-if="mode=='edit'" size="mini" @click="handleDel" :loading="saveLoading" :disabled="saveloading" type="warn">
				删除
			</button>
			<ticketd_b v-if="form.ticket_" :t_id="form.id" :ticket_="form.ticket_" 
			:ticket_data="ticket_data" @success="submitSuccess" ref="ticketd_b"></ticketd_b>
			<button v-else size="mini" @click="handleSave" :loading="saveLoading" :disabled="saveloading" type="primary">
				提交审批
			</button>
		</view>
	</view>
</template>

<script>
import ticketd_b from "../wf/ticketd_b.vue"
import ticketd from "../wf/ticketd.vue"
import {actStateEnum} from "@/utils/enum.js"
	export default {
		components: { ticketd_b, ticketd },
		data(){
			return{
				saveloading: false,
				mode:"show",
				t_id: null,
				form:{
					reason:"",
					employee:"",
					end_date:"",
				},
				ticket_data:{
					handle_date:""
				},
				userInfo:{},
				type:0,
				hobby: [
					{text: '省级平台',value: '省级平台'},
					{text: '市级平台',value: '市级平台'},
				],
				header:"",
				customRules: {
					filename: {
						rules: [{
							required: true,
							errorMessage: '姓名不能为空'
						}]
					},
					age: {
						rules: [{
							required: true,
							errorMessage: '年龄不能为空'
						}]
					},
				},
			}
		},
		async onLoad(options) {
			let that = this;
			that.mode = options.mode?options.mode:'show';
			that.t_id = options.t_id?options.t_id:null;
			if(that.t_id) {
					that.form = await that.$api.resignationItem(that.t_id);
					if(that.form.ticket_.state_.type == 1 && that.form.create_by == uni.getStorageSync("userInfo").id ) {
						that.mode = "edit";
					}else{
						that.mode = "show";
					}
				}
			else{
				that.getEmployee();
			}
		},
		methods:{
			async getEmployee(){
				let res = await this.$api.employeeInfo();
				this.form.employee_name = res.name;
				this.form.belong_dept_name = res.belong_dept_name;
				this.form.post_name = res.post_name;
				this.form.employee = res.id;
				this.mode = "add";
			},
			async handleDel(){
				let that = this;
				await that.$api.resignationDelete(that.form.id)
				uni.navigateBack()
			},
			async handleSave(){
				let that = this;
				that.$refs.customForm.validate().then(res => {
					
				}).catch(err => {
					console.log('err', err);
				})
				await that.$api.resignationCreate(that.form)
				uni.navigateBack()
			},
			submitSuccess(){
				uni.navigateBack()
			},
		}
	}
</script>

<style scoped>
	.uni-data-checklist .checklist-group .checklist-box{
		margin: 10px 0!important;
	}
	.flex_file_picker>.uni-file-picker__files{
		flex-direction: row;
	}
	.flex_file_picker{
		width: 90px;
		flex: none;
	}
</style>