index.vue 8.06 KB
<template>
    <div class="clerk-wrapper queueManagementContainer">
        <div class="header manage-head-wrapper">
            <el-form ref="form" label-width="100px" inline class="searchForm boxShadow searchFormSocial">
                <el-form-item :label="$t('table.mall')">
                    <el-select v-model="searchForm.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>
                </el-form-item>
                <el-form-item :label="$t('table.areaName')">
                  <el-select v-model="searchForm.areaId" filterable :placeholder="$t('pholder.select')" @change="areaChange">
                    <el-option v-for="item in tableData" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </el-form-item>
                <el-form-item>
                   <el-button type="primary" class="search-btn" size="mini" plain @click="searchFun">{{$t('button.search')}}</el-button>
                   <el-button type="primary" class="search-btn" size="mini" plain @click="bindRow">{{$t('button.positionCalibration')}}</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="manage-content">
            <div class="asis-table-content boxShadow" v-loading="loading">
              <div class="draw_desks">
                  <div class="gateWrap" id="gateManageChannel">
                      <img :src="floorImg" class="fimg" @load="loadGateData">
                      <div class="grender" ref="gRender"></div>
                  </div>
              </div>
            </div>
        </div>
        <bind-dev-dialog ref="bindDevModel"></bind-dev-dialog>
    </div>
</template>

<script>
    import bindDevDialog from "./bindDev";
    import drawUtils from './drawUtils';
    import _ from 'underscore';
    export default {
      extends:drawUtils,
        data() {
            return {
              mallListForTerm:[],
              tableData: [],
              total: 0,
              pageSize: 10,
              currentPage: 1,
              loading: false,
              searchForm:{
                  mallId:'',
                  areaId:''
              },
              floorImg: '',
              width:0,
              height:0,
              groupList:[],
              areaObj:{}
            }
        },
        components:{
            bindDevDialog
        },
        mounted() {
            this.getMallListForTerm()
        },
        computed: {
            tableHeight() {
                const windowInnerHeight = window.innerHeight;
                return windowInnerHeight - windowInnerHeight * 0.24;
            },
        },
        methods: {
            getMallListForTerm() {
                this.mallListForTerm = [];
                this.searchForm.mallId = "";
                this.$api.base.mall({
                    accountId: this.$cookie.get('accountId'),
                    status_arr: "1,3"
                }).then(data => {
                    let result = data.data;
                    if (result.data.length) {
                        if (this.getSessionLocal("mallId")) {
                          this.searchForm.mallId = Number(this.getSessionLocal("mallId"));
                        } else {
                        this.searchForm.mallId = result.data[0].id;
                        this.setSessionLocal("mallId", this.searchForm.mallId);
                        }
                        this.mallListForTerm = result.data;
                    }
                    this.getTableData();
                })
            },
            mallChange(val) {
                this.setSessionLocal("mallId", val);
                this.getTableData();
            },
            bindRow(row){
                this.$refs.bindDevModel.dialogInit(this.areaObj.pic,this.gateList);
            },
            searchFun(){
                this.currentPage = 1;
                this.getTableData()
            },
            getTableData() {
                this.loading = true;
                this.tableData = [];
                this.$api.queueManagementApi.getAreaList({
                    mallId: this.searchForm.mallId,
                    pageNum: 1,
                    pageSize: 99999
                }).then(res => {
                    let result = res.data;
                    if(result.code==200){
                       this.tableData = result.data.list;
                       this.searchForm.areaId = this.tableData.length && this.tableData[0].id;
                       this.areaObj = {...this.tableData[0]}
                       this.floorImg = window._vionConfig.picUrl+this.areaObj.pic
                    }
                    this.loading = false;
                })
            },
            areaChange(val){
              this.tableData.forEach(item=>{
                if(item.id==val){
                  this.areaObj = {...item}
                  this.floorImg = window._vionConfig.picUrl+this.areaObj.pic
                }
              })
            },
            loadGateData() {
                let {width,height} = document.getElementById('gateManageChannel').getBoundingClientRect();
                this.width = width;
                this.height = height;
                this.groupList = [];
                this.zr = zrender.init(this.$refs.gRender, {
                    renderer: 'canvas',
                    devicePixelRatio: 2,
                    width: width,
                    height: height
                });
                window.zr = this.zr;
                this.$api.queueManagementApi.getDevices({
                    areaId: this.searchForm.areaId
                }).then(res=>{
                    let data = res.data.data
                    data.forEach(item=>{
                        item.name = this.areaObj.name;
                        item.id = item.serialnum;
                        item.picUrl = window._vionConfig.picUrl + "/snapshot/real/" + item.serialnum + "-01.jpg?t=" + Date.parse(new Date()) / 1000;
                        item.coordinate&&(item.coordinate=JSON.parse(item.coordinate))
                    })
                    this.gateList =data;
                    this.drawJoinMap()
                });
            },
            drawJoinMap(){
                let that = this;
                _.each(this.gateList,(item,index)=>{
                    if(item.picUrl){
                      let img = new Image();
                      img.src = item.picUrl;
                      img.onload = function(){
                          item.width = this.width;
                          item.height = this.height;
                          that.createGroup(item,index+1);
                      }
                    }
                })
            },
            createGroup(data,index){
                let left = 0;
                let top = 0;
                let that = this;
                let group = new zrender.Group({
                  z:1,
                  draggable:true,
                  gateId:data.id,
                  gateName:data.name,
                  picUrl:data.picUrl,
                  position:[left,top],
                  hoverable: false,
                  draggable: false,
                })
                // .on('mouseup', function (evt) {
                //     that.saveGateData(data.id);
                // })
                this.groupList.push(group);
                this.zr.add(group);
                window.group = group;
                this.drawPolyImage(data,group);
            },
        }
    }
</script>

<style scoped="scoped" lang="less">
    .draw_desks {
        position: relative;
        width: 100%;
        // height: 700px;
    }
    .gateWrap{
        position: relative;
        width: 100%;
        box-shadow: 0px 3px 12px 0px rgba(196, 200, 207, 0.8);
    }
    .gateWrap .fimg{
        display: block;
        width: 100%;
    }
    .gateWrap .grender{
       position: absolute;
       left: 0;
       top: 0;
       width:100%;
       height: 100%;
       opacity: 0.7;
    }
</style>