<template>
  <view class="showModel">
		<view class="showModel__wrap">
			<view class="content" v-if="speDATA && speDATA.data">
				<view class="content-box">
					<view class="icon">
						<text class="red newicon newicon-guanbi1"></text>
						<!-- <text class="error-text">提示</text> -->
					</view>
					<view class="list weight red">{{speDATA.msg}}</view>
					<view class="list flex">
						<view>条码：<text class="mar-rig" :class="speDATA.data.urgent==0?'green':'red'">{{speDATA.data.urgent==0?'普':'急'}}</text> {{speDATA.data.scode}}</view>
						<view>{{speDATA.data.speState ? speDATA.data.speState.name : ''}}</view>
					</view>
					<view class="list">检查项目：{{ speDATA.data.specimenDesc || "-" }}</view>
					<view class="list">类型：{{speDATA.data.stype ? speDATA.data.stype.name : ''}} <text v-if="speDATA.data.tubeType">、</text> {{speDATA.data.tubeType && speDATA.data.tubeType.name || ''}}</view>
					<view class="list">患者：{{ speDATA.data.patientName}} <text v-if="speDATA.data.bedNum">（{{speDATA.data.bedNum}}）</text></view>
					<view class="list">{{speDATA.data.sickRoom.dept}}
					<text style="width: 4em;text-align: center;margin-left: 1em;margin-right: 1em;" class="newicon newicon-arrow-right-full"></text>
					{{speDATA.data.checkDept.dept}}</view>
					<view class="list" v-if="speDATA.speVerifyType=='collectDept'
					|| speDATA.speVerifyType=='testDept' || speDATA.speVerifyType=='tubeType'
					|| speDATA.speVerifyType=='urgent'">
						<checkbox-group @change="forceDeptInputBlur">
						  <checkbox value="addConfig" :checked="addConfig" color="#49b856" />{{msg}}
						</checkbox-group>
					</view>
				</view>
			</view>
			<view class="foot_btn_spe">
			  <view class="btn green" @click="confirm()">是</view>
			  <view class="btn gray" @click="cancel()">否</view>
			</view>
		</view>
  </view>
</template>

<script>
import {
    get,
    post,
    SM
  } from "../../http/http.js";
