<!-- 离职申请 -->
<template>
	<view class="container" style="height: 1400upx">
		<scroll-view scroll-y style="padding-bottom: 180rpx;background-color: #fff;height: 60%;">
			<uni-forms v-model="form" label-width="140upx"  ref="customForm" style="height: 60%;">
				<ticketd :ticket_="form.ticket_"></ticketd>
				<uni-forms-item label="创建时间" required v-if="mode!== 'add'">
					<span>{{form.create_time}}</span>
				</uni-forms-item>
				<uni-forms-item label="维修设备" required>
					<searchSelect 
					v-model="form.equipment" 
					:apiobjs="apiobj" 
					v-if="mode== 'add'"/>
					<span v-else>{{form.equipment_fullname}}</span>
				</uni-forms-item>
				<uni-forms-item label="故障描述" required>
					<textarea placeholder-style="color:#efefef" v-model="form.fault_description"  placeholder="故障描述" v-if="mode!='show'" style="width:100%; border: 2upx solid #e5e5e5;padding: 10upx;"/>
					<span v-else>{{form.fault_description}}</span>			
				</uni-forms-item>
				<uni-forms-item label="故障类别" required v-if="mode!== 'add'">
					<uni-data-select
					  v-if="form.ticket && form.ticket_.state_.name == '条保负责人分派'" 
					  v-model="ticket_data.fault_cate"
					  :localdata="cateList"
					  :disabled="mode=='show'" 
					></uni-data-select>
					<span v-else>{{form.fault_cate}}</span>
				</uni-forms-item>
				<uni-forms-item label="维修人" required v-if="mode!== 'add'">
					<searchSelect v-model="ticket_data.repair_user" :apiobjs="userApiobj" v-if="form.ticket && form.ticket_.state_.name == '条保负责人分派'"/>
					<span v-else>{{form.repair_user_name}}</span>
				</uni-forms-item>
				<uni-forms-item label="维修开始时间" required v-if="mode!== 'add'">
					<uni-datetime-picker v-model="ticket_data.repair_start_time" type="date" v-if="form.ticket && form.ticket_.state_.name == '维修人员处理'" :clear-icon="false"/>
					<span v-else>{{form.repair_start_time}}</span>
				</uni-forms-item>
				<uni-forms-item label="维修工时" required v-if="mode!== 'add'">
					<uni-number-box v-model="ticket_data.repair_duration"  v-if="form.ticket && form.ticket_.state_.name == '维修人员处理'"></uni-number-box>
					<span v-else>{{form.repair_duration}}</span>
				</uni-forms-item>
				<uni-forms-item label="维修描述" required v-if="mode!== 'add'">
					<textarea v-model="ticket_data.repair_description"  placeholder="故障描述"  placeholder-style="color:#efefef" v-if="form.ticket && form.ticket_.state_.name == '维修人员处理'" style="width:100%; border: 2upx solid #e5e5e5;padding: 10upx;"/>
					<span v-else>{{form.repair_description}}</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>
			<button v-if="mode!='show'" size="mini" @click="handleSave" :loading="saveLoading" :disabled="saveLoading" type="primary">
				提交审批
			</button>
			<ticketd_b v-if="form.ticket_ && mode == 'show'" :t_id="form.id" :ticket_="form.ticket_" 
			:ticket_data="ticket_data" @success="()=>{uni.navigateBack()}" ref="ticketd_b"></ticketd_b>
		</view>
	</view>
</template>

<script>
import ticketd_b from "../wf/ticketd_b.vue"
import ticketd from "../wf/ticketd.vue"
import searchSelect from "@/components/searchselect.vue"
export default {
	components: { ticketd_b, ticketd, searchSelect },
	data(){
		return{
			mode:"show",
			t_id: null,
			form:{
				equipment:"",
				fault_description:"",
			},
			apiobj:this.$api.equipmentList,
			userApiobj:this.$api.userList,
			userInfo:{},
			ticket_data:{},
			cateList:[
				{text: '机械',value: '机械'},
				{text: '电气',value: '电气'},
			],
		}
	},
	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.$api.repairItem(that.t_id).then(res=>{
				that.form = res;
				if(that.form.ticket_.state_.type == 1 && that.form.create_by == uni.getStorageSync("userInfo").id ) {
					that.mode = "edit";
				}else{
					that.mode = "show";
				}
			})
		}
	},
	methods:{
		async handleDel(){
			let that = this;
			await that.$api.repairDelete(that.form.id)
			uni.navigateBack()
		},
		handleSave(){
			let that = this;
			that.$refs.customForm.validate().then(res => {
				that.$api.repairCreate(that.form).then(ress=>{
					uni.navigateBack()
				})
			}).catch(err => {
				console.log('err', err);
			})
		},
	}
}
</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>