<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="日期" prop="checkDateM">
        <el-date-picker
          v-model="queryParams.checkDateM"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期"
          @change="handleQuery">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :search="false"></right-toolbar>
    </el-form>

    <table class="patrolTable" style="width: 100%;">
      <tr>
        <td rowspan="3"  colspan="2">漏点巡检记录表</td>
        <td>日期</td>
        <td colspan="2">{{ parseTime(pointPatrol.checkDateM,'{y}年{m}月{d}日')}}</td>
        <td colspan="2">{{ parseTime(pointPatrol.checkDateN,'{y}年{m}月{d}日')}}</td>
      </tr>
      <tr>
        <td>班组</td>
        <td colspan="2">{{pointPatrol.teamM}}班</td>
        <td colspan="2">{{pointPatrol.teamN}}班</td>
      </tr>
      <tr>
        <td>时间</td>
        <td colspan="2">早班一次</td>
        <td colspan="2">夜班一次</td>
      </tr>
      <tr>
        <td>漏点编号</td>
        <td>漏点位置</td>
        <td>介质</td>
        <td>挂牌（是/否）</td>
        <td>泄露状态<br/>（未检出/轻微/严重）</td>
        <td>挂牌（是/否）</td>
        <td>泄露状态<br/>（未检出/轻微/严重）</td>
      </tr>
    </table>
  </div>
</template>

<script>
import {
  addPointPatrol,
  delPointPatrol,
  getPointPatrol,
  listPointPatrol,
  updatePointPatrol
} from "@/api/asset/pointPatrol";
import {parseTime} from "../../../utils/ruoyi";
import PointRecord from "@/views/asset/pointRecord/index.vue";

export default {
  name: "PointPatrol",
  components: {PointRecord},
  data() {
    return {
      // 页面高度
      clientHeight: 300,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 漏点巡检表格数据
      pointPatrolList: [],
      pointPatrol: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        teamM: null,
        checkDateM: new Date(),
        signM: null,
        teamN: null,
        checkDateN: null,
        signN: null,
        remarks: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = (document.body.clientHeight - 80) * 0.8
    });
  },
  methods: {
    parseTime,
    /** 查询漏点巡检列表 */
    getList() {
      this.loading = true;
      if (this.queryParams.checkDateM) {
        this.queryParams.checkDateM = new Date();
      }
      listPointPatrol(this.queryParams).then(response => {
        this.pointPatrolList = response.rows;
        if (this.pointPatrolList.length > 0) {
          this.pointPatrol = this.pointPatrolList[0]
        }
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        teamM: null,
        checkDateM: null,
        signM: null,
        teamN: null,
        checkDateN: null,
        signN: null,
        remarks: null,
        delFlag: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加漏点巡检";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPointPatrol(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改漏点巡检";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePointPatrol(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPointPatrol(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除漏点巡检编号为"' + ids + '"的数据项？').then(function () {
        return delPointPatrol(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('asset/pointPatrol/export', {
        ...this.queryParams
      }, `pointPatrol_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped lang="scss">
/* 表格边框 */
table {
  border-collapse: collapse;
}

table td {
  border: 1px #b4b4b4 solid;
  padding: 10px;
  text-align: center;
}
</style>
