<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>
    </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') ||
        (infoDATA.status == 200 && type == 'jPBag')
      ">已到达目标科室,请扫描药包或静配包.</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>
    <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>
    <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()">继续扫描</view>
    </view>
    <view class="foot_btn" 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-ddd-1') & (type1 != 'spe-ddd-2'))
      ">
      <view class="btn1" @click="Scanning_again()">继续扫描</view>
      <view class="btn2" @click="Scanning_complete(ids)">完成扫描</view>
    </view>
    <view class="foot_btn" v-if="
        (type == 'specimenPlan' && type1 == 'plan-spe-ddd-2') ||
        (type == 'specimen' && type1 == 'spe-ddd-2')
      ">
      <view class="btn1" @click="Scanning_again()">继续扫描</view>
      <view class="btn2" @click="Scanning_complete(ids)">完成扫描</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>
    <!-- 弹窗 -->
    <showModel :title="models.title" :icon="models.icon" :disjunctor="models.disjunctor" :content="models.content"
      @ok="ok" @cancel="cancel" :operate="models.operate"></showModel>
  </view>
</template>
<script>
  import showModel from "../../components/showModel/showModel.vue";
  import {
    get,
    post,
    SM,
    webHandle
  } from "../../http/http.js";
  export default {
    data() {
      return {
        // 弹窗model
        models: {
          disjunctor: false,
        },
        wcId: "", //工单完成ID
        modelFlag: "", //工单完成类型
        infoDATA: [],
        ids: [],
        speNum: 0,
        type: "",
        type1: "",
        queryObj: {}, //路由传递过来的参数
      };
    },
    methods: {
      // 确定
      ok() {
        if (this.modelFlag === "complete") {
          //完成扫描
          let postType = "";
          if (this.queryObj.type1 == "plan-spe-ddd-2") {
            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) => {
            uni.hideLoading();
            this.models.disjunctor = false;
            if (res.status == 200) {
              uni.reLaunch({
                url: "../receiptpage/receiptpage",
              });
            } else {
              uni.showToast({
                icon: "none",
                title: "请求失败！",
              });
            }
          });
        } else if (this.modelFlag === "complete1") {
          //1对1标本完成工单
          let ids = this.wcId;
          uni.showLoading({
            title: '加载中',
            mask: true,
          });
          post("/workerOrder/finishSpeOrder", ids).then((res) => {
            uni.hideLoading();
            this.models.disjunctor = false;
            if (res.status == 200) {
              uni.reLaunch({
                url: "../receiptpage/receiptpage",
              });
            } else {
              uni.showToast({
                icon: "none",
                title: "请求失败！",
              });
            }
          });
        }
      },
      // 取消
      cancel() {
        this.models.disjunctor = false;
      },
      //完成扫描
      Scanning_complete(id) {
        this.modelFlag = "complete";
        if (
          this.queryObj.type1 == "plan-spe-ddd-2" ||
          this.queryObj.type1 == "spe-ddd-2"
        ) {
          this.wcId = id;
          this.models = {
            disjunctor: true,
            title: "提示",
            content: "是否确定标本已扫描完成?",
            icon: "warn",
            operate: {
              ok: "确定",
              cancel: "取消",
            },
          };
        } 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.ids))}`,
          });
        }
      },
      //一对一完成工单
      Scanning_complete1(id) {
        this.modelFlag = "complete1";
        this.wcId = id;
        this.models = {
          disjunctor: true,
          title: "提示",
          content: "是否确定标本配送完成?",
          icon: "warn",
          operate: {
            ok: "确定",
            cancel: "取消",
          },
        };
      },
      //继续扫描
      Scanning_again() {
        SM().then((ress1) => {
          // ----------------
          //检验二维码的有效性
          post("/dept/scanning", {
            content: ress1,
          }).then((result) => {
            if (result.state == 200 || result.state == 201) {
              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 == "specimen") {
                postType = "handleSpes";
                data["speCode"] = data.code;
                delete data.code;
              }
              if (this.type == "specimenPlan") {
                postType = "handlePlanSpes";
                data["speCode"] = data.code;
                delete data.code;
              }
              if (this.type == "inspect") {
                postType = "handleIns";
              }
              if (this.type == "patientTransport") {
                postType = "handleTrans";
              }
              post("/workerOrder/" + postType, data).then((ress) => {
                if (ress.status == 200) {
                  this.speNum++;
                  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)
                  )}&speNum=${this.speNum}&model=${encodeURIComponent(
                    JSON.stringify(ress)
                  )}`,
                  });
                  uni.setStorageSync("speNum", this.speNum);
                } 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)
                  )}&speNum=${this.speNum}&infoData=${encodeURIComponent(
                    JSON.stringify(ress.data)
                  )}&model=${encodeURIComponent(JSON.stringify(ress))}`,
                  });
                }
              });
            } else {
              uni.showToast({
                icon: "none",
                title: "请求失败！",
              });
            }
          });
          // ------------------------------
        });
      },
      // 知道了
      showAlert() {
        uni.navigateTo({
          url: "../receiptpage/receiptpage",
        });
      },
    },
    onLoad(options) {
      console.log(options, "djEnd");
      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 (options.speNum) {
        this.speNum = options.speNum;
      } else {
        this.speNumLocal = uni.getStorageSync("speNum");
        // 本地存在speNum的时候
        if (this.speNumLocal) {
          this.speNum = Number(this.speNumLocal);
        }
      }
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less">
  .Scanning_djEnd {
    padding: 0px 74rpx;

    .Scanning_top {
      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;

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

      .btn1 {
        float: left;
      }

      .btn2 {
        float: right;
      }

      .btn3 {
        margin: 0 auto;
      }
    }
  }
</style>
