<!--
 * @Author: SunTao 328867980@qq.com
 * @Date: 2024-11-20 11:58:33
 * @LastEditors: SunTao 328867980@qq.com
 * @LastEditTime: 2024-11-26 15:49:28
 * @FilePath: \znxjxt-ui\src\views\xj\document\maintenance-notice\index.vue
 * @Description: 养护通知单
-->
<template>
  <div class="content">
    <el-form
      :model="noticeForm"
      ref="noticeForm"
      size="small"
      :inline="true"
      label-width="5rem"
    >
      <el-form-item label="道路名称" prop="segmentName">
        <el-select
          v-model="noticeForm.segmentName"
          placeholder="请选择路段"
          clearable
        >
          <el-option
            v-for="item in segmentList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="采集时间" prop="dateTime">
        <el-date-picker
          v-model="dateTime"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          clearable
        />
      </el-form-item>
      <el-form-item label="病害类型" prop="paramsDefectType">
        <el-cascader
          v-model="paramsDefectType"
          :options="tableDefect"
          :props="{
            checkStrictly: true,
            emitPath: true,
            children: 'subTypes',
          }"
          clearable
        ></el-cascader>
      </el-form-item>
      <el-form-item label="病害状态" prop="state">
        <el-select
          v-model="noticeForm.state"
          placeholder="请选择病害状态"
          clearable
        >
          <el-option
            v-for="item in defectStatus"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上下行" prop="inspectDirection">
        <el-select
          v-model="noticeForm.inspectDirection"
          placeholder="请选择"
          clearable
        >
          <el-option label="上行" value="0" />
          <el-option label="下行" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="公里桩" prop="stakeRange">
        <el-input
          v-model="noticeForm.stakeStart"
          placeholder="起始公里桩"
          style="width: 10rem"
          clearable
        />
        <span style="margin: 0 5px">-</span>
        <el-input
          v-model="noticeForm.stakeEnd"
          placeholder="终止公里桩"
          style="width: 10rem"
          clearable
        />
        <el-tooltip
          class="item"
          effect="dark"
          content="格式为K0000+000"
          placement="top"
        >
          <i class="el-icon-info"></i>
        </el-tooltip>
      </el-form-item>
      <el-form-item label="病害长度" prop="lengthRange">
        <el-input-number
          v-model="noticeForm.minLen"
          controls-position="right"
          placeholder="最小长度"
          :min="0"
        ></el-input-number>
        <span style="margin: 0 5px">-</span>
        <el-input-number
          v-model="noticeForm.maxLen"
          controls-position="right"
          placeholder="最大长度"
          :min="0"
        ></el-input-number>
      </el-form-item>

      <el-form-item label="病害面积" prop="areaRange">
        <el-input-number
          v-model="noticeForm.minArea"
          controls-position="right"
          placeholder="最小面积"
          :min="0"
        ></el-input-number>
        <span style="margin: 0 5px">-</span>
        <el-input-number
          v-model="noticeForm.maxArea"
          controls-position="right"
          placeholder="最大面积"
          :min="0"
        ></el-input-number>
      </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>
    </el-form>
    <!-- 导航栏 -->
    <el-tabs v-model="activeName" @tab-click="getList">
      <el-tab-pane
        v-for="(item, index) in editableTabs"
        :key="`tabs-${index}`"
        :label="item.title"
        :name="item.value"
      >
        <!-- 标签页头 -->
        <span slot="label"
          ><i
            v-if="item.status === '1'"
            style="color: #67c23a"
            class="el-icon-success"
          ></i>
          <i
            v-if="item.status === '2'"
            style="color: #e6a23c"
            class="el-icon-info"
          ></i
          >{{ item.title }}</span
        >
        <!-- 表格 -->
        <el-table
          ref="noticeTable"
          :data="noticeList"
          v-loading="loading"
          style="width: 100%"
        >
          <el-table-column type="index" label="序号"> </el-table-column>
          <el-table-column
            width="200"
            label="时间"
            align="center"
            prop="segmentName"
          >
            <template slot-scope="scope">
              <span class="table-index">asd</span>
              {{ scope.row.segmentName }}
            </template>
          </el-table-column>
          <el-table-column label="消息内容" align="center" prop="stakeStart" />
          <el-table-column label="车牌号" align="center" prop="stakeEnd" />
          <el-table-column label="设备id" align="center" prop="stakeEnd" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                v-if="activeName === '1'"
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleView(scope.row)"
                v-hasPermi="['system:defect:edit']"
                >查看
              </el-button>
              <el-button
                v-if="activeName === '2'"
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:defect:edit']"
                >编辑
              </el-button>
              <el-button
                v-if="activeName === '1'"
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:defect:remove']"
                >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <div class="pagination-part">
          <el-pagination
            background
            :current-page.sync="pagination.page"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30, 40]"
            :page-size.sync="pagination.size"
            @size-change="handleSizeChange"
            layout="total, sizes, prev, pager, next, jumper"
            :total="tableTotal"
          >
          </el-pagination>
        </div>
      </el-tab-pane>
    </el-tabs>
    <!-- 编辑弹窗 -->
    <el-dialog
      title="生成表单"
      :visible.sync="editVisible"
      width="40rem"
      append-to-body
      :close-on-click-modal="false"
      destroy-on-close
      @close="editCancel"
    >
      <edit-dialog v-if="editVisible" @cancel="editCancel" />
    </el-dialog>

    <!-- 查看弹窗 -->
    <el-dialog
      title="查看表单"
      :visible.sync="viewVisible"
      width="60rem"
      append-to-body
      :close-on-click-modal="false"
      destroy-on-close
      @close="viewCancel"
    >
      <view-dialog v-if="viewVisible" @cancel="viewCancel" />
    </el-dialog>
  </div>
