<style lang="scss" scoped>
// 盒条件-卷烟二维码查询
@import "/public/assets/css/styles.scss";

* {
  margin: 0;
  padding: 0;
}

.icon-gantanhao {
  font-size: 45px;
}


.text-container {
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 强制在单词边界内换行 */
  word-break: break-all; /* 在需要时打破单词进行换行 */
  cursor: pointer; /* 显示手势指针 */
  max-width: 100%; /* 限制最大宽度，确保不遮挡其他元素 */
  overflow-wrap: break-word; /* 兼容性样式，强制换行 */
}

.full-width {
  margin-top: 5px; /* 上边距 */
}

.long-text-container {
  font-size: 30px;
  padding: 10px; /* 内边距 */
  border: 1px solid #ddd; /* 边框 */
  border-radius: 4px; /* 圆角边框 */
  background-color: #f9f9f9; /* 背景色 */
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 强制在单词边界内换行 */
  overflow-wrap: break-word; /* 兼容性样式，强制换行 */
}

:deep(.van-col) {
  padding: 0 10px; /* 添加一些内边距 */
  margin-top: 25px; /* 每个列的上边距 */
}

/* 可选：加上复制按钮样式 */
.copy-button {
  position: absolute;
  right: 10px; /* 右边距离 */
  top: 50%; /* 垂直居中 */
  transform: translateY(-50%); /* 垂直居中 */
}

.verifyname {
  width: 680px;
  margin: 30px auto;
  background-color: rgb(255, 255, 255);
}

.van-cell {
  height: 100px;
  line-height: 100px;
  font-size: 26px;
  padding-left: 20px;
  padding-right: 20px;
  font-weight: 500;
}

.van-cell:after {
  border-bottom: 2px solid #e7e7e7ff;
}

:deep(.van-tab__text) {
  font-size: 26px;
  height: 100%;
  line-height: 45px;
}

:deep(.van-tabs__line) {
  background: none;
  background-color: rgba(0, 105, 83, 1);
  width: 80px;
}

:deep(.van-tab__panel .wrap) {
  height: 300px;
  overflow: scroll;
}

:deep(.van-tab__panel p) {
  word-break: break-word;
  font-size: 20px;
  padding: 10px;
}

.van-hairline--top-bottom:after,
.van-hairline-unset--top-bottom:after {
  border-width: 0 0;
}


.orderNotarizeList {
  overflow-y: auto; /* 启用垂直滚动 */
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 2;
  display: flex;
  padding-top: .8rem;
  justify-content: center;
}

.orderNotarizeList > div#scan {
  overflow-y: auto; /* 允许内容滚动 */
  width: 93%;
  height: 30%;
  background: #ffffff;
  border-radius: 10px;
  font-size: 24px;
  font-family: "SourceHanSansCN-Medium",sans-serif;
}

.orderNotarizeList > div#dispose {
  overflow-y: auto; /* 允许内容滚动 */
  width: 93%;
  height: 50%;
  background: #ffffff;
  border-radius: 10px;
}

.orderNotarizeList > div {
  overflow-y: auto; /* 允许内容滚动 */
  width: 93%;
  height: 95%;
  background: #ffffff;
  border-radius: 10px;
}

.orderNotarizeList h4 {
  overflow-y: auto; /* 允许内容滚动 */
  font-size: 32px;
  font-family: "SourceHanSansCN-Medium",sans-serif;
  font-weight: 500;
  color: #000000;
  text-align: center;
  margin-top: 50px;
  margin-bottom: 20px;
}

.orderNotarizeList h6 {
  overflow-y: auto; /* 允许内容滚动 */
  border-bottom: 3px #939393 solid;
  text-align: left;
  margin-bottom: 7px;
  margin-top: 10px;
  padding: 7px;
  font-size: 30px;
  color: black;
  font-weight: 500;
  font-family: "SourceHanSansCN-Medium",sans-serif;
}

.orderNotarizeList h5 {
  overflow-y: auto; /* 允许内容滚动 */
  margin-top: 15px;
  font-size: 24px;
  font-family: "SourceHanSansCN-Medium",sans-serif;
  font-weight: 500;
  color: #000000;
  text-align: center;
}


.listname#errorList {
  height: 300px;
  overflow: scroll;
  margin-top: 10px;
}


