index.vue 9.45 KB
<template>
  <div class="video-container clerk-wrapper">
    <el-row class="manage-head-wrapper">
      <el-col :xs="22" :sm="22">
        <div class="manage-select-box">
          <el-select v-model="queryForm.mallId" filterable :placeholder="$t('pholder.select')" @change="mallChange">
            <el-option v-for="item in mallListForTerm" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </div>
        <!-- 设备名称 -->
        <!-- <div class="manage-select-box">
          <el-input v-model="queryForm.deviceName" class="search-inp" placeholder="请输入设备名称" clearable />
        </div> -->
        <!-- 序列号 -->
        <div class="manage-select-box">
          <el-input v-model="queryForm.deviceSerial" class="search-inp" :placeholder="$t('pholder.deviceSerial')" clearable />
        </div>
        <el-button type="primary" class="search-btn" plain  @click="searchFun">{{$t('button.search')}}</el-button>
      </el-col>
      <el-col :xs="2" :sm="2">
        <el-button type="primary" class="manage-add-btn" @click="addDevice" icon="el-icon-circle-plus-outline">{{$t('button.groupAdd')}}</el-button>
      </el-col>
    </el-row>
    <el-row class="manage-content">
      <el-col :span="24">
        <el-table
          ref="row_table"
          class="gate-table"
          :data="tableData"
          :max-height="tableHeight"
          style="width: 100%"
          @expand-change="expandHandle"
          header-row-class-name="manage-tab-head"
        >
          <el-table-column type="expand" prop="children">
            <template slot-scope="scope">
              <el-table
                :data="scope.row.children"
                :show-header="false"
                :empty-text="noDataText"
                class="expand-table"
                v-loading='loading'
              >
                <el-table-column align="center" width="148">
                  <template slot-scope="scope">
                    <div class="child-order-column">
                      <div class="child-order__icon-inner">{{ scope.row.childOrder }}</div>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="channelName" align="center">
                  <template slot-scope="scope">
                    <span v-if="scope.row.name">{{scope.row.name}}({{scope.row.channelName}})</span>
                    <span v-else>{{scope.row.channelName}}</span>
                  </template>
                </el-table-column>
                <el-table-column :label="$t('table.operate')" align="center">
                  <template slot-scope="scope">
                    <el-button @click="editChannelRow(scope.row)" type="text" size="small" class="tab-btn">{{$t('button.edit')}}</el-button>
                    <el-button @click="playVideo(scope.row)" type="text" size="small" class="tab-btn">{{$t('button.play')}}</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column prop="order" :label="$t('table.order')" align="center" width="100"></el-table-column>
          <el-table-column prop="name" :label="$t('table.deviceName')" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.name}}</span><span v-if="scope.row.deviceName">({{scope.row.deviceName}})</span>
            </template>
          </el-table-column>
          <el-table-column prop="platform" :label="$t('table.videoSource')" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.platform==1 ? '拾联': '萤石云'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="deviceSerial" :label="$t('table.deviceSerial')" align="center"></el-table-column>
          <el-table-column :label="$t('table.operate')" align="center">
            <template slot-scope="scope">
              <el-button @click="editRow(scope.row)" type="text" size="small" class="tab-btn">{{$t('button.edit')}}</el-button>
              <!-- <el-button @click="delRow(scope.row)" type="text" size="small" class="tab-btn">{{$t('button.delete')}}</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          class="manage-pagination-box"
          background
          :current-page="currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          @size-change="sizeChange"
          @current-change="cerrentChange"
          layout="sizes, prev, pager, next, slot"
          :total="total"
        >
          <span
            class="slot-ele-total"
          >{{$t('table.pageHead')}} {{ total }} {{$t('table.pageTail')}}</span>
        </el-pagination>
      </el-col>
    </el-row>
    <add-device-dialog ref="adddeviceModel"></add-device-dialog>
    <edit-channel-dialog ref="editChannelModel"></edit-channel-dialog>
    <video-dialog ref="videoModel"></video-dialog>
  </div>
</template>

