<template>
  <!-- 编码绑定查看与编码页面 -->
  <div>
    <el-form
      size="small"
      :model="maForm"
      :inline="true"
      ref="maFormRef"
      label-width="100px"
    >
      <el-form-item label="类型规格" prop="typeId">
        <!-- <el-input
          clearable
          maxlength="50"
          style="width: 240px"
          v-model="maForm.keyWord"
          placeholder="请输入类型规格"
        /> -->
        <el-select v-model="maForm.typeId" placeholder="请选择类型规格" clearable filterable style="width: 240px">
          <el-option
            v-for="dict in materialModelList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="机具厂家" prop="typeId">
        <el-select
          clearable
          filterable
          style="width: 240px"
          v-model="maForm.typeId"
          placeholder="请选择机具厂家"
        >
          <el-option
            :key="m.value"
            :value="m.value"
            :label="m.label"
            v-for="m in millList"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="出厂日期" prop="productionTime">
        <el-date-picker
          type="date"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          placeholder="请选择出厂日期"
          v-model="maForm.productionTime"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          size="mini"
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
        >
          查询
        </el-button>
        <el-button size="mini" icon="el-icon-refresh" @click="resetQuery">
          重置
        </el-button>
      </el-form-item>
    </el-form>
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          type="danger"
          icon="el-icon-plus"
          @click="handleBackAll"
          v-if="!isView"
        >
          驳回
        </el-button>
      </el-col>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="codeList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" v-if="!isView"/> -->
      <el-table-column align="center" label="序号" type="index" width="55" />
      <el-table-column
        align="center"
        label="物资名称"
        prop="maTypeName"
        show-overflow-tooltip
      ></el-table-column>
      <el-table-column
        align="center"
        label="规格型号"
        prop="typeName"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="验收数量"
        prop="purchaseNum"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="待绑定数量"
        prop=""
        show-overflow-tooltip
      >
        <template slot-scope="scope">
           <span>{{ Number(scope.row.purchaseNum)-Number(scope.row.bindNum) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="已绑定数量"
        prop="bindNum"
        show-overflow-tooltip
      />
      <el-table-column align="center" label="单位" prop="unitName" />
      <!-- <el-table-column
        align="center"
        label="供应商"
        prop="supplierName"
        show-overflow-tooltip
      /> -->
      <el-table-column
        align="center"
        label="出厂日期"
        prop="productionTime"
        show-overflow-tooltip
      />

      <el-table-column label="相关配套资料" align="center" prop="bmFileInfos">
        <template slot-scope="scope">
          <div style="color: #02A7F0;cursor: pointer;" @click="openFileDialog(scope.row)" v-if="scope.row.isExitFile==0">报告管理</div>
          <div style="color: red;cursor: pointer;" @click="openFileDialog(scope.row)" v-if="scope.row.isExitFile==1">报告管理</div>
        </template>
      </el-table-column>

      <el-table-column align="center" label="状态">
        <template slot-scope="{ row }">
          <dict-tag
            :value="row.status"
            :options="dict.type.purchase_task_status"
          />
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" width="400">
        <template slot-scope="{ row }">
          <el-button
            size="mini"
            type="primary" v-if="row.manageType==0"
            icon="el-icon-zoom-in"
            @click="handleView(row)"
          >
            查看
          </el-button>
          <el-button plain size="mini" type="warning" @click="handleBind(row)" v-if="!isView&&row.manageType==0&&(row.status==3||row.status==14)">
            <svg-icon icon-class="bind-icon" />
            绑定
          </el-button>
          <!-- <el-button
            size="mini"
            type="danger"
            icon="el-icon-close"
            @click="handleReject(row)"
            v-if="!isView&&row.manageType==0&&(row.status==3||row.status==14)"
          >
            驳回
          </el-button> -->
          <!-- 当从主列表点击查看时可显示二维码下载按钮 -->
          <el-button
            plain
            size="mini"
            type="success" v-if="row.manageType==0"
            @click="onDownloadQr(row)"
          >
            <svg-icon icon-class="qr-icon" />
            下载
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="maForm.pageNum"
      :limit.sync="maForm.pageSize"
      @pagination="getCodeList"
    /> -->

    <!-- 编码查看弹框-->
    <el-dialog width="70%" append-to-body title="查看编码" :visible.sync="viewCodeVisible">
      <el-row :gutter="12" class="mb8">
        <el-col :span="8">
          <el-form size="small" :model="codeForm" :inline="true" label-width="80px" >
            <el-form-item label="关键字" prop="keyWord">
              <el-input clearable maxlength="50" style="width: 100%" v-model="codeForm.keyWord" placeholder="请输入关键字" />
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="1.5">
            <el-button type="primary" size="mini" @click="codeQuery">查询</el-button>
        </el-col>
        <!-- <el-col :span="1.5" v-if="!isView">
            <el-button type="danger" size="mini"  @click="codeUnBind">解绑</el-button>
        </el-col> -->
      </el-row>
      <el-table border max-height="600px" :data="viewCodeList" row-key="id" @selection-change="codeSelection">
        <!-- <el-table-column type="selection" width="55" align="center" v-if="!isView" :selectable="selectable"/> -->
        <el-table-column label="序号" align="center" type="index" />
        <el-table-column align="center" label="类型名称" prop="maTypeName" />
        <el-table-column align="center" label="规格型号" prop="typeName" />
        <el-table-column align="center" label="设备编码" prop="maCode" />
        <el-table-column align="center" label="绑定人员" prop="createBy" />
        <el-table-column align="center" label="绑定时间" prop="createTime" />
        <el-table-column align="center" label="出厂编号" prop="outFacCode" />
        <el-table-column align="center" label="状态" prop="status">
            <template slot-scope="scope">
                  <span v-if="scope.row.status==0">未入库</span>
                  <span v-if="scope.row.status==1">已入库</span>
            </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 绑定弹框-->
    <el-dialog
      width="70%"
      append-to-body
      title="编码绑定"
      :visible.sync="bindCodeVisible"
    >
      <el-form
        size="small"
        :inline="true"
        ref="queryFormBindRef"
        :model="queryBindForm"
        :rules="queryBindFormRules"
      >
        <el-form-item label="前缀" prop="codePrefix">
          <el-input
            clearable
            maxlength="20"
            placeholder="请输入前缀"
            v-model="queryBindForm.codePrefix"
          />
        </el-form-item>

        <el-form-item label="后缀范围" prop="codeSuffixStart">
          <el-input
            clearable
            placeholder="开始数值"
            v-model="queryBindForm.codeSuffixStart"
          />
        </el-form-item>
        <el-form-item prop="codeSuffixEnd">
          <el-input
            clearable
            placeholder="结束数值"
            v-model="queryBindForm.codeSuffixEnd"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="handleAdd"
            >填充</el-button
          >
          <el-button type="primary" size="mini" @click="handleCodeBinding"
            >绑定</el-button
          >
        </el-form-item>
        <el-form-item>
          <div style="margin-left: 10px">
            当前待绑定数量：
            <span style="font-weight: bold; color: #ff4949">
              {{ waitBindNum }}
            </span>
          </div>
        </el-form-item>
      </el-form>
      <el-table border max-height="600px" :data="codeTableList">
        <el-table-column align="center" label="序号" type="index" />
        <el-table-column align="center" label="设备名称" prop="maTypeName" />
        <el-table-column align="center" label="规格型号" prop="typeName" />
        <el-table-column align="center" label="设备编码">
          <template slot-scope="{ row }">
            <el-input clearable v-model="row.maCode" placeholder="请填写编码" />
          </template>
        </el-table-column>
        <el-table-column align="center" label="出厂编号">
          <template slot-scope="{ row }">
            <el-input
              clearable
              v-model="row.outFacCode"
              placeholder="请填写出厂编号"
            />
          </template>
        </el-table-column>
        <!-- <el-table-column align="center" label="出厂时间">
          <template slot-scope="{ row }">
            <el-date-picker
              type="date"
              v-model="row.productDate"
              placeholder="请选择出厂日期"
            />
          </template>
        </el-table-column> -->
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-remove"
              @click="handleRemove(scope.$index)"
            >
              移除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      title="报告管理"
      :visible.sync="open"
      width="900px"
      append-to-body
    >
      <el-table :data="fileDataList" width="100%" height="350px">
        <el-table-column label="序号" type="index" width="55" align="center" />
        <el-table-column
          label="报告类型"
          align="center"
          prop="dictLabel"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="文件名称"
          align="center"
          prop="name"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="类型名称"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template>
            <div>{{ this.rowData.maTypeName }}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="规格型号"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template>
            <div>{{ this.rowData.typeName }}</div>
          </template>
        </el-table-column>
        <!-- <el-table-column label="报告日期" align="center" prop="orgName" :show-overflow-tooltip="true"/>
                <el-table-column label="截止有效期" align="center" prop="orgName" :show-overflow-tooltip="true"/> -->
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope">
            <div style="display: flex;align-items: center;justify-content: space-between;">
              <el-upload
                ref="upload"
                :limit="3"
                :headers="upload.headers"
                :action="upload.url"
                :show-file-list="false"
                accept=".png, .jpg, .jpeg, .pdf, .doc, .docx"
                :on-success="handleFileSuccess"
                :auto-upload="true"
                v-if="!isView"
              >
                <el-button
                  size="mini"
                  type="text"
                  @click="beforeFileUpload(scope.row)"
                >
                  上传
                </el-button>
              </el-upload>

              <el-button
                size="mini"
                type="text"
                @click="picturePreview(scope.row)"
                v-if="scope.row.url"
              >
                查看
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 图片查看弹窗 -->
    <el-dialog :visible.sync="dialogVisible" width="500px" height="500px">
      <img width="100%" height="500px" :src="dialogImageUrl" />
    </el-dialog>
  </div>
</template>

<script>
import {
  bindAllData,
  getListDetailById,
  getNewBuyBindListDetailsApi,
  getMaCodeInfo,
  exportNewBuy,
  rejectBind,
  unBindCodeApi
} from "@/api/purchase/goodsBind";
import { downloadFile } from '@/utils/download'
import { getToken } from "@/utils/auth";
import {
  uploadPurchaseFile,
  getPurchaseFileList,
} from "@/api/purchase/goodsAccept";
import { getDeviceType} from "@/api/ma/device"

export default {
  name: "BindTools",
  dicts: ["purchase_task_status"],
  props: {
    // 查询参数 taskId
    queryTaskId: {
      type: [String, Number],
      default: () => "",
    },
    // 查询参数 id
    queryId: {
      type: [String, Number],
      default: () => "",
    },
    // 页面展示类型 1. 查看 2. 编码
    queryType: {
      type: Number,
      default: () => 1,
    },
    isView: {
        type: Boolean,
        default: () => {
            return false
        },
    },
  },
  data() {
    return {
      total: 0, //                列表总条数
      waitBindNum: 0, //          待绑定数量
      loading: false, //          列表 loading 遮罩层
      showSearch: true, //        显示搜索条件
      viewCodeVisible: false, //  查看弹框
      bindCodeVisible: false, //  绑定弹框
      millList: [{ label: "测试公司", value: 1 }], //            厂家列表
      codeList: [], //            列表
      selectList: [], //          列表复选框选中数据
      viewCodeList: [], //        查看编码列表
      codeForm:{},
      unbindIds:[],
      codeTableList: [], //       填充列表
      // 编码绑定表单数据源
      queryBindForm: {
        typeId: "", //          物资typeId
        typeName: "", //        规格型号
        codePrefix: "", //      编码前缀
        maTypeName: "", //      物资名称
        codeSuffixEnd: "", //   后缀结束
        codeSuffixStart: "", // 后缀开始
      },
      // 编码校验规则
      queryBindFormRules: {
        codePrefix: [
          { required: true, message: "请输入前缀", trigger: "blur" },
        ],
        codeSuffixStart: [
          {
            required: true,
            trigger: "blur",
            message: "请输入前缀",
          },
          {
            pattern: /^[0-9][0-9]*$/,
            message: "请输入大于0且不能以0开头的正整数",
          },
        ],
        codeSuffixEnd: [
          {
            required: true,
            trigger: "blur",
            message: "请输入后缀",
          },

          {
            pattern: /^[0-9][0-9]*$/,
            message: "请输入大于0且不能以0开头的正整数",
          },
        ],
      },
      // 列表查询参数
      maForm: {
        pageNum: 1,
        pageSize: 10,
        taskId: "",
        keyWord: "",
        productionTime: "",
        taskStage: 3,
        typeId: ''
      },
      materialModelList: [],
      taskId: "",
      // 是否显示弹出层
      open: false,
      rowData: {},
      fileDataList: [
        { dictLabel: "合格证", fileType: "0", name: "", url: "" },
        { dictLabel: "型式试验报告", fileType: "1", name: "", url: "" },
        { dictLabel: "出厂检测报告", fileType: "2", name: "", url: "" },
        { dictLabel: "第三方检测报告", fileType: "3", name: "", url: "" },
        { dictLabel: "其他", fileType: "4", name: "", url: "" },
      ],
      //图片查看弹窗
      dialogImageUrl: "",
      dialogVisible: false,
      //上传
      upload: {
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/file/upload",
      },
    };
  },
  created() {
    // 绑定按钮事件添加防抖 防止重复编码
    this.handleCodeBinding = this.debounce(this.handleCodeBinding, 1000);
  },
  mounted() {
    this.taskId = this.queryTaskId;
    this.getCodeList();
    this.getDeviceType()
  },
  methods: {
    getDeviceType(){
          getDeviceType({level:4,skipPermission:1}).then(response => {
          let matModelRes = response.data;
          this.materialModelList = matModelRes.map((item) => {
                  return {
                  label: item.typeName,
                  value: item.typeId,
                  };
              });
          });
      },
    // 获取列表数据
    async getCodeList() {
      this.loading = true;
      this.maForm.taskId = this.queryTaskId;
      this.maForm.id = this.queryId;
      // this.maForm.statusList = [3, 13];
      this.maForm.taskStage = 3;
      const { data: res } = await getNewBuyBindListDetailsApi(this.maForm);
      this.loading = false;
      // this.total = res.total
      this.codeList = res.purchaseCheckDetailsList;
      this.total = res.purchaseCheckDetailsList.length || 0;
    },
    // 搜索
    handleQuery() {
      this.getCodeList();
    },
    // 重置
    resetQuery() {
      this.resetForm("maFormRef");
      this.getCodeList();
    },
    // 驳回 (批量)
    handleBackAll() {
      if (this.selectList.length < 1) {
        this.$modal.msgError("请勾选数据！");
        return;
      }
    },
    // 列表复选框事件
    handleSelectionChange(list) {
      this.selectList = list;
    },
    // 查看编码
    handleView(row) {
      this.codeForm=row
      this.viewCodeVisible = true;
      getMaCodeInfo({ taskId: row.taskId, typeId: row.typeId, keyWord:this.codeForm.keyWord }).then(
        (response) => {
          this.viewCodeList = response.data;
          this.titleBind = "查看";
        }
      );
    },
    //是否可用勾选框
    selectable(row) {
      if (row.status == 0) {
          return true
      } else {
          return false
      }
    },
    //编码勾选
    codeSelection(selection){
      console.log(selection)
      this.unbindIds = selection.map(item => {return item.id})
    },
    codeUnBind(){
      if(this.unbindIds.length == 0){
        this.$modal.msgError("请勾选数据！");
        return;
      }
      console.log("xxxxxxxxx",this.unbindIds)
      let param = {

      }
      unBindCodeApi(this.unbindIds).then((response) => {
        this.codeQuery()
      });
    },
    // 查询编码
    codeQuery() {
      getMaCodeInfo({ taskId: this.codeForm.taskId, typeId: this.codeForm.typeId, keyWord:this.codeForm.keyWord }).then(
        (response) => {
          this.viewCodeList = response.data;
        }
      );
    },
    // 绑定
    handleBind(row) {
      this.bindCodeVisible = true;
      this.waitBindNum = row.checkNum - row.bindNum;
      this.queryBindForm.typeId = row.typeId;
      this.queryBindForm.typeName = row.typeName;
      this.queryBindForm.maTypeName = row.maTypeName;
    },
    // 驳回
    handleReject(row) {
      this.$modal
        .confirm("是否确定驳回？")
        .then(function () {
          return rejectBind({"purchaseId":row.id})
        })
        .then(() => {
          this.getCodeList();
          this.$modal.msgSuccess("驳回成功");
        })
        .catch(() => {});
    },

    //文件管理
    openFileDialog(row) {
      this.rowData = row;
      this.fileDataList = [
        { dictLabel: "合格证", fileType: "0", name: "", url: "" },
        { dictLabel: "型式试验报告", fileType: "1", name: "", url: "" },
        { dictLabel: "出厂检测报告", fileType: "2", name: "", url: "" },
        { dictLabel: "第三方检测报告", fileType: "3", name: "", url: "" },
        { dictLabel: "其他", fileType: "4", name: "", url: "" },
      ];
      if (this.taskId == "") {
        // console.log(this.rowData)
        // console.log(this.rowData.bmFileInfos)
        if (this.rowData.bmFileInfos.length > 0) {
          this.rowData.bmFileInfos.forEach((item) => {
            let index = this.fileDataList.findIndex(
              (v) => v.fileType == item.fileType
            );
            this.fileDataList[index].name = item.name;
            this.fileDataList[index].url = item.url;
          });
        }
      } else {
        this.getFileData();
      }
      this.open = true;
    },
    getFileData() {
      let param = {
        modelId: this.rowData.typeId,
        taskType: 0,
        taskId: this.rowData.taskId,
      };
      getPurchaseFileList(param)
        .then((response) => {
          if (response.rows.length > 0) {
            response.rows.forEach((item) => {
              let index = this.fileDataList.findIndex(
                (v) => v.fileType == item.fileType
              );
              this.fileDataList[index].name = item.name;
              this.fileDataList[index].url = item.url;
            });
          }
        })
        .catch(() => {});
    },
    beforeFileUpload(row) {
      this.rowData.fileType = row.fileType;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      if (response.code == 200) {
        if (this.taskId == "") {
          //新增逻辑
          // console.log(response)
          // console.log(this.rowData)
          // console.log(this.rowData.bmFileInfos)
          let obj = {
            taskId: this.taskId,
            taskType: "0",
            name: response.data.name,
            url: response.data.url,
            modelId: this.rowData.typeId,
            fileType: this.rowData.fileType,
            //   "dictLabel": this.rowData.dictLabel,
          };
          //根据文件上传返回更新文件管理弹窗内容
          let index = this.fileDataList.findIndex(
            (v) => v.fileType == this.rowData.fileType
          );
          this.fileDataList[index].name = response.data.name;
          this.fileDataList[index].url = response.data.url;
          //判断当前上传的文件是否已上传过-再往机具类型数据中插入
          if (this.rowData.bmFileInfos.length > 0) {
            let index2 = this.rowData.bmFileInfos.findIndex(
              (v) => v.fileType == this.rowData.fileType
            );
            if (index2 > -1) {
              //相同类型文件重复上传-替换
              this.rowData.bmFileInfos.splice(index2, 0, obj);
            } else {
              //不存在相同类型文件-添加
              this.rowData.bmFileInfos.push(obj);
            }
          } else {
            this.rowData.bmFileInfos.push(obj);
          }
        } else {
          //编辑逻辑
          let param = {
            taskId: this.taskId,
            taskType: "0",
            name: response.data.name,
            url: response.data.url,
            modelId: this.rowData.typeId,
            fileType: this.rowData.fileType,
            //   "dictLabel": this.rowData.dictLabel,
          };
          uploadPurchaseFile(param)
            .then((response) => {
              this.$modal.msgSuccess("上传成功");
              this.getFileData();
            })
            .catch(() => {
              this.$modal.msgError("上传失败");
            });
        }
      }
    },
    //图片查看
    picturePreview(file) {
      this.dialogImageUrl = file.url.replaceAll('#','%23');
      const parts = file.name.split(".");
      const extension = parts.pop();
      if (extension === 'doc' || extension === 'DOC' || extension === 'docx' || extension === 'DOCX' || extension === 'pdf' || extension === 'PDF') {
        const windowName = file.name;
        window.open(file.url, windowName);
      } else {
        this.dialogVisible = true;
      }
    },

    /** 导出二维码按钮操作 */
    onDownloadQr(row) {
        exportNewBuy(row.id).then(res => {
          downloadFile({ fileName: `二维码_${new Date().getTime()}.zip`, fileData: res, fileType: 'application/zip;charset=utf-8' })
        })
      },
    // 填充
    handleAdd() {
      // 1. 校验表单
      this.$refs.queryFormBindRef.validate((valid) => {
        if (valid) {
          // 1.1 判断结束值是否大于开始值
          const {
            typeName,
            codePrefix,
            maTypeName,
            codeSuffixEnd,
            codeSuffixStart,
          } = this.queryBindForm;
          if (parseInt(codeSuffixEnd) < parseInt(codeSuffixStart)) {
            this.$modal.msgError("结束值不可小于开始值");
            return;
          }
          // 1.2 判断可编码数量
          let waitCodeNum = this.waitBindNum; // 待编码数量
          // 可编码数量 如相减大于代编码数量 则取待编码数量 如小于待编码数量 则取相减后值
          let passCodeNUm =
            codeSuffixEnd - codeSuffixStart + 1 > waitCodeNum
              ? waitCodeNum
              : codeSuffixEnd - codeSuffixStart + 1;

          this.codeTableList = [];
          // 1.3 循环生成编码
          for (let i = 0; i < passCodeNUm; i++) {
            // 计算当前的后缀值，保留前导零
            const currentSuffix = (parseInt(codeSuffixStart) + i).toString().padStart(codeSuffixStart.length, '0');
            const codeItem = {
              typeName,
              maTypeName,
              outFacCode: "",
              //   productDate: "",
              maCode: `${codePrefix}${currentSuffix}`,
            };
            this.codeTableList.push(codeItem);
          }
        }
      });
    },
    //  绑定
    async handleCodeBinding() {
      if (this.codeTableList.length < 1) {
        this.$modal.msgError("请填充编码");
        return;
      }

      let isCodePass = false;
      try {
        this.codeTableList.forEach((e, index) => {
          if (!e.maCode) {
            this.$modal.msgError(`序号为${index + 1}的编码为空，请填写`);
            isCodePass = true;
            throw new Error();
          }
        });
      } catch (error) {}

      if (isCodePass) return;
      // 调后台接口
      const res = await bindAllData({
        taskId: this.queryTaskId,
        dtoList: this.codeTableList,
        typeId: this.queryBindForm.typeId,
      });
      if (res.code == 200) {
        this.$modal.msgSuccess("绑定成功");
      }
      this.getCodeList();
      this.bindCodeVisible = false;
      this.resetForm("queryFormBindRef");
      this.codeTableList = [];
      console.log(res, "编码结果--");
    },
    //  移除
    handleRemove(index) {
      this.codeTableList.splice(index, 1);
    },

    // 防抖函数
    debounce(fn, delay) {
      let timer = null;
      return (...args) => {
        if (timer) {
          clearTimeout(timer);
        }
        // 设置新的定时器，延迟执行函数
        timer = setTimeout(() => {
          fn.apply(...args);
        }, delay);
      };
    },
  },
};
</script>
