<template>
  <view class="Scanning_djEnd">
    <view class="Scanning_top" v-if="infoDATA.status == 200">
      <view class="Scanning_top_icon">
        <text class="cubeic-ok icon_transport transport-duigou"></text>
      </view>
      <view class="Scanning_top_text">
        <view class="text1">操作成功</view>
      </view>
    </view>

    <view class="Scanning_top" v-if="
        infoDATA.status == 10005 ||
        infoDATA.status == 100018 ||
        infoDATA.status == 10004 ||
        infoDATA.status == 100021 ||
        infoDATA.status == 500 ||
        infoDATA.status == 100031
      ">
      <view class="Scanning_top_icon">
        <text class="cubeic-close icon_transport transport-shibai"></text>
      </view>
      <view class="Scanning_top_text">
        <view class="text1">操作失败</view>
        <view class="text1 f30" v-if="queryObj.qrcode !== undefined">扫描内容:{{queryObj.qrcode}}</view>
      </view>
    </view>

    <view class="Scanning_cont" v-if="
        (infoDATA.status == 200 && type == 'specimenPlan') ||
        (infoDATA.status == 200 && type == 'specimen')
      "></view>
    <view class="Scanning_cont" v-if="
        (infoDATA.status == 200 && type == 'patientTransport') ||
        (infoDATA.status == 200 && type == 'inspect')
      ">扫描患者腕带并将患者送往目标科室.</view>
    <view class="Scanning_cont" v-if="
        (infoDATA.status == 200 &&
          type == 'drugsBag' &&
          (type1 == 'drug-ddd-2' || type1 == 'drug-dsd-2')) ||
        (infoDATA.status == 200 &&
          type == 'jPBag' &&
          (type1 == 'jp-ddd-2' || type1 == 'jp-dsd-2'))
      ">已到达目标科室,请扫描药包或静配包.</view>
    <view class="Scanning_cont" v-if="
        (infoDATA.status == 200 &&
          type == 'drugsBag' &&
          (type1 == 'drug-ddd-1' || type1 == 'drug-dsd-1')) ||
        (infoDATA.status == 200 &&
          type == 'jPBag' &&
          (type1 == 'jp-ddd-1' || type1 == 'jp-dsd-1'))
      ">
      <view v-if="accountObj"> 交接人工号 : {{ accountObj.account }} </view>
      <view v-if="accountObj"> 交接人姓名 : {{ accountObj.accountName }} </view>
      <view>已到达目标科室,请取药包或静配包后送达目标科室.</view>
    </view>
    <view class="Scanning_cont" v-if="
        infoDATA.status == 200 && type == 'other' && infoDATA.type == 'qt-ddd-1'
      ">已到达目标科室,请执行该工单.</view>
    <view class="Scanning_cont" v-if="
        (infoDATA.state == 'finish' &&
          infoDATA.status == 200 &&
          type == 'specimenPlan' &&
          infoDATA.type == 'plan-spe-dsd-1') ||
        (infoDATA.status == 200 &&
          type == 'other' &&
          infoDATA.type == 'qt-dsd-1')
      ">已到达目标科室,工单已完成.</view>
    <view class="Scanning_cont" v-if="
        (infoDATA.status == 200 &&
          type == 'specimenPlan' &&
          infoDATA.type != 'plan-spe-ddd-1' &&
          infoDATA.type != 'plan-spe-dsd-1') ||
        (infoDATA.status == 200 &&
          type == 'specimen' &&
          infoDATA.type != 'spe-ddd-1' &&
          infoDATA.type != 'spe-dsd-1')
      ">已到达目标科室,请扫描标本.</view>
    <view class="Scanning_cont" v-if="
        (infoDATA.status == 200 &&
          type == 'specimenPlan' &&
          infoDATA.type == 'plan-spe-ddd-1') ||
        (infoDATA.status == 200 &&
          type == 'specimen' &&
          infoDATA.type == 'spe-ddd-1')
      ">
      <view v-if="accountObj"> 交接人工号 : {{ accountObj.account }} </view>
      <view v-if="accountObj"> 交接人姓名 : {{ accountObj.accountName }} </view>
      <view>已到达目标科室,请取标本后送达目标科室.</view>
    </view>
    <view class="Scanning_cont" v-if="
        (infoDATA.state != 'finish' &&
          infoDATA.status == 200 &&
          type == 'specimenPlan' &&
          infoDATA.type == 'plan-spe-dsd-1') ||
        (infoDATA.status == 200 &&
          type == 'specimen' &&
          infoDATA.type == 'spe-dsd-1')
      ">
      <view v-if="accountObj"> 交接人工号 : {{ accountObj.account }} </view>
      <view v-if="accountObj"> 交接人姓名 : {{ accountObj.accountName }} </view>
      <view>已到达目标科室,请放置标本完成该工单.</view>
    </view>
    <view class="Scanning_cont" v-if="infoDATA.status != 200">
      <view>{{ infoDATA.msg }}</view>
    </view>
    <view class="foot_btn" v-if="type == 'inspect' || type == 'patientTransport'">
      <view class="btn3" @click="Scanning_again()">继续扫描</view>
    </view>
    <view class="foot_btn" v-if="type == 'drugsBag' || type == 'jPBag'">
      <view class="btn3" @click="Scanning_again()" v-if="
          type1 === 'drug-ddd-2' ||
          type1 === 'drug-dsd-2' ||
          type1 === 'jp-ddd-2' ||
          type1 === 'jp-dsd-2'
        ">继续扫描</view>
      <view class="btn3" @click="showHandViewDrugsbag()" v-if="
          type1 === 'drug-ddd-2' ||
          type1 === 'drug-dsd-2' ||
          type1 === 'jp-ddd-2' ||
          type1 === 'jp-dsd-2'
        ">手动录入</view>
      <view class="btn3" @click="showAlert()" v-if="
          type1 === 'drug-ddd-1' ||
          type1 === 'drug-dsd-1' ||
          type1 === 'jp-ddd-1' ||
          type1 === 'jp-dsd-1'
        ">知道了</view>
    </view>
    <view class="foot_btn_spe" v-if="
        (type == 'specimenPlan' &&
          type1 != 'plan-spe-dsd-1' &&
          (type1 != 'plan-spe-ddd-1') & (type1 != 'plan-spe-ddd-2')) ||
        (type == 'specimen' &&
          type1 != 'spe-dsd-1' &&
          type1 != 'spe-dsd-4' &&
          (type1 != 'spe-ddd-1') & (type1 != 'spe-ddd-2'))
      ">
      <view class="btn1" @click="Scanning_again()">扫描标本</view>
      <view class="btn3" @click="showHandViewSpecimen()">手动录入</view>
      <view class="btn3" @click="getNoScanSpecimen(false)">未扫描标本</view>
      <view class="btn3" @click="getNoScanSpecimen(true)">已扫描标本</view>
      <view class="btn2" @click="Scanning_complete(ids)">完成扫描</view>
      <view class="btn2" @click="checkNumber()" v-if="queryObj.isDigitalHandover==1">数量核对</view>
    </view>
    <view class="foot_btn_spe" v-if="
        (type == 'specimenPlan' && type1 == 'plan-spe-ddd-2') ||
        (type == 'specimen' && type1 == 'spe-ddd-2')
      ">
      <view class="btn1" @click="Scanning_again()">扫描标本</view>
      <view class="btn3" @click="showHandViewSpecimen()">手动录入</view>
      <view class="btn3" @click="getNoScanSpecimen(false)">未扫描标本</view>
      <view class="btn3" @click="getNoScanSpecimen(true)">已扫描标本</view>
      <view class="btn2" @click="Scanning_complete(ids)">完成扫描</view>
      <view class="btn2" @click="checkNumber()" v-if="queryObj.isDigitalHandover==1">数量核对</view>
    </view>
    <view class="foot_btn" v-if="
        (infoDATA.state != 'finish' &&
          type == 'specimenPlan' &&
          type1 == 'plan-spe-dsd-1') ||
        (type == 'specimen' && type1 == 'spe-dsd-1')
      ">
      <view class="btn1" @click="Scanning_complete1(ids)">完成工单</view>
      <view class="btn2" @click="showAlert()">继续配送</view>
    </view>
    <view class="foot_btn" v-if="
        infoDATA.status != 200 &&
        type != 'specimenPlan' &&
        type != 'specimen' &&
        type !== 'jPBag' &&
        type !== 'inspect' &&
        type !== 'drugsBag' &&
        type !== 'patientTransport'
      ">
      <view class="btn3" @click="showAlert()">知道了</view>
    </view>
    <view class="foot_btn" v-if="
        (infoDATA.status == 200 && type1 == 'spe-ddd-1') ||
        (infoDATA.status == 200 && type1 == 'plan-spe-ddd-1')
      ">
      <view class="btn3" @click="showAlert()">知道了</view>
    </view>
    <view class="foot_btn" v-if="
        (infoDATA.state == 'finish' &&
          infoDATA.status == 200 &&
          type == 'specimenPlan' &&
          type1 == 'plan-spe-dsd-1') ||
        (infoDATA.status == 200 && type == 'other')
      ">
      <view class="btn3" @click="showAlert()">知道了</view>
    </view>
    <view class="foot_btn" v-if="infoDATA.status != 200 && type1 == 'spe-dsd-4'">
      <view class="btn3" @click="showAlert()">知道了</view>
    </view>
    <!-- 弹窗 -->
    <showModel :title="models.title" :icon="models.icon" :disjunctor="models.disjunctor" :content="models.content"
      @ok="ok" @cancel="cancel" :operate="models.operate"></showModel>
    <!-- 弹窗 -->
    <showModel :title="models2.title" :icon="models2.icon" :disjunctor="models2.disjunctor" :content="models2.content"
      @ok="ok2" @know="know2" @cancel="cancel2" :operate="models2.operate">
    </showModel>
    <!-- 手动查询标本弹窗 -->
    <handViewSpecimen v-if="speModels.disjunctor" :title="speModels.title" :disjunctor="speModels.disjunctor"
      @ok="speOk" @cancel="speCancel">
    </handViewSpecimen>
    <!-- 手动查询药品弹窗 -->
    <handViewDrugsBag v-if="drugbagModels.disjunctor" :title="drugbagModels.title"
      :disjunctor="drugbagModels.disjunctor" @ok="drugbagOk" @cancel="drugbagCancel">
    </handViewDrugsBag>
    <!-- 修改标本数量弹窗 -->
    <changeSpeNum v-if="changeSpeModels.disjunctor" :operate="{ok:'确认数量',check:'详细核对',cancel:'取消'}"
      :title="changeSpeModels.title" :content="changeSpeModels.content" :disjunctor="changeSpeModels.disjunctor"
      @ok="changeSpeOk" @check="changeSpeCheck" @cancel="changeSpeCancel" :num="speNumChange" :modifyReason="modifyReason" :isFirstShowReason="false">
    </changeSpeNum>
  </view>