</template>

<script>
import EditDialog from "./components/edit-dialog.vue";
import ViewDialog from "./components/view-dialog.vue";
import { getSegment, getDefectList, getDefectStatus } from "@/api/xj/document";
export default {
  name: "MaintenanceNotice",
  components: {
    EditDialog,
    ViewDialog,
  },
  data() {
    return {
      // 查询表单
      noticeForm: {
        // 道路名称
        segmentName: "",
        // 病害状态
        state: "",
        // 上下行
        inspectDirection: "",
        // 公里桩
        stakeStart: "",
        stakeEnd: "",
        // 病害长度
        minLen: "",
        maxLen: "",
        // 病害面积
        minArea: "",
        maxArea: "",
      },
      // 接口查询表单
      searchForm: {},
      // 采集时间
      dateTime: [],
      // 病害类型
      paramsDefectType: [],
      // 道路名称下拉
      segmentList: [],
      // 病害类型下拉级联
      tableDefect: [],
      // 病害状态
      defectStatus: [],
      // 导航栏选择绑定
      activeName: "1",
      // 导航栏列表
      editableTabs: [
        { title: "已生成", value: "1",  status: "1" },
        { title: "未生成", value: "2", status: "2" },
      ],

      // 表格加载状态
      loading: false,

      // 表格数据
      noticeList: [],
      // 表格总数
      tableTotal: 0,
      // 分页
      pagination: {
        page: 1,
        size: 10,
      },

      // 编辑弹窗显隐控制
      editVisible: false,
      // 查看弹窗显隐控制
      viewVisible: false,
    };
  },
  created() {
    this.getList();
    this.getSegmentList();
    this.getDefectData();
    this.getDefectStatusList();
  },
  methods: {
    /**
     * @description: 获取路段下拉数据
     * @return {*}
     */
    getSegmentList() {
      getSegment().then(({ code, data }) => {
        if (code === 200) {
          this.segmentList = data;
        }
      });
    },

    /**
     * @description: 获取病害类型下拉数据
     * @return {*}
     */
    getDefectData() {
      getDefectList().then(({ code, data }) => {
        if (code === 200) {
          this.tableDefect = data;
        }
      });
    },

    /**
     * @description: 获取病害状态下拉数据
     * @return {*}
     */
    getDefectStatusList() {
      getDefectStatus().then(({ code, data }) => {
        if (code === 200) {
          this.defectStatus = data;
        }
      });
    },

    /**
     * @description: 点击查询
     * @param {*}
     * @return {*}
     */
    handleQuery() {
      this.searchForm = JSON.parse(JSON.stringify(this.noticeForm));
      this.pagination.page = 1;
      this.getList();
    },

    /**
     * @description: 点击重置
     * @param {*}
     * @return {*}
     */
    resetQuery() {
      this.noticeForm = {
        // 道路名称
        segmentName: "",
        // 病害状态
        state: "",
        // 上下行
        inspectDirection: "",
        // 公里桩
        stakeStart: "",
        stakeEnd: "",
        // 病害长度
        minLen: "",
        maxLen: "",
        // 病害面积
        minArea: "",
        maxArea: "",
      };
      this.searchForm = {};
      this.pagination.page = 1;
      this.getList();
    },

    /**
     * @description: 获取列表数据
     * @return {*}
     */
    getList() {
      this.loading = true;
      const data = {
        ...this.searchForm,
        ...this.pagination,
        activeName: this.activeName,
        startTime: this.dateTime ? this.dateTime[0] : "",
        endTime: this.dateTime ? this.dateTime[1] : "",
      };
      setTimeout(() => {
        this.noticeList = [{ id: "1", segmentName: "sSSSSSS" }];
        this.loading = false;
      }, 100);
    },

    /**
     * @description: 表格查看事件
     * @param {*} row
     * @return {*}
     */
    handleView(row) {
      this.viewVisible = true;
    },

    /**
     * @description: 表格编辑事件
     * @param {*} row
     * @return {*}
     */
    handleUpdate(row) {
      this.editVisible = true;
    },

    /**
     * @description: 表格删除事件
     * @param {*} row
     * @return {*}
     */
    handleDelete(row) {
      this.$modal
        .confirm(`是否确认删除选中的${[row.id].length}条记录？`)
        .then(() => {
          //   return deleteRoad([row.id]);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    /**
     * @description: 切换分页
     * @param {*} arg
     * @return {*}
     */
    handleCurrentChange(arg) {
      this.pagination.page = arg;
      this.getList();
    },

    /**
     * @description: 切换每页条数
     * @param {*} arg
     * @return {*}
     */
    handleSizeChange(arg) {
      this.pagination.size = arg;
      this.getList();
    },

    /**
     * @description: 编辑弹窗关闭事件
     * @param {*}
     * @return {*}
     */
    editCancel() {
      this.editVisible = false;
      this.getList();
    },

    /**
     * @description: 查看弹窗关闭事件
     * @param {*}
     * @return {*}
     */
    viewCancel() {
      this.viewVisible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  height: calc(100vh - 5.4rem);
  padding: 1rem;
}

/* 分页样式 */
.pagination-part {
  width: 100%;
  display: flex;
  padding-top: 1rem;
  justify-content: flex-end;
}
</style>