export default {
  data() {
    return {
      addConfig:false,
			msg:null,
			// 终点科室标红
			isEndDeptRed: false,
			currentCode: '', //当前小扫描的科室二维码
			deptId: undefined,
			handover: undefined,
			SMFlag: true,
			// 交接人信息
			accountObj: undefined,
			// 完成扫描的id
			wcId: "",
			wcFlag: false,
			// 弹窗model
			models: {
			  disjunctor: false,
			},
			// 单选框弹窗model1
			models1: {
			  disjunctor: false,
			},
			// 完成扫描弹窗model1
			models2: {
			  disjunctor: false,
			},
			infoDATA: {},
			res: {},
			infoType: "",
			DEPTCode: "",
			RESData: {},
			DEPT: "",
			dataId: "",
			type: "",
			model: {},
			speNum: 0,
			queryObj: {}, //路由传递过来的数据
			selectRadio: [], //单选框选中的数据，第一项是qrcode，第二项是名称
			gotoFlag: true,
			content: "",
			taskTypeId:"",
			errorModal:null,
			speDATA:null,
			interceptData:null,
			intercept:null,
    };
  },
	onLoad(options){
		console.log(77776666,options)
		this.intercept = options.intercept
		this.queryObj = options;
		if (options.model) {
		  this.infoDATA = JSON.parse(options.model);
			this.speDATA = JSON.parse(options.model);
		}
		
		if (options.accountObj && options.accountObj != "undefined") {
		  this.accountObj = JSON.parse(options.accountObj);
		}
		if (options.deptId && options.deptId != "undefined") {
		  this.deptId = options.deptId;
		}
		if (options.handover && options.handover != "undefined") {
		  this.handover = options.handover;
		}
		this.dataId = options.id;
		if(options.taskTypeId){
			this.taskTypeId = options.taskTypeId
		}else if(this.infoDATA.workOrderList && this.infoDATA.workOrderList.length>0){
			this.taskTypeId = this.infoDATA.workOrderList[0].taskType.id
		}
		this.RESData = options.resData;
		this.res["status"] = options.status;
		this.res["msg"] = options.msg;
		this.res["patient"] = options.patient;
		this.res["patientCode"] = options.patientCode;
		this.res["deptName"] = options.deptName;
		this.res["bedNum"] = options.bedNum;
		this.infoType = options.type1;
	
		if (options.dept) {
		  this.DEPT = options.dept;
		}
		if (options.speNum) {
		  this.speNum = options.speNum;
		}
		this.DEPTCode = options.deptCode;
		this.type = options.type;
		this.setMsg()
	},
  methods: {
		setMsg(){
			if(this.speDATA.speVerifyType=='collectDept'){
				this.msg = '增加收取科室'
			}else if(this.speDATA.speVerifyType=='testDept'){
				this.msg = '收取本科室不在提示'
			}else if(this.speDATA.speVerifyType=='tubeType'){
				this.msg = '收取此试管类型不在提示'
			}else if(this.speDATA.speVerifyType=='urgent'){
				this.msg = '记录本次操作，不在提示'
			}
		},
		forceDeptInputBlur(e){
			this.addConfig = e.detail.value.length > 0
		},
    confirm(){
			if(this.speDATA.speVerifyType!='collectDept'
			&& this.speDATA.speVerifyType!='testDept' && this.speDATA.speVerifyType!='tubeType'
			&& this.speDATA.speVerifyType!='urgent'){
				this.addConfig = true
			}
			let data = {
				code: this.speDATA.data.scode,
				addConfig: this.addConfig
			}
			this.interceptData = data
			this.hand_scanning_common(this.interceptData.code, 'scan')
    },
		// 手动输入标本和扫码公共方法
		hand_scanning_common(ress1, type) {
		  // ----------------
		  uni.showLoading({
		    title: "加载中",
		    mask: true,
		  });
		  //检验二维码的有效性
		  post("/dept/scanning", {
		    content: ress1,
		  }).then((result) => {
		    this.SMFlag = true;
		    this.currentCode = result.code;
		    if (result.state == 200 || result.state == 201) {
		      let codes = result.code;
		      if (codes) {
		        let speCode = codes;
		        let data = {
		          code: speCode,
		          type: this.queryObj.type1,
		          deptCode: this.DEPTCode,
		          ids: [],
							speVerifyType:null,
							addConfig:null
		        };
						if(this.speDATA){
							data.speVerifyType = this.speDATA.speVerifyType
						}else{
							delete data.speVerifyType
						}
						if(this.interceptData && this.interceptData.addConfig){
							data.addConfig = 1
						}else{
							delete data.addConfig
						}
		        data.ids.push(this.dataId);
		        let postType = "";
		        if (this.type == "jPBag" || this.type == "drugsBag") {
		          postType = "handleDrugsAndJp";
		          if(this.type == "drugsBag"){
		            delete data.ids;
		          }
		          data.deptId = this.deptId;
		          data.handover = this.handover;
		        }
		        if (this.type == "specimen") {
		          data["speCode"] = data.code;
		          delete data.code;
		          postType = "handleSpes";
		        }
		        if (this.type == "specimenPlan") {
		          data["speCode"] = data.code;
		          delete data.code;
		          postType = "handlePlanSpes";
		        }
		        if (this.type == "inspect") {
		          postType = "handleIns";
		        }
		        if (this.type == "patientTransport") {
		          postType = "handleTrans";
		        }
		        post("/workerOrder/" + postType, data).then((ress) => {
		          uni.hideLoading();
							this.speDATA = null
							this.interceptData = null
		          if (ress.status == 200 || ress.status == 11111) {
		            //标本和标本轮巡工单，扫描标本后会自动调用摄像头，继续扫描，直到status不是200
		            if ((this.type == "specimenPlan" || this.type == "specimen") && ress.status != 11111) {
									if(ress){
										this.infoDATA = ress.data;
										this.speNum = ress.specimenCount;
										uni.redirectTo({
											url: `../scanning_Result/scanning_Result?type=${
											this.queryObj.type
										}&type1=${
											this.queryObj.type1
										}&infoData=${encodeURIComponent(
											JSON.stringify(ress.data)
										)}&status=${ress.status}&msg=${ress.msg}&deptCode=${
											this.queryObj.deptCode
										}&dept=${this.queryObj.dept}&id=${this.dataId}&model=${encodeURIComponent(JSON.stringify(ress))}&speNum=${this.speNum}&scanOrHand=scan&isEndDeptRed=${this.isEndDeptRed}`,
										});
									}
		            }
		          } else if (ress.status==513){
								this.speDATA = ress
								this.setMsg()
							} else if(ress.status==10004){
		            uni.showToast({
		              icon: "none",
		              title: ress.msg,
		            });
		          }else{
								uni.redirectTo({
								  url: `../scanning_Result/scanning_Result?type=${
								  this.queryObj.type
								}&type1=${this.queryObj.type1}&status=${ress.status}&msg=${
								  ress.msg
								}&deptCode=${this.queryObj.deptCode}&dept=${
								  this.queryObj.dept
								}&id=${this.dataId}&model=${encodeURIComponent(
								  JSON.stringify(this.infoDATA)
								)}&accountObj=${encodeURIComponent(JSON.stringify(this.accountObj))}&deptId=${this.deptId}&handover=${this.handover}&scanOrHand=scan&qrcode=${this.currentCode}`,
								});
							}
		        });
		      } else {
		        uni.hideLoading();
		      }
		    } else {
		      uni.hideLoading();
		      uni.showToast({
		        icon: "none",
		        title: result.info || "接口获取数据失败！",
		      });
		    }
		  });
		},
    cancel(){
			uni.navigateBack();
    },
  },
};
</script>

