<template>
  <div class="app-container">
    <div class="listTitle">
      <span>隐患整改台账</span>
      <span class="addBtn" @click="handleAdd(2)">
        <i class="el-icon-plus"></i>
        添加
      </span>
    </div>
    <el-table v-loading="loading" :data="filingsList">
      <el-table-column label="序号" type="index" width="50" align="center" />
      <el-table-column
        label="整改状态"
        align="center"
        prop="rectificationStatus"
        min-width="120"
      />
      <el-table-column
        label="隐患描述"
        align="center"
        prop="hazardDescription"
        min-width="120"
      />
      <el-table-column
        label="整改措施"
        align="center"
        prop="rectificationMeasures"
        min-width="120"
      />
      <el-table-column
        label="所在工区"
        align="center"
        prop="hazardLocationArea"
        min-width="120"
      />

      <el-table-column
        label="整改日期"
        align="center"
        prop="rectificationDate"
        min-width="120"
      />

      <el-table-column
        label="整改后审核意见"
        align="center"
        prop="reviewOpinionsAfterRectification"
        min-width="120"
      />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="180"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改安全备案对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
      @close="closeDialog"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="整改状态" prop="rectificationStatus">
          <el-input
            v-model="form.rectificationStatus"
            type="textarea"
            placeholder="请输入整改状态"
          />
        </el-form-item>

        <el-form-item label="隐患描述" prop="hazardDescription">
          <el-input
            v-model="form.hazardDescription"
            type="textarea"
            placeholder="请输入隐患描述"
          />
        </el-form-item>
        <el-form-item label="整改措施" prop="rectificationMeasures">
          <el-input
            v-model="form.rectificationMeasures"
            type="textarea"
            placeholder="请输入整改措施"
          />
        </el-form-item>
        <el-form-item label="所在工区" prop="hazardLocationArea">
          <el-input
            v-model="form.hazardLocationArea"
            type="textarea"
            placeholder="请输入所在工区"
          />
        </el-form-item>
        <el-form-item label="整改日期" prop="rectificationDate">
          <el-date-picker
            v-model="form.rectificationDate"
            type="year"
            placeholder="请选择整改日期"
            style="width: 100%"
            value-format="yyyy"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="整改后审核意见"
          prop="reviewOpinionsAfterRectification"
        >
          <el-input
            v-model="form.reviewOpinionsAfterRectification"
            type="textarea"
            placeholder="请输入整改后审核意见"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRectification,
  getRectification,
  addRectification,
  updateRectification,
  delRectification,
  exportRectification,
} from "@/api/build/rectification";

export default {
  name: "Filings",
  props: ["proNo", "proCode"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ids: null,
        data: {},
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},

      filingsList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    closeDialog() {},
    /** 查询安全备案列表 */
    getList() {
      this.loading = true;
      this.queryParams.data.proNo = this.proNo;
      this.queryParams.data.proCode = this.proCode;
      listRectification(this.queryParams).then((response) => {
        this.filingsList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
      };
      this.resetForm("form");
    },
    // 查询表单重置
    resetQueryForm() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        data: {},
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetQueryForm();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd(type) {
      this.reset();
      this.open = true;
      this.form.type = type;
      if (this.form.type == 1) {
        this.title = "添加整体措施方案";
      } else {
        this.title = "添加度汛方案";
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getRectification(id).then((response) => {
        this.form = response.data;
        this.open = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.proNo = this.proNo;
          this.form.proCode = this.proCode;
          if (this.form.id != null) {
            updateRectification(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addRectification(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      if (ids) {
        this.$confirm("是否删除选中的数据？", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return delRectification(ids);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(function () {});
      } else {
        this.$message.warning("请选择要删除的数据！！");
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/css/dialog.scss";
// ::v-deep {
// .el-dialog {
//   margin-top: 10vh !important;
// }
// }
.listTitle {
  font-size: 14px;
  padding-left: 10px;
  padding-right: 30px;
  margin: 20px 0;
  border-left: 2px solid #36b29e;
  display: flex;
  justify-content: space-between;
  span:nth-child(1) {
    font-weight: bold;
  }
  .addBtn {
    color: #36b29e;
    cursor: pointer;
  }
  .addBtn:hover {
    color: #31a08e;
  }
}
</style>
