<template>
  <div class="global-variable" v-loading="loading">
    <div class="condition">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="批次名称:" prop="batchName">
          <el-input
            v-model="formInline.batchName"
            placeholder="请输入批次名称"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="风场名称:" prop="fieldName">
          <el-input
            v-model="formInline.fieldName"
            placeholder="请输入风场名称"
            size="small"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="状态:" prop="transferState">
          <el-select
            v-model="formInline.transferState"
            placeholder="请选择状态"
            size="small "
          >
            <el-option
              v-for="item in stateDataList"
              :key="item.value"
              :label="item.lable"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="onSubmit" size="small"
            >查询</el-button
          >
          <el-button @click="reset('ruleForm')" size="small">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="list-page">
      <div class="newly">
        <el-button
          v-hasPermi="['dataManage:dataAdministration:add']"
          type="primary"
          @click="addData"
          size="small"
          >新增</el-button
        >
      </div>
      <el-table
        class="center-align-table"
        :data="tableData"
        border
        stripe
        style="width: 100%"
        :row-key="(row) => row.uniqueCode"
        lazy
        :load="load"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        ref="table"
        @expand-change="handleExpandChange"
      >
        <!-- Table Columns -->
        <el-table-column prop="fieldName" label="风场名称" min-width="200">
        </el-table-column>
        <el-table-column
          prop="batchName"
          align="center"
          label="批次名称"
          min-width="200"
        >
        </el-table-column>

        <el-table-column
          prop="engineCount"
          align="center"
          label="机组数量"
          min-width="100"
        >
        </el-table-column>
        <el-table-column
          prop="transferTypeName"
          align="center"
          label="类型"
          min-width="200"
        >
        </el-table-column>
        <el-table-column
          prop="transferProgress"
          align="center"
          label="进度"
          min-width="200"
        >
          <template slot-scope="scope">
            <el-progress
              v-if="scope.row.transferState == 0"
              :indeterminate="true"
              :stroke-width="20"
              :percentage="scope.row.transferProgress"
              class="animated-progress"
            ></el-progress>
            <span v-else>/</span>
          </template>
        </el-table-column>
        <el-table-column prop="" align="center" label="状态" min-width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.transferState == -1">未转换</span>
            <span v-else-if="scope.row.transferState == 0" style="color: #f90"
              >转换中</span
            >
            <span
              v-else-if="scope.row.transferState == 1"
              style="color: #4caf50"
              >转换成功</span
            >
            <span v-else-if="scope.row.transferState == 2" style="color: #f00"
              >转换失败</span
            >
            <span v-else>/</span>
          </template>
        </el-table-column>
        <el-table-column
          prop=""
          align="center"
          label="异常状态"
          min-width="100"
        >
          <template slot-scope="scope">
            {{ scope.row.transferState == 2 ? "异常" : "未异常" }}
          </template>
        </el-table-column>
        <el-table-column
          prop="abnormal"
          label="异常信息"
          min-width="100"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.transferState == 2"
              @click="particulars(scope.row)"
              type="text"
              size="small"
              >详情</el-button
            >
            <span v-else>/</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="transferFinishTime"
          align="center"
          label="转换时间"
          min-width="230"
        >
        </el-table-column>
        <el-table-column
          prop="transition"
          align="center"
          fixed="right"
          label="操作"
          min-width="150"
        >
          <template slot-scope="scope">
            <div v-if="scope.row.transferType">
              <el-button
                v-if="
                  scope.row.transferState !== -1 &&
                  (scope.row.transferAddr !== null ||
                    scope.row.transferAddr !== '')
                "
                v-hasPermi="['dataManage:dataAdministration:edit']"
                @click="handleEdit(scope.row)"
                type="text"
                size="small"
                >编辑</el-button
              >
              <el-button
                @click="handleClick(scope.row.downloadUrl)"
                type="text"
                size="small"
                >下载</el-button
              >
              <el-button
                v-if="
                  scope.row.transferState == -1 &&
                  (scope.row.transferAddr === null ||
                    scope.row.transferAddr === '')
                "
                v-hasPermi="['dataManage:dataAdministration:editState']"
                @click="editTransferState(scope.row, '转换')"
                type="text"
                size="small"
                >转换</el-button
              >
              <el-button
                v-else
                @click="editTransferState(scope.row, '重新转换')"
                type="text"
                size="small"
                v-hasPermi="['dataManage:dataAdministration:editState']"
                :disabled="scope.row.transferState == 0"
                >重新转换</el-button
              >
            </div>
            <div v-else>/</div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page.sync="formInline.pageNum"
          layout="total, prev, pager, next"
          :page-size="formInline.pageSize"
          :total="formInline.totalSize"
        >
        </el-pagination>
      </div>
    </div>
    <!-- 弹出层 -->
    <!-- 新增 -->
    <el-dialog
      title="新增（批次列表为空时，请前往性能分析下批次管理中添加批次！）"
      :visible.sync="nuedialog"
      class="dialogBox"
      width="900px"
      :before-close="handleCloses"
    >
      <div v-loading="loadingView" class="views">
        <el-form ref="form" :model="newform" label-width="150px">
          <el-row>
            <el-form-item
              label="批次名称:"
              prop="batchCode"
              :rules="batchCodeRules"
            >
              <el-select
                filterable
                v-model="newform.batchCode"
                placeholder="请选择批次名称"
                size="small"
              >
                <el-option
                  v-for="item in batchList"
                  :key="item.batchCode"
                  :label="item.batchName"
                  :value="item.batchCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row
            v-for="(item, index) in newform.dataTransferTypePathDtoList"
            :key="item.transferType"
          >
            <el-col :span="11">
              <el-form-item
                :prop="'transferAddr_' + index"
                :rules="getFileAddrRules(index)"
              >
                <span slot="label">
                  <el-tooltip
                    content="路径输入例如：/XX/XX/XX路径"
                    placement="bottom-start"
                  >
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                  {{ item.transferTypeName + "路径" + ":" }}
                </span>
                <el-input
                  :min="1"
                  v-model="item.transferAddr"
                  :placeholder="'请输入' + item.transferTypeName"
                  size="small"
                  @change="ensureMinValue(item, 'transferAddr')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="13">
              <el-form-item
                :label="item.transferTypeName + '时间粒度' + ':'"
                :prop="'timeGranularity_' + index"
                :rules="getTimeGranularityRules(index)"
              >
                <el-input
                  type="number"
                  :min="1"
                  v-model="item.timeGranularity"
                  :placeholder="'请输入' + item.transferTypeName"
                  size="small"
                  @input="ensureMinValue(item, 'timeGranularity')"
                >
                  <template slot="append">秒</template></el-input
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="cancel('form')" size="small">取 消</el-button>
          <el-button type="primary" @click="newly('form')" size="small"
            >确 定</el-button
          >
        </span>
      </div>
    </el-dialog>
    <!-- 编辑 -->
    <el-dialog
      title="编辑"
      :visible.sync="editNuedialog"
      class="dialogBox"
      width="900px"
      :before-close="handleCloses"
    >
      <div v-loading="loadingViewEdit" class="views">
        <el-form
          ref="editForm"
          :model="newEditForm"
          label-width="160px"
          :rules="editRules"
        >
          <el-row>
            <el-form-item label="批次名称:" prop="batchCode">
              <el-select
                v-model="newEditForm.batchName"
                placeholder="请选择批次名称"
                size="small"
                disabled
              >
                <el-option
                  v-for="item in batchList"
                  :key="item.batchCode"
                  :label="item.batchName"
                  :value="item.batchCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item prop="dataTransferTypePathDtoList.0.transferAddr">
                <span slot="label">
                  <el-tooltip
                    content="路径输入例如：/XX/XX/XX路径"
                    placement="bottom-start"
                  >
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                  {{
                    newEditForm.dataTransferTypePathDtoList[0]
                      .transferTypeName +
                    "路径" +
                    ":"
                  }}
                </span>
                <!-- :rules="{
                  required: true,
                  message:
                    '请输入' +
                    newEditForm.dataTransferTypePathDtoList[0].transferTypeName,
                  trigger: 'blur',
                }" -->
                <el-input
                  disabled
                  v-model="
                    newEditForm.dataTransferTypePathDtoList[0].transferAddr
                  "
                  :placeholder="
                    '请输入' +
                    newEditForm.dataTransferTypePathDtoList[0].transferTypeName
                  "
                  size="small"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="13">
              <el-form-item
                :label="
                  newEditForm.dataTransferTypePathDtoList[0].transferTypeName +
                  '时间粒度' +
                  ':'
                "
                prop="dataTransferTypePathDtoList.0.timeGranularity"
                :rules="{
                  required: true,
                  message:
                    '请输入' +
                    newEditForm.dataTransferTypePathDtoList[0].transferTypeName,
                  trigger: 'blur',
                }"
              >
                <el-input
                  type="number"
                  :min="1"
                  v-model="
                    newEditForm.dataTransferTypePathDtoList[0].timeGranularity
                  "
                  :placeholder="
                    '请输入' +
                    newEditForm.dataTransferTypePathDtoList[0].transferTypeName
                  "
                  size="small"
                >
                  <template slot="append">秒</template></el-input
                >
              </el-form-item>
            </el-col>
          </el-row>
          <el-row> </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editCancel('editForm')" size="small"
            >取 消</el-button
          >
          <el-button type="primary" @click="editly('editForm')" size="small"
            >确 定</el-button
          >
        </span>
      </div>
    </el-dialog>
    <!-- 异常信息详情 -->
    <el-dialog
      title="异常详情"
      :visible.sync="unusualdialog"
      width="800px"
      :before-close="handleCloses"
    >
      {{ errInfo }}
    </el-dialog>
    <!-- 转换\重新转换 -->
    <el-dialog
      :title="editTransferStateTitle"
      :visible.sync="editTransferStateLoading"
      width="900px"
      :before-close="handleCloses"
      class="TransferState"
    >
      <div v-loading="loadingViewEdit" class="views">
        <el-form
          ref="editStateForm"
          :model="editTransferStateForm"
          label-width="170px"
        >
          <el-row>
            <el-form-item label="批次名称:" prop="batchCode">
              <el-select
                v-model="editTransferStateForm.batchName"
                placeholder="请选择批次名称"
                size="small"
                disabled
              >
                <el-option
                  v-for="item in batchList"
                  :key="item.batchCode"
                  :label="item.batchName"
                  :value="item.batchCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                prop="dataTransferTypePath"
                :rules="{
                  required: true,
                  message: `请输入${editTransferStateForm.transferTypeName}`,
                  trigger: 'blur',
                }"
              >
                <span slot="label">
                  <el-tooltip
                    content="路径输入例如：/XX/XX/XX路径"
                    placement="bottom-start"
                  >
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                  {{ editTransferStateForm.transferTypeName + "路径" + ":" }}
                </span>
                <el-input
                  v-model="editTransferStateForm.dataTransferTypePath"
                  :placeholder="'请输入数据转换路径'"
                  size="small"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item
                label="时间粒度"
                prop="timeGranularity"
                :rules="{
                  required: true,
                  message: '请输入时间粒度',
                  trigger: 'blur',
                }"
              >
                <el-input
                  type="number"
                  :min="1"
                  v-model="editTransferStateForm.timeGranularity"
                  placeholder="
                      请输入时间粒度
                    "
                  size="small"
                >
                  <template slot="append">秒</template></el-input
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-divider>映射点表配置</el-divider>
        <WindCodeAndTypeForPlt ref="forPltRef"></WindCodeAndTypeForPlt>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editstateCancel('editStateForm')" size="small"
            >取 消</el-button
          >
          <el-button
            type="primary"
            @click="editStately('editStateForm')"
            size="small"
            >确 定</el-button
          >
        </span>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  queryDataTransferGroup,
  queryDataTransferByBatchCode,
  fieldBatchListForDataTransfer,
  addDataTransferList,
  editTimeGranularityQuery,
  dataTransfer,
} from "@/api/dataManage";
import axios from "axios";
import WindCodeAndTypeForPlt from "./components/WindCodeAndTypeForPlt.vue";
export default {
  components: {
    WindCodeAndTypeForPlt,
  },
  data() {
    return {
      intervalId: null,
      startTime: null,
      maxPollingTime: 5 * 60 * 1000, //轮询最大时间
      expandedKeys: new Set(), // 用于存储展开行的唯一标识
      loading: false,
      forPltFrom: {},
      editTransferStateForm: {
        transferAddr: "",
        dataTransferTypePath: "",
        batchName: "",
        batchCode: "",
        timeGranularity: "",
      },
      editTransferStateTitle: "",
      editTransferStateLoading: false,
      loadingView: false,
      formInline: {
        fieldName: "",
        batchName: "",
        // transferState: "",
        pageNum: 1,
        pageSize: 10,
        totalSize: 0,
      },
      batchCodeRules: [
        {
          required: true,
          message: "批次编号不能为空",
          trigger: ["change", "blur"],
        },
      ],
      editRules: {
        batchCode: {
          required: true,
          message: "批次编号不能为空",
          trigger: ["change", "blur"],
        },
      },
      rules: {
        batchCode: {
          required: true,
          message: "批次编号不能为空",
          trigger: "change",
        },
      },
      errInfo: "",
      stateDataList: [
        {
          lable: "未转换",
          value: -1,
        },
        {
          lable: "转换中",
          value: 0,
        },
        {
          lable: "转换成功",
          value: 1,
        },
        {
          lable: "转换失败",
          value: 2,
        },
      ],
      batchList: [],
      tableData: [],
      nuedialog: false,
      unusualdialog: false,
      newform: {
        batchCode: "",
        dataTransferTypePathDtoList: [],
      },
      editNuedialog: false,
      loadingViewEdit: false,
      newEditForm: {
        batchCode: "",
        batchName: "",
        dataTransferTypePathDtoList: [{}],
      },
    };
  },
  created() {
    this.fetchData();
    this.getBatchCodeList();
  },
  methods: {
    // 处理行展开和收起事件
    handleExpandChange(row, expandedRows) {
      if (expandedRows) {
        this.expandedKeys.add(row.uniqueCode); // 添加到展开列表
      } else {
        this.expandedKeys.delete(row.uniqueCode); // 从展开列表中删除
      }
    },
    load(tree, treeNode, resolve) {
      const { batchCode } = tree; // 假设每行都有唯一的 id
      // 调用接口获取子级数据
      queryDataTransferByBatchCode({ batchCode })
        .then((data) => {
          resolve(data.data);
        })
        .catch((error) => {
          console.error("Failed to load child nodes", error);
          resolve([]); // 确保 resolve 被调用
        });
    },
    async fetchData() {
      try {
        const result = await queryDataTransferGroup({
          ...this.formInline,
          totalSize: undefined,
        });
        this.tableData = result.data.list.map((item) => {
          return {
            ...item,
            hasChildren: true,
            uniqueCode: item.batchCode + item.fieldCode,
            children: [],
          };
        });
        this.formInline.totalSize = result.data.totalSize;
        // 恢复展开状态
        this.$nextTick(() => {
          this.tableData.forEach((row) => {
            if (this.expandedKeys.has(row.uniqueCode)) {
              this.$refs.table.toggleRowExpansion(row, true);
              // 手动触发子节点加载
              this.load(row, {}, (children) => {
                row.children = children;
              });
            }
          });
        });
      } catch (error) {
        this.$message({
          type: "error",
          message: "请检查是否连接网络",
        });
      }
    },

    stopPolling() {
      if (this.intervalId) {
        clearInterval(this.intervalId);
        this.intervalId = null;
      }
    },
    startPolling() {
      this.startTime = new Date().getTime();
      this.intervalId = setInterval(() => {
        const currentTime = new Date().getTime();
        if (currentTime - this.startTime >= this.maxPollingTime) {
          this.stopPolling();
        } else {
          this.fetchData();
        }
      }, 10000); // 每10秒调用一次
    },
    handleCloses(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.getBatchCodeList();
          done();
        })
        .catch((_) => {});
    },
    ensureMinValue(item, field) {
      if (item[field] < 1) {
        item[field] = 1;
      }
    },
    editstateCancel(formName) {
      this.$refs[formName] && this.$refs[formName].resetFields();
      this.editTransferStateForm = {
        transferAddr: "",
        dataTransferTypePath: "",
        batchName: "",
        batchCode: "",
        timeGranularity: "",
        transferType: "",
        transferTypeName: "",
        timeGranularityName: "",
      };
      this.editTransferStateLoading = false;
      this.loadingViewEdit = false;
      this.getBatchCodeList();
    },
    editStately(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loadingViewEdit = true;
          this.$confirm("请检查平台内的风机名称和转换数据的风机名称是否一致!")
            .then((_) => {
              const token = JSON.parse(sessionStorage.getItem("vuex"))?.auth
                ?.userInfo?.token;
              axios
                .post(
                  "/transDataWeb/transConf/insertOrUpdate",
                  {
                    type: this.forPltFrom.transferType,
                    windCode: this.forPltFrom.fieldCode,
                    windName: this.forPltFrom.fieldName,
                    ...this.$refs.forPltRef.formData,
                  },
                  {
                    headers: {
                      token,
                    },
                  }
                )
                .then((pltRes) => {
                  if (pltRes.data.code === 200) {
                    dataTransfer({
                      dataTransferAddr:
                        this.editTransferStateForm.dataTransferTypePath,
                      dataTransferType: this.editTransferStateForm.transferType,
                      batchCode: this.editTransferStateForm.batchCode,
                      timeGranularity:
                        this.editTransferStateForm.timeGranularity,
                    })
                      .then((res) => {
                        this.$message({
                          message: "操作成功",
                          type: "success",
                        });
                        this.$refs.forPltRef.reset("fromPlt");
                        this.fetchData();
                        this.editstateCancel();
                      })
                      .catch((error) => {
                        this.loadingViewEdit = false;
                      });
                  } else {
                    this.$message({
                      message: pltRes.message,
                      type: "error",
                    });
                  }
                })
                .catch((error) => {
                  this.loadingViewEdit = false;
                });
            })
            .catch((_) => {
              this.loadingViewEdit = false;
            });
        } else {
          return false;
        }
      });
    },
    //转换\重新转换
    editTransferState(row, title) {
      this.forPltFrom = { ...row };
      this.editTransferStateForm.timeGranularity = row.timeGranularity;
      this.editTransferStateForm.dataTransferTypePath = row.transferAddr
        ? row.transferAddr
        : "";
      this.editTransferStateForm.batchCode = row.batchCode;
      this.editTransferStateForm.batchName = row.batchName;
      this.editTransferStateForm.transferType = row.transferType;
      this.editTransferStateForm.transferTypeName = row.transferTypeName;
      this.editTransferStateForm.timeGranularityName = row.timeGranularityName;
      this.editTransferStateTitle = title;
      this.editTransferStateLoading = true;
      // if (title === "重新转换") {
      this.$nextTick(() => {
        this.$refs.forPltRef.reset("fromPlt");
        this.$refs.forPltRef.reSetByWindCodeAndTypeForPlt({
          type: this.forPltFrom.transferType,
          windCode: this.forPltFrom.fieldCode,
        });
      });
      // } else {
      //   this.$nextTick(() => {
      //     this.$refs.forPltRef.reset("fromPlt");
      //   });
      // }
    },
    handleEdit(row) {
      this.editNuedialog = true;
      this.newEditForm.batchCode = row.batchCode;
      this.newEditForm.batchName = row.batchName;
      this.newEditForm.dataTransferTypePathDtoList[0] = { ...row };
    },
    editCancel(name) {
      this.newform = {
        batchCode: "",
        dataTransferTypePathDtoList: [{}],
      };
      this.editNuedialog = false;
      this.loadingViewEdit = false;
      if (!name) {
        this.fetchData();
      }
      this.getBatchCodeList();
    },
    editly(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loadingViewEdit = true;
          editTimeGranularityQuery({
            timeGranularity:
              this.newEditForm.dataTransferTypePathDtoList[0].timeGranularity,
            dataTransferType:
              this.newEditForm.dataTransferTypePathDtoList[0].transferType,
            batchCode: this.newEditForm.batchCode,
          })
            .then((res) => {
              this.$message({
                message: "编辑成功",
                type: "success",
              });

              this.editCancel();
            })
            .catch((error) => {
              this.loadingViewEdit = false;
            });
        } else {
          return false;
        }
      });
    },
    getFileAddrRules(index) {
      return [{ validator: this.validateFileAddr, trigger: "blur" }];
    },
    getTimeGranularityRules(index) {
      return [
        {
          validator: (rule, value, callback) =>
            this.validateTimeGranularity(rule, value, callback, index),
          trigger: "blur",
        },
      ];
    },
    validateFileAddr(rule, value, callback) {
      // 判断是否至少有一项 transferAddr 有值
      const hasFileAddr = this.newform.dataTransferTypePathDtoList.some(
        (item) => item.transferAddr
      );
      if (!hasFileAddr) {
        callback(new Error("请至少填写一个数据路径"));
      } else {
        callback();
      }
    },
    validateTimeGranularity(rule, value, callback, index) {
      // 判断对应的 transferAddr 有值，则对应的 timeGranularity 也必须有值
      const currentItem = this.newform.dataTransferTypePathDtoList[index];
      if (currentItem.transferAddr && !currentItem.timeGranularity) {
        callback(new Error("请填写时间粒度"));
      } else {
        callback();
      }
    },
    cancel(formName) {
      this.$refs[formName] && this.$refs[formName].resetFields();
      this.newform = {
        batchCode: "",
        dataTransferTypePathDtoList: [],
      };
      this.getBatchCodeList();
      this.nuedialog = false;
      this.loadingView = false;
    },
    rowStyle() {
      return "text-align:center";
    },
    // 查询
    onSubmit() {
      this.fetchData();
    },
    // 重置
    reset(formName) {
      this.$refs[formName].resetFields();
      this.fetchData();
    },
    // 新增
    newly(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loadingView = true;
          addDataTransferList({ ...this.newform })
            .then((res) => {
              this.$message({
                message: "新增成功",
                type: "success",
              });
              this.fetchData();
              this.cancel();
              this.loadingView = false;
            })
            .catch(() => {
              this.loadingView = false;
            });
        } else {
          return false;
        }
      });
    },
    //异常详情
    particulars(row) {
      this.unusualdialog = true;
      this.errInfo = row.errInfo;
    },
    //下载
    async handleClick(downloadUrl) {
      let newWindow = window.open(downloadUrl, "_blank");
      if (
        !newWindow ||
        newWindow.closed ||
        typeof newWindow.closed == "undefined"
      ) {
        alert("弹出窗口已被阻止！请允许弹出式窗口访问本网站。");
      }
    },

    //分页数据切换
    handleCurrentChange(val) {
      this.formInline.pageNum = val;
      this.fetchData();
    },
    //新增按钮
    addData() {
      if (this.batchList === null || this.batchList.length === 0) {
        this.$confirm(
          "批次列表为空，请前往性能分析菜单下的批次管理中添加批次！确认跳转到批次管理菜单吗？",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(() => {
            this.$router.push("/home/performance/batchMag?id=22");
            this.$message({
              type: "success",
              message: "成功!",
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      } else {
        this.nuedialog = true;
      }
    },
    //获取批次编号列表接口
    async getBatchCodeList() {
      this.loading = true;
      try {
        const result = await fieldBatchListForDataTransfer();
        this.batchList = result.data.batchCodeList;
        this.newform.dataTransferTypePathDtoList =
          result.data.dataTransferTypeVoList;
        this.loading = false;
      } catch (error) {
        this.loading = false;
      }
    },
  },
  mounted() {
    this.startPolling();
  },
  beforeDestroy() {
    this.stopPolling();
  },
};
</script>
<style lang="scss" scoped>
@keyframes striped-flow {
  from {
    background-position: 0 100px;
  }
  to {
    background-position: 1.25em 1.25em;
  }
}
::v-deep.dialogBox {
  .el-form-item__content .el-input--small .el-input__inner {
    width: 188px !important;
  }
  .el-row {
    margin: 5px 0;
  }
  .dialog-footer {
    margin-top: 20px;
    justify-content: center !important;
  }
  .el-input-group {
    width: auto;
  }
}
::v-deep .animated-progress .el-progress-bar__outer {
  height: 15px; /* Adjust height as needed */
  background-color: rgb(235, 238, 245);
  background-image: linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.1) 25%,
    transparent 25%,
    transparent 50%,
    rgba(0, 0, 0, 0.1) 50%,
    rgba(0, 0, 0, 0.1) 75%,
    transparent 75%,
    transparent
  );
  background-size: 1.25em 1.25em;
  animation: striped-flow 3s linear infinite;
}
.TransferState .el-form-item {
  width: 343px;
}
</style>
