<template>
  <div class="contradiction-div">
    <div class="head-title">{{ pageTitle }}</div>
    <div class="search-div">
      <div style="width:90%;float: left;">
        <Row class="mb10">
          <Col span="8">
            <span>身份证号码：</span>
            <Input style="width: 70%;" clearable v-model="searchInfo.cardno" />
          </Col>
          <Col span="8">
            <span>姓名：</span>
            <Input style="width: 70%;" clearable v-model="searchInfo.name" />
          </Col>
          <Col span="8">
            <span>联系电话：</span>
            <Input style="width: 70%;" clearable v-model="searchInfo.tel" />
          </Col>
        </Row>
        <Row class="mb10">
          <Col span="8">
            <span>矛盾数量：</span>
            <Input style="width: 74%;" clearable type="number" v-model="searchInfo.trigger_num" />
          </Col>
          <Col span="16">
            <span>重点人员类别：</span>
            <Select style="width: 81%;" multiple v-model="user_types" :clearable="true">
              <Option v-for="item in constentObject.keyPopulationTypes" :key="item.value" :value="item.value">{{ item.label }}</Option>
            </Select>
          </Col>
        </Row>
        <Row class="">
          <Alert type="warning">自动触发“重点人”预警的矛盾纠纷事件。</Alert>
        </Row>
      </div>
      <div style="width:10%;float: left;">
        <Row>
          <Col>
            <Button type="primary" @click="searchData">搜索</Button>
            <Button type="primary" @click="resert" style="margin-left: 10px;">重置</Button>
          </Col>
        </Row>
      </div>
    </div>
    <Table stripe :columns="columns" :data="dataList">
      <template slot-scope="{row, index}" slot="name">
        <div style="">{{row.name}}</div>
      </template>
      <template slot-scope="{row, index}" slot="cardno">
        <div style="">{{row.cardno}}</div>
      </template>
      <template slot-scope="{row, index}" slot="action">
        <Button type="primary" @click="getInfo(row)">详情</Button>
      </template>
    </Table>
    <Page class="page_style"  :total="params.totalRecord" :current="params.pageNo"
            :page-size="params.pageSize" @on-change="changePageNo" show-total  show-sizer @on-page-size-change="size"/>
    <Modal v-model="modal" width="1000" title="预警详情">
      <Table stripe :columns="columns1" :data="monthFocusList">
        <template slot-scope="{ row, index }" slot="status">
          <div v-if="row.status == '1'">待处理</div>
          <div v-else-if="row.status == '2'">已受理</div>
          <div v-else-if="row.status == '3'">已完成</div>
        </template>
        <template slot-scope="{ row, index }" slot="log_type">
          <div v-if="row.log_type === '1'">已上报</div>
          <div v-else-if="row.log_type === '2'">已办结</div>
          <div v-else-if="row.log_type === '3'">已转办</div>
          <div v-else-if="row.log_type === '4'">已退回</div>
          <!--        <div v-else-if="row.logType === '5'">横传</div>-->
          <div v-else-if="row.log_type === '6'">已下派</div>
        </template>
        <template slot-scope="{ row, index }" slot="event_source">
          <div v-if="row.event_source == '1'">pc端</div>
          <div v-else-if="row.event_source == '2'">app端</div>
          <div v-else-if="row.event_source == '3'">第三方对接</div>
        </template>
        <template slot-scope="{ row, index }" slot="is_early_warning">
          <div class="flex-div">
            <div class="circle-div3" v-if="row.is_early_warning == '1'"></div>
            <div class="circle-div2" v-if="row.is_early_warning == '3'"></div>
            <div class="circle-div1" v-if="row.is_early_warning == '4'"></div>
          </div>
        </template>
        <template slot-scope="{ row, index }" slot="risk_level">
          <div class="flex-div">
            <div v-if="row.risk_level == '一般矛盾纠纷'">
              <img class="level-option-img" src="@/assets/images/warning4.png" alt="">
              <span style="padding-left: 10px;">一般矛盾纠纷</span>
            </div>
            <div v-if="row.risk_level == '复杂矛盾纠纷'">
              <img class="level-option-img" src="@/assets/images/warning5.png" alt="">
              <span style="padding-left: 10px;">复杂矛盾纠纷</span>
            </div>
            <div v-if="row.risk_level == '重大矛盾纠纷'">
              <img class="level-option-img" src="@/assets/images/warning6.png" alt="">
              <span style="padding-left: 10px;">重大矛盾纠纷</span>
            </div>
          </div>
        </template>
        <!-- <template slot-scope="{ row, index }" slot="is_point_event">
          <div v-if="row.is_point_event == '1'">是</div>
          <div v-else-if="row.is_point_event == '2'">否</div>
        </template> -->
        <template slot-scope="{ row, index }" slot="occurrence_address">
          <span>{{row.city}}{{row.area}}{{row.street}}{{row.community}}</span>
        </template>
        <template slot-scope="{row, index}" slot="action">
          <Button type="primary" class="mr5" @click="getEventInfo(row)">详情</Button>
        </template>
      </Table>
      <Page class="page_style"  :total="params1.totalRecord" :current="params1.pageNo"
              :page-size="params1.pageSize" @on-change="changePageNo1" show-total  show-sizer @on-page-size-change="size1"/>
    </Modal>
  </div>
