<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" style="position: relative">
       <el-form-item label="时间" prop="timeRanage">
        <el-date-picker
            v-model="queryParams.timeRanage"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </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-button icon="el-icon-plus" size="mini" @click="goAdd">新增</el-button>
      </el-form-item>

      <div style="    position: absolute;top: 0;right: 0;">
        <el-button type="primary" icon="el-icon-warning-outline" size="mini" @click="handleQuery">冲突检测</el-button>
        <el-button type="primary" icon="el-icon-help" size="mini" @click="handleQuery">合并检测</el-button>
      </div>
    </el-form>


    <el-table v-loading="loading" :data="reportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <el-table-column label="施工路段" align="center" prop="section" width='200' fixed="left"/>
      <el-table-column label="方向" align="center" prop="direction" width='100'>
      <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_direction" :value="scope.row.direction"/>
        </template>
      </el-table-column>
      <el-table-column label="起止桩号" align="center"  width='300'>
        <template v-slot="scope">
          <div>K{{scope.row.startKm?scope.row.startKm:'0' }}+{{scope.row.startHectometer?scope.row.startHectometer:'0' }} ~ K{{scope.row.endKm?scope.row.endKm:'0' }}+{{scope.row.endHectometer?scope.row.endHectometer:'0' }}</div>
        </template>

      </el-table-column>
<!--      <el-table-column label="开始公里桩" align="center" prop="startKm" width='100'/>-->
<!--      <el-table-column label="开始百米桩" align="center" prop="startHectometer" width='100'/>-->
<!--      <el-table-column label="结束公里桩" align="center" prop="endKm" width='100'/>-->
<!--      <el-table-column label="结束百米桩" align="center" prop="endHectometer" width='100'/>-->
       <el-table-column label="施工内容一" align="center" prop="contentOne" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.content_one" :value="scope.row.contentOne"/>
        </template>
      </el-table-column>
       <el-table-column label="施工内容二" align="center" prop="contentTwo" width="120">
        <template slot-scope="scope">
          <dict-tag v-if="scope.row.contentOne == 2" :options="dict.type.content_two" :value="scope.row.contentTwo"/>
          <div v-if="scope.row.contentOne != 2">{{scope.row.contentTwo}}</div>
        </template>
      </el-table-column>
      <el-table-column label="占用车道" align="center" prop="lane" />
      <el-table-column label="预计开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预计结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="现场负责人" align="center" prop="manageUser" width="120"/>
      <el-table-column label="现场负责人手机号" align="center" prop="managePhone" width="120"/>
      <el-table-column label="现场安全员" align="center" prop="saveUser" width="120"/>
      <el-table-column label="安全员手机号" align="center" prop="savePhone" width="120"/>
      <!-- <el-table-column label="填报人" align="center" prop="createUser" /> -->
      <!-- <el-table-column label="修改人" align="center" prop="updateUser" /> -->
      <!-- <el-table-column label="是否合并 0：否 1：是" align="center" prop="isMerge" /> -->
       <el-table-column label="状态" align="center" prop="status" width="120" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.report_status" :value="scope.row.status"/>
          <!-- <div v-if="scope.row.report_status != 2">{{scope.row.contentTwo}}</div> -->
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:report:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:report:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="施工计划id" prop="planId">
          <el-input v-model="form.planId" placeholder="请输入施工计划id" />
        </el-form-item>
        <el-form-item label="占用车道" prop="lane">
          <el-input v-model="form.lane" placeholder="请输入占用车道" />
        </el-form-item>
        <el-form-item label="预计开始时间" prop="startTime">
          <el-date-picker clearable
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预计开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预计结束时间" prop="endTime">
          <el-date-picker clearable
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预计结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="现场负责人" prop="manageUser">
          <el-input v-model="form.manageUser" placeholder="请输入现场负责人" />
        </el-form-item>
        <el-form-item label="现场负责人手机号" prop="managePhone">
          <el-input v-model="form.managePhone" placeholder="请输入现场负责人手机号" />
        </el-form-item>
        <el-form-item label="现场安全员" prop="saveUser">
          <el-input v-model="form.saveUser" placeholder="请输入现场安全员" />
        </el-form-item>
        <el-form-item label="安全员手机号" prop="savePhone">
          <el-input v-model="form.savePhone" placeholder="请输入安全员手机号" />
        </el-form-item>
        <el-form-item label="填报人" prop="createUser">
          <el-input v-model="form.createUser" placeholder="请输入填报人" />
        </el-form-item>
        <el-form-item label="修改人" prop="updateUser">
          <el-input v-model="form.updateUser" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="是否合并 0：否 1：是" prop="isMerge">
          <el-input v-model="form.isMerge" placeholder="请输入是否合并 0：否 1：是" />
        </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 { listReport, getReport, delReport, addReport, updateReport } from "@/api/system/report";

export default {
  name: "Report",
  dicts: ['sys_direction','content_one','content_two','report_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planId: null,
        lane: null,
        startTime: null,
        endTime: null,
        manageUser: null,
        managePhone: null,
        saveUser: null,
        savePhone: null,
        createUser: null,
        updateUser: null,
        isMerge: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
     goAdd(){
          this.$router.push({path: '/addReport',query:{ routerName:'新增'}})
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listReport(this.queryParams).then(response => {
        this.reportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        planId: null,
        lane: null,
        startTime: null,
        endTime: null,
        manageUser: null,
        managePhone: null,
        saveUser: null,
        savePhone: null,
        createUser: null,
        createTime: null,
        updateUser: null,
        updateTime: null,
        isMerge: 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) {
      row.routerName = '修改'
       this.$router.push({path: '/addReport',query:row})
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReport(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 delReport(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/report/export', {
        ...this.queryParams
      }, `report_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
