<template>
  <div>
    <!--    <a-card :bordered="false" style="margin-bottom: 10px;">
      &lt;!&ndash; 条件搜索 &ndash;&gt;
      <div class="table-page-search-wrapper">
        <a-form :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="公告标题">
                <a-input v-model="queryParam.noticeTitle" placeholder="请输入" allow-clear/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="操作人员">
                <a-input v-model="queryParam.createBy" placeholder="请输入" allow-clear/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="公告类型">
                <a-select placeholder="请选择" v-model="queryParam.noticeType" style="width: 100%" allow-clear>
                  <a-select-option v-for="(d, index) in typeOptions" :key="index" :value="d.dictValue">{{ d.dictLabel }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col>
              <span class="table-page-search-submitButtons" style="float: right;">
                <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button>
                <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>-->
    <a-card :bordered="false" class="table-card">
      <advance-table
        :columns="columns"
        :data-source="list"
        title="摄像头管理"
        :loading="loading"
        rowKey="id"
        size="middle"
        tableKey="system-notic-NoticIndex-table"
        @refresh="getList"
        :format-conditions="true"
        :pagination="{
          current: queryParam.pageNum,
          pageSize: queryParam.pageSize,
          total: total,
          showSizeChanger: true,
          showLessItems: true,
          showQuickJumper: true,
          showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
          onChange: changeSize,
          onShowSizeChange: onSizeChange,
        }"
      >
        <span slot="cameraType" slot-scope="{text, record}">
          <a-tag :color="text | noticeTypeFilter">
            {{ typeFormat(record) }}
          </a-tag>
        </span>
        <span slot="onlineStatus" slot-scope="{text, record}">
          <a-badge :status="Number(record.onlineStatus)===0?'error': 'processing'" :text="statusFormat(record) " />
        </span>
        <span slot="operation" slot-scope="{text, record}">
          <a @click="handleLive(record)" >
            实时视频
          </a>
        </span>
      </advance-table>
    </a-card>

    <ant-modal
      modalWidth="1000"
      modalHeight="800"
      :visible="showLiveModal"
      modal-title="播放器"
      :adjust-size="true"
      @cancel="cancel"
    >
      <div class="videoPlayer" slot="content">
        <SpeedDial :url="videoUrl" @triggerEvent="triggerEvent" ></SpeedDial>
      </div>
      <template slot="footer">
        <div></div>
      </template>
    </ant-modal>
  </div>
</template>
<script>
import { list, getLive } from '@/api/camera/camera'
import SpeedDial from '@/views/camera/modules/player'
import AdvanceTable from '@/components/pt/table/AdvanceTable'
import AntModal from '@/components/pt/dialog/AntModal'
export default {
  name: 'Camera',
  components: {
    SpeedDial, AdvanceTable, AntModal
  },
  data () {
    return {
      list: [],
      total: 0,
      // 类型数据字典
      typeOptions: [],
      statusOptions: [],
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      queryParam: {
        pageNum: 1,
        pageSize: 10
      },
      columns: [
        {
          title: '设备号',
          dataIndex: 'deviceSn',
          ellipsis: true,
          width: '10%'
        },
        {
          title: '通道号',
          dataIndex: 'channelNo',
          align: 'center'
        },
        {
          title: '设备名称',
          dataIndex: 'deviceName',
          align: 'center'
        },
        {
          title: '固件版本',
          dataIndex: 'hwVer',
          align: 'center'
        },
        {
          title: '软件版本',
          dataIndex: 'swVer',
          align: 'center'
        },
        {
          title: '设备状态',
          dataIndex: 'onlineStatus',
          scopedSlots: { customRender: 'onlineStatus' },
          align: 'center'
        },
        {
          title: '摄像头类型',
          dataIndex: 'cameraType',
          scopedSlots: { customRender: 'cameraType' }
        },
        {
          title: '设备接入时间',
          dataIndex: 'createTime',
          scopedSlots: { customRender: 'createTime' }
        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: '200',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      showLiveModal: false,
      showEditModal: false,
      videoUrl: ''
    }
  },
  filters: {
    noticeTypeFilter (type) {
      let value = 'blue'
      if (type === 'CF') {
        value = 'orange'
      } else if (type === 'CG') {
        value = 'pink'
      } else if (type === 'CB') {
        value = 'green'
      } else if (type === 'CH') {
        value = 'cyan'
      }
      return value
    }
  },
  created () {
    this.getDicts('sys_camera_status').then(response => {
      this.statusOptions = response.data
    })
    this.getDicts('sys_camera_type').then(response => {
      this.typeOptions = response.data
    })
    this.getList()
  },
  computed: {
  },
  watch: {
  },
  methods: {
    /** 查询定时任务列表 */
    getList () {
      this.loading = true
      list(this.queryParam).then(response => {
          this.list = response.data.records
          this.total = response.data.total
          this.loading = false
        }
      )
    },
    // 状态字典翻译
    statusFormat (row) {
      return this.selectDictLabel(this.statusOptions, row.onlineStatus)
    },
    // 类型字典翻译
    typeFormat (row) {
      return this.selectDictLabel(this.typeOptions, row.cameraType)
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParam.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10
      }
      this.handleQuery()
    },
    onShowSizeChange (current, pageSize) {
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    onSizeChange (current, size) {
      this.queryParam.pageNum = 1
      this.queryParam.pageSize = size
      this.getList()
    },
    changeSize (current, pageSize) {
      this.queryParam.pageNum = current
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      this.ids = this.selectedRows.map(item => item.id)
      this.single = selectedRowKeys.length !== 1
      this.multiple = !selectedRowKeys.length
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    handleAdd () {
      this.showAddModal = true
      this.$nextTick(() => (
        this.$refs.noticeAddForm.handleAdd()
      ))
    },
    handleUpdate (record) {
      this.showEditModal = true
      this.$nextTick(() => (
        this.$refs.noticeEditForm.handleUpdate(record)
      ))
    },
    handleLive(record) {
      const _this = this
      getLive(record).then((response) => {
        console.log(response)
        // 初始话播放器
        _this.videoUrl = response.data.url
        _this.showLiveModal = true
      })
    },
    // 监听到子组件传过来的播放状态 true是播放 false是暂停
    triggerEvent(value) {
      console.log('是否播放：', value)
    },
    // 取消按钮
    cancel () {
      this.showLiveModal = false
    }
  }

}
</script>

<style scoped>
.videoPlayer{
  height: 100%;
  width: 100%;
  position: absolute;
  left: 10;
  top: 18;
  z-index: 99;
}
</style>
