<template>
	<view>
		<scroll-view scroll-y="true" class="detail_top" :style="datailData.status == 0 ? 'height:68vh;' : 'height:90vh;'"  v-if="datailData != null">
			<view class="detail_topbox">
				<view class="detail_topbox_1">
					<text v-if="datailData.purpose==1">教学借单</text>
					<text v-else-if="datailData.purpose==0">科研借单</text>
					<text
						style="background-color: #d9ecff;margin: 0rpx 10rpx;padding: 4rpx 10rpx; color: #007cff; font-size: 23rpx; ">借单号：{{datailData.encoding}}</text>
					<block>
						<text class="detail_zt">{{status[datailData.status]}}</text>
					</block>
				</view>
				<view class="detail_topbox_2">
					<view class="">
						<text class="detail_tou">借取人:</text><text style="width: 30%;"
							class="detail_tou2">{{datailData.username}}</text>
						<block v-if="datailData.status==0|| datailData.status==1">
							<view class="detail_tou">仪器总数:</view>{{yiqisum}}{{'&nbsp;'}}
						</block>
						<block v-else>
							<view class="detail_tou">仪器总数:</view>{{datailData.asset.length}}{{'&nbsp;'}}
						</block>
					</view>
					<uv-line></uv-line>
					<view class="" v-if="datailData.purpose==0">
						<view class="detail_tou">项目编号:</view>{{datailData.project_number}}{{'&nbsp;'}}
					</view>
					<uv-line v-if="datailData.purpose==0"></uv-line>
					<view class="">
						<view class="detail_tou">申请时间:</view>{{datailData.create_time}}{{'&nbsp;'}}
					</view>
					<uv-line></uv-line>
					<uni-collapse accordion v-model="accordionVal" @change="change">
						<block v-if="datailData.borrow_reason!=null">
							<uni-collapse-item
								:title="'借取用途：&nbsp;&nbsp;&nbsp;' +datailData.borrow_reason.slice(0, 13)+'.....'"
								v-if="datailData.borrow_reason.length > 13 ">
								<view class="content">
									<text class="text">{{datailData.borrow_reason}}</text>
								</view>
							</uni-collapse-item>
							<block v-else>
								<view class="">
									<view class="detail_tou">借取用途:</view>{{datailData.borrow_reason}}{{'&nbsp;'}}
								</view>
								<uv-line></uv-line>
							</block> 
						</block>
						<block v-if="datailData.remarks!=null">
							<uni-collapse-item :title="'借取人备注：&nbsp;&nbsp;&nbsp;'+ datailData.remarks.slice(0, 13)+'.....'"
								v-if="datailData.remarks.length > 13">
								<view class="content">
									<text class="text">{{datailData.remarks}}{{'&nbsp;'}}</text>
								</view>
							</uni-collapse-item>
							<block v-else>
								<view class="">
									<view class="detail_tou">借取人备注:</view>

								</view>
								<uv-line></uv-line>
							</block>
						</block>
						<view class="" v-if="datailData.status !== 0">
							<view class="detail_tou">实验室审批人:</view>{{datailData.approval_person}}{{'&nbsp;'}}
						</view>
						<view class="" v-else>
							<view class="detail_tou">仪器管理员:</view>{{datailData.approval_person}}{{'&nbsp;'}}
						</view>
						<uv-line></uv-line>
						
						<view class="" v-if="datailData.purpose == 0 ">
							<view class="detail_tou">学院审批人:</view>{{datailData.college_leader}}{{'&nbsp;'}}
						</view>
						<uv-line></uv-line>
						
						<block v-if="datailData.annotation!=null">

							<uni-collapse-item
								:title="'批注：&nbsp;&nbsp;&nbsp;'+ datailData.annotation.slice(0, 13)+'.....'"
								v-if="datailData.annotation.length > 13">
								<view class="content">
									<text class="text">{{datailData.annotation}}{{'&nbsp;'}}</text>
								</view>
							</uni-collapse-item>
							<block v-else>
								<view class="">
									<view class="detail_tou">批注:</view>{{datailData.annotation}}{{'&nbsp;'}}
								</view>
							</block>
						</block>
						
						<view class="" v-if="datailData.status == 0">
							<view class="detail_tou">电子签名:</view>
							<view class="" style="float: left;">
								<image style="width: 200px; height: 200px; background-color: #eeeeee;" :src="'https://yxy.glut.cc/' + datailData.usersign"></image>
							</view>
						</view>
						<uv-line></uv-line>
					</uni-collapse>

					<view style="margin-top: 20rpx;" v-if="userInfo.userInfo.group == 1|| userInfo.userInfo.group == 2">
						<view class="detail_tou" style="color: #2d8cf0;font-weight: bold;">留存拍照</view>
						<view class="" style="float: left;">
							<uv-upload :fileList="fileList1" name="1" multiple :maxCount="3" @afterRead="afterRead"
								@delete="deletePic"></uv-upload>
						</view>
					</view>
		
					
				</view>
			</view>

			<view class="biaoge_box">
			<view style="background-color: #f4f5f9; width: 100%;height: 20rpx;">

			</view>
				<block v-if="datailData.status==0|| datailData.status==1 ||datailData.status==6 ||datailData.status==7">
					<uni-table border stripe emptyText="暂无更多数据">
						<!-- 表头行 -->
						<uni-tr>
							<uni-th align="left" width=180>仪器名称</uni-th>
							<uni-th align="left" width=100>数量</uni-th>
						</uni-tr>
						<!-- 表格数据行 -->
						<uni-tr v-for="(item, index) in datailData.asset" :key="index">
							<uni-td>{{item.model}}</uni-td>
							<uni-td>{{item.num}}</uni-td>
						</uni-tr>
					</uni-table>
				</block>
				<block v-else>
					<view class="unfold" v-if="unfold!='true'">
						<image @click="unfold='true'" src="../../static/img/unfold.png" mode="widthFix"
							style="width: 35rpx;"></image>
					</view>
					<uni-table border stripe emptyText="暂无更多数据">
						<!-- 表头行 -->
						<uni-tr>
							<uni-th align="left" width=70>状态</uni-th>
							<uni-th align="left" width=130>仪器名称</uni-th>
							<uni-th align="left" width=100>仪器编号</uni-th>
							<block v-if="datailData.purpose==1">
								<uni-th align="left" width=70>借取人</uni-th>
							</block>
							<block v-if="unfold">
								<uni-th align="left" width=100>借出处理人</uni-th>
								<uni-th align="left" width=100>归还处理人</uni-th>
								<uni-th align="left" width=160>领取时间</uni-th>
								<uni-th align="left" width=160>归还时间</uni-th>
							</block>
						</uni-tr>
						<!-- 表格数据行 -->
						<uni-tr v-for="(item, index) in datailData.asset" :key="index">
							<uni-td>
								<text class="uni_zt" v-if="item.status==-1">待借出</text>
								<text style="color: #2d8cf0;" class="uni_zt" v-else-if="item.status==0">使用中</text>
								<text class="uni_zt" v-else-if="item.status==1">损坏</text>
								<text style="color: #19be6b;" class="uni_zt" v-else-if="item.status==2">归还</text>
								<text style="color: #808695;" class="uni_zt" v-else-if="item.status==3">已替换</text>
							</uni-td>
							<uni-td>{{item.asset_name}}</uni-td>
							<uni-td>{{item.asset_id}}</uni-td>
							<block v-if="datailData.purpose==1">
								<uni-td>{{item.student_name}}</uni-td>
							</block>
							<block v-if="unfold">
								<uni-td>{{item.lend_processor}}</uni-td>
								<uni-td>{{item.restitution_processor}}</uni-td>
								<uni-td>{{item.collection_time}}</uni-td>
								<uni-td>{{item.restitution_time}}</uni-td>
							</block>
						</uni-tr>
						<!-- 占位 -->
						<view class="" style="height: 200rpx; width: 100%;">
						</view>
					</uni-table>
				</block>
				
				<block>
					<uni-table border stripe emptyText="暂无更多数据" >
						<block v-if="datailData?.accessories != null">
							<!-- 表头行 -->
							<uni-tr>
								<uni-th align="left" width=180>配件名称</uni-th>
								<uni-th align="left" width=100>数量</uni-th>
							</uni-tr>
							<!-- 表格数据行 -->
							<uni-tr v-if="datailData.accessories?.w_battery !== null && datailData.accessories?.w_battery !== 0">
								<uni-td>无人机电池</uni-td>
								<uni-td>{{ datailData.accessories.w_battery }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.w_remote_control !== null &&datailData.accessories?.w_remote_control !== 0"> 
								<uni-td>无人机遥控器</uni-td>
								<uni-td>{{ datailData.accessories.w_remote_control }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.w_remote_control_battery !== null &&datailData.accessories?.w_remote_control_battery !== 0">
								<uni-td>无人机遥控器电池</uni-td>
								<uni-td>{{ datailData.accessories.w_remote_control_battery }}</uni-td>
							</uni-tr>	 
							<uni-tr v-if="datailData.accessories?.w_charge_housekeeper !== null &&datailData.accessories?.w_charge_housekeeper !== 0">
								<uni-td>无人机充电管家</uni-td>
								<uni-td>{{ datailData.accessories.w_charge_housekeeper }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.w_propeller !== null &&datailData.accessories?.w_propeller !== 0">
								<uni-td>螺旋桨</uni-td>
								<uni-td>{{ datailData.accessories.w_propeller }}</uni-td>
							</uni-tr>	  
							<uni-tr v-if="datailData.accessories?.w_sd !== null &&datailData.accessories?.w_sd !== 0">
								<uni-td>SD卡</uni-td>
								<uni-td>{{ datailData.accessories.w_sd }}</uni-td>
							</uni-tr>	 	 
									 
							<uni-tr v-if="datailData.accessories?.q_battery !== null &&datailData.accessories?.q_battery !== 0">
								<uni-td>全站仪主机电池</uni-td>
								<uni-td>{{ datailData.accessories.q_battery }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.q_charge_housekeeper !== null &&datailData.accessories?.q_charge_housekeeper !== 0"> 
								<uni-td>全站仪主机充电器</uni-td>
								<uni-td>{{ datailData.accessories.q_charge_housekeeper }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.q_tripod !== null &&datailData.accessories?.q_tripod !== 0">
								<uni-td>全站仪三脚架</uni-td>
								<uni-td>{{ datailData.accessories.q_tripod }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.q_prism !== null &&datailData.accessories?.q_prism !== 0">
								<uni-td>全站仪棱镜</uni-td>
								<uni-td>{{ datailData.accessories.q_prism }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.q_center_bar !== null &&datailData.accessories?.q_center_bar !== 0">
								<uni-td>对中杆</uni-td>
								<uni-td>{{ datailData.accessories.q_center_bar }}</uni-td>
							</uni-tr>	  
							<uni-tr v-if="datailData.accessories?.q_data_line !== null &&datailData.accessories?.q_data_line !== 0">
								<uni-td>数据线</uni-td>
								<uni-td>{{ datailData.accessories.q_data_line }}</uni-td>
							</uni-tr>	 	 
						
							<uni-tr v-if="datailData.accessories?.s_battery !== null &&datailData.accessories?.s_battery !== 0">
								<uni-td>水准仪主机电池</uni-td>
								<uni-td>{{ datailData.accessories.s_battery }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.s_charge_housekeeper !== null &&datailData.accessories?.s_charge_housekeeper !== 0"> 
								<uni-td>水准仪充电器</uni-td>
								<uni-td>{{ datailData.accessories.s_charge_housekeeper }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.s_tripod !== null &&datailData.accessories?.s_tripod !== 0">
								<uni-td>水准仪三脚架</uni-td>
								<uni-td>{{ datailData.accessories.s_tripod }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.s_level_gauge !== null &&datailData.accessories?.s_level_gauge !== 0">
								<uni-td>水准尺</uni-td>
								<uni-td>{{ datailData.accessories.s_level_gauge }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.s_ruler_pad !== null &&datailData.accessories?.s_ruler_pad !== 0">
								<uni-td>水准尺尺垫</uni-td>
								<uni-td>{{ datailData.accessories.s_ruler_pad }}</uni-td>
							</uni-tr>	  
							<uni-tr v-if="datailData.accessories?.s_data_line !== null &&datailData.accessories?.s_data_line !== 0">
								<uni-td>水准仪电源线</uni-td>
								<uni-td>{{ datailData.accessories.s_data_line }}</uni-td>
							</uni-tr>		
							<uni-tr v-if="datailData.accessories?.s_adjustment_wrench !== null &&datailData.accessories?.s_adjustment_wrench !== 0">
								<uni-td>水准仪调节扳手</uni-td>
								<uni-td>{{ datailData.accessories.s_adjustment_wrench }}</uni-td>
							</uni-tr>	
							<uni-tr v-if="datailData.accessories?.s_rain_proof_cloth !== null &&datailData.accessories?.s_rain_proof_cloth !== 0">
								<uni-td>防雨布</uni-td>
								<uni-td>{{ datailData.accessories.s_rain_proof_cloth }}</uni-td>
							</uni-tr>	 
								 
							
								 
							<uni-tr v-if="datailData.accessories?.r_battery !== null &&datailData.accessories?.r_battery !== 0">
								<uni-td>RTK主机电池</uni-td>
								<uni-td>{{ datailData.accessories.r_battery }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.r_charge_housekeeper !== null &&datailData.accessories?.r_charge_housekeeper !== 0"> 
								<uni-td>RTK充电器</uni-td>
								<uni-td>{{ datailData.accessories.r_charge_housekeeper }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.r_charging_head !== null &&datailData.accessories?.r_charging_head !== 0">
								<uni-td>手簿</uni-td>
								<uni-td>{{ datailData.accessories.r_charging_head }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.r_hand_book_holder !== null &&datailData.accessories?.r_hand_book_holder !== 0">
								<uni-td>手簿夹</uni-td>
								<uni-td>{{ datailData.accessories.r_hand_book_holder }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.r_hand_book_pen !== null &&datailData.accessories?.r_hand_book_pen !== 0">
								<uni-td>手簿笔</uni-td>
								<uni-td>{{ datailData.accessories.r_hand_book_pen }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.r_charging_head !== null &&datailData.accessories?.r_charging_head !== 0">
								<uni-td>手簿充电头</uni-td>
								<uni-td>{{ datailData.accessories.r_charging_head }}</uni-td>
							</uni-tr>
							<uni-tr v-if="datailData.accessories?.r_flashlight !== null &&datailData.accessories?.r_flashlight !== 0">
								<uni-td>手电</uni-td>
								<uni-td>{{ datailData.accessories.r_flashlight }}</uni-td>
							</uni-tr>	  
							<uni-tr v-if="datailData.accessories?.r_connection_head !== null &&datailData.accessories?.r_connection_head !== 0">
								<uni-td>连接头</uni-td>
								<uni-td>{{ datailData.accessories.r_connection_head }}</uni-td>
							</uni-tr>		
							<uni-tr v-if="datailData.accessories?.r_height_measuring_plate !== null &&datailData.accessories?.r_height_measuring_plate !== 0">
								<uni-td>测高片</uni-td>
								<uni-td>{{ datailData.accessories.r_height_measuring_plate }}</uni-td>
							</uni-tr>	
							<uni-tr v-if="datailData.accessories?.r_long_antenna !== null &&datailData.accessories?.r_long_antenna !== 0">
								<uni-td>长天线</uni-td>
								<uni-td>{{ datailData.accessories.r_long_antenna }}</uni-td>
							</uni-tr>	   
							<uni-tr v-if="datailData.accessories?.r_short_antenna !== null &&datailData.accessories?.r_short_antenna !== 0">
								<uni-td>短天线</uni-td>
								<uni-td>{{ datailData.accessories.r_short_antenna }}</uni-td>
							</uni-tr>	   
							<uni-tr v-if="datailData.accessories?.r_instruction_manual !== null &&datailData.accessories?.r_instruction_manual !== 0">
								<uni-td>说明书</uni-td>
								<uni-td>{{ datailData.accessories.r_instruction_manual }}</uni-td>
							</uni-tr>	   
							<uni-tr v-if="datailData.accessories?.r_cdrow !== null &&datailData.accessories?.r_cdrow !== 0">
								<uni-td>光盘</uni-td>
								<uni-td>{{ datailData.accessories.r_cdrow }}</uni-td>
							</uni-tr>	   
							<uni-tr v-if="datailData.accessories?.r_usb !== null &&datailData.accessories?.r_usb !== 0">
								<uni-td>USB线</uni-td>
								<uni-td>{{ datailData.accessories.r_usb }}</uni-td>
							</uni-tr>	   
						</block>
					</uni-table>
				</block>
			
			</view>
			<view style="width: 10vw;height: 10vh;">

			</view>

		</scroll-view>
	</view>
	<view class="detail_bottom" v-if="userInfo.userInfo.group != 4">
		<block>
			<view class="detail_topbox">
				<!-- 待审批状态 -->
				<block
					v-if="(datailData.status==0 && userInfo.userInfo.group!=3)||(datailData.status==6 && userInfo.userInfo.group==3)">
					<view class="">
						<view class="detail_topbox_1">
							<text>审批</text>
						</view>
						<view class="">
							<uni-forms ref="baseForm" :modelValue="baseFormData">
								<uni-forms-item label="批注">
									<uni-easyinput v-model="remark" type="textarea" placeholder="请输入驳回理由" />
								</uni-forms-item>

							</uni-forms>
							<view class="button-group">
								<button @click="overrule" type="warn" style="background-color: #ff9900;">驳回</button>
								<button @click="pass" type="primary" style="background-color: #2d8cf0;">审批通过</button>
							</view>
						</view>
					</view>
				</block>


				<!-- 待使用 -->
				<view class="" v-if="userInfo.userInfo.group != 3">
					<view class="" v-if="datailData.status==2 ">
						<!-- 						<view class="detail_topbox_1">
							<text>操作</text>
						</view> -->
						<view class="jiechu">
							<!-- 科研借单 -->
							<button v-if="datailData.purpose==0" @click="jiechuscan" type="primary"
								style="background-color: #2d8cf0; margin-bottom: 20rpx;">借出扫码</button>
							<!-- 教学借单 -->
							<block v-else-if="datailData.purpose==1">
								<button @click="jiechuscan2" type="primary"
									style="background-color: #2d8cf0; margin-bottom: 20rpx;">扫仪器借出</button>
								<view style="color: #808695;">
									提示：教学借单需先扫一台仪器，再扫一次学生
								</view>
							</block>

						</view>
					</view>
					<!-- 借出状态 -->
					<view class="" v-else-if="datailData.status==3 || datailData.status==5">
						<view class="jiechu">
							<view class="button-group">
								<button @click="replaceScan" type="primary"
									style="background-color: #19be6b;width: 50%;border-radius: 5px 0 0 5px; ">替换扫码</button>
								<button type="warn" @click="damageScan"
									style="background-color: #ff9900;width: 50%;border-radius: 0px 5px 5px 0px; ">损坏扫码</button>
							</view>

							<button v-if="datailData.purpose==0" @click="returnScan" type="primary"
								style="background-color: #2d8cf0; ">归还扫码</button>
							<button v-else-if="datailData.purpose==1" @click="returnScan2" type="primary"
								style="background-color: #2d8cf0; ">归还扫码</button>
						</view>
					</view>

				</view>
			</view>
		</block>
	</view>
	<view class="">
		<uni-popup ref="popup" type="bottom">
			<view class="tihuan_box">
				<view class="" style="text-align: center; margin-bottom: 20rpx; font-size: 35rpx; font-weight: bold;">
					仪器替换理由
				</view>
				<uni-forms-item label="备注">
					<uni-easyinput type="textarea" v-model="replaceNote" placeholder="请输入备注" />
				</uni-forms-item>
				<button @click="replaceReturnScan" type="primary"
					style="background-color: #2d8cf0; margin-bottom: 30rpx;">归还</button>
				<button @click="replaceDamageScan" type="primary" style="background-color: #ff9900; ">损坏</button>
			</view>
		</uni-popup>
		<uni-popup ref="stupopup" type="bottom">
			<view class="tihuan_box" style="height: 200rpx;">
				<view class=""
					style="text-align: center; margin-bottom: 20rpx; font-size: 35rpx; font-weight: bold;margin-bottom: 30rpx;">
					请扫学生码
				</view>
				<button @click="stuScan" type="primary"
					style="background-color: #2d8cf0; margin-bottom: 30rpx;">扫学生码</button>
			</view>
		</uni-popup>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad,
		uploadFile
	} from '@dcloudio/uni-app'
	import {
		requestApi
	} from '@/api/request.js'

	// 重要路径修改
	const baseUrl = 'https://yxy.glut.cc/'

	let unfold = ref(false)
	let data_scan = ref(null)
	let data_scan2 = ref(null)
	let stu_scan = ref(null)
	let return_data = ref(null)
	let return_data2 = ref(null)
	let damage_data = ref(null)
	let replace_data = ref(null)
	const status = ref(['待审批', '已驳回', '待使用', '使用中', '已归还', '已逾期', '领导审批中', '领导驳回'])
	const remark = ref(null)
	var analyze = ref(null)
	// var datailData = ref(null)
	let userInfo = wx.getStorageSync('userInfos')
	const yiqisum = ref(null)
	const xiangqinData = ref(null)
	const popup = ref(null); //替换弹窗
	const stupopup = ref(null);
	const replaceNote = ref(null)
	let replaceReturn_data = ref(null)

	// 存储图片
	const fileList1 = ref([

		])
			

	let datailData = ref({
	  accessories: {
		w_battery: 0,
		w_remote_control: 0,
		w_remote_control_battery: 0,
		w_charge_housekeeper: 0,
		w_propeller: 0,
		w_sd: 0,
		q_battery: 0,
		q_charge_housekeeper: 0,
		q_tripod: 0,
		q_prism: 0,
		q_center_bar: 0,
		q_data_line: 0,
		s_battery: 0,
		s_charge_housekeeper: 0,
		s_tripod: 0,
		s_level_gauge: 0,
		s_ruler_pad: 0,
		s_data_line: 0,
		s_adjustment_wrench: 0,
		s_rain_proof_cloth: 0,
		r_battery: 0,
		r_charge_housekeeper: 0,
		r_charging_head: 0,
		r_hand_book_holder: 0,
		r_hand_book_pen: 0,
		r_flashlight: 0,
		r_connection_head: 0,
		r_height_measuring_plate: 0,
		r_long_antenna: 0,
		r_short_antenna: 0,
		r_instruction_manual: 0,
		r_cdrow: 0,
		r_usb: 0
	  }
	});
	// 数据
	onLoad(async (event) => {
		wx.showLoading({
			title: '加载中',
			mask: false,
		})
		// console.log(event)
		analyze = JSON.parse(event.data)
		// console.log(analyze)

		xiangqinData.value = await requestApi('admin/borrow.BorrowApp/edit?id=' +
			analyze + '&server=1')
		datailData.value = xiangqinData.value.data.row
		 
		wx.hideLoading()
		const updatedArray = datailData.value.sign.map(item => ({
			...item,
			url: `${baseUrl}${item.url}`,
			url2: `${item.url}`,
		}));
		console.log('f', updatedArray)

		fileList1.value.push(...updatedArray);
		console.log('r', fileList1.value)

		const price = ref(datailData.value.asset)
		yiqisum.value = price.value.reduce((sum, e) => sum + Number(e.num || 0), 0)
		// console.log(yiqisum.value)
	})

	// 审批通过
	async function pass() {
		if (userInfo.userInfo.group != 3 && datailData.value.purpose == 0) {
			datailData.value.status = 6
		} else {
			datailData.value.status = 2
		}

		datailData.value.annotation = remark.value
		console.log(datailData.value)
		wx.showToast({
			title: '审批完成',
			icon: 'success',
			// duration: 2000
		})
		const passData = await requestApi(
			'admin/borrow.BorrowApp/edit?server=1', {
				data: datailData.value
			},
			'POST'
		)
		wx.hideLoading()
		jiazhai()
		console.log(xiangqinData.value)
		wx.hideLoading()


	}

	// 审批驳回
	async function overrule() {
		if (userInfo.userInfo.group != 3) {
			datailData.value.status = 1
		} else {
			datailData.value.status = 7
		}
		datailData.value.annotation = remark.value
		console.log('datailData.value', datailData.value)
		wx.showLoading({
			title: '加载中',
		})
		const overruleData = await requestApi(
			'admin/borrow.BorrowApp/edit?server=1', {
				data: datailData.value
			},
			'POST'
		)
		console.log('overruleData', overruleData)
		jiazhai()
		if (overruleData.code == 0) {
			wx.showModal({
				title: '提示',
				content: overruleData.msg,
				showCancel: false
			})
		}

		
		console.log('data', xiangqinData.value)
		setTimeout(function() {
			wx.hideLoading()
		}, 1000)
	}

	// 科研借出扫码
	function jiechuscan() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {
				// console.log(res)
				wx.showLoading({
					title: '加载中',
				})
				data_scan.value = res
				console.log(data_scan.value.result)
				const keyanBorrow = await requestApi(
					'admin/borrow.BorrowUseing/scientificBind?server=1&asset_id=' + data_scan.value
					.result + '&borrow_id=' + datailData.value.id + '&server=1',
				)
				console.log('keyanBorrow', keyanBorrow)

				jiazhai()
				wx.showToast({
					title: keyanBorrow.msg,
					icon:'none',
					duration: 1000
				})
				console.log('科研借出', xiangqinData.value)
			}
		})

	}
	// 科研归还扫码
	function returnScan() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {
				// console.log(res)
				wx.showLoading({
					title: '加载中',
				})
				return_data.value = res
				console.log(return_data.value.result)
				const returndata = await requestApi(
					'admin/borrow.BorrowUseing/scientificComplete?server=1&asset_id=' + return_data.value
					.result+ '&borrow_id=' + datailData.value.id,
				)
				console.log(returndata)
				jiazhai()

				wx.showToast({
					title: returndata.msg,
					icon:'none',
					duration: 1000
				})
				console.log('科研借出', xiangqinData.value)
				wx.hideLoading()
			}
		})
	}

	// 损坏扫码
	function damageScan() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {
				// console.log(res)
				wx.showLoading({
					title: '加载中',
				})
				damage_data.value = res
				console.log(damage_data.value.result)

				const damagedata = await requestApi(
					'admin/borrow.BorrowUseing/assetDamage?server=1&asset_id=' + damage_data.value.result+ '&borrow_id=' + datailData.value.id,
				)
				console.log(damagedata)

				jiazhai()
				wx.showToast({
					title: damagedata.msg,
					icon:'none',
					duration: 1000
				})
				console.log('科研借出', xiangqinData.value)
				wx.hideLoading()
			}
		})
	}

	// 替换扫码
	function replaceScan() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {
				// console.log(res)
				replace_data.value = res
				console.log(replace_data.value.result)
				popup.value.open('top');

			}
		})
	}
	// 替换里的归还扫码
	function replaceReturnScan() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {
				// console.log(res)
				replaceReturn_data.value = res
				console.log(replaceReturn_data.value.result)
				const replacedata = await requestApi(
					'admin/borrow.BorrowUseing/assetChange?server=1&old_asset_id=' + replace_data.value
					.result + '&new_asset_id=' + replaceReturn_data.value.result + '&borrow_id=' +
					datailData.value.id + '&isDamage=' + 0
				)
				console.log(replacedata)
				popup.value.close('top');
				jiazhai()
				console.log(xiangqinData.value)

				wx.showToast({
					title: replacedata.msg,
					icon:'none',
					duration: 1000
				})
				setTimeout(function() {
					wx.hideLoading()
				}, 1500)
			}
		})
	}

	// 替换里的损坏扫码
	function replaceDamageScan() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {

				// console.log(res)
				replaceReturn_data.value = res
				console.log(replaceReturn_data.value.result)
				const replacedata = await requestApi(
					'admin/borrow.BorrowUseing/assetChange?server=1&old_asset_id=' + replace_data.value
					.result + '&new_asset_id=' + replaceReturn_data.value.result + '&borrow_id=' +
					datailData.value.id + '&isDamage=' + 1
				)
				console.log(replacedata)
				popup.value.close('top');
				xiangqinData.value = await requestApi('admin/borrow.BorrowApplication/edit?id=' +
					analyze + '&server=1')
				datailData.value = xiangqinData.value.data.row
				jiazhai()
				console.log(xiangqinData.value)
				wx.showToast({
					title: replacedata.msg,
					icon:'none',
					duration: 1000
				})
				setTimeout(function() {
					wx.hideLoading()
				}, 1500)
			}
		})
	}

	// 教学借出扫码
	function jiechuscan2() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {
				// console.log(res)
				data_scan2.value = res
				console.log(data_scan2.value.result)
				stupopup.value.open('top');
				// console.log(event)
				// console.log(analyze)

			}
		})
	}
	// 教学借单扫学生
	async function stuScan() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {
				wx.showLoading({
					title: '加载中',
				})
				// console.log(res)
				stu_scan.value = res
				console.log(stu_scan.value.result)
				stupopup.value.open('top');
				const keyanBorrow2 = await requestApi(
					'admin/borrow.BorrowUseing/courseBind?server=1&asset_id=' + data_scan2.value
					.result + '&borrow_id=' + datailData.value.id + '&student_phone=' + stu_scan.value
					.result + '&server=1',
				)
				console.log(keyanBorrow2)
				stupopup.value.close('top');
				
				wx.showLoading({
					title: keyanBorrow2.msg,
					mask: false,
				})
				jiazhai()
				setTimeout(function() {
					wx.hideLoading()
				}, 1500)

			}
		})
	}

	// 教学归还扫码
	function returnScan2() {
		wx.scanCode({
			// 只允许相机
			// onlyFromCamera: true,
			async success(res) {
				// console.log(res)
				return_data2.value = res
				console.log(return_data2.value.result)
				const returndata = await requestApi(
					'admin/borrow.BorrowUseing/courseComplete?server=1&asset_id=' + return_data2.value
					.result + '&borrow_id=' + datailData.value.id,
				)
				console.log(returndata)
				jiazhai()
			}
		})
	}

	// 删除图片的函数
	const deletePic = async (event) => {
		wx.showLoading({
			title: '加载中',
			mask: false,
		})
		// TODO: 如果需要，这里先发送删除请求到后端，确保文件从服务器上也被删除
		console.log('e', fileList1.value[event.index].url2)
		const returndata = await requestApi(
			'admin/borrow.BorrowUseing/delImg?server=1', {
				borrow_id: datailData.value.id,
				url: fileList1.value[event.index].url2,
			},
			'POST'
		)
		console.log(returndata)

		wx.showToast({
			title: returndata.msg,
			icon: 'none',
			duration: 2000
		})
		fileList1.value.splice(event.index, 1);
	};

	const afterRead = async (event) => {
		let lists = [].concat(event.file);
		let fileListLen = fileList1.value.length
		lists.forEach((item, index) => {
			fileList1.value.push({
				...item,
				status: 'uploading',
				message: '上传中'
			});
			uploadFilePromise(item.url).then(result => {
				console.log('www', result)
				fileList1.value[fileList1.value.length - lists.length + index] = {
					...item,
					status: 'success',
					message: '',
					url: baseUrl + result, // 假设result就是图片的URL
					url2: result
				};
				fileListLen++
			}).catch(error => {
				fileList1.value[fileList1.value.length - lists.length + index] = {
					...item,
					status: 'fail',
					message: '上传失败',
				};
				console.error('上传失败:', error);
			});
		});
	};


	function encryptToken() {
		const a = wx.getStorageSync('userInfos')
		let userInfo;
		if (a === '' || a === null || a === undefined || !"userInfo" in a) {
			return '';
		} else {
			userInfo = a.userInfo;
		}
		console.log(userInfo)
		if (userInfo === '' || userInfo === null || userInfo === undefined || !"token" in userInfo) {
			return '';
		} else {
			// const auth = Base64.encode(user_Token + ':')
			const Batoken = userInfo.token
			return Batoken
		}
	}
	const uploadFilePromise = (filePath) => {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				header: {
					Batoken: encryptToken()
				},
				url: baseUrl + 'admin/ajax/upload?server=1',
				filePath: filePath,
				name: 'file',
				formData: {
					user: 'test'
				},
				success: (res) => {
					setTimeout(() => {
						// console.log(res)
						var responseObject = JSON.parse(res.data);
						// console.log(responseObject)
						var fileUrl = responseObject.data.file.url;
						// 传图片接口
						const returndata = requestApi(
							'admin/borrow.BorrowUseing/uniUpload?server=1', {
								borrow_id: datailData.value.id,
								url: fileUrl
							},
							'POST'
						)
						console.log(returndata)
						console.log(fileUrl, 123)
						console.log('w', fileList1.value)
						resolve(fileUrl);
					}, 1000);
				},
				fail: (err) => {
					reject(err);
				}
			});
		});
	};
	async function jiazhai(){
		xiangqinData.value = await requestApi('admin/borrow.BorrowApp/edit?id=' +
			analyze + '&server=1')
		datailData.value = xiangqinData.value.data.row
		console.log('我更新了')
	}
	// console.log(data_scan.value)