<script>
  import addDeviceDialog from './add.vue'
  import editChannelDialog from './editChannel.vue'
  import videoDialog from './videoDialog.vue'
  export default{
    data(){
      return {
        mallListForTerm:[],
        tableData: [],
        total: 0,
        pageSize: 10,
        currentPage: 1,
        queryForm:{
          accountId: this.$cookie.get('accountId')
        },
        noDataText:'',
        loading:false,
      }
    },
    components: {
      "add-device-dialog": addDeviceDialog,
      'edit-channel-dialog':editChannelDialog,
      'video-dialog':videoDialog
    },
    mounted(){
      this.getMallListForTerm()
    },
    computed: {
      tableHeight() {
        const windowInnerHeight = window.innerHeight;
        return windowInnerHeight - windowInnerHeight * 0.24;
    	}
    },
    methods:{
      getMallListForTerm() {
        this.mallListForTerm = [];
        this.queryForm.mallId = "";
        this.$api.base.mall(
            {
              accountId: this.$cookie.get('accountId'),
              status_arr: "1,3"
            },
            null,
            true
          )
          .then(data => {
            let result = data.data;
            if (result.data.length) {
              if (this.getSessionLocal("mallId")) {
                this.queryForm.mallId = Number(this.getSessionLocal("mallId"));
              } else {
                this.queryForm.mallId = result.data[0].id;
                this.setSessionLocal("mallId", this.queryForm.mallId);
              }
              this.mallListForTerm = result.data;
            }
            this.getTableData();
          })
          .catch(error => {});
      },
      mallChange() {
        this.setSessionLocal("mallId", this.queryForm.mallId);
        this.getTableData();
      },
      getTableData() {
        this.dataMsg = this.$t("echartsTitle.loading");
        let tabelParams = {
          pageNum: this.currentPage,
          pageSize: this.pageSize,
          ...this.queryForm
        };
        Object.keys(tabelParams).map(key => (!tabelParams[key] ? delete tabelParams[key] : ''));
        this.$api.videoShopTourReport
          .getDeviceList(tabelParams, null, true)
          .then(data => {
            this.tableData = [];
            var result = data.data;
            result.data.list.forEach((item, index) => {
              // item.isExpand = false;
              item.order = (this.currentPage - 1) * this.pageSize + index + 1;
              item.children = [];
            });
            this.tableData = result.data.list;
            this.total = result.data.total;
          })
      },
      sizeChange(val) {
        this.pageSize = val;
        this.getTableData();
      },
      cerrentChange(val) {
        if (this.currentPage != val) {
          this.currentPage = val;
          this.getTableData();
        }
      },
      expandHandle(row, expandedRows,deviceId){
        this.loading = true;
        let RowId = deviceId?deviceId:row.id
        this.$refs.row_table.store.states.expandRows = expandedRows.length ? [row]: [];
        let isExpand = false;
        if (this.$refs.row_table.store.states.expandRows.length > 0) {
          if (this.$refs.row_table.store.states.expandRows[0].id == RowId) {
            isExpand = true;
          }
        }
        // this.noDataText = "无数据";
        if (!isExpand) return;
        row.children = [];
        this.$api.videoShopTourReport.getPatrolDeviceChannelList({ deviceId:  RowId,pageSize: 999999,page:1})
          .then(res => {
            this.loading = false;
            let result = res.data;
            if (result.data.list.length == 0){
              this.noDataText = this.$t("echartsTitle.noData");
            }
            result.data.list.forEach((item, index) => {
              item.childOrder = ++index;
            });
            row.children = result.data.list;
          })
      },
      addDevice(){
        this.$refs.adddeviceModel.dialogInit(this.queryForm.mallId,'add');
      },
      editRow(row){
        this.$refs.adddeviceModel.dialogInit(this.queryForm.mallId,'edit',row);
      },
      editChannelRow(row){
        this.$refs.editChannelModel.dialogInit(row);
      },
      searchFun(){
        this.currentPage = 1;
        this.getTableData();
      },
      playVideo(row){
        this.$refs.videoModel.dialogInit(row,1);
      }
    }
  }
</script>

<style scoped="scoped" lang="less">
  .manage-container{
    width: 100%;
  }
  .manage-select-box{
    /deep/.el-select{
      width: 180px;
    }
  }
</style>