<style lang="less" scoped>
.showModel {
  // position: fixed;
  // left: 0;
  // right: 0;
  // top: 0;
  // bottom: 0;
  // background-color: rgba(0, 0, 0, 0.2);
  // z-index: 99;

  .showModel__wrap {
    // width: 90%;
    // position: absolute;
    // left: 50%;
    // top: 50%;
    // transform: translate(-50%, -50%);
    background-color: #fff;
    // border-radius: 12rpx;
		height: 100vh;
    .showModel__header {
      font-size: 36rpx;
      color: #000;
			font-weight: bold;
      height: 84rpx;
      display: flex;
      justify-content: center;
      align-items: center;
    }
		.content{
			background: #fff;
			border-top: 1px solid #E6E6E6;
			.content-tip{
				text-align: center;
				padding: 50rpx 0 30rpx 0;
				font-size: 28rpx;
			}
			.content-box{
				padding: 24rpx;
				height: 83vh;
				
				.icon{
					display: flex;
					justify-content: center;
					align-items: center;
					.red{
						font-size: 80rpx;
					}
					.error-text{
						margin-left: 30rpx;
						font-size: 40rpx;
					}
				}
				
				.flex{
					display: flex;
					justify-content: space-between;
				}
				
				.weight{
					font-weight: bold;
					text-align: center;
					font-size: 38rpx;
				}
				
				.list{
					padding: 20rpx 0;
				}
				
				.content-item{
					width: 80rpx;
					height: 80rpx;
					border-radius: 10rpx;
					border: 1px solid #CCCCCC;
					color: #000;
					font-size: 32rpx;
					// margin: 0 20rpx;
					text-align: center;
				}
			}
		}
		.foot_btn_spe {
			padding: 24rpx;
		  line-height: 88rpx;
		  height: 100rpx;
		  text-align: center;
		  display: flex;
		  justify-content: space-between;
		  flex-wrap: wrap;
			
		  view {
		    height: 88rpx;
		    width: 48%;
		    color: #fff;
		    border-radius: 8rpx;
		    font-size: 32rpx;
		    margin-top: 16rpx;
		  }
			
			.green{
				background-image: linear-gradient(to right, #72c172, #3bb197);
				color: #fff !important;
			}
			
			.gray{
				background: #afafaf;
				color: #fff;
			}
		}
  }
	.green{
		color: #49B856;
	}
	.mar-rig{
		margin-right: 8rpx;
	}
}
</style>
