<template>
  <!-- 盒条件-获取一维码 -->
  <div id="qualitytesting">
    <!-- 导航条  -->
    <van-nav-bar
      title="获取一维码"
      left-arrow
      @click-left="onClickLeft"
      z-index="1"
      id="topDiv"
    />
    <div class="list">
      <h6 class="mesTitle">获取码信息</h6>
      <van-row class="listTab">
        <van-col class="tabTitle" span="6">一维码</van-col>
        <van-col class="tabValue" span="18">{{ obj.piece_codes[0].piece_1d_code }}</van-col>
        <van-col class="tabTitle code" span="6">二维码</van-col>
        <van-col class="tabValue code" span="18">{{ obj.piece_codes[0].piece_2d_code }}</van-col>
      </van-row>
    </div>
    <div class="twobtn">
      <div class="btnassociated" id="btnassociated" v-on:click="unbundlingbtn">返回</div>
    </div>
  </div>
</template>
  
  <script>
import { getPieceDetails } from "@/api/qrcode/oneCode/index";
import {
  Search,
  Button,
  NavBar,
  Empty,
  Card,
  Cell,
  CellGroup,
  Col,
  Row,
  Notify
} from "vant";
import { ref, watch } from "vue";
import ScanOverlay from "@/components/overlay/scanOverlay/ScanOverlay";
import {getStringByTwo} from "@/utils/transition";

export default {
  name: "qualitytesting",
  components: {
    [Search.name]: Search,
    [Button.name]: Button,
    [NavBar.name]: NavBar,
    [Empty.name]: Empty,
    [Card.name]: Card,
    [Cell.name]: Cell,
    [Col.name]: Col,
    [Row.name]: Row,
    [CellGroup.name]: CellGroup,
    [Notify.name]: Notify,
  },

  setup() {
    return {
      getPieceDetails,
    };
  },
  data() {
    return {
      listHeight: 0,
      obj: {
        apply_id: "",
        piece_codes:[{
          piece_1d_code:"",
          piece_2d_code:""
        }],
      },
    };
  },
  mounted() {
    this.initHeight();
    this.$nativeQRCode.setCallBackFun((res) => {
      let qrCode = getStringByTwo(res)
      this.onScanQrCode(qrCode);
    });
    ScanOverlay.show('请扫描二维码')
    // this.onScanQrCode("HTTPS://T2DC.CN/99.1000.1/AC30154602037000169010280752752202312180844460107B00223301040003R2OH8ENHB3QYXX3")
  },
  methods: {
    // 返回
    unbundlingbtn(){
      window.history.go(-1);
    },
    // 获取一二维码信息
    onScanQrCode(data) {
      let arr = {piece_2d_codes:[
          data
        ]}
      getPieceDetails(arr).then((res) => {
        if(res.code=='200'){
          this.obj = res.data
            Notify({type: "success", message: "获取成功！！", duration: 1500});
        }else{
            Notify({type: 'danger', message: "获取失败！！", duration: 1500});
        }
      });
    },
    // 屏幕高度
    initHeight() {
      this.$nextTick(() => {
        // 屏幕高度
        let windowH = document.documentElement.clientHeight;
        // 顶部内容区域高度
        let topDivH = document.getElementById("topDiv").offsetHeight;
        this.listHeight = windowH - topDivH - 46;
      });
    },
    // 点击返回
    onClickLeft() {
      window.history.go(-1);
    },
  },
};
</script>
  
  <style scoped>
.list {
  margin-left: 20px;
  width: 660px;
  height: 360px;
  background: #ffffff;
  border-radius: 10px;
  padding: 10px;
  margin-top: 20px;
}
.mesTitle {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
}
.code{
  border: 1px solid #f1f1f1;
  height: 2.0rem !important;
  line-height: 0.5rem !important;
  padding-left: 0.13889rem;
  word-break: break-all;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-family: "SourceHanSansCN-Medium",sans-serif;
  border-bottom: 0.01389rem solid #d8d8d8;
}
.tabValue {
  font-family: Source Han Sans CN,sans-serif;
  font-weight: 400;
  font-size: 22px;
  color: #434343;
}
.tabTitle {
  font-family: Source Han Sans CN,sans-serif;
  font-weight: 500;
  font-size: 22px;
  color: #000000;
}
.twobtn {
    text-align: center;
    position: fixed;
    width: 100%;
    display: flex;
    justify-content: space-around;
    box-sizing: border-box;
    bottom: 0px;
    background-color: white;
    height: 90px;
    padding-top: 15px;
    padding-bottom: 15px;
}
.btnassociated {
    bottom: 10px;
    background: linear-gradient(-90deg, rgba(0, 105, 83, 1), rgba(33, 143, 120, 0.6));
    width: 40%;
    height: 65px;
    line-height: 65px;
    border-radius: 30px;
    color: rgba(255, 255, 255, 1);
    font-size: 26px;
}
.tabValue,
.tabTitle {
  border: 1px solid #f1f1f1;
  height: 1.2rem;
  line-height: 0.5rem;
  padding-left: 0.13889rem;
  font-family: "SourceHanSansCN-Medium",sans-serif;
  border-bottom: 0.01389rem solid #d8d8d8;
  display: flex;
  flex-direction: column;
justify-content: center;
  word-break: break-all;
}
.listTab {
  margin-top: 30px;
}
</style>
  