<template>
  <view class="pharmacyDetails" v-show="nucleicAcidDto.batchNo">
    <view class="pharmacyDetails_title">核酸信息</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">批次号：{{ nucleicAcidDto.batchNo||'-' }}</text>
            </view>
            <view class="page_item_top_R">
              <text class="L_iocn">{{
                nucleicAcidDto.state == 1 ? "已闭环" : "未闭环"
              }}</text>
            </view>
          </view>
        </view>
        <view class="page_item_cont">
          <view class="page_item_cont_B">
            <view class="page_item_cont_title">
              <text>楼栋名称</text>
              <text class="text_big">
                <text>
                  {{nucleicAcidDto.BuildName || "-"}}
                </text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text>工单总数</text>
              <text class="text_big">
                <text>{{ nucleicAcidDto.orderCount||'-' }}</text>
              </text>
            </view>
          </view>
          <view class="page_item_cont_C">
            <view class="page_item_cont_title_C">
              <text style="flex: 1;flex-shrink: 0;">起点科室</text>
              <text class="text_big" style="flex: 1;text-align:justify;overflow:hidden;">
                <text style="float:right;">{{
                  nucleicAcidDto.deptNames ? nucleicAcidDto.deptNames.toString() : "-"
                }}</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="foot_btn">
      <view class="btn3" v-if="nucleicAcidDto.state == 0" @click="closedLoop()">闭环工单</view>
      <view class="btn3" @click="goBack()">返回</view>
    </view>
    <!-- 弹窗 -->
    <nucleicAcidCollection v-if="changeSpeModels.disjunctor" :title="changeSpeModels.title" :content="changeSpeModels.content"
      :disjunctor="changeSpeModels.disjunctor" @ok="changeSpeOk" @cancel="changeSpeCancel">
    </nucleicAcidCollection>
  </view>
</template>
<script>
  import {
    webHandle,
    post
  } from "../../http/http.js";
  export default {
    data() {
      return {
        options:{},
        // 弹窗
        changeSpeModels: {
          disjunctor: false,
        },
        nucleicAcidDto: {}, //核酸信息
        gotoFlag: true,
      };
    },
    methods: {
      // 闭环工单 - 确定
      changeSpeOk(data) {
        console.log(data);
        const pathUrl = uni.getStorageSync("path");
        const {
          reason,
          imageValue
        } = data;
        this.changeSpeModels.disjunctor = false;
        uni.showLoading({
          mask: true,
          title: "加载中",
        });
        let postData = {
          qrcode: this.options.qrcode,
          remark: reason,
        };
        post("/api/closedLoopNucleicAcid", postData).then((res) => {
          this.gotoFlag = true;
          if (res.status == 200) {
            console.log(imageValue);
            if (!imageValue.length) {
              uni.hideLoading();
              uni.navigateTo({
                url: "../receiptpage/receiptpage",
              });
              return;
            }
            let n = 0;
            imageValue.forEach((v) => {
              // 图片上传 start
              console.log("压缩前");
              let canvasWidth = v.image.width; //图片原始长宽
              let canvasHeight = v.image.height;
              let img = new Image();
              img.src = v.path;
              let canvas = document.createElement("canvas");
              let ctx = canvas.getContext("2d");
              canvas.width = canvasWidth;
              canvas.height = canvasHeight;
              ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);
              canvas.toBlob(
                (fileSrc) => {
                  let tp = window.URL.createObjectURL(fileSrc);
                  console.log("压缩后");
                  n++;
                  uni.uploadFile({
                    url: pathUrl +
                      "/common/common/uploadAttachment/nucleicAcidPhotos/" +
                      res.nucleicAcidId +
                      "/666",
                    filePath: tp,
                    name: "file",
                    formData: {
                      filename: v.name,
                    },
                    success: (uploadFileRes) => {
                      console.log(uploadFileRes);
                      if (--n === 0) {
                        uni.hideLoading();
                        uni.navigateTo({
                          url: "../receiptpage/receiptpage",
                        });
                      }
                    },
                    fail: (err) => {
                      n--;
                      console.error(err);
                      uni.hideLoading();
                      uni.showToast({
                        icon: "none",
                        title: "上传失败",
                        duration: 2000,
                      });
                    },
                  });
                },
                "image/jpeg",
                0.3
              );
              // 图片上传 end
            });
          } else {
            uni.hideLoading();
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        });
      },
      // 闭环工单-取消
      changeSpeCancel() {
        this.gotoFlag = true;
        this.changeSpeModels.disjunctor = false;
      },
      goBack() {
        uni.navigateTo({
          url: "../receiptpage/receiptpage",
        });
      },
      // 闭环工单
      closedLoop() {
        if (!this.gotoFlag) {
          return;
        }
        this.gotoFlag = false;
        this.changeSpeModels = {
          title: "提示",
          content: `您确定要闭环${this.nucleicAcidDto.BuildName}的关联工单吗，您可填写备注和图片`,
          disjunctor: true,
        };
      },
      //获取信息
      showNucleicAcid(qrcode) {
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        post("/api/showNucleicAcid", {
          code:qrcode,
        }).then((res) => {
          uni.hideLoading();
          if (res.status == 200) {
            this.nucleicAcidDto = res || {};
            console.log(this.nucleicAcidDto)
          } else {
            uni.showToast({
              icon: "none",
              title: res.msg || "接口获取数据失败！",
            });
          }
        });
      },
    },
    onShow() {
      this.gotoFlag = true;
    },
    onLoad(options) {
      console.log(options);
      this.options = options;
      let { qrcode } = options;
      qrcode && this.showNucleicAcid(qrcode);
      // #ifdef APP-PLUS
      webHandle("no", "app");
      // #endif
      // #ifdef H5
      webHandle("no", "wx");
      // #endif
    },
  };
</script>
<style lang="less" scoped>
  .pharmacyDetails {
    background-color: rgb(249, 250, 251);
    padding-top: 10%;
    margin-bottom: 100rpx;

    .pharmacyDetails_title {
      font-size: 46rpx;
      font-weight: 550;
      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;
          // max-height: 424rpx;
          padding: 0 16rpx;
          text-align: left;
          position: relative;

          .text_big {
            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;
            }
          }

          #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 {
      width: 710rpx;
      height: 68rpx;
      line-height: 68rpx;
      position: fixed;
      left: 20rpx;
      bottom: 160rpx;
      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;
    }
    .foot_btn {
      background-color: #fff;
      position: fixed;
      bottom: 0;
      width: 100%;
      line-height: 88rpx;
      height: 100rpx;
      margin: 40rpx 16rpx 0;
      display: flex;
      justify-content: center;

      .btn3 {
        flex: 1;
        height: 88rpx;
        background-image: linear-gradient(to right, #72c172, #3bb197);
        color: #fff;
        border-radius: 8rpx;
        font-size: 32rpx;
        margin-top: 16rpx;
        margin-right: 16rpx;
        text-align: center;

        &:last-of-type {
          margin-right: 0;
        }
      }
    }
  }
</style>