</template>
<script>
  import showModel from "../../components/showModel/showModel.vue";
  import {
    get,
    post,
    SM,
    webHandle
  } from "../../http/http.js";
  export default {
    data() {
      return {
        speNumChange: 0,
        modifyReason:'',
        changeSpeObj: {},
        // 修改标本数量弹窗model
        changeSpeModels: {
          disjunctor: false,
        },
        currentCode: '', //当前小扫描的科室二维码
        // 手动查询标本弹窗model
        speModels: {
          disjunctor: false,
        },
        // 手动查询药品弹窗model
        drugbagModels: {
          disjunctor: false,
        },
        // 交接人信息
        accountObj: undefined,
        //传给后端查询是否继续扫描
        deptId: undefined,
        SMFlag: true,
        // 弹窗model
        models: {
          disjunctor: false,
        },
        // 完成扫描弹窗model1
        models2: {
          disjunctor: false,
        },
        wcId: "", //工单完成ID
        wcFlag: false,
        modelFlag: "", //工单完成类型
        infoDATA: [],
        ids: [],
        type: "",
        type1: "",
        queryObj: {}, //路由传递过来的参数
        gotoFlag: true,
        speNum: 0,
        content: "",
      };
    },
    methods: {
      // 修改标本数量-核对
      changeSpeCheck() {
        console.log(this.infoDATA);
        this.changeSpeModels.disjunctor = false;
        uni.navigateTo({
          url: `/pages/specimenCheckingDetail/specimenCheckingDetail?infoDATA=${encodeURIComponent(JSON.stringify({startDept:this.queryObj.startDeptId,uuid:this.queryObj.gdId}))}&id=${this.queryObj.signDeptId}&t=big&gdState=${this.queryObj.gdState}`
        })
      },
      // 修改标本数量-确认
      changeSpeOk(data) {
        console.log(data);
        const pathUrl = uni.getStorageSync("path");
        const {
          speNum,
          reason,
          imageValue
        } = data;
        this.changeSpeModels.disjunctor = false;
        uni.showLoading({
          mask: true,
          title: "加载中",
        });
        let postData = {
          checkDept: this.queryObj.endDepts, //终点科室
          transDeptId: this.changeSpeObj.infoDATA.startDept,
          gdId: this.changeSpeObj.infoDATA.uuid,
          deptId: this.changeSpeObj.id == "undefined" ?
            this.changeSpeObj.infoDATA.startDept : this.changeSpeObj.id,
          specimensNum: speNum,
          modifyReason: reason,
        };
        post("/api/updateCheckDeptSpecimensNum", postData).then((res) => {
          if (res.status == 200) {
            console.log(imageValue);
            if (!imageValue.length) {
              uni.hideLoading();
              if (this.changeSpeObj.t == "big") {
                if (this.changeSpeObj.gdState == 4) {
                  // 待到达
                  uni.navigateTo({
                    url: `../../pages/receiptpage/receiptpage`,
                  });
                } else if (this.changeSpeObj.gdState == 5) {
                  // 待送达
                  if (res.type1 === "plan-spe-ddd-2") {} else {
                    let content = `本工单已签到<strong class="red">${
                    res.scanSet ? res.scanSet.join("、") : ""
                  }</strong>,剩余需签到科室<strong class="red">${
                    res.notScanSet ? res.notScanSet.join("、") : ""
                  }</strong>,您确定完成工单吗?`;
                    uni.navigateTo({
                      url: `../scanning/scanning?type=${res.type}&type1=${
                      res.type1
                    }&id=${encodeURIComponent(
                      JSON.stringify([res.gdid])
                    )}&content=${content}`,
                    });
                  }
                }
              } else if (this.changeSpeObj.t == "small") {
                if (this.changeSpeObj.id == "undefined") {
                  //快捷建单建单进入
                  uni.navigateTo({
                    url: `../../pages/receiptpage/receiptpage`,
                  });
                } else {
                  if (this.changeSpeObj.gdState == 4) {
                    // 待到达
                    uni.navigateTo({
                      url: `../../pages/receiptpage/receiptpage`,
                    });
                  } else if (this.changeSpeObj.gdState == 5) {
                    // 待送达
                    if (res.type1 === "plan-spe-ddd-2") {} else {
                      let content = `本工单已签到<strong class="red">${
                      res.scanSet ? res.scanSet.join("、") : ""
                    }</strong>,剩余需签到科室<strong class="red">${
                      res.notScanSet ? res.notScanSet.join("、") : ""
                    }</strong>,您确定完成工单吗?`;
                      uni.navigateTo({
                        url: `../scanning/scanning?type=${res.type}&type1=${
                        res.type1
                      }&id=${encodeURIComponent(
                        JSON.stringify([res.gdid])
                      )}&content=${content}`,
                      });
                    }
                  }
                }
              } else {
                uni.navigateTo({
                  url: `../../pages/specimenChecking/specimenChecking?infoDATA=${encodeURIComponent(
                  JSON.stringify(this.changeSpeObj.infoDATA)
                )}`,
                });
              }
              return;
            }
            let n = 0;
            imageValue.forEach((v) => {
              // 图片上传 start
              console.log("压缩前");
              let canvasWidth = v.image.width; //图片原始长宽
              let canvasHeight = v.image.height;
              let img = new Image();
              img.src = v.path;
              let canvas = document.createElement("canvas");
              let ctx = canvas.getContext("2d");
              canvas.width = canvasWidth;
              canvas.height = canvasHeight;
              ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
              canvas.toBlob(
                (fileSrc) => {
                  let tp = window.URL.createObjectURL(fileSrc);
                  console.log("压缩后");
                  n++;
                  uni.uploadFile({
                    url: pathUrl +
                      "/common/common/uploadAttachment/specimenPhotos/" +
                      res.deptSpecimensNumId +
                      "/666",
                    filePath: tp,
                    name: "file",
                    formData: {
                      filename: v.name,
                    },
                    success: (uploadFileRes) => {
                      console.log(uploadFileRes);
                      if (--n === 0) {
                        uni.hideLoading();
                        uni.showModal({
                          title: "提示",
                          content: "修改成功!",
                          showCancel: false,
                          success: (result) => {
                            if (result.confirm) {
                              console.log("用户点击确定", this.changeSpeObj.t);
                              if (this.changeSpeObj.t == "big") {
                                if (this.changeSpeObj.gdState == 4) {
                                  // 待到达
                                  uni.navigateTo({
                                    url: `../../pages/receiptpage/receiptpage`,
                                  });
                                } else if (this.changeSpeObj.gdState == 5) {
                                  // 待送达
                                  if (res.type1 === "plan-spe-ddd-2") {} else {
                                    let content = `本工单已签到<strong class="red">${
                                    res.scanSet ? res.scanSet.join("、") : ""
                                  }</strong>,剩余需签到科室<strong class="red">${
                                    res.notScanSet ? res.notScanSet.join("、") : ""
                                  }</strong>,您确定完成工单吗?`;
                                    uni.navigateTo({
                                      url: `../scanning/scanning?type=${res.type}&type1=${
                                      res.type1
                                    }&id=${encodeURIComponent(
                                      JSON.stringify([res.gdid])
                                    )}&content=${content}`,
                                    });
                                  }
                                }
                              } else if (this.changeSpeObj.t == "small") {
                                if (this.changeSpeObj.id == "undefined") {
                                  //快捷建单建单进入
                                  uni.navigateTo({
                                    url: `../../pages/receiptpage/receiptpage`,
                                  });
                                } else {
                                  if (this.changeSpeObj.gdState == 4) {
                                    // 待到达
                                    uni.navigateTo({
                                      url: `../../pages/receiptpage/receiptpage`,
                                    });
                                  } else if (this.changeSpeObj.gdState == 5) {
                                    // 待送达
                                    if (res.type1 === "plan-spe-ddd-2") {} else {
                                      let content = `本工单已签到<strong class="red">${
                                      res.scanSet ? res.scanSet.join("、") : ""
                                    }</strong>,剩余需签到科室<strong class="red">${
                                      res.notScanSet ? res.notScanSet.join("、") : ""
                                    }</strong>,您确定完成工单吗?`;
                                      uni.navigateTo({
                                        url: `../scanning/scanning?type=${res.type}&type1=${
                                        res.type1
                                      }&id=${encodeURIComponent(
                                        JSON.stringify([res.gdid])
                                      )}&content=${content}`,
                                      });
                                    }
                                  }
                                }
                              } else {
                                uni.navigateTo({
                                  url: `../../pages/specimenChecking/specimenChecking?infoDATA=${encodeURIComponent(
                                  JSON.stringify(this.changeSpeObj.infoDATA)
                                )}`,
                                });
                              }
                            } else if (result.cancel) {
                              console.log("用户点击取消");
                            }
                          },
                        });
                      }
                    },
                    fail: (err) => {
                      n--;
                      console.error(err);
                      uni.hideLoading();
                      uni.showToast({
                        icon: "none",
                        title: "上传失败",
                        duration: 2000,
                      });
                    },
                  });
                },
                "image/jpeg",
                0.3
              );
              // 图片上传 end
            });
          } else {
            uni.hideLoading();
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败!",
            });
          }
        });
      },
      // 修改标本数量-取消
      changeSpeCancel() {
        this.changeSpeModels.disjunctor = false;
      },
      // 修改标本数量弹窗
      showChangeSpe() {
        uni.showLoading({
          mask: true,
          title: "加载中",
        });
        let postData = {
          deptId: this.deptId,
          gdId: this.queryObj.gdId,
        };
        post(`/api/getStartDeptSpecimensNum`, postData).then((res) => {
          uni.hideLoading();
          if (res.status == 200) {
            this.speNumChange = res.data[0].deptSpecimensNum;
            this.modifyReason = res.data[0].modifyReason;
            this.changeSpeModels = {
              title: "修改标本数量",
              content: `您已到达<span class="red">${this.queryObj.dept}</span>本科室标本数量为<span class="red">${this.speNumChange}</span>,请确认标本数量`,
              disjunctor: true,
            };
          } else {
            this.speNumChange = "";
            this.modifyReason = "";
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败!",
            });
          }
        });
      },
      // 数量核对 queryObj
      checkNumber() {
        this.changeSpeObj = {
          infoDATA: {
            startDept: this.queryObj.startDeptId,
            uuid: this.queryObj.gdId
          },
          id: this.queryObj.signDeptId,
          t: 'big',
          gdState: this.queryObj.gdState,
        }
        this.showChangeSpe();
      },
      // 手动查询药品-确认
      drugbagOk(data) {
        console.log(data);
        if (!data.id) {
          //没有查询到药品
          uni.showModal({
            title: '提示',
            content: "没有查询到发药单号!",
            showCancel: false,
            success: function(res) {
              if (res.confirm) {
                console.log('用户点击确定');
              } else if (res.cancel) {
                console.log('用户点击取消');
              }
            }
          });
          return;
        }
        this.drugbagModels.disjunctor = false;
        this.hand_scanning_common(data.packid, 'hand');
      },
      // 手动查询药品-取消
      drugbagCancel() {
        this.drugbagModels.disjunctor = false;
      },
      // 手动查询药品弹窗
      showHandViewDrugsbag() {
        this.drugbagModels = {
          title: '填写发药单号',
          disjunctor: true,
        }
      },
      // 手动查询标本-确认
      speOk(data) {
        console.log(data);
        if (!data.id) {
          //没有查询到标本
          uni.showModal({
            title: '提示',
            content: "没有查询到标本!",
            showCancel: false,
            success: function(res) {
              if (res.confirm) {
                console.log('用户点击确定');
              } else if (res.cancel) {
                console.log('用户点击取消');
              }
            }
          });
          return;
        }
        this.speModels.disjunctor = false;
        this.hand_scanning_common(data.scode, 'hand');
      },
      // 手动查询标本-取消
      speCancel() {
        this.speModels.disjunctor = false;
      },
      // 手动查询标本弹窗
      showHandViewSpecimen() {
        this.speModels = {
          title: '填写标本编码',
          disjunctor: true,
        }
      },
      // 手动输入标本和扫码公共方法
      hand_scanning_common(ress1, type) {
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        // ----------------
        //检验二维码的有效性
        post("/dept/scanning", {
          content: ress1,
        }).then((result) => {
          this.SMFlag = true;
          if (result.state == 200 || result.state == 201) {
            this.currentCode = result.code;
            let ress = result.code;
            let speCode = ress;
            let data = {
              code: speCode,
              type: this.queryObj.type1,
              deptCode: this.code,
              ids: this.ids,
            };
            let postType = "";
            if (this.type == "jPBag" || this.type == "drugsBag") {
              postType = "handleDrugsAndJp";
              if(this.type == "drugsBag"){
                delete data.ids;
              }
              if (this.accountObj) {
                data.handover = this.accountObj.accountId;
              }
              data.deptId = this.deptId;
            }
            if (this.type == "specimen") {
              postType = "handleSpes";
              data["speCode"] = data.code;
              delete data.code;
              if (this.accountObj) {
                data.handover = this.accountObj.accountId;
              }
            }
            if (this.type == "specimenPlan") {
              postType = "handlePlanSpes";
              data["speCode"] = data.code;
              delete data.code;
              if (this.accountObj) {
                data.handover = this.accountObj.accountId;
              }
            }
            if (this.type == "inspect") {
              postType = "handleIns";
            }
            if (this.type == "patientTransport") {
              postType = "handleTrans";
            }
            post("/workerOrder/" + postType, data).then((ress) => {
              uni.hideLoading();
              if (ress.status == 200 || ress.status == 11111) {
                //标本和标本轮巡工单,扫描标本后会自动调用摄像头,继续扫描,直到status不是200
                if ((this.type == "specimenPlan" || this.type == "specimen") && ress.status != 11111) {
                  if (type === 'scan') {
                    setTimeout(() => {
                      this.Scanning_again();
                    }, 500)
                  }
                }
                if(this.type === 'patientTransport' && this.queryObj.type1 == 'trans-dsd-1'){
                  // 门诊服务点
                  if(ress.orderList){
                    uni.navigateTo({
                      url: `/pages/outpatient/outpatientEndSignIn/outpatientEndSignIn?model=${encodeURIComponent(JSON.stringify(ress))}`,
                    });
                  }else{
                    this.speNum = ress.specimenCount;
                    uni.navigateTo({
                      url: `../scanning_djInfo/scanning_djInfo?type=${
                      this.queryObj.type
                    }&type1=${
                      this.queryObj.type1
                    }&infoData=${encodeURIComponent(
                      JSON.stringify(ress.data)
                    )}&status=${ress.status}&msg=${ress.msg}&deptCode=${
                      this.queryObj.code
                    }&dept=${this.queryObj.dept}&ids=${encodeURIComponent(
                      JSON.stringify(this.ids)
                    )}&model=${encodeURIComponent(
                      JSON.stringify(ress)
                    )}&speNum=${this.speNum}&accountObj=${encodeURIComponent(
                      JSON.stringify(this.accountObj)
                    )}&deptId=${this.deptId}&scanOrHand=${type}`,
                    });
                  }
                }else{
                  this.speNum = ress.specimenCount;
                  uni.navigateTo({
                    url: `../scanning_djInfo/scanning_djInfo?type=${
                    this.queryObj.type
                  }&type1=${
                    this.queryObj.type1
                  }&infoData=${encodeURIComponent(
                    JSON.stringify(ress.data)
                  )}&status=${ress.status}&msg=${ress.msg}&deptCode=${
                    this.queryObj.code
                  }&dept=${this.queryObj.dept}&ids=${encodeURIComponent(
                    JSON.stringify(this.ids)
                  )}&model=${encodeURIComponent(
                    JSON.stringify(ress)
                  )}&speNum=${this.speNum}&accountObj=${encodeURIComponent(
                    JSON.stringify(this.accountObj)
                  )}&deptId=${this.deptId}&scanOrHand=${type}`,
                  });
                }

              } else {
                uni.navigateTo({
                  url: `../scanning_djInfo/scanning_djInfo?type=${
                  this.queryObj.type
                }&type1=${this.queryObj.type1}&status=${ress.status}&msg=${
                  ress.msg
                }&deptCode=${this.queryObj.code}&dept=${
                  this.queryObj.dept
                }&ids=${encodeURIComponent(
                  JSON.stringify(this.ids)
                )}&infoData=${encodeURIComponent(
                  JSON.stringify(ress.data)
                )}&model=${encodeURIComponent(
                  JSON.stringify(ress)
                )}&accountObj=${encodeURIComponent(
                  JSON.stringify(this.accountObj)
                )}&deptId=${this.deptId}&scanOrHand=${type}&qrcode=${this.currentCode}`,
                });
              }
            });
          } else {
            uni.hideLoading();
            uni.showToast({
              icon: "none",
              title: result.info || "接口获取数据失败!",
            });
          }
        });
        // ------------------------------
      },
      // 查看未扫描标本
      // isScan true已扫描标本,false未扫描标本
      getNoScanSpecimen(isScan) {
        if (!this.gotoFlag) {
          return;
        }
        this.gotoFlag = false;
        let ids = JSON.parse(this.queryObj.ids);
        if (isScan) {
          uni.navigateTo({
            url: `../noScanSpecimen/noScanSpecimen?deptName=${this.queryObj.dept}&workOrderId=${encodeURIComponent(
            JSON.stringify(ids)
          )}&deptCode=${this.queryObj.code}&isScan=1`,
          });
        } else {
          uni.navigateTo({
            url: `../noScanSpecimen/noScanSpecimen?deptName=${this.queryObj.dept}&workOrderId=${encodeURIComponent(
            JSON.stringify(ids)
          )}&deptCode=${this.queryObj.code}`,
          });
        }
      },
      // 正常完成扫描
      overFinish() {
        //完成扫描
        let postType = "";
        if (
          this.queryObj.type1 === "plan-spe-ddd-2" ||
          this.queryObj.type1 === "plan-spe-dsd-2" ||
          this.queryObj.type1 === "plan-spe-dsd-3"
        ) {
          postType = "finishPlanSpes";
        } else if (this.queryObj.type1 == "spe-ddd-2") {
          postType = "finishSpes";
        }
        let data = {
          type: this.queryObj.type1,
          ids: this.wcId,
        };
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        post("/workerOrder/" + postType, data).then((res) => {
          if (res.status == 200) {
            this.models2 = {
              disjunctor: true,
              title: "提示",
              content: `完成扫描成功`,
              icon: "success",
              operate: {
                know: "知道了",
              },
            };
          } else {
            uni.hideLoading();
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败!",
            });
          }
        });
      },
      // 确定
      ok() {
        this.models.disjunctor = false;
        if (this.modelFlag === "complete") {
          uni.showLoading({
            title: "加载中",
            mask: true,
          });
          let ids = JSON.parse(this.queryObj.ids);
          let postData = {
            ids,
            sign: true,
            deptQrCode: this.queryObj.code,
          };
          post("/workerOrder/expectedAndActual", postData).then((ress) => {
            uni.hideLoading();
            if (ress.status == 200) {
              if (this.wcFlag) {
                //正常完成扫描
                this.overFinish();
              } else {
                this.gotoOver();
              }
            } else if (ress.status == 1000035) {
              let content = "";
              if (
                this.queryObj.type1 === "spe-ddd-2" ||
                this.queryObj.type1 === "plan-spe-ddd-2"
              ) {
                //待到达
                content =
                  `系统内预计标本<strong class="red">${ress.expectReceiveNum}</strong>只,您扫描收取标本<strong class="red">${ress.actualReceiveNum}</strong>只,其中<strong class="red">${ress.notReceiveNum}</strong>只未扫描;`;
              } else {
                //待送达
                this.content = `本工单已签到<strong class="red">${
                ress.scanSet ? ress.scanSet.join("、") : ""
              }</strong>,剩余需签到科室<strong class="red">${
                ress.notScanSet ? ress.notScanSet.join("、") : ""
              }</strong>,总签收<strong class="red">${
                ress.totalAcceptance
              }</strong>只,剩余<strong class="red">${
                ress.notAcceptance
              }</strong>只未签收,您确定完成工单吗?`;
                content =
                  `您在<strong class="red">${ress.deptName}</strong>检验科扫描了<strong class="red">${ress.deptScanNum}</strong>个标本,还需扫描<strong class="red">${ress.deptNotScanNum}</strong>标本。`;
              }
              // 取消弹窗 2022年10月10日
              this.ok2();
              // this.models2 = {
              //   disjunctor: true,
              //   title: "提示",
              //   content,
              //   icon: "warn",
              //   operate: {
              //     ok: "确定",
              //     cancel: "取消",
              //   },
              // };
            } else {
              uni.showToast({
                icon: "none",
                title: ress.msg || "接口获取数据失败!",
              });
            }
          });
        } else if (this.modelFlag === "complete1") {
          //1对1标本完成工单
          let ids = this.wcId;
          uni.showLoading({
            title: "加载中",
            mask: true,
          });
          post("/workerOrder/finishSpeOrder", ids).then((res) => {
            if (res.status == 200) {
              uni.reLaunch({
                url: "../receiptpage/receiptpage",
              });
            } else {
              uni.hideLoading();
              uni.showToast({
                icon: "none",
                title: res.msg || "接口获取数据失败!",
              });
            }
          });
        }
      },
      // 取消
      cancel() {
        this.models.disjunctor = false;
      },
      // 确定
      ok2() {
        this.models2.disjunctor = false;
        let ids = JSON.parse(this.queryObj.ids);
        let postData = {
          ids,
          deptQrCode: this.queryObj.code,
        };
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        post("/workerOrder/expectedAndActual", postData).then((ress) => {
          uni.hideLoading();
          if (ress.status == 200) {
            if (this.wcFlag) {
              this.overFinish();
            } else {
              this.gotoOver();
            }
          } else {
            uni.showToast({
              icon: "none",
              title: ress.msg || "接口获取数据失败!",
            });
          }
        });
      },
      // 取消
      cancel2() {
        this.models2.disjunctor = false;
      },
      know2() {
        this.models2.disjunctor = false;
        uni.reLaunch({
          url: "../receiptpage/receiptpage",
        });
      },
      //完成扫描
      Scanning_complete(id) {
        // 如果是标本配送和标本轮巡,则进入标本核对页面
        if((this.type === 'specimen' || this.type === 'specimenPlan') && this.queryObj.type1.includes('ddd')){
          uni.navigateTo({
            url: `../checkAfterScanning/checkAfterScanning?id=${id}&type=${this.queryObj.type}&type1=${this.queryObj.type1}&dept=${this.queryObj.dept}&deptId=${this.queryObj.deptId}&deptCode=${this.queryObj.deptCode}&speNum=${this.speNum}&content=${this.content}`,
          });
          return;
        }
        this.modelFlag = "complete";
        this.wcId = id;
        if (
          this.queryObj.type1 == "plan-spe-ddd-2" ||
          this.queryObj.type1 == "spe-ddd-2"
        ) {
          this.wcFlag = true;
          this.models = {
            disjunctor: true,
            title: "提示",
            content: "是否确定标本已扫描完成?",
            icon: "warn",
            operate: {
              ok: "确定",
              cancel: "取消",
            },
          };
        } else if (
          this.queryObj.type1 == "plan-spe-dsd-2" ||
          this.queryObj.type1 == "plan-spe-dsd-3" ||
          this.queryObj.type1 == "spe-dsd-2" ||
          this.queryObj.type1 == "spe-dsd-3"
        ) {
          this.wcFlag = false;
          this.models = {
            disjunctor: true,
            title: "提示",
            content: "是否确定标本已扫描完成?",
            icon: "warn",
            operate: {
              ok: "确定",
              cancel: "取消",
            },
          };
        } else {
          this.gotoOver();
        }
      },
      // 跳转完成工单页面
      gotoOver() {
        if(this.queryObj.type === 'specimenPlan'){
          uni.navigateTo({
            url: `../specimenCheckingEnd/specimenCheckingEnd?type=${this.queryObj.type}&type1=${
            this.queryObj.type1
          }&deptCode=${this.queryObj.code}&dept=${
            this.queryObj.dept
          }&id=${encodeURIComponent(JSON.stringify(this.wcId))}&content=${
            this.content
          }`,
          });
        }else{
          uni.navigateTo({
            url: `../scanning/scanning?type=${this.queryObj.type}&type1=${
            this.queryObj.type1
          }&deptCode=${this.queryObj.code}&dept=${
            this.queryObj.dept
          }&id=${encodeURIComponent(JSON.stringify(this.wcId))}&content=${
            this.content
          }`,
          });
        }
      },
      //一对一完成工单
      Scanning_complete1(id) {
        this.modelFlag = "complete1";
        this.wcId = id;
        this.models = {
          disjunctor: true,
          title: "提示",
          content: "是否确定标本配送完成?",
          icon: "warn",
          operate: {
            ok: "确定",
            cancel: "取消",
          },
        };
      },
      //继续扫描
      Scanning_again() {
        if (!this.SMFlag) {
          return;
        }
        this.SMFlag = false;
        SM()
          .then((ress1) => {
            this.hand_scanning_common(ress1, 'scan');
          })
          .catch((err) => {
            this.SMFlag = true;
          });
      },
      // 知道了
      showAlert() {
        uni.navigateTo({
          url: "../receiptpage/receiptpage",
        });
      },
    },
    onShow() {
      this.SMFlag = true;
      this.gotoFlag = true;
    },
    onLoad(options) {
      console.log(options, "djEnd");
      if (options.speNum) {
        this.speNum = options.speNum;
      }
      if (options.accountObj && options.accountObj != "undefined") {
        this.accountObj = JSON.parse(options.accountObj);
      }
      if (options.deptId && options.deptId != "undefined") {
        this.deptId = options.deptId;
      }
      this.queryObj = options;
      let list = JSON.parse(options.model); //签到返回的信息
      this.code = options.code; //二维码code
      this.ids = options.ids && JSON.parse(options.ids); //科室ID数组
      this.infoDATA = list;
      if (options.type) {
        //关联类型
        this.type = options.type;
      } else {
        this.type = list.type;
      }
      this.type1 = options.type1;
      if(this.queryObj.isDigitalHandover==1){
        this.checkNumber();//自动弹出数量核对
      }
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less">
  .Scanning_djEnd {
    padding: 0px 20rpx;

    .Scanning_top {
      min-height: 270rpx;

      .Scanning_top_icon {
        width: 140rpx;
        height: 140rpx;
        margin: 0 auto;
        // margin-top: 116rpx;
        border-radius: 50%;
        line-height: 140rpx;

        .cubeic-ok {
          font-size: 140rpx;
          color: #35b34a;
        }

        .cubeic-close {
          font-size: 140rpx;
          color: #ff3b53;
        }
      }

      .Scanning_top_text {
        .text1 {
          margin-top: 40rpx;
          font-size: 48rpx;
          text-align: center;
        }
      }
    }

    .Scanning_cont {
      font-size: 32rpx;
      text-align: center;

      view {
        margin-bottom: 16rpx;
      }

      .text {
        margin-top: 24rpx;
        color: #35b34a;
      }

      .text1 {
        margin-top: 24rpx;
        color: #ff3b53;
      }
    }

    .foot_btn {
      line-height: 88rpx;
      height: 100rpx;
      margin-top: 40rpx;
      text-align: center;
      display: flex;

      view {
        height: 88rpx;
        flex: 1;
        margin: 0 1%;
        background-image: linear-gradient(to right, #72c172, #3bb197);
        color: #fff;
        border-radius: 8rpx;
        font-size: 32rpx;
        margin-top: 16rpx;
      }
    }

    .foot_btn_spe {
      line-height: 88rpx;
      height: 100rpx;
      margin-top: 40rpx;
      text-align: center;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;

      &::after {
        content: '';
        flex: 1;
      }

      view {
        height: 88rpx;
        width: 48%;
        margin: 0 1%;
        background-image: linear-gradient(to right, #72c172, #3bb197);
        color: #fff;
        border-radius: 8rpx;
        font-size: 32rpx;
        margin-top: 16rpx;
      }
    }
  }
</style>