<template>
  <view class="bloodDetails">
    <view class="Scanning_top">
      <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="page_item_wrap">
      <view class="page_item">
        <view class="page_item_top">
          <view class="page_item_top-inner">
            <view class="page_item_top_L">
              <text class="L_text">血袋号：{{ bloodDTO.bloodCode||'无' }}</text>
            </view>
            <view class="page_item_top_R">
              <text class="L_iocn"></text>
            </view>
          </view>
        </view>
        <view class="page_item_cont">
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>血液类型</text>
              <text class="text_big">
                <text>
                  {{bloodDTO.type ? bloodDTO.type.name : "无"}}
                </text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>血量</text>
              <text class="text_big">
                <text>{{ bloodDTO.volume?bloodDTO.volume+'ML':'无' }}</text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>采血日期</text>
              <text class="text_big">
                <text v-if="bloodDTO.printDate">{{bloodDTO.printDate | formatDate('yyyy-MM-dd hh:mm')}}</text>
                <text v-else>无</text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>有效期至</text>
              <text class="text_big">
                <text v-if="bloodDTO.overDate">{{bloodDTO.overDate | formatDate('yyyy-MM-dd hh:mm')}}</text>
                <text v-else>无</text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>血型</text>
              <text class="text_big">
                <text>{{ bloodDTO.aboType||'无' }}</text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>RH(D)</text>
              <text class="text_big">{{bloodDTO.rhType || '无'}}</text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>患者</text>
              <text class="text_big">
                <text>{{ bloodDTO.patientName }}<text v-if="bloodDTO.hosNum">({{ bloodDTO.hosNum }})</text></text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>申请科室</text>
              <text class="text_big">
                <text>{{ bloodDTO.applyDeptDTO?bloodDTO.applyDeptDTO.dept:'无' }}</text>
              </text>
            </view>
          </view>
        </view>
        <view class="L"></view>
        <view class="R"></view>
      </view>
      <view class="L-l"></view>
      <view class="R-l"></view>
    </view>
    <view class="cube-toolbar-item-wrap" v-show="bloodDTO.id">
      <button class="cube-toolbar-item" v-show="orderId && receiveOrder" @click="receiveOrderAndSign()">
        接单并签到
      </button>
      <button class="cube-toolbar-item" v-show="!orderId && buildOrder" @click="buildOrderAndSign()">
        建单并签到
      </button>
      <button class="cube-toolbar-item" @click="goBack()">
        知道了
      </button>
    </view>
  </view>