.confirmBtnBox {
  display: flex;
}

.confirmBtn {
  width: 40%;
  height: 70px;
  line-height: 70px;
  margin: auto;
  text-align: center;
  margin-top: 40px;
  font-size: 22px;
  font-family: Source Han Sans CN,sans-serif;
  font-weight: 500;
  color: #ffffff;
  background: linear-gradient(
          -90deg,
          rgba(33, 143, 120, 1),
          rgba(120, 202, 185, 1)
  );
  border-radius: 33px;
}

.confirmBtnRed {
  width: 40%;
  height: 70px;
  line-height: 70px;
  margin: auto;
  text-align: center;
  margin-top: 40px;
  font-size: 22px;
  font-family: Source Han Sans CN,sans-serif;
  font-weight: 500;
  color: #ffffff;
  background: linear-gradient(-90deg, rgb(252, 20, 20), rgb(239, 123, 123));
  border-radius: 33px;
}

.confirmBtnGray {
  width: 40%;
  height: 70px;
  line-height: 70px;
  margin: auto;
  text-align: center;
  margin-top: 40px;
  font-size: 22px;
  font-family: Source Han Sans CN,sans-serif;
  font-weight: 500;
  color: #ffffff;
  background: linear-gradient(-90deg, rgb(103, 112, 110), rgb(200, 208, 206));
  border-radius: 33px;
}


.cardlist_four_btn {
  width: 150px;
  height: 50px;
  margin-left: 77%;
  background: linear-gradient(-90deg, rgba(0, 105, 83, 1), rgba(33, 143, 120, 0.6));
  color: white;
}

.flagErrorBox {
  float: right;
  width: 25%;
  height: 50px;
  line-height: 50px;
  text-align: center;
  font-size: 20px;
  margin-top: 10px;
  margin-right: 10px;
  font-family: Source Han Sans CN,sans-serif;
  font-weight: 500;
  color: #ffffff;
  background: linear-gradient(
          -90deg,
          rgba(33, 143, 120, 1),
          rgba(120, 202, 185, 1)
  );
  border-radius: 33px;
}

.qr-container {
  display: flex;
  flex-direction: column;
  gap: 30px;
  text-align: center;
}

.qr-item {
  padding: 20px;
  border: 1px solid #f0f0f0;
  border-radius: 10px;
  background-color: #f9f9f9;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.qr-title {
  font-size: 40px;
  font-weight: bold;
  margin-bottom: 10px;
  color: #333;
}

.qr-code {
  margin-bottom: 10px;
  width: 400px; /* 设置二维码的宽度 */
  height: 400px; /* 设置二维码的高度 */
}

.qr-text {
  font-size: 24px;
  color: #666;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.flagErrorBoxGray {
  float: right;
  width: 25%;
  height: 50px;
  line-height: 50px;
  margin: auto;
  text-align: center;
  font-size: 20px;
  margin-top: 10px;
  font-family: Source Han Sans CN,sans-serif;
  font-weight: 500;
  color: #ffffff;
  background: linear-gradient(-90deg, rgb(103, 112, 110), rgb(200, 208, 206));
  border-radius: 33px;
}