</template>
<script>
import {
  findTriggerEventList, findTriggerEventIdList, findImportantUserHistoryPageList
} from '@/api/contradiction.js'
import { desensitizationIDCard } from '@/libs/tools.js'
import constentObject from '@/libs/constentObject'
export default {
  name: 'register',
  data () {
    return {
      user_types: [],
      searchInfo: {},
      columns: [
        { type: 'index', title: '序号', align: 'center', width: '80px' },
        { title: '姓名', slot: 'name', align: 'center' },
        { title: '身份证号码', slot: 'cardno', align: 'center' },
        { title: '联系电话', key: 'tel', align: 'center' },
        { title: '重点人员类别', key: 'user_type', align: 'center' },
        { title: '触发时间', key: 'trigger_time', align: 'center' },
        { title: '触发矛盾条数', key: 'trigger_num', align: 'center' },
        { title: '操作', slot: 'action', align: 'center' }
      ],
      dataList: [],
      monthFocusList: [],
      modal: false,
      columns1: [
        { type: 'index', fixed: 'left', title: '序号', align: 'center', width: '80px' },
        { title: '矛盾事件状态', slot: 'log_type', align: 'center', width: '100px' },
        { title: '矛盾来源', slot: 'event_source', align: 'center', width: '100px' },
        { title: '纠纷编号', key: 'event_code', align: 'center', width: '160px' },
        { title: '超时提示', slot: 'is_early_warning', align: 'center', width: '90px' },
        { title: '风险等级', slot: 'risk_level', align: 'center', width: '140px' },
        // { title: '预计办结时间', key: 'term_time', align: 'center', width: '150px' },
        // { title: '重点矛盾', slot: 'is_point_event', align: 'center', width: '90px' },
        { title: '纠纷大类', key: 'event_category_id', align: 'center', width: '90px' },
        { title: '纠纷小类', key: 'event_type_id', align: 'center', width: '200px' },
        { title: '纠纷发生时间', key: 'occurrence_time', align: 'center', width: '150px' },
        { title: '纠纷描述', key: 'dispute_description', align: 'center', width: '200px' },
        { title: '纠纷发生地', slot: 'occurrence_address', align: 'center', width: '140px' },
        { title: '详细地址', key: 'address', align: 'center', width: '140px' },
        { title: '上报人', key: 'reporting_name', align: 'center', width: '90px' },
        { title: '上报单位', key: 'reporting_unit', align: 'center', width: '100px' },
        { title: '操作', fixed: 'right', slot: 'action', align: 'center', width: '100px' }
      ],
      params: {
        pageNo: 1,
        pageSize: 10,
        totalRecord: 0
      },
      params1: {
        pageNo: 1,
        pageSize: 10,
        totalRecord: 0,
        trigger_event_id: ''
      },
      id: '',
      list_url: '',
      pageTitle: ''
    }
  },
  beforeDestroy () {
    this.list_url = ''
    this.searchInfo = {}
    this.params.pageNo = 1
    this.params.pageSize = 10
    this.user_types = []
  },
  deactivated () {
    this.list_url = ''
    this.searchInfo = {}
    this.params.pageNo = 1
    this.params.pageSize = 10
    this.user_types = []
  },
  mounted () {
    const { history, cityId, areaId } = this.$route.query
    // 综合谈判预警历史 判断
    if (history) {
      this.list_url = findImportantUserHistoryPageList
      this.pageTitle = '重点人员历史'
    } else {
      this.list_url = findTriggerEventList
      this.pageTitle = '重点人员'
    }
    if (cityId) {
      this.searchInfo.cityId = cityId
    }
    if (areaId) {
      this.searchInfo.areaId = areaId
    }
    this.getList()
  },
  activated () {
    const { history, cityId, areaId } = this.$route.query
    // 综合谈判预警历史 判断
    if (history) {
      this.list_url = findImportantUserHistoryPageList
      this.pageTitle = '重点人员历史'
    } else {
      this.list_url = findTriggerEventList
      this.pageTitle = '重点人员'
    }
    if (cityId) {
      this.searchInfo.cityId = cityId
    }
    if (areaId) {
      this.searchInfo.areaId = areaId
    }
    this.getList()
  },
  methods: {
    desensitizationIDCard (idCard) {
      return desensitizationIDCard(idCard)
    },
    getList (item) {
      let params = {
        pageNo: this.params.pageNo,
        pageSize: this.params.pageSize,
        totalRecord: this.params.totalRecord,
        user_type: this.user_types.join('|') || undefined
      }
      if (item) {
        params = Object.assign(params, item)
      } else {
        params = Object.assign(params, this.searchInfo)
      }
      this.list_url(params).then(res => {
        if (res.data.errcode === 0) {
          // 总数小于每页分页数（例如：10） 且 当前页大于1（例如 2）
          if (res.data.data.totalRecord <= this.params.pageSize && res.data.data.pageNo > 1) {
            this.params.pageNo = 1
            this.getList()
          } else {
            this.dataList = res.data.data.results
            this.params.totalRecord = res.data.data.totalRecord
          }
          return
        }
        this.$Message.error(res.data.errmsg)
      })
    },
    size (pageSize) {
      this.params.pageSize = pageSize
      this.searchData()
    },
    changePageNo (pageNo) {
      this.params.pageNo = pageNo
      this.getList()
    },
    searchData () { // 搜索
      this.params.pageNo = 1
      const { cityId, areaId } = this.$route.query
      if (cityId) {
        this.searchInfo.cityId = cityId
      }
      if (areaId) {
        this.searchInfo.areaId = areaId
      }
      this.getList(this.searchInfo)
    },
    resert () {
      this.searchInfo = {}
      this.params.pageNo = 1
      this.searchData()
      this.user_types = []
    },
    getInfo (item) {
      this.params1.pageNo = 1
      this.params1.pageSize = 10
      this.modal = true
      this.id = item.trigger_event_id
      this.getEventList()
    },
    getEventList () {
      this.params1.trigger_event_id = this.id
      findTriggerEventIdList(this.params1).then(res => {
        if (res.data.errcode === 0) {
          this.monthFocusList = res.data.data.results
          this.params1.totalRecord = res.data.data.totalRecord
          return
        }
        this.$Message.error(res.data.errmsg)
      })
    },
    size1 (pageSize) {
      this.params1.pageSize = pageSize
      this.changePageNo1()
    },
    changePageNo1 (pageNo) {
      this.params1.pageNo = pageNo
      this.getEventList()
    },
    getEventInfo (row) { // 详情页矛盾列表看详情
      this.$router.push({
        name: 'contradictionRegisterAdd',
        params: {
          what: 'edit',
          id: row.id,
          type: row.type
          // isShowInfo: true, // 控制化解过程显隐
          // isInfo: true
        }
      })
    }
  },
  computed: {
    constentObject () {
      return constentObject
    },
    serverUserInfo () {
      return this.$store.state.user.severUserInfo
    }
  }
}
</script>
<style scoped lang="less">
  .contradiction-div {
    padding: 10px;
    .search-div {
      float: left;
      width: 100%;
      padding: 15px 30px 15px 15px;
      // min-height: 200px;
      border: 1px solid skyblue;
      border-radius: 5px;;
      background-color: #f6fdfd;
      margin-bottom: 15px;
    }
  }
  .mb10 {
    margin-bottom: 10px;
  }
  .mt8 {
    margin-top: 8px;
  }
  .mr15 {
    margin-right: 15px;
  }
  .mr5 {
    margin-right: 5px;
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .flex-div {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }
  .circle-div1 {
    width: 10px;
    height: 10px;
    border-radius: 5px;
    background-color: red;
  }
  .circle-div2 {
    width: 10px;
    height: 10px;
    border-radius: 5px;
    background-color: orange;
  }
  .circle-div3 {
    width: 10px;
    height: 10px;
    border-radius: 5px;
    background-color: green;
  }
  .level-option-img{
    width: 20px;
    height: 20px;
    vertical-align: middle;
    margin-bottom: 3px;
  }
  .head-title{
    width: 100%;
    height: 35px;
    font-size: 16px;
    line-height: 30px;
  }
</style>
