<!-- 上传整改 -->
<template>
	<view class="upload">
		<view class="upload_Info">
			<!-- 质控信息 -->
			<view class="cardInfo">
				<uni-card>
					<uni-section title="质控信息" type="line"></uni-section>
					<view class="list_content">
						<view class="list_item">质控名称</view>
						<view class="list_item_text">{{pageData.zkInfoList.taskName}}</view>
					</view>
					<view class="list_content">
						<view class="list_item">质控结果</view>
						<view class="list_item_text">{{pageData.zkInfoList.zkResult=='1'?'合格':'不合格'}}</view>
					</view>
					<view class="list_content">
						<view class="list_item">质控日期</view>
						<view class="list_item_text">{{pageData.zkInfoList.zkTime}}</view>
					</view>
				</uni-card>
			</view>
			<!-- 整改/改进信息 -->
			<view class="cardInfo">
				<uni-card>
					<uni-section title="整改/改进信息" type="line"></uni-section>
					<view class="list_content">
						<view class="list_item">类型</view>
						<view class="list_item_text">{{pageData.zgInfoList.type}}</view>
					</view>
					<view class="list_content">
						<view class="list_item">整改/改进截止日期</view>
						<view class="list_item_text">{{pageData.zgInfoList.endTime}}</view>
					</view>
					<view class="list_content">
						<view class="list_item">整改项数</view>
						<view class="list_item_text">{{pageData.zgInfoList.rectificationCount}}</view>
					</view>
					<view class="list_content">
						<view class="list_item">整改情况</view>
						<view class="list_item_text">{{"第"+pageData.zgInfoList.level+"次"}}</view>
					</view>
					<view class="list_content">
						<view class="list_item">整改/改进上传日期</view>
						<view class="list_item_text">{{pageData.zgInfoList.createTime}}</view>
					</view>
					<view class="list_content">
						<view class="list_item">整改/改进审核日期</view>
						<view class="list_item_text">{{pageData.zgInfoList.processTime!=null?pageData.zgInfoList.processTime:'--'}}</view>
					</view>
					<view class="list_content">
						<view class="list_item">整改/改进审核结果</view>
						<view class="list_item_text">{{pageData.zgInfoList.processResult!=null?pageData.zgInfoList.processResult:'--'}}</view>
					</view>
				</uni-card>
			</view>
			<!-- 整改/改进措施 -->
			<view class="measure_card">
				<uni-card padding="0" spacing="0">
					<uni-section title="整改/改进措施" type="line"></uni-section>
					<view v-for="(item,index) in pageData.zgMeasureList" class="measure_card_info">
						<ZgMeasureList :zgData="item" :disabled="pageData.disabled"></ZgMeasureList>
					</view>
				</uni-card>
			</view>
		</view>
		<!-- 整改/改进提交 -->
		<view class="upload_button" v-if="pageData.status!='2'">
			<button class="button" @click="finishTask()">整改/改进提交</button>
		</view>
	</view>
</template>

<script setup>
import { ref,reactive } from "vue";
import {onLoad,onShow,onUnload,onPullDownRefresh} from "@dcloudio/uni-app";
import http from '@/utils/request';
import {uploadImageModelValue} from '@/pages/controls/image/OssService';
import ZgMeasureList from './zgMeasureList.vue'

const pageData=reactive({
	id:'',
	// 整改状态
	status:'',
	// 质控信息
	zkInfoList:[],
	//  整改/改进信息
	zgInfoList:[],
	// 整改/改进措施
	zgMeasureList:[],
	// 图片列表
	imageList:[],
	disabled:false
})

const saveData=reactive({
	taskInfo:{},
	zgInfo:{},
	detail:[]
})

// 判断整改措施是否为空
const isEmptyMeasure=()=>{
	let isEmptyMeasure=false
	pageData.zgMeasureList.forEach(item=>{
		if(item.rectificationMeasure=='' || item.rectificationMeasure==null){
			return isEmptyMeasure=true
		}
	})
	return isEmptyMeasure
}


const finishTask=()=>{
	pageData.zgMeasureList.forEach(item=>{
		if(item.measureUrls!=null ||item.measureUrls!=undefined){
			item.measureUrls=item.measureUrls.toString()
		}
	})
	if(isEmptyMeasure()==false){
		saveData.taskInfo=pageData.zkInfoList
		saveData.zgInfo=pageData.zgInfoList
		saveData.detail=pageData.zgMeasureList
		uni.showLoading({
			title: '提交中.....',
			mask: true
		});
		http.post("app-api/rectify/save",saveData).then(res=>{
			uni.hideLoading()
			uni.navigateBack({
				delta: 1
			});
		})
	}else{
		uni.showToast({
			title: '请填写整改措施',
			icon: 'none'
		});
	}
}

// 显示图片
const showImage=(id)=>{
	return uploadImageModelValue(id)
}

// 获取整改数据
const getRectificationData=()=>{
	uni.showLoading({
		title: '',
		mask: true
	});
	http.get("app-api/rectify/getZgDetail",{id:pageData.id}).then(res=>{
		uni.hideLoading()
		console.log(res)
		pageData.zkInfoList=res.taskInfo
		pageData.zgInfoList=res.zgInfo
		pageData.zgMeasureList=res.detail
		res.detail.forEach(item=>{
			if(typeof(item.measureUrls)=='string'){
				var urls=item.measureUrls.split(",")
				item.measureUrls=[]
				urls.forEach(e=>{
					item.measureUrls.push(e)
				})
			}
		})
	})
}

onLoad((type)=>{
	if(type.id!=null){
		pageData.id=type.id
	}
	if(type.status!=null){
		pageData.status=type.status
		if(pageData.status=='2'){
			pageData.disabled=true
		}
	}
	getRectificationData()
})
</script>

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