<template>
	<view class="qualitycontrolTask">
		<!-- 飞行质控任务 -->
		<view class="flightTask">
			<uni-card>
				<uni-section title="飞行质控任务" type="line">
					<template v-slot:right>
						<image style="width: 50rpx; height: 50rpx;" :src="showIcon.nowIcon" @click="changeState()"></image>
					</template>
				</uni-section>
				<view class="flightTask_list">
					<view class="flightTask_title">
						<view class="flightTask_text">被质控代煎企业</view>
						<view class="flightTask_righttext">{{pageData.taskList.bzkOrgName}}</view>
					</view>
					<view class="flightTask_title">
						<view class="flightTask_text">组长</view>
						<view class="flightTask_righttext">{{pageData.taskList.zzName}}</view>
					</view>
					<view class="flightTask_title">
						<view class="flightTask_text">组员</view>
						<view class="flightTask_righttext">{{pageData.taskList.zyNames}}</view>
					</view>
					<view class="flightTask_title">
						<view class="flightTask_text">地址</view>
						<view class="flightTask_righttext">{{pageData.taskList.address}}</view>
					</view>
					<view class="flightTask_title">
						<view class="flightTask_text">总数量:</view>
						<view class="flightTask_righttext">{{pageData.taskList.totalCyCount+'/'+pageData.taskList.totalWcCount}}</view>
					</view>
					<view class="flightTask_title">
						<view class="flightTask_text">代煎完成数量:</view>
						<view class="flightTask_righttext">{{pageData.taskList.djCyCount+'/'+pageData.taskList.djWcCount}}</view>
					</view>
					<view class="flightTask_title">
						<view class="flightTask_text">代配完成数量:</view>
						<view class="flightTask_righttext">{{pageData.taskList.dpCyCount+'/'+pageData.taskList.dpWcCount}}</view>
					</view>
					<view class="flightTask_title">
						<view class="flightTask_text">7贴完成数量:</view>
						<view class="flightTask_righttext">{{pageData.taskList.t7CyCount+'/'+pageData.taskList.t7WcCount}}</view>
					</view>
					<view class="flightTask_title">
						<view class="flightTask_text">14贴完成数量:</view>
						<view class="flightTask_righttext">{{pageData.taskList.t14CyCount+'/'+pageData.taskList.t14WcCount}}</view>
					</view>
				</view>
			</uni-card>
		</view>
		<!-- 代配作业质控 -->
		<view class="dp_or_dj_Task">
			<uni-card>
				<uni-section title="待配作业质控" type="line">
					<template v-slot:right>
						<view class="sub_title">不合格数<view class="sub_title_text">{{pageData.detailList.dpbhg}}</view></view>
					</template>
				</uni-section>
				<view class="sub_head">
					<view class="sub_head_title">代配7贴：<view class="sub_title_text">{{pageData.detailList.dp7twc+"/"+pageData.detailList.dp7t}}</view></view>
					<view class="sub_head_title">代配14贴：<view class="sub_title_text">{{pageData.detailList.dp14twc+"/"+pageData.detailList.dp14t}}</view></view>
				</view>
				<view>
					<button class="button" @click="addTask('dp')"> + 新增</button>
				</view>
				<uni-table class="dp_table">
					<!-- 表头行 -->
					<uni-tr>
						<uni-th align="center" width="150rpx">处方编号</uni-th>
						<uni-th align="center" width="150rpx">贴数(贴)</uni-th>
						<uni-th align="center" width="150rpx">平均误差(%)</uni-th>
						<uni-th align="center" width="150rpx">创建人</uni-th>
					</uni-tr>
					<!-- 表格数据行 -->
					<uni-tr v-for="(item, index) in pageData.dpList" :key="index">
						<uni-td align="center">{{item.cfbh}}</uni-td>
						<uni-td align="center">{{item.ts}}</uni-td>
						<uni-td align="center">{{item.bhgx}}</uni-td>
						<uni-td align="center">{{item.creatorName}}</uni-td>
					</uni-tr>
				</uni-table>
				<view class="see_more" @click="seeMore('dp')">
					<text>查看更多</text>
					<uni-icons type="right"></uni-icons>
				</view>
			</uni-card>
		</view>
		<!-- 代煎作业质控 -->
		<view class="dp_or_dj_Task">
			<uni-card>
				<uni-section title="待煎作业质控" type="line">
					<template v-slot:right>
						<view class="sub_title">不合格数<view class="sub_title_text">{{pageData.detailList.djbhg}}</view></view>
					</template>
				</uni-section>
				<view class="sub_head">
					<view class="sub_head_title">代煎7贴：<view class="sub_title_text">{{pageData.detailList.dj7twc+"/"+pageData.detailList.dj7t}}</view></view>
					<view class="sub_head_title">代煎14贴：<view class="sub_title_text">{{pageData.detailList.dj14twc+"/"+pageData.detailList.dj14t}}</view></view>
				</view>
				<view>
					<button class="button" @click="addTask('dj')"> + 新增</button>
				</view>
				<uni-table class="dp_table">
					<!-- 表头行 -->
					<uni-tr>
						<uni-th align="center" width="150rpx">处方编号</uni-th>
						<uni-th align="center" width="150rpx">贴数(贴)</uni-th>
						<uni-th align="center" width="150rpx">不合格项</uni-th>
						<uni-th align="center" width="150rpx">创建人</uni-th>
					</uni-tr>
					<!-- 表格数据行 -->
					<uni-tr v-for="(item, index) in pageData.djList" :key="index">
						<uni-td align="center">{{item.cfbh}}</uni-td>
						<uni-td align="center">{{item.ts}}</uni-td>
						<uni-td align="center">{{item.bhgx}}</uni-td>
						<uni-td align="center">{{item.creatorName}}</uni-td>
					</uni-tr>
				</uni-table>
				<view class="see_more" @click="seeMore('dj')">
					<text>查看更多</text>
					<uni-icons type="right"></uni-icons>
				</view>
			</uni-card>
		</view>
		<!-- 代煎企业作业环境质控 -->
		<view class="djqyhj_Task">
			<uni-card>
				<uni-section title="代煎企业作业环境质控" type="line">
					<template v-slot:right>
						<view class="sub_title">不合格数<view class="sub_title_text">{{pageData.detailList.djqyzkbhg}}</view></view>
					</template>
				</uni-section>
				<view class="image_upload">
					<uni-file-picker limit="4" :v-model="pageData.imageList" @select="selectImg" @delete="deleteImg"></uni-file-picker>
				</view>
			</uni-card>
		</view>
		<!-- 完成质控 -->
		<view class="finish_button">
			<button class="button" @click="finishTask()">完成质控</button>
		</view>
	</view>
