<template>
  <view class="Scanning_djInfo">
    <view class="Scanning_top" v-if="res.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="
        res.status == 10005 ||
        res.status == 100018 ||
        res.status == 500 ||
        res.status == 10004 ||
        res.status == 100021 ||
        res.status == 100020 ||
        res.status == 100019 ||
        res.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="res.status != 200 || res.msg != '成功！'">
      <view>{{ res.msg }}</view>
    </view>
    <view
      class="Scanning_cont"
      v-if="
        (res.status == 200 && type == 'specimenPlan') ||
        (res.status == 200 && type == 'specimen')
      "
    >
      <view>标本类型 : {{ infoDATA.data.stype.name || "-" }}</view>
      <view>标本编号 : {{ infoDATA.data.scode || "-" }}</view>
      <view>患者姓名 : {{ infoDATA.data.patientName || "-" }}</view>
      <view>已扫描 : {{ speNum }}</view>
    </view>
    <view
      class="Scanning_cont"
      v-if="
        (res.status == 200 && type == 'inspect') || type == 'patientTransport'
      "
    >
      <view v-if="infoDATA.patient"
        >患者姓名 : {{ infoDATA.patient || "-" }}</view
      >
      <view v-if="infoDATA.patient"
        >患者编号 : {{ infoDATA.patientCode || "-" }}</view
      >
      <view v-if="infoDATA.patient"
        >住院科室 : {{ infoDATA.deptName || "-" }}</view
      >
      <view v-if="infoDATA.patient">床号 : {{ infoDATA.bedNum || "-" }}</view>
      <view v-if="infoDATA.data">
        检查项目 :
        <text v-for="(data, i) in infoDATA.data" :key="i"
          >{{ data.inspectName }},</text
        >
      </view>
      <view
        v-if="
          infoType == 'ins-dsd-1' ||
          infoType == 'trans-dsd-1' ||
          infoDATA.type == 'trans-dsd-1'
        "
        >工单已完成</view
      >
    </view>
    <view
      class="Scanning_cont"
      v-if="
        (res.status == 200 && type == 'drugsBag') ||
        (res.status == 200 && type == 'jPBag')
      "
    >
      <view v-if="res.status == 200 && type == 'drugsBag'"
        >药包编码 : #{{ infoDATA.data.packid }}</view
      >
      <view v-if="res.status == 200 && type == 'jPBag'"
        >静配编码 : #{{ infoDATA.data.packid }}</view
      >
      <view>所属科室 : {{ infoDATA.data.target.dept }}</view>
      <text v-if="infoType == 'drug-dsd-2' || infoType == 'jp-dsd-2'"
        >工单已完成。</text
      >
    </view>

    <!-- <view class="foot_btn" v-if="idsType==1&&res.status==200">
      <view class="btn1" @click="Scanning_again()">继续扫描</view>
      <view class="btn2" @click="showAlert()">知道了</view>
    </view> -->
    <view
      class="foot_btn"
      v-if="
        res.status == 100018 || type == 'specimen' || type == 'specimenPlan'
      "
    >
      <view class="btn1" @click="Scanning_again()">继续扫描</view>
      <view class="btn2" @click="Scanning_complete(ids)">完成扫描</view>
    </view>
    <view
      class="foot_btn"
      v-if="
        type != 'specimen' &&
        res.status != 200 &&
        type != 'specimenPlan' &&
        type !== 'drugsBag' &&
        type !== 'jPBag' &&
        type !== 'patientTransport'
      "
    >
      <view class="btn3" @click="showAlert()">知道了</view>
    </view>
    <view
      class="foot_btn"
      v-if="
        (res.status != 200 && type == 'drugsBag') ||
        (res.status != 200 && type == 'jPBag') ||
        (res.status != 200 && type == 'patientTransport')
      "
    >
      <view class="btn3" @click="Scanning_again()">继续扫描</view>
    </view>
    <view
      class="foot_btn"
      v-if="
        idsType == 2 &&
        res.status == 200 &&
        type != 'specimen' &&
        idsType == 2 &&
        res.status == 200 &&
        type != 'specimenPlan'
      "
    >
      <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
      infoDATA: [],
      res: { status: "", msg: "" },
      infoType: "",
      DEPTCode: "",
      RESData: {},
      DEPT: "",
      dataId: "",
      type: "",
      model: {},
      idsType: 1,
      packid: "",
      speNum: 0,
      queryObj: {}, //路由传递过来的参数
    };
  },
  methods: {
    // 确定
    ok() {
      let postType = "";
      if (this.queryObj.type1 == "plan-spe-ddd-2") {
        postType = "finishPlanSpes";
      } else if (this.queryObj.type1 == "spe-ddd-2") {
        postType = "finishSpes";
      }
      this.models.disjunctor = false;
      let data = {
        type: this.queryObj.type1,
        ids: this.wcId,
      };
      post("/workerOrder/" + postType, data).then((res) => {
        if (res.status == 200) {
          uni.navigateTo({
            url: "../receiptpage/receiptpage",
          });
        } else {
          uni.showToast({
            icon: "none",
            title: "请求失败！",
          });
        }
      });
    },
    // 取消
    cancel() {
      this.models.disjunctor = false;
    },
    //完成扫描
    Scanning_complete(id) {
      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
          }&id=${encodeURIComponent(JSON.stringify(id))}&deptCode=${
            this.queryObj.deptCode
          }&dept=${this.queryObj.dept}`,
        });
      }
    },
    // 继续扫描
    Scanning_again() {
      let list = [];
      let postType = "";
      let ids = [];
      if (this.ids && this.ids[0]) {
        ids = this.ids;
      } else if (this.dataId) {
        ids = [];
        ids.push(this.dataId);
      }
      let data = {
        ids: ids,
        deptCode: this.DEPTCode,
        code: "", // 2
      };
      SM().then((ress1) => {
        // ----------------
        //检验二维码的有效性
        post("/dept/scanning", {
          content: ress1,
        }).then((result) => {
          if (result.state == 200 || result.state == 201) {
            let ress = result.code;
            if (ress) {
              data.code = ress;
              if (this.type == "inspect") {
                postType = "handleIns";
                list = data;
              }
              if (this.type == "jPBag" || this.type == "drugsBag") {
                postType = "handleDrugsAndJp";
                data["type"] = this.infoType;
                list = data;
              }
              if (this.type == "specimen") {
                postType = "handleSpes";
                data["speCode"] = data.code;
                delete data.code;
                data["type"] = this.infoType;
                list = data;
              }
              if (this.type == "specimenPlan") {
                postType = "handlePlanSpes";
                data["speCode"] = data.code;
                delete data.code;
                data["type"] = this.infoType;
                list = data;
              }
              if (this.type == "patientTransport") {
                postType = "handleTrans";
                list = data;
              }
              post("/workerOrder/" + postType, list).then((res) => {
                if (res.status == 200) {
                  if (
                    this.type == "inspect" ||
                    this.type == "patientTransport"
                  ) {
                    if (res.ids) {
                      for (var i = 0; i < this.ids.length; i++) {
                        if (this.ids[i] == res.ids[0]) {
                          this.ids.splice(i, 1);
                        }
                      }
                      if (this.ids.length > 1) {
                        this.idsType = 1;
                      } else {
                        this.idsType = 2;
                      }
                    }
                    this.infoDATA = res;
                    this.type = this.type;
                    this.DEPTCode = this.DEPTCode;
                  } else if (this.type == "drugsBag") {
                    // this.infoDATA.data.packid = res.data.packid;
                    this.infoDATA = res;
                    this.res["status"] = res.status;
                    this.res["msg"] = res.msg;
                  } else if (
                    this.type == "specimenPlan" ||
                    this.type == "specimen"
                  ) {
                    this.infoDATA = res;
                    this.speNum++;
                    uni.setStorageSync("speNum", this.speNum); //seimin 2020年6月15日18:45:46
                    // --------------------------
                    this.res["status"] = res.status;
                    this.res["msg"] = res.msg;
                    // --------------------------
                  } else if (this.type == "jPBag") {
                    // this.infoDATA.data.packid = res.data.packid;
                    this.infoDATA = res;
                    this.res["status"] = res.status;
                    this.res["msg"] = res.msg;
                  } else {
                    uni.navigateTo({
                      url: `../scanning_djEnd/scanning_djEnd?type=${
                        this.queryObj.type
                      }&type1=${this.queryObj.type1}&code=${
                        this.queryObj.deptCode
                      }&dept=${this.queryObj.dept}&ids=${encodeURIComponent(
                        JSON.stringify(this.ids)
                      )}&speNum=${this.speNum}&model=${encodeURIComponent(
                        JSON.stringify(res)
                      )}`,
                    });
                  }
                } else {
                  uni.navigateTo({
                    url: `../scanning_djEnd/scanning_djEnd?type=${
                      this.queryObj.type
                    }&type1=${this.queryObj.type1}&code=${
                      this.queryObj.deptCode
                    }&dept=${this.queryObj.dept}&ids=${encodeURIComponent(
                      JSON.stringify(this.ids)
                    )}&speNum=${this.speNum}&model=${encodeURIComponent(
                      JSON.stringify(res)
                    )}`,
                  });
                }
              });
            }
          } else {
            uni.showToast({
              icon: "none",
              title: "请求失败！",
            });
          }
        });
        // ------------------------------
      });
    },
    // 知道了
    showAlert() {
      uni.navigateTo({
        url: "../receiptpage/receiptpage",
      });
    },
  },
  onLoad(options) {
    this.queryObj = options;
    if (this.queryObj.model) {
      let list = JSON.parse(this.queryObj.model);
      this.infoDATA = list;
    } else {
      this.infoDATA = this.queryObj.infoData;
    }

    this.RESData = this.queryObj.resData;
    this.res["status"] = this.queryObj.status;
    this.res["msg"] = this.queryObj.msg;
    this.res["patient"] = this.queryObj.patient;
    this.infoType = this.queryObj.type1;
    if (this.queryObj.dept) {
      this.DEPT = this.queryObj.dept;
    }
    this.queryObj.ids = JSON.parse(this.queryObj.ids);
    if (this.queryObj.ids) {
      this.ids = this.queryObj.ids;
      if (this.ids.length > 1) {
        this.idsType = 1;
      } else {
        this.idsType = 2;
      }
    }
    if (this.queryObj.speNum) {
      this.speNum = this.queryObj.speNum;
    } else {
      this.speNum = uni.getStorageSync("speNum");
      this.speNum = Number(this.speNum);
    }
    this.DEPTCode = this.queryObj.deptCode;
    this.type = this.queryObj.type;
    // #ifdef APP-PLUS
    webHandle("no", "app");
    // #endif
    // #ifdef H5
    webHandle("no", "wx");
    // #endif
  },
};
</script>
<style lang="less">
.Scanning_djInfo {
  padding: 0 74rpx;

  .Scanning_top {
    height: 270rpx;

    .red {
      background-color: #ff3b53 !important;
    }

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

    .btn1,
    .btn2,
    .btn3 {
      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>
