<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-select
          v-model="query.visualIntercomId"
          filterable
          clearable
          size="small"
          placeholder="请选择可视对讲"
          class="filter-item"
          style="width: 160px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.VisualIntercom"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select
          v-model="query.majorType"
          filterable
          clearable
          size="small"
          placeholder="请选择主要类型"
          class="filter-item"
          style="width: 160px"
          @change="majorTypeChangeHandle"
        >
          <el-option
            v-for="item in optionsObj.MajorType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select
          v-model="query.minorType"
          filterable
          clearable
          size="small"
          placeholder="请选择次要类型"
          class="filter-item"
          style="width: 160px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in optionsObj.MinorType"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-cascader
          v-model="query.personId"
          filterable
          :options="optionsObj.Name"
          :props="{ checkStrictly: true, emitPath: false }"
          clearable
          size="small"
          placeholder="请选择人员"
          style="width: 200px"
          class="filter-item"
          @change="crud.toQuery"
        />
        <el-input
          v-model="query.content"
          clearable
          size="small"
          placeholder="请输入筛选内容"
          style="width: 200px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <date-range-picker
          type="datetimerange"
          v-model="customs.timeRange"
          class="date-item"
          style="width: 400px !important"
          @change="crud.toQuery"
        />
        <rrOperation />
      </div>
      <crudOperation :permission="permission"></crudOperation>
    </div>
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :visible.sync="dialogVisible"
      title="图片预览"
      width="800px"
    >
      <el-image
        fit="contain"
        :src="`${VUE_APP_BASE_API}${form.picPath}`"
        :preview-src-list="[`${VUE_APP_BASE_API}${form.picPath}`]"
      />
    </el-dialog>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      style="width: 100%"
      @selection-change="crud.selectionChangeHandler"
    >
      <!-- <el-table-column type="selection" width="55" /> -->
      <el-table-column
        v-for="item in visualIntercomLogTableOptions"
        :key="item.prop"
        :label="item.label"
        :prop="item.prop"
        :width="item.width"
        :align="item.align"
        :fixed="item.fixed"
        :sortable="item.sortable"
      >
      </el-table-column>
      <el-table-column label="操作" width="130px" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.picPath"
            size="mini"
            type="success"
            icon="el-icon-view"
            @click="toView(scope.row)"
            style="margin-right: 5px"
          />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import permission from '@/directive/permission'
import DateRangePicker from '@/components/DateRangePicker'
//import crudRailAreaInOutLog from '@/api/positioning/railAreaInOutLog'
import { getOptions } from '@/api/visualIntercom/public'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import { crudOperation, rrOperation, udOperation, pagination } from '@crud'
import crudComps from '@crud'
import { visualIntercomLogTableOptions } from '../tableConfig'
import Dayjs from 'dayjs'
const defaultForm = {
  id: '',
}

export default {
  name: 'VisualIntercomLog',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, DateRangePicker },
  cruds() {
    return CRUD({
      title: '可视对讲事件记录',
      url: 'visualIntercom/log/getListJson',
      listOrder: [],
      //crudMethod: { ...crudRailAreaInOutLog },
      optShow: { add: false, edit: false, del: false },
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    },
    VUE_APP_BASE_API() {
      return process.env.VUE_APP_BASE_API
    },
  },
  created() {
    this.getOptions()
  },
  data() {
    return {
      dialogVisible: false,
      dialogType: '',
      datetimeRange: undefined,
      visualIntercomLogTableOptions,
      viewLoading: false,
      permission: {},
      optionsObj: {
        VisualIntercom: [],
        MajorType: [],
        MajorType: [],
        Name: [],
      },
    }
  },
  methods: {
    toView(data) {
      this.form = data
      ;(this.dialogType = 'view'), (this.dialogVisible = true)
    },
    closeDialog() {
      this.dialogVisible = false
    },
    async majorTypeChangeHandle(data) {
      this.query.minorType = ''
      if (data) await this.getMinorTypeOptions(data)
      else this.optionsObj['MinorType'] = []
      this.crud.toQuery()
    },
    async getOptions() {
      Object.keys(this.optionsObj).forEach(async (key) => {
        if (key == 'MinorType') return
        try {
          let res = await getOptions(key)
          if (res.code === 20000) this.optionsObj[key] = res.data.content
        } catch (error) {
          console.log(error)
        }
      })
    },
    async getMinorTypeOptions(data) {
      try {
        this.optionsObj['MinorType'] = []
        let res = await getOptions('MinorType', { id: data })
        if (res.code === 20000) this.optionsObj['MinorType'] = res.data.content
      } catch (error) {
        console.log(error)
      }
    },
  },
}
</script>

<style></style>