</template>

<script setup>
import { reactive } from "vue";
import {onLoad,onShow,onUnload,onPullDownRefresh} from "@dcloudio/uni-app";
import http from '@/utils/request';

const pageData=reactive({
	detailList:{},
	// 质控任务
	taskList:{},
	// 代配
	dpList:{},
	// 代煎
	djList:{},
	// 图片列表
	imageList:[],
	// 质控状态
	taskStatus:''
})

const showIcon=reactive({
	nowIcon:'',
	showIcon:'/static/blackDisplay.png',
	hideIcon:'/static/blackHide.png'
})

const findZkzyData=reactive({
	id:'1661969828969525249'
})

// 切换显示状态
const changeState=()=>{
	if(showIcon.nowIcon==showIcon.showIcon){
		showIcon.nowIcon=showIcon.hideIcon
	}else{
		showIcon.nowIcon=showIcon.showIcon
	}
}

// 新增代配/代煎质控
const addTask=(type)=>{
	if(type=='dp'){
		// 新增代配
		console.log("新增代配")
		pageData.taskStatus='dp'
	}else if(type=='dj'){
		// 新增代煎
		console.log("新增代煎")
		pageData.taskStatus='dj'
	}
	uni.navigateTo({
		url:'/pages/ypczk/zkTask/choosePrescription?taskStatus='+pageData.taskStatus
	})
}

// 查看更多
const seeMore =(type)=>{
	if(type=='dp'){
		// 代配跳转
		console.log("代配跳转")
	}else if(type=='dj'){
		// 代煎跳转
		console.log("代煎跳转")
	}
	uni.navigateTo({
		url:'/pages/ypczk/zkTask/zkTaskDetail/detailsList'
	})
}

// 选中图片，将选中的图片添加列表
const selectImg=(e)=>{
	console.log(e)
	e.tempFiles.forEach(item=>{
		pageData.imageList.push(item)
	})
}

// 删除图片，并将其从列表中删除
const deleteImg=(e)=>{
	console.log(e)
	let index=0
	index = pageData.imageList.indexOf(e.tempFilePaths)
	pageData.imageList.splice(index, 1)
}

// 完成质控
const finishTask=()=>{
	console.log("完成质控")
}

// 查询质控作业--根据Id
const getZkData=()=>{
	http.get("app-api/zkzy/findZkzyById",findZkzyData).then(res=>{
		console.log(res)
		pageData.detailList=res
		pageData.taskList=res.task
		pageData.djList=res.djCfDetail
		pageData.dpList=res.dpCfDetail
		// 获取图片
		if(pageData.detailList.imgUrl!=null){
			pageData.imageList=pageData.detailList.imgUrl
		}
	})
}

// 存入taskData(taskId)
const setTaskId=()=>{
	uni.setStorageSync("saveTaskId",{taskId:findZkzyData.id})
}

onLoad((data)=>{
	if(data!=null){
		findZkzyData.id=data.taskId
	}
	setTaskId()
})

onShow(()=>{
	showIcon.nowIcon=showIcon.hideIcon
	getZkData()
})
</script>

<style lang="scss" scoped>
@import './index.scss'
</style>