<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">
          <template v-if="taskTypeConfig.speExpandTube == 1">
            <uni-collapse :border="false">
              <uni-collapse-item titleBorder="none" :open="taskTypeConfig.speDefaultExpandTube == 1">
                <template v-slot:title>
                  <view class="page_item_cont_title_coll">
                    <view>{{item.deptName}}</view>
                    <view class="text_big" style="padding-right: 20rpx;" @click.stop="goToSpeDetail(item.deptName,item.deptQrCode)"><text class="underline">{{item.speCount}}</text>只</view>
                  </view>
                </template>
                <view class="content">
                  <view class="list" v-for="x in item.tubeTypeData" :key="x.id" @click="viewSpe(item.deptName,item.deptQrCode,x.tubeTypeId)">
                    {{x.tubeTypeName}}：<text class="underline-item">{{x.speCount}}</text>
                  </view>
                </view>
              </uni-collapse-item>
            </uni-collapse>
          </template>
          <template v-else>
            <view class="page_item_cont_title_coll" style="width: 100%;">
            	<view>{{item.deptName}}</view>
            	<view class="text_big" @click.stop="goToSpeDetail(item.deptName,item.deptQrCode)"><text class="underline">{{item.speCount}}</text>只</view>
            </view>
          </template>
        </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 {
        hosId: uni.getStorageSync('userData').user.currentHospital.id,
        taskTypeConfig: {},
        // 弹窗model
        models: {
          disjunctor: false,
        },
        // 填写交接人工号弹窗model
        hosModels: {
          disjunctor: false,
        },
        info: {},
        queryObj: {}, //路由传递过来的数据
      };
    },
    methods: {
      // 获取配置
			getSpecimenTaskTypeConfig(){
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        post("/simple/data/fetchDataList/taskTypeConfig", {
          "idx": 0,
          "sum": 1,
          "taskTypeConfig": {
            "taskTypeDTO": {
              "hosId": {
                  "id": this.hosId
              },
              "associationType": {
                  "key": "association_types",
                  "value": "specimen"
              }
            }
          }
        }).then((result) => {
          uni.hideLoading();
          if (result.status == 200) {
            if(result.list.length){
              this.taskTypeConfig = result.list[0] || {};
            }else{
              uni.showToast({
                icon: "none",
                title: "请配置标本配送任务类型！",
              });
            }
          } else {
            uni.showToast({
              icon: "none",
              title: result.msg || "接口获取数据失败！",
            });
          }
        });
      },
			viewSpe(deptName, qrCode, id){
				uni.navigateTo({
				  url: `../viewSpe/viewSpe?deptName=${deptName}&workOrderId=${this.queryObj.ids}&deptCode=${qrCode}&tubeTypeId=${id}&isScan=1&specimensCheck=1&noScan=1`,
				});
			},
      // 填写交接人工号-确认
      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);
      this.getSpecimenTaskTypeConfig();
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less" scoped>
	/deep/ .uni-collapse-item--border{
		border-bottom-color: #fff !important;
	}

	/deep/ .uni-collapse-item__title-arrow{
		margin-right: 0 !important;
	}
  .checkAfterScanning {
    .checkAfterScanning_title {
      padding: 50rpx 0;
      font-size: 46rpx;
      font-weight: 550;
      text-align: center;
      // border-bottom: 1px solid #ccc;
    }

    .page_item_cont {
      height: 73vh;
      overflow-y: auto;
      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;
        }
      }

			.underline-item{
				// text-decoration: underline;
				// margin-right: 40rpx;
			}

      .page_item_cont_T {
        padding-top: 28rpx;
        padding-bottom: 28rpx;
        font-size: 28rpx;
        background: #fff;
        border: 1px solid #CBCBCB;
        border-radius: 10rpx;
        padding: 20rpx;

        .page_item_cont_title {
          height: 100%;
          font-size: 32rpx;
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-top: 10rpx;
					.content{
						display: flex;
						flex-wrap: wrap;
						.list{
							font-size: 28rpx;
							height: 60rpx;
							line-height: 60rpx;
							width: 50%;
							border-bottom: 1rpx solid #E6E6E6;
						}
					}
        }

        .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_title_coll{
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-right: 8rpx;
			}

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