<template>
  <el-dialog
    title="详情"
    :visible.sync="open"
    width="90%"
    :close-on-click-modal="false"
    @close="handleClose"
  >
    <div class="tableHeight">
      <Com-table :tableFormat="tableFormat" :tableData="tableData"></Com-table>
    </div>
     <pagination
        :total="pages.total"
        :page.sync="pages.pageNo"
        :limit.sync="pages.pageSize"
        @pagination="getDetail"
      />
      <span slot="footer">
        <el-button @click="open = false">关 闭</el-button>
      </span>
  </el-dialog>
</template>

<script>
import { faultMessagePage } from "@/api/home";
import { detailTableFormat } from "../utils/index.json";
export default {
  data() {
    return {
      tableFormat: detailTableFormat,
      tableData: [],
      open: false,
      currentData: {},
      type: "",
      time: null,
      pages: {
        pageNo: 1,
        pageSize: 50,
        total: 0,
      },
    };
  },
  methods: {
    handleInit({ data, type, time }) {
      this.currentData = data;
      this.type = type;
      this.time = time;
      this.open = true;
      this.getDetail();
    },
    getDetail() {
      let obj = {
        orgNo: this.currentData.orgNo,
        mtrlNo: this.currentData.mtrlNo,
        mtrlDes: this.currentData.mtrlDes,
        startTime: this.time && this.time[0] || null,
        endTime: this.time && this.time[1] || null,
        identify: this.type === "workNumber" ? 0 : 1,
        ...this.pages,
      };
      faultMessagePage(obj).then((res) => {
        if (res && res.code == 200) {
          this.tableData = res.data.records || [];
          this.pages.total = res.data.total;
        } else {
          this.$message.warning(res.msg || "加载失败");
        }
      });
    },
    handleClose() {
      this.open = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.tableHeight {
  height: 500px;
}
::v-deep {
  .el-dialog__footer {
    text-align: center;
  }
}
</style>
