<template>
  <div class="global-variable">
    <div class="condition">
      <el-form
        :inline="true"
        ref="ruleForm"
        :model="formInline"
        class="demo-form-inline"
        :rules="rules"
      >
        <el-form-item label="风场名称:" prop="fieldName">
          <el-input
            size="small"
            v-model="formInline.fieldName"
            placeholder="请输入风场名称"
          ></el-input>
        </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">
      <el-table
        v-loading="loading"
        class="center-align-table"
        :data="tableData"
        border
        :cell-style="rowStyle"
      >
        <el-table-column
          align="center"
          fixed
          prop="fieldName"
          label="风场名称"
          width="100"
        >
        </el-table-column>
        <el-table-column align="center" label="批次编号" prop="batchCode">
        </el-table-column>
        <el-table-column prop="loginName" align="center" label="分析状态">
          <template slot-scope="scope">
            <span>
              {{
                scope.row.analysisState == 0
                  ? "分析中"
                  : scope.row.analysisState == -1
                  ? "未分析"
                  : scope.row.analysisState == 1
                  ? "分析完成"
                  : "/"
              }}</span
            >
          </template>
        </el-table-column>
        <el-table-column
          prop="errState"
          align="center"
          label="异常状态"
          width="100"
        >
          <template slot-scope="scope">
            <span>
              {{
                scope.row.errState == 0
                  ? "未异常"
                  : scope.row.errState == 1
                  ? "异常"
                  : "/"
              }}</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="roleName" align="center" label="异常信息">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.errState == 1"
              @click="abnormalDialog(scope.row, '异常详情')"
              type="text"
              size="small"
              >异常详情</el-button
            >
            <span v-else>/</span>
          </template>
        </el-table-column>
        <el-table-column prop="roleName" align="center" label="分析记录">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.analysisState == 1 && scope.row.errState !== 1"
              @click="handleAssetssDetail(scope.row)"
              type="text"
              size="small"
              >分析详情</el-button
            >
            <span v-else>/</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" align="center" label="创建时间">
        </el-table-column>
        <el-table-column
          prop="transition"
          align="center"
          fixed="right"
          label="操作"
          width="200"
        >
          <template slot-scope="scope">
            <el-button
              @click="handleAssetss(scope.row)"
              type="text"
              size="small"
              >分析</el-button
            >
            <el-button
              @click="abnormalDialog(scope.row, '异常描述')"
              type="text"
              size="small"
              >异常描述</el-button
            >
          </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>
    <!-- 弹出层 -->
    <!-- 异常信息 /异常描述-->
    <my-dialog
      :visible="dialogVisible"
      :errorInfo="errorInfo"
      :title="title"
      :rowInfo="rowInfo"
      @confirm="handleConfirm"
    >
      <div slot="tableEl">
        <el-empty description="暂无数据"></el-empty>
      </div>
    </my-dialog>
  </div>
</template>

<script>
import MyDialog from "./components/dialogCom.vue";
import { getAnalysisResultList } from "@/api/performance";
export default {
  components: {
    MyDialog,
  },
  data() {
    return {
      dialogVisible: false,
      loadingView: false,
      loading: false, //数据加载中
      errorInfo: "",
      rules: {
        fieldName: { trigger: "blur" },
      },
      roleList: [],
      formInline: {
        fieldName: undefined,
        pageNum: 1,
        pageSize: 10,
        totalSize: 0,
      },
      tableData: [],
      rowInfo: {},
      title: "",
    };
  },
  created() {
    this.getTableList();
  },

  methods: {
    //分析
    handleAssetss(row) {
      this.$router.push({
        path: "/home/performance/editAssets",
        query: {
          batchCode: row.batchCode,
          analysisTypeCode: row.analysisTypeCode,
          fieldEngineCode: row.fieldCode,
        },
      });
    },
    //分析详情
    handleAssetssDetail(row) {
      this.$router.push({
        path: "/home/performance/assetssDetail",
        query: {
          batchCode: row.batchCode,
          analysisTypeCode: row.analysisTypeCode,
          fieldEngineCode: row.fieldEngineCode,
        },
      });
    },
    abnormalDialog(row, title) {
      this.dialogVisible = true;
      if (title === "异常详情") {
        this.errorInfo = row.errInfo;
        this.rowInfo = {};
      } else if (title === "异常描述") {
        this.errorInfo = "";
        this.rowInfo = row;
      }
      this.title = title;
    },
    handleConfirm(slotContent) {
      this.dialogVisible = false;
    },
    //分页数据切换
    handleCurrentChange(val) {
      this.formInline.pageNum = val;
      this.getTableList();
    },
    async getTableList() {
      try {
        this.loading = true;
        const result = await getAnalysisResultList({
          ...this.formInline,
          totalSize: undefined,
        });
        this.tableData = result.data.list;
        this.formInline.totalSize = result.data.totalSize;
        this.loading = false;
      } catch (error) {
        this.$message({
          type: "error",
          message: "请检查是否连接网络",
        });
      }
    },
    rowStyle() {
      return "text-align:center";
    },
    // 查询
    onSubmit() {
      this.getTableList();
    },
    // 重置
    reset(formName) {
      this.$refs[formName].resetFields();
      this.getTableList();
    },
  },
};
</script>

<style lang="scss" scoped>
.general {
  display: flex;
  flex-wrap: wrap;

  .condition {
    width: 50%;
    display: flex;

    p {
      width: 100px;
      text-align: right;
      line-height: 40px;
    }

    span {
      line-height: 40px;

      padding-left: 20px;
    }

    .el-select {
      width: 100%;
      margin-bottom: 20px;
    }

    .el-input {
      margin-bottom: 20px;
    }
  }
}

.attachment {
  display: flex;
  padding-top: 10px;

  p {
    margin-right: 20px;
    color: #409eff;
  }
}

.addition {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.demo-ruleForm {
  .el-form-item {
    margin-bottom: 25px;
  }
}
</style>
