<!-- 档案借阅 -->
<template>
	<view class="container">
		<scroll-view scroll-y style="padding-bottom: 180rpx;background-color: #fff;">
			<uni-forms v-model="form" label-width="170upx">
				<ticketd :ticket_="form.ticket_"></ticketd>
				<uni-forms-item label="档案名称" required>
					<uni-data-select
						v-if="mode!='show'"
						multiple 
						v-model="form.borrow_file"
						:localdata="fileList"
						:disabled="mode=='show'"
						@change="mdateChange" 
					></uni-data-select>
					<span v-else>
						<text v-for="(item,index) in form.file_name">{{item}}
							<span v-if="index<(form.file_name.length-1)">、</span>
						</text>
					</span>
				</uni-forms-item>
				<uni-forms-item label="申请人电话">
					<uni-easyinput v-model="form.contacts" v-if="mode!='show'"/>
					<span v-else>{{form.contacts}}</span>
				</uni-forms-item>
				<uni-forms-item label="借阅时间" required>
					<uni-datetime-picker type="date" v-if="mode!='show'" :clear-icon="false" v-model="form.borrow_date"/>
					<span v-else>{{form.borrow_date}}</span>
				</uni-forms-item>
				<uni-forms-item label="借阅数量" required>
					<uni-number-box v-model="form.count"  v-if="mode!='show'"></uni-number-box>
					<span v-else>{{form.count}}</span>
				</uni-forms-item>
				<uni-forms-item label="用途">
					<uni-data-checkbox multiple v-model="form.remark" :localdata="hobby" :disabled="mode=='show'"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="归还时间" required  v-if="form.ticket_?.state_">
					<uni-datetime-picker type="date" v-if="form.ticket_?.state_?.name=='档案管理员审批'" :clear-icon="false" v-model="ticket_data.return_date"/>
					<span v-else>{{form.ticket_.ticket_data.return_date}}</span>
				</uni-forms-item>
			</uni-forms>
		</scroll-view>
		<view class="footer_fixed">
			<ticketd_b :workflow_key="'wf_borrowrecord'" title="档案借阅" :t_id="form.id" :ticket_="form.ticket_" :ticket_data="ticket_data"
				@success="submitSuccess" :submit_b_func="submit_b_func" ref="ticketd_b_start"></ticketd_b>
		</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{
				form:{
					id:null,
					borrow_file:"",
					contacts:"",
					borrow_date:"",
					remark:"",
					ticket_:null,
				},
				ticket_data:{
					return_date:""
				},
				hobby:[{
					text: '借阅',
					value: '借阅',
				}, {
					text: '复印',
					value: '复印',
				}, {
					text: '查阅',
					value: '查阅',
				}],
				fileList:[],
				vehicle_list:[],
			}
		},
		async onLoad(options) {
			let that = this;
			that.form.id='';
			that.mode = options.mode?options.mode:'show';
			that.t_id = options.t_id?options.t_id:null;
			if(that.mode != "add"){
				if(that.t_id) {
					that.form = await that.$api.borrowItem(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";
					}
				}
			}
		},
		mounted() {
			this.getfileList();
		},
		methods:{
			getfileList(){
				let that = this;
				let data = [];
				that.$api.fileRecord({page:0}).then(res=>{
					res.forEach(item=>{
						let obj = item;
						obj.text = item.name;
						obj.value = item.id;
						data.push(obj)
					})
					console.log(data)
					that.fileList = data;
				})
			},
			//选择会议室和日期后查询有无预定
			async submit_b_func(id){
				let that = this;
				if (that.mode != 'show') {
					if(that.form.id) {
						await that.$api.borrowUpdate(that.form.id, that.form);
					}else{
						let res = await that.$api.borrowCreate(that.form);
						that.form.id = res.id;
					}
				}
			},
			submitSuccess(){
				uni.navigateTo({
					url: "/pages/index/index"
				})
			},
		}
	}
</script>

<style scoped>
	
</style>