.code-display {
  padding: 8px 12px; /* 内边距 */
  border: 1px solid #e0e0e0;
  border-radius: 6px; /* 圆角 */
  background-color: #f9f9f9; /* 背景色 */
  font-family: monospace;
  font-size: 30px;
  color: #333;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  max-width: 100%;
  overflow: auto;
  box-sizing: border-box;
}
#scrapButton {
  height: 100px;
  width: 100%;
  position: fixed;
  bottom: 0px;
  padding-top: 20px;

  background: #FFFFFF;
}
.btn_enable {
  width: 100%;
  height: 80px;
  background: rgba(33, 143, 120, 0.9);
  border-radius: 20px;
  color: rgba(230, 230, 230, 1);
}
</style>
<template>
  <van-nav-bar title="二维码流向查询" left-text left-arrow @click-left="onClickLeft" id="topDiv"/>
  <div v-if="listfalg" class="cardlist" id="orderList">
    <h3 class="mesTitle">二维码流向数据信息</h3>
    <van-row class="listTab">
      <!-- 查询码 -->
      <div class="code-display">
        查询码: {{ rows.codeTid || '-' }}
      </div>

      <!-- 环节编码 -->
      <van-col class="tabTitle" span="8">环节编码</van-col>
      <van-col class="tabValue" span="16">
        {{ rows.flowInfos?.[0]?.flowNodeCode || '-' }}
      </van-col>

      <!-- 环节编码名称 -->
      <van-col class="tabTitle" span="8">环节编码名称</van-col>
      <van-col class="tabValue" span="16">
        {{ rows.flowInfos?.[0]?.flowNodeName || '-' }}
      </van-col>

      <!-- 出库单号 -->
      <van-col class="tabTitle" span="8">出库单号</van-col>
      <van-col class="tabValue" span="16">
        {{ rows.flowInfos?.[0]?.flowNo || '-' }}
      </van-col>

      <!-- 开单日期 -->
      <van-col class="tabTitle" span="8">开单日期</van-col>
      <van-col class="tabValue" span="16">
        {{ rows.flowInfos?.[0]?.flowDate || '-' }}
      </van-col>

      <!-- 单据类型 -->
      <van-col class="tabTitle" span="8">单据类型</van-col>
      <van-col class="tabValue" span="16">
        {{
          rows.flowInfos?.[0]?.flowType != null
              ? rows.flowInfos[0].flowType == "1"
                  ? "入库"
                  : rows.flowInfos[0].flowType == "-1"
                      ? "出库"
                      : "未知"
              : '-'
        }}
      </van-col>
    </van-row>
  </div>

  <van-row id="scrapButton">
    <van-button class="btn_enable" @click="dialogBr">继续查询</van-button>
  </van-row>


</template>

<script>
import {Button, Card, Cell, CellGroup, Col, Dialog, NavBar, Notify, Popup, Row, Search, Tab, Tabs, Toast} from "vant";

import ScanOverlay from "@/components/overlay/scanOverlay/ScanOverlay";
import {QrCodeUtil} from "@/api/qrcode/device/brand/brand";
import "/public/assets/iconfont/iconfont.css";
import {qrCodeFlowNodes} from "@/api/qrcode/upload/uploadTaskDetail";
import {insertQrCodeDisassociation} from "@/api/qrcode/relation/qrDiscardCode";
import {getStringByTwo} from "@/utils/transition";

