<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <!-- <el-form-item label="行政区划" prop="xzqh">
        <el-input
          v-model="queryParams.xzqh"
          placeholder="请输入行政区划"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="案件编号" prop="ajbh">
        <el-input
          v-model="queryParams.ajbh"
          placeholder="请输入案件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="案件描述" prop="ajms">
        <el-input
          v-model="queryParams.ajms"
          placeholder="请输入案件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="归队时间" prop="gdsj">
        <el-date-picker clearable
          v-model="queryParams.gdsj"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择归队时间">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="jjyxm">
        <el-input
          v-model="queryParams.jjyxm"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="时间戳" prop="sjc">
        <el-date-picker clearable
          v-model="queryParams.sjc"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择时间戳">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="纬度" prop="wd">
        <el-input
          v-model="queryParams.wd"
          placeholder="请输入纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="jd">
        <el-input
          v-model="queryParams.jd"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="备注信息" prop="bcxx">
        <el-input
          v-model="queryParams.bcxx"
          placeholder="请输入备注信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="案发地址" prop="afdz">
        <el-input
          v-model="queryParams.afdz"
          placeholder="请输入案发地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间范围">
        <el-date-picker
          v-model="timeScope"
          type="datetimerange"
          range-separator="至"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      
      <!-- <el-form-item label="结束时间" prop="jssj">
        <el-date-picker clearable
          v-model="queryParams.jssj"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="出动时间" prop="cdsj">
        <el-date-picker clearable
          v-model="queryParams.cdsj"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出动时间">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="立案方式代码" prop="lafsdm">
        <el-input
          v-model="queryParams.lafsdm"
          placeholder="请输入立案方式代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="topic" prop="topic">
        <el-input
          v-model="queryParams.topic"
          placeholder="请输入topic"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="xdsj">
        <el-date-picker clearable
          v-model="queryParams.xdsj"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="立案时间" prop="lasj">
        <el-date-picker clearable
          v-model="queryParams.lasj"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择立案时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="行政区划名称" prop="xzqhmc">
        <el-input
          v-model="queryParams.xzqhmc"
          placeholder="请输入行政区划名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到达现场时间" prop="ddxcsj">
        <el-date-picker clearable
          v-model="queryParams.ddxcsj"
          type="date"
          value-format="yyyy-MM-dd"
          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-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" v-if="false">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:fire:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:fire:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:fire:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:fire:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fireList" @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="xzqh" />
      <el-table-column label="案件编号" align="center" prop="ajbh" />
      <el-table-column label="案件描述" align="center" prop="ajms" />
      <!-- <el-table-column label="归队时间" align="center" prop="gdsj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gdsj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="${comment}" align="center" prop="jjyxm" /> -->
      <!-- <el-table-column label="时间戳" align="center" prop="sjc" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sjc, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="纬度" align="center" prop="wd" />
      <el-table-column label="经度" align="center" prop="jd" />
      <el-table-column label="备注信息" align="center" prop="bcxx" /> -->
      <!-- <el-table-column label="结束时间" align="center" prop="jssj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jssj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="案发地址" align="center" prop="afdz" />
      <!-- <el-table-column label="出动时间" align="center" prop="cdsj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cdsj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="立案方式代码" align="center" prop="lafsdm" />
      <el-table-column label="topic" align="center" prop="topic" />
      <el-table-column label="${comment}" align="center" prop="xdsj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xdsj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="立案时间" align="center" prop="lasj" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lasj, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="行政区划名称" align="center" prop="xzqhmc" />
      <!-- <el-table-column label="到达现场时间" align="center" prop="ddxcsj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ddxcsj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:fire:edit']"
          >修改</el-button> -->
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:fire:remove']"
          >删除</el-button> -->
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />

    <!-- 添加或修改119数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" disabled :inline="true">
        <el-row>
          <el-col :span="12">
            <el-form-item label="行政区划" class="item-ajms" prop="xzqh">
              <el-input v-model="form.xzqh" placeholder="请输入行政区划" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件编号" class="item-ajms" prop="ajbh">
              <el-input v-model="form.ajbh" placeholder="请输入案件编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="归队时间" class="item-ajms" prop="gdsj">
              <el-date-picker clearable
                v-model="form.gdsj"
                type="date"
                value-format="yyyy-MM-dd"
                >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注信息" class="item-ajms" prop="bcxx">
              <el-input v-model="form.bcxx" placeholder="请输入备注信息" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束时间" class="item-ajms" prop="jssj">
              <el-date-picker clearable
                v-model="form.jssj"
                type="date"
                value-format="yyyy-MM-dd"
                >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案发地址" class="item-ajms" prop="afdz">
              <el-input v-model="form.afdz" placeholder="请输入案发地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出动时间" class="item-ajms" prop="cdsj">
              <el-date-picker clearable
                v-model="form.cdsj"
                type="date"
                value-format="yyyy-MM-dd"
                >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="立案方式" class="item-ajms" prop="lafsdm">
              <el-input v-model="form.lafsdm" placeholder="请输入立案方式代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="立案时间" class="item-ajms" prop="lasj">
              <el-date-picker clearable
                v-model="form.lasj"
                type="date"
                value-format="yyyy-MM-dd"
                >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="行政区划名称" class="item-ajms" prop="xzqhmc">
              <el-input v-model="form.xzqhmc" placeholder="请输入行政区划名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="到达现场时间" class="item-ajms" prop="ddxcsj">
              <el-date-picker clearable
                v-model="form.ddxcsj"
                type="date"
                value-format="yyyy-MM-dd"
                >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="案件描述" prop="ajms" class="item-ajms">
              <el-input v-model="form.ajms" type="textarea" resize="none" :rows="3" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        
        <!-- <el-form-item label="${comment}" prop="jjyxm">
          <el-input v-model="form.jjyxm" placeholder="请输入${comment}" />
        </el-form-item> -->
        <!-- <el-form-item label="时间戳" prop="sjc">
          <el-date-picker clearable
            v-model="form.sjc"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择时间戳">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="纬度" prop="wd">
          <el-input v-model="form.wd" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="经度" prop="jd">
          <el-input v-model="form.jd" placeholder="请输入经度" />
        </el-form-item> -->
        
        <!-- <el-form-item label="topic" prop="topic">
          <el-input v-model="form.topic" placeholder="请输入topic" />
        </el-form-item> -->
        <!-- <el-form-item label="${comment}" prop="xdsj">
          <el-date-picker clearable
            v-model="form.xdsj"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </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> -->
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFire, getFire, delFire, addFire, updateFire } from "@/api/page/fire";

