<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="事件标题" prop="eventName">
        <el-input
          v-model="queryParams.eventName"
          placeholder="请输入事件标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="事件等级" prop="eventLevel">
        <el-input
          v-model="queryParams.eventLevel"
          placeholder="请输入事件等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="事发时间范围">
        <!-- <el-date-picker clearable
          v-model="queryParams.eventDateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择事发时间">
        </el-date-picker> -->
        <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="创建时间范围">
        <el-date-picker
          v-model="creatTimeScope"
          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="eventArea">
        <el-input
          v-model="queryParams.eventArea"
          placeholder="请输入事发地区(行政区划)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细位置" prop="eventAddress">
        <el-input
          v-model="queryParams.eventAddress"
          placeholder="请输入详细位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="经度" prop="eventLongitude">
        <el-input
          v-model="queryParams.eventLongitude"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="维度" prop="eventLatitude">
        <el-input
          v-model="queryParams.eventLatitude"
          placeholder="请输入维度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="出动次数" prop="sendAmbCount">
        <el-input
          v-model="queryParams.sendAmbCount"
          placeholder="请输入出动次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否关联其他单位事件" prop="selectIsNull">
        <el-select 
          clearable
          v-model="queryParams.selectIsNull"
          placeholder="请选择是否关联其他单位事件"
          @keyup.enter.native="handleQuery"
        >
        <el-option :value="1" label="是"></el-option>
        <el-option :value="2" label="否"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="报送单位" prop="alarmUnit">
        <el-input
          v-model="queryParams.alarmUnit"
          placeholder="请输入报送单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报送单位联系人" prop="alarmUnitContactor">
        <el-input
          v-model="queryParams.alarmUnitContactor"
          placeholder="请输入报送单位联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报送单位联系电话" prop="alarmUnitTelephone">
        <el-input
          v-model="queryParams.alarmUnitTelephone"
          placeholder="请输入报送单位联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="附件资料" prop="attachmentInfo">
        <el-input
          v-model="queryParams.attachmentInfo"
          placeholder="请输入附件资料"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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="['page:event: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="['page:event: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="['page:event: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="['page:event:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="eventList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="事件编码主键" align="center" prop="eventId" width="100"/> -->
      <el-table-column label="事件标题" align="center" prop="eventName" width="220" />
      <el-table-column label="出动次数" align="center" prop="sendAmbCount" width="80" />
      <el-table-column label="详细位置" align="center" prop="eventAddress" width="220" />
      <el-table-column label="事件类型" align="center" prop="eventType" />
      <el-table-column label="ai_110_id" align="center" prop="ai110Id" />
      <el-table-column label="事故类型" align="center" prop="accidentType" />
      
      
      <el-table-column label="事发地区(行政区划)" align="center" prop="eventArea"/>
      
      <!-- <el-table-column label="经度" align="center" prop="eventLongitude" />
      <el-table-column label="维度" align="center" prop="eventLatitude" /> -->
      <el-table-column label="事发时间" align="center" prop="eventDateTime">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.eventDateTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime">
        <!-- <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="eventDescribe" />
      <el-table-column label="报送单位" align="center" prop="alarmUnit" />
      <el-table-column label="报送单位联系人" align="center" prop="alarmUnitContactor" width="180"/>
      <el-table-column label="报送单位联系电话" align="center" prop="alarmUnitTelephone" width="180"/>
      <el-table-column label="附件资料" align="center" prop="attachmentInfo" />
      <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['page:event:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['page:event: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.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改事故对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :inline="true" label-width="150px" disabled>
        <el-row>
          <el-col :span="12">
            <el-form-item label="事件标题" prop="eventName" class="item-sjms">
              <el-input v-model="form.eventName" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="事件等级" prop="eventLevel" class="item-sjms">
              <el-input v-model="form.eventLevel" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="事发时间" prop="eventDateTime" class="item-sjms">
              <el-date-picker clearable
                v-model="form.eventDateTime"
                type="date"
                value-format="yyyy-MM-dd"
                >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="事发地区(行政区划)" prop="eventArea" class="item-sjms">
              <el-input v-model="form.eventArea" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="详细位置" prop="eventAddress" class="item-sjms">
              <el-input v-model="form.eventAddress" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出动次数" prop="sendAmbCount" class="item-sjms">
              <el-input v-model="form.sendAmbCount" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报送单位" prop="alarmUnit" class="item-sjms">
              <el-input v-model="form.alarmUnit" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报送单位联系人" prop="alarmUnitContactor" class="item-sjms">
              <el-input v-model="form.alarmUnitContactor" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报送单位联系电话" prop="alarmUnitTelephone" class="item-sjms">
              <el-input v-model="form.alarmUnitTelephone" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="附件资料" prop="attachmentInfo" class="item-sjms">
              <el-input v-model="form.attachmentInfo"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark" class="item-sjms">
              <el-input v-model="form.remark" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="事件描述" class="item-sjms" prop="eventDescribe">
              <el-input resize="none" :rows="3" v-model="form.eventDescribe" type="textarea" />
            </el-form-item>
          </el-col>
        </el-row>
        
        
        
        
        
        <!-- <el-form-item label="经度" prop="eventLongitude">
          <el-input v-model="form.eventLongitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="维度" prop="eventLatitude">
          <el-input v-model="form.eventLatitude" 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 { listEvent, getEvent, delEvent, addEvent, updateEvent } from "@/api/page/event";

export default {
  name: "Event",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 事故表格数据
      eventList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        eventName: null,
        eventType: null,
        eventLevel: null,
        eventDateTime: null,
        eventArea: null,
        eventAddress: null,
        selectIsNull: null,
        eventLongitude: null,
        eventLatitude: null,
        sendAmbCount: null,
        eventDescribe: null,
        alarmUnit: null,
        alarmUnitContactor: null,
        alarmUnitTelephone: null,
        attachmentInfo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      timeScope: [],
      creatTimeScope: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询事故列表 */
    getList() {
      this.loading = true;
      listEvent(this.queryParams).then(response => {
        this.eventList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        eventId: null,
        eventName: null,
        eventType: null,
        eventLevel: null,
        eventDateTime: null,
        eventArea: null,
        eventAddress: null,
        selectIsNull:null,
        eventLongitude: null,
        eventLatitude: null,
        sendAmbCount: null,
        eventDescribe: null,
        alarmUnit: null,
        alarmUnitContactor: null,
        alarmUnitTelephone: null,
        attachmentInfo: null,
        remark: null
      };
      this.resetForm("form");
      this.timeScope = [];
      this.creatTimeScope = [];
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
      this.queryParams.createStartTime = "";
      this.queryParams.createEndTime = "";
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.startTime = this.timeScope[0];
      this.queryParams.endTime = this.timeScope[1];
      this.queryParams.createStartTime = this.creatTimeScope[0];
      this.queryParams.createEndTime = this.creatTimeScope[1];
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.timeScope = [];
      this.creatTimeScope = [];
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
      this.queryParams.createStartTime = "";
      this.queryParams.createEndTime = "";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.eventId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加事故";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const eventId = row.eventId || this.ids
      getEvent(eventId).then(response => {
        this.form = response.data;
        this.open = true;
        // this.title = "修改事故";
        this.title = "详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.eventId != null) {
            updateEvent(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEvent(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const eventIds = row.eventId || this.ids;
      this.$modal.confirm('是否确认删除事故编号为"' + eventIds + '"的数据项？').then(function() {
        return delEvent(eventIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('page/event/export', {
        ...this.queryParams
      }, `event_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