</script>

<style lang="less">
	page {
		background-color: rgb(244, 245, 249);
	}

	.zp-swiper-super.data-v-bd8ff6a5 {
		background-color: rgb(244, 245, 249);
	}

	.detail_bottom {
		background-color: #fff;
		width: 100%;
	}

	.uni-table-td {
		padding: 10rpx 20rpx !important;
	}

	.detail_top {
		
		background-color: #fff;
	}

	.detail_tou2 {
		float: left;
	}

	.detail_bottom {
		margin-top: 25rpx;
		position: fixed;
		bottom: 0;
		padding-bottom: 20rpx;
	}

	.uni-collapse-item__title-box {
		padding: 0 !important;
		line-height: 80rpx !important;
		height: 80rpx !important;
		font-size: 32rpx !important;
	}

	.detail_topbox {
		padding: 5rpx 25rpx 0 25rpx;

	}

	.detail_topbox_21 {
		height: 55rpx;
	}

	.detail_zt {
		float: right;
		color: #F89898;
	}

	.detail_topbox_1 {
		font-size: 38rpx;
		margin-bottom: 20rpx;
	}

	.uni-table-scroll {
		width: 99.5% !important;
		overflow-x: auto;
	}

	.tihuan_box {
		width: 84%;
		height: 500rpx;
		padding: 30rpx;
		background-color: #fff;
		margin: 30% auto;
		border-radius: 20rpx;
	}

	.unfold {
		position: relative;
		z-index: 999;
		top: 30rpx;
		left: 94%;
		width: 35rpx;
		height: 0px;
	}

	.detail_topbox_2 {
		line-height: 80rpx;
		color: #464749;
		font-size: 32rpx;
	}

	.uni-collapse-item__title-text {
		font-size: 32rpx !important;
	}


	.detail_topbox_2>view {
		width: 100%;
		// height: 50rpx;
	}

	.detail_tou {
		width: 29%;
		float: left;
	}

	.button-group {
		margin-top: 20rpx;
		display: flex;
		justify-content: space-around;
		margin-bottom: 20rpx;
	}

	.uni_zt {
		color: #F89898;
	}

	.biaoge_box {
		width: 100%;
		overflow-y: auto
	}

	.uni-table {
		position: none;
	}

	.jiechu {
		margin: 40rpx 0 30rpx 0;
	}
</style>