</template>
<script>
  import {
    webHandle,
    post
  } from "../../http/http.js";
  export default {
    data() {
      return {
        receiveOrder: false,
        buildOrder: false,
        bloodDTO: {}, //血制品信息
        taskTypeConfig: {}, //血制品配置信息
        orderId:'',//工单id
        gotoFlag: true,
      };
    },
    methods: {
      goBack() {
        uni.navigateTo({
          url: "../receiptpage/receiptpage",
        });
      },
      // 接单并签到
      receiveOrderAndSign() {
        if (!this.gotoFlag) {
          return;
        }
        this.gotoFlag = false;
        uni.showModal({
          title: "提示",
          content: "请确认是否接单并签到？",
          success: (result) => {
            if (result.confirm) {
              console.log("用户点击确定");
              let postData = {
                type: 'blood',
                id: this.bloodDTO.id,
                orderId: this.orderId
              };
              uni.showLoading({
                title: "加载中",
                mask: true,
              });
              post("/transflow/createOrTakeOrder", postData).then((ress) => {
                uni.hideLoading();
                if (ress.state == 200) {
                  uni.navigateTo({
                    url: `../scanning_blood_process/scanning_blood_process?orderId=${ress.data.orderId}&bloodDTO=${encodeURIComponent(JSON.stringify(this.bloodDTO))}&scanCount=${ress.data.scanCount}&status=${ress.state}`,
                  });
                } else {
                  uni.showToast({
                    icon: "none",
                    title: "请求失败！",
                  });
                }
              });
            } else if (result.cancel) {
              console.log("用户点击取消");
            }
          },
        });
      },
      // 建单并签到
      buildOrderAndSign() {
        if (!this.gotoFlag) {
          return;
        }
        this.gotoFlag = false;
        uni.showModal({
          title: "提示",
          content: "请确认是否建单并签到？",
          success: (result) => {
            if (result.confirm) {
              console.log("用户点击确定");
              let postData = {
                type: 'blood',
                id: this.bloodDTO.id,
              };
              uni.showLoading({
                title: "加载中",
                mask: true,
              });
              post("/transflow/createOrTakeOrder", postData).then((ress) => {
                uni.hideLoading();
                if (ress.state == 200) {
                  uni.navigateTo({
                    url: `../scanning_blood_process/scanning_blood_process?orderId=${ress.data.orderId}&bloodDTO=${encodeURIComponent(JSON.stringify(this.bloodDTO))}&scanCount=${ress.data.scanCount}&status=${ress.state}`,
                  });
                } else {
                  uni.showToast({
                    icon: "none",
                    title: "请求失败！",
                  });
                }
              });
            } else if (result.cancel) {
              console.log("用户点击取消");
            }
          },
        });
      },
      //获取血制品信息及其关联的工单信息
      scanInfo(qrcode) {
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        post("/common/common/getDictionary", {"type":"list","key":"ttconfig_sign_type"}).then((res1) => {
          post("/transflow/scanInfo", {
            type: 'blood',
            code: qrcode,
          }).then((res) => {
            uni.hideLoading();
            if (res.state == 200) {
              this.bloodDTO = res.data.dto || {};
              this.orderId = res.data.orderId;
              console.log(this.orderId);
              this.taskTypeConfig = res.data.taskTypeConfig;
              let sign_ids = this.taskTypeConfig.signTypeIds?this.taskTypeConfig.signTypeIds.split(','):[];
              console.log(sign_ids);
              this.receiveOrder = false;
              this.buildOrder = false;
              sign_ids.forEach(v => {
                let obj = res1.find(vv => vv.id == v);
                console.log(obj);
                if(obj && obj.value == 1){
                  this.receiveOrder = true;
                }
                if(obj && obj.value == 2){
                  this.buildOrder = true;
                }
              })
            } else {
              uni.showToast({
                icon: "none",
                title: "请求失败",
              });
            }
          });
        });
      },
    },
    onShow() {
      this.gotoFlag = true;
    },
    onLoad(options) {
      console.log(options);
      let {
        qrcode
      } = options;
      if (qrcode) {
        this.scanInfo(qrcode);
      }
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less" scoped>
  .bloodDetails {
    background-color: rgb(249, 250, 251);
    .Scanning_top {
    
      .Scanning_top_icon {
        width: 140rpx;
        height: 140rpx;
        margin: 0 auto;
        border-radius: 50%;
        line-height: 140rpx;
        text-align: center;
    
        .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;
        }
      }
    }

    .page_item_wrap {
      position: relative;
      margin-top: 32rpx;

      .page_item {
        margin-top: 16rpx;
        margin-bottom: 124rpx;
        background: #fff;
        border-radius: 8rpx;
        margin: 0 20rpx;
        border: 2rpx solid #e5e9ed;
        position: relative;
        overflow: hidden;
        padding: 0 16rpx;

        .L {
          width: 40rpx;
          height: 40rpx;
          border-radius: 50%;
          background: #f9fafb;
          position: absolute;
          left: -20rpx;
          top: 68rpx;
          border: 2rpx solid #e5e9ed;
        }

        .R {
          width: 40rpx;
          height: 40rpx;
          border-radius: 50%;
          background: #f9fafb;
          position: absolute;
          float: right;
          right: -20rpx;
          top: 68rpx;
          border: 2rpx solid #e5e9ed;
        }

        .page_item_top {
          height: 88rpx;
          border-bottom: 2rpx dashed #e5e9ed;
          padding: 0 16rpx;

          .page_item_top-inner {
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 100%;

            .page_item_top_L {
              .L_text {
                font-size: 32rpx;
                font-weight: 700;
              }
            }

            .page_item_top_R {
              font-size: 32rpx;

              .L_iocn {
                color: rgb(7, 134, 60);
                font-size: 36rpx;
                font-weight: 700;
              }
            }
          }
        }

        .page_item_cont {
          min-height: 180rpx;
          padding: 0 16rpx;
          text-align: left;
          position: relative;

          .text_big {
            width: 50%;
            text-align: right;
            font-size: 32rpx;
            font-weight: 700;

            text {
              font-weight: 700;
              line-height: 1.5;
            }
          }

          .line {
            height: 20rpx;
            width: 2rpx;
            border-left: 2rpx solid #e5e9ed;
            position: absolute;
            top: 82rpx;
            left: 40rpx;
          }

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

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

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

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

          .page_item_cont_C {
            margin-bottom: 28rpx;

            .page_item_cont_title_C {
              font-size: 32rpx;
              display: flex;
              justify-content: space-between;
              align-items: center;
              &>text{
                flex-shrink: 0;
              }
            }
          }

          #infos {
            display: none;
          }
        }
      }

      .L-l {
        width: 2rpx;
        height: 40rpx;
        background: #f9fafb;
        position: absolute;
        left: 20rpx;
        top: 72rpx;
      }

      .R-l {
        width: 2rpx;
        height: 40rpx;
        background: #f9fafb;
        position: absolute;
        right: 20rpx;
        top: 72rpx;
      }
    }

    .cube-toolbar-item-wrap {
      display: flex;
      position: fixed;
      left: 0;
      bottom: 20rpx;
      width: 100%;
      .cube-toolbar-item {
        flex: 1;
        margin: 0 18rpx;
        height: 68rpx;
        line-height: 68rpx;
        border-radius: 8rpx;
        background: linear-gradient(to right, #72c172, #3bb197);
        font-size: 36rpx;
        color: #fff;
        text-align: center;
      }
    }

    .btn-wrap {
      display: flex;
      justify-content: space-between;
      position: fixed;
      left: 20rpx;
      bottom: 160rpx;
    }

    .cube-toolbar-item1 {
      width: 350rpx;
      height: 68rpx;
      line-height: 68rpx;
      border-radius: 8rpx;
      margin: 0 5rpx;
      background: linear-gradient(to right, #72c172, #3bb197);
      font-size: 36rpx;
      color: #fff;
      text-align: center;
    }
  }
</style>