export default {
  name: "CartonRetailerInspection",
  components: {
    [Search.name]: Search,
    [Button.name]: Button,
    [Dialog.name]: Dialog,
    [NavBar.name]: NavBar,
    [Tabs.name]: Tabs,
    [Tab.name]: Tab,
    [Popup.name]: Popup,
    [Card.name]: Card,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Toast.name]: Toast,
    [Col.name]: Col,
    [Row.name]: Row
  },
  setup() {
  },
  data() {
    return {
      errovalue: "",
      currentQRCodeUrl: '',  // 存储当前码二维码的 URL
      parentQRCodeUrl: '',    // 存储上级码二维码的 URL
      errotitle: "",
      showDialog: false,
      listfalg: false,
      dialog: false,
      rows: {
        codeTid: '', // 当前码初始为空
        parentCodeTid: '', // 上级码初始为空
      },
      qrCodeDisassociation: {
        userName: "",
        productLineName: "",
        operationType: "",
        qrCode: "",
        productLineId: "",
        createTime: "",
        codeType: "",
        content: "",
        subCode: "",
        subName: "",
        operationResult: "",
      },
      tabs: {
        height: "",
        conHeight: ""
      },
    };
  },
  created() {
    ScanOverlay.show('请扫描二维码获取流向数据')
    this.$nextTick(() => {
      //监听扫码枪
      this.$nativeQRCode.setCallBackFun((res) => {
        let qrCode = getStringByTwo(res)
        this.onScanQrCode(qrCode);
      });
    });
    // this.onScanQrCode("HTTPS://T2DC.CN/99.1000.1/AC30212262037000169010280752062202503180016460168A00296CVITQRCMST0FSBN04DHM5TW1");
  },
  computed: {},
  methods: {
    // 继续扫描
    dialogBr() {
      this.resetData()
      ScanOverlay.show('请扫描二维码获取流向数据')
      // 监听扫码枪
      this.$nativeQRCode.setCallBackFun(res => {
        let qrCode = getStringByTwo(res)
        this.onScanQrCode(qrCode);
      });
    },
    //排序
    compare(property) {
      return function (a, b) {
        let value1 = a[property];
        let value2 = b[property];
        return value1 - value2;
      };
    },
    // 返回
    onClickLeft() {
      window.history.back(-1);
    },
    // 重置数据
    resetData() {
      this.errovalue = null;
      this.currentQRCodeUrl = null;
      this.parentQRCodeUrl = null;
      this.errotitle = null;
      this.showDialog = null;
      this.listfalg = null;
      this.dialog = null;
      this.rows = {};
      this.tabs = {
        height: null,
        conHeight: null
      };
    },
    //获取扫到的二维码
    onScanQrCode(qrcode) {
      if (qrcode == null || qrcode == '' || qrcode == undefined) {
        return;
      }
      //  10 盒  20 条  30 件'
      QrCodeUtil({qrcode: qrcode}).then(resx => {
        console.log(qrcode, 'aaa')
        if (resx.code == 500 || resx.data.qrBrand == null) {
          Notify({type: 'warning', message: '无法获取到品规'});
        } else {
          let qrCodeProductLine = JSON.parse(localStorage.getItem('qrCodeProductLine'))
          console.log(qrCodeProductLine, 'aaa')

          // 插入成功记录
          this.qrCodeDisassociation.userName = qrCodeProductLine.userName
          this.qrCodeDisassociation.operationType = 14
          this.qrCodeDisassociation.qrCode = qrcode
          this.qrCodeDisassociation.createTime = this.getNowFormatDate()
          this.qrCodeDisassociation.codeType = resx.data.typeCode
          this.qrCodeDisassociation.subCode = qrCodeProductLine.code
          this.qrCodeDisassociation.subName = qrCodeProductLine.name
          // 构造 content 对象
          const content = {
            "code": qrcode,
            "codeType": resx.data.typeCode
          };

          // 将 content 转换为 JSON 字符串
          this.qrCodeDisassociation.content = JSON.stringify(content)
          let codeList = [qrcode]
          qrCodeFlowNodes(codeList).then(res => {
            if (res.code != 200) {
              Notify({type: 'warning', message: '暂未找到此码流向数据!', duration: 2000});
            } else {
              if (res.data.length > 0) {
                this.rows = res.data[0]
                this.listfalg = true

              } else {
                Notify({type: 'warning', message: '暂未找到此码流向数据!', duration: 2000});
              }
            }
            this.qrCodeDisassociation.operationResult = 21
            insertQrCodeDisassociation(this.qrCodeDisassociation).then(() => {
            })
          }).catch(() => {
            this.qrCodeDisassociation.operationResult = 20
            insertQrCodeDisassociation(this.qrCodeDisassociation).then(() => {
            })
          });
        }
      });
    },
    //格式化时间
    formatDate(date) {
      let dateTime =
          date.substring(0, 4) +
          "-" +
          date.substring(4, 6) +
          "-" +
          date.substring(6, 8);
      return dateTime;
    },
    //获取当前时间
    getNowFormatDate() {
      var date = new Date();
      var separator = "-"; // 分隔符
      var year = date.getFullYear(); // 获取年份
      var month = date.getMonth() + 1; // 获取月份（注意：月份从 0 开始，所以要加 1）
      var day = date.getDate(); // 获取日期
      var hours = date.getHours(); // 获取小时
      var minutes = date.getMinutes(); // 获取分钟
      var seconds = date.getSeconds(); // 获取秒钟

      // 如果月份小于10，前面补零
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }

      // 如果日期小于10，前面补零
      if (day >= 1 && day <= 9) {
        day = "0" + day;
      }

      // 如果小时小于10，前面补零
      if (hours >= 0 && hours <= 9) {
        hours = "0" + hours;
      }

      // 如果分钟小于10，前面补零
      if (minutes >= 0 && minutes <= 9) {
        minutes = "0" + minutes;
      }

      // 如果秒钟小于10，前面补零
      if (seconds >= 0 && seconds <= 9) {
        seconds = "0" + seconds;
      }

      // 格式化日期和时间
      var currentDate = year + separator + month + separator + day + " " + hours + ":" + minutes + ":" + seconds;
      return currentDate;
    },
  },

  destroyed() {
    //清除定时器
    clearInterval(this.countdowns);
  }
};
</script>

