<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               ref="crud"
               @row-del="rowDel"
               v-model="form"
               :permission="permissionList"
               @row-update="rowUpdate"
               @row-save="rowSave"
               :before-open="beforeOpen"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-turn-off"
                   plain>消警
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-turn-off"
                   plain>撤防
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-turn-off"
                   plain>旁路恢复
        </el-button>
        <el-button type="warning"
                   size="small"
                   icon="el-icon-download"
                   plain>导出
        </el-button>
        <!-- <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   v-if="permission.notice_delete"
                   @click="handleDelete">删 除
        </el-button> -->
      </template>
      <template slot-scope="{row}"
                slot="alarmInfo">
        <!-- <el-tag type="danger"> -->
          {{row.alarmInfo}}
          <!-- </el-tag> -->
      </template>
      <template #menu="{row,index}">
        <el-button @click="tip(row,index)"
                 type="primart" plain
                 size="small" >详情</el-button>
        <el-button 
          @click="tip(row,index)"
          type="primart" plain
          size="small"
          :disabled="row.cancelTime == ''">
          消警
        </el-button>
        <!-- <el-button @click="tip(row,index)"
        type="primart" plain
                 size="small">撤防</el-button> -->
        <!-- <el-button @click="tip(row,index)"
        type="primart" plain
                 size="small">旁路恢复</el-button> -->
        <el-button 
          @click="linkVideo(row,index)"
          type="primart" 
          plain
          size="small" 
          :disabled="row.cancelTime == ''">
          视频联动
        </el-button>
      </template>
    </avue-crud>
    <!-- 视频联动弹窗 -->
    <el-dialog  
      title="视频联动"
      :visible.sync="dialogVisible"
      :append-to-body="true"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      custom-class="video_dia"
      width="65%">

      <div class="video_box">
        <!-- <div class="video_item" v-for="item in videoData" :key="item.id">
          <div class="top_item">{{item.url}}</div>
          <div class="bottom_item">{{item.name}}</div>
        </div> -->
        <el-row :gutter="20">
          <el-col :span="6" v-for="item in videoData" :key="item.id">
            <video class="grid-content" src="">
            </video>
          </el-col>
        </el-row>
      </div>
    </el-dialog>
  </basic-container>
</template>

<script>
  import {getList, remove, update, add, getNotice} from "@/api/desk/notice";
  import {mapGetters} from "vuex";

  export default {
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        dialogVisible:false,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height: 'auto',
          calcHeight: 30,
          dialogWidth: 950,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          // index: true,
          menuWidth: 320,
          viewBtn: false,
          addBtn: false,
          editBtn: false,
          delBtn: false,
          selection: true,
          dialogClickModal: false,
          column: [
            {
              label: "设备名称",
              prop: "title",
              span: 24,
              row: true,
              search: true,
            },
            {
              label: "设备编号",
              prop: "deviceNo",
              span: 24,
              row: true,
            },
            {
              label: "设备大类",
              prop: "deviceType",
              span: 24,
              row: true,
            },
            {
              label: "品牌编号",
              prop: "brandNo",
              span: 24,
              row: true,
            },
            // {
            //   label: "报警类型",
            //   type: "select",
            //   dicUrl: "/api/blade-system/dict/dictionary?code=notice",
            //   props: {
            //     label: "dictValue",
            //     value: "dictKey"
            //   },
            //   dataType: "number",
            //   slot: true,
            //   prop: "category",
            //   search: true,
            // },
            {
              label: "所属区域",
              prop: "floor",
              // slot: true,
            },
            {
              label: "安装位置",
              prop: "address",
              // slot: true,
            },
            {
              label: "报警信息",
              prop: "alarmInfo",
              slot: true,
              overHidden:true
            },
            {
              label: "报警时间",
              prop: "alarmTime",
              type: "date",
            },
            {
              label: "消报时间",
              prop: "cancelTime",
              type: "date",
            },
          ]
        },
        data: [],
        videoData:[]
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.notice_add, false),
          viewBtn: this.vaildData(this.permission.notice_view, false),
          delBtn: this.vaildData(this.permission.notice_delete, false),
          editBtn: this.vaildData(this.permission.notice_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      rowSave(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          window.console.log(error);
          loading();
        });
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          window.console.log(error);
          loading();
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getNotice(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      currentChange(currentPage) {
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        // const {releaseTimeRange} = this.query;
        // let values = {
        //   ...params,
        //   ...this.query
        // };
        // if (releaseTimeRange) {
        //   values = {
        //     ...values,
        //     releaseTime_datege: releaseTimeRange[0],
        //     releaseTime_datelt: releaseTimeRange[1],
        //   };
        //   values.releaseTimeRange = null;
        // }
        // this.loading = true;
        // getList(page.currentPage, page.pageSize, values).then(res => {
        //   const data = res.data.data;
        //   this.page.total = data.total;
        //   this.data = data.records;
        //   this.loading = false;
        //   this.selectionClear();
        // });
        this.data = [
          {title:'空调',deviceNo:'A101',deviceType:'空调设备',brandNo:'格力AT51',floor:'一号楼一层北',address:'1011室',alarmInfo:'无法制冷',alarmTime:'2023-07-14 09:55:23',cancelTime:'2023-07-15 15:23:10'},
          {title:'空调',deviceNo:'A101',deviceType:'空调设备',brandNo:'格力AT51',floor:'一号楼一层北',address:'1011室',alarmInfo:'无法制冷,无法制冷无法制冷',alarmTime:'2023-07-14 09:55:23',cancelTime:''},
        ];
        this.loading = false;
        this.page.total = this.data.length
      },
      // 视频联动按钮
      linkVideo(){
        this.dialogVisible = true;
        this.videoData = [
          {id:'001',url:'cdcdcdcd',name:'视频一'},
          {id:'002',url:'cdcdcdcd',name:'视频一'},
          {id:'003',url:'cdcdcdcd',name:'视频一'},
          {id:'004',url:'cdcdcdcd',name:'视频一'},
          {id:'005',url:'cdcdcdcd',name:'视频一'},
          {id:'006',url:'cdcdcdcd',name:'视频一'},
          {id:'007',url:'cdcdcdcd',name:'视频一'},
          {id:'008',url:'cdcdcdcd',name:'视频一'},
        ]
      },
    }
  };
</script>

<style lang="scss" scoped>
</style>
<style lang="scss">
  .video_dia{
    .video_box{
      width: 100%;
      // display: flex;
      // justify-content: space-between;
      // flex-wrap: wrap;

      .grid-content {
        width: 100%;
        height: 200px;
        margin-bottom: 18px;
        background: #959595;


        video{
          width: 100%;
          height: 100%;
        }
      }
    }
  }
</style>