export default {
  name: "Fire",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 119数据表格数据
      fireList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        // xzqh: null,
        ajbh: null,
        ajms: null,
        // gdsj: null,
        // jjyxm: null,
        // sjc: null,
        // wd: null,
        // jd: null,
        // bcxx: null,
        jssj: null,
        afdz: null,
        cdsj: null,
        // lafsdm: null,
        // topic: null,
        // xdsj: null,
        // lasj: null,
        // xzqhmc: null,
        // ddxcsj: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      timeScope: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询119数据列表 */
    getList() {
      this.loading = true;
      listFire(this.queryParams).then(response => {
        this.fireList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        xzqh: null,
        ajbh: null,
        ajms: null,
        gdsj: null,
        jjyxm: null,
        sjc: null,
        wd: null,
        jd: null,
        bcxx: null,
        jssj: null,
        afdz: null,
        cdsj: null,
        lafsdm: null,
        topic: null,
        xdsj: null,
        lasj: null,
        xzqhmc: null,
        ddxcsj: null,
        createTime: null
      };
      this.timeScope = [];
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.queryParams.startTime = this.timeScope[0];
      this.queryParams.endTime = this.timeScope[1];
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.timeScope = [];
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
      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 = "添加119数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFire(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) {
            updateFire(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFire(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除119数据编号为"' + ids + '"的数据项？').then(function() {
        return delFire(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/fire/export', {
        ...this.queryParams
      }, `fire_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
