<template>
  <view class="checkAfterScanning">
    <view class="checkAfterScanning_title">标本核对</view>
    <view class="page_item_cont">
      <view class="page_item_cont_T">
        <view class="page_item_cont_title">
          <view> 工单数量 </view>
          <view class="text_big">{{info.gdNum}}</view>
        </view>
        <view class="page_item_cont_title">
          <view> 标本总数 </view>
          <view class="text_big" @click="goToSpeDetail()"><text class="underline">{{info.total}}</text>只</view>
        </view>
        <view class="page_item_cont_title">
          <view class="text_title"> 临床科室 </view>
          <view class="text_big">{{info.LCDept}}</view>
        </view>
        <view class="page_item_cont_title2">
          检验科室标本数量:
        </view>
        <view class="page_item_cont_title" v-for="(item, i) in info.data" :key="i">
          <view>{{item[1]}}</view>
          <view class="text_big" @click="goToSpeDetail(item[1],item[2])"><text class="underline">{{item[3]}}</text>只
          </view>
        </view>
      </view>
    </view>
    <view class="foot_btn_spe">
      <view class="btn1" @click="allStart()">核对完成</view>
      <view class="btn3" @click="goBack">取消</view>
    </view>
    <!-- 填写交接人工号弹窗 -->
    <selectAccount v-if="hosModels.disjunctor" :disjunctor="hosModels.disjunctor" @ok="hosOk"
      @cancel="hosCancel">
    </selectAccount>
    <!-- 弹窗 -->
    <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 {
    get,
    post,
    SM,
    webHandle
  } from "../../http/http.js";
  export default {
    data() {
      return {
        // 弹窗model
        models: {
          disjunctor: false,
        },
        // 填写交接人工号弹窗model
        hosModels: {
          disjunctor: false,
        },
        info: {},
        queryObj: {}, //路由传递过来的数据
      };
    },
    methods: {
      // 填写交接人工号-确认
      hosOk(data) {
        console.log(data);
        const {
          accountName,
          account,
          accountId
        } = data;
        if (!accountName && !account) {
          //没有填写交接人
          uni.showModal({
            title: "提示",
            content: "请填写交接人工号!",
            showCancel: false,
            success: function(res) {
              if (res.confirm) {
                console.log("用户点击确定");
              } else if (res.cancel) {
                console.log("用户点击取消");
              }
            },
          });
          return;
        } else if ((!accountName && account) || (accountName && !account)) {
          //没有填写交接人
          uni.showModal({
            title: "提示",
            content: "请填写正确的交接人工号!",
            showCancel: false,
            success: function(res) {
              if (res.confirm) {
                console.log("用户点击确定");
              } else if (res.cancel) {
                console.log("用户点击取消");
              }
            },
          });
          return;
        }
        this.hosModels.disjunctor = false;
        this.orderDeptHandler(false, data);
      },
      // 填写交接人工号-取消
      hosCancel() {
        this.hosModels.disjunctor = false;
      },
      // 填写交接人工号弹窗
      showSelectAccount() {
        this.hosModels = {
          disjunctor: true,
        };
      },
      // 获取核对信息
      getInfo(gdIds) {
        gdIds = JSON.parse(gdIds).toString();
        uni.showLoading({
          title: '加载中',
          mask: true
        });
        let postData = {
          gdIds,
        };
        post("/api/specimensCheck", postData).then((res) => {
          uni.hideLoading();
          if (res.status == 200) {
            console.log(res)
            res.LCDept = res.LCDept.join(',');
            this.info = res;
          } else {
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败!",
            });
          }
        })
      },
      // 取消
      goBack() {
        uni.navigateTo({
          url: "../receiptpage/receiptpage",
        });
      },
      // 跳转到已扫描标本详情页
      goToSpeDetail(deptName='', qrCode='') {
        uni.navigateTo({
          url: `../noScanSpecimen/noScanSpecimen?deptName=${deptName}&workOrderId=${this.queryObj.ids}&deptCode=${qrCode}&isScan=1&specimensCheck=1&noScan=1`,
        });
      },
      ok(){
        this.models.disjunctor = false;
        this.orderDeptHandler(true);
      },
      // 取消
      cancel() {
        this.models.disjunctor = false;
      },
      //核对完成
      allStart() {
        this.models = {
          disjunctor: true,
          title: "提示",
          content: "是否确定标本已核对完成?",
          icon: "warn",
          operate: {
            ok: "确定",
            cancel: "取消",
          },
        };
      },
      //科室签到
      //bigScanner----判断是否需要交接人
      //accountObj----弹窗填写的交接人信息
      orderDeptHandler(bigScanner, accountObj) {
        let type = "orderSign/" + this.queryObj.code;
        let list = {
          ids: JSON.parse(this.queryObj.ids),
        };
        bigScanner && (list.bigScanner = ['666']);
        if (accountObj) {
          list.handover = [accountObj.accountId];
        }
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        post("/workerOrder/" + type, list).then((res) => {
          uni.hideLoading();
          if (res.status == 200) {
            uni.navigateTo({
              url: "../receiptpage/receiptpage",
            });
            uni.showToast({
            	title: '工单完成!',
              icon: 'success',
            	duration: 3000,
            });
          } else if (res.status == "0000") {
            this.showSelectAccount();
          } else {
            this.flag = true;
            uni.navigateTo({
              url: `../scanning_djEnd/scanning_djEnd?type=specimen&type1=${
              res.type
            }&code=${this.queryObj.code}&dept=${res.dept}&ids=${this.queryObj.ids}&model=${encodeURIComponent(JSON.stringify(res))}&deptId=${res.deptId}`,
            });
          }
        });
      },
    },
    onLoad(options) {
      console.log(options);
      this.queryObj = options;
      this.getInfo(this.queryObj.ids);
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less" scoped>
  .checkAfterScanning {
    .checkAfterScanning_title {
      padding: 50rpx 0;
      font-size: 46rpx;
      font-weight: 550;
      text-align: center;
      border-bottom: 1px solid #ccc;
    }

    .page_item_cont {
      min-height: 90rpx;
      padding: 0 20rpx;
      text-align: left;
      position: relative;
      
      .text_title{
        flex-shrink: 0;
        margin-right: 16rpx;
      }

      .text_big {
        font-size: 32rpx;
        font-weight: 700;
        margin-top: 10rpx;

        .underline {
          text-decoration: underline;
        }
      }

      .page_item_cont_T {
        padding-top: 28rpx;
        padding-bottom: 28rpx;
        font-size: 28rpx;

        .page_item_cont_title {
          height: 100%;
          font-size: 32rpx;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }

        .page_item_cont_title2 {
          margin-top: 36rpx;
          margin-bottom: 18rpx;
          height: 100%;
          font-size: 32rpx;
          font-weight: bold;
          display: flex;
          align-items: center;
        }
      }

      .page_item_cont_B {
        padding-top: 28rpx;
        margin-bottom: 28rpx;

        .page_item_cont_title {
          font-size: 32rpx;
          display: flex;
          justify-content: space-between;
        }

        .page_item_cont_title1 {
          height: 60rpx;
          line-height: 60rpx;
          font-size: 32rpx;
          padding-left: 64rpx;
        }
      }
    }

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

      .btn1,
      .btn2,
      .btn3 {
        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;
        text-align: center;
      }
    }

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