device-search.vue 4.59 KB
<template>
  <div class="manage-container deviceStatus-wrapper">
    <el-row class="manage-content device-content">
      <el-col :span="8">
        <el-input
          ref="textareaRef"
          type="textarea"
          :rows="24"
          v-model="devSerialnum"
          size="mini"
          :placeholder="$t('pholder.deviceNumber')"
          clearable
        />
      </el-col>
      <el-col :span="2">
        <div class="search-wrapper" :style="{ height: (btnWrapperHeight || 100) + 'px' }">
          <el-button
            type="primary"
            class="search-btn"
            plain
            size="mini"
            @click="onSearchClick"
          >{{$t('button.search')}}</el-button>
        </div>
      </el-col>
      <el-col :span="14">
        <el-table
          :data="list"
          :max-height="tableHeight"
          :empty-text="dataMsg"
          style="width: 100%"
          header-row-class-name="manage-tab-head"
        >
          <!-- <el-table-column prop="tabOrder" align="center" :label="$t('table.order')" width="100">
          </el-table-column>-->
          <el-table-column prop="serialnum" :label="$t('table.deviceNum')" align="center"></el-table-column>
          <el-table-column prop="localIp" :label="$t('table.localIP')" align="center"></el-table-column>
          <el-table-column :label="$t('table.bloc')" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.account ? scope.row.account.name : '--' }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('table.square')" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.mall ? scope.row.mall.name : '--' }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="gate.name" :label="$t('table.controlPoints')" align="center">
          </el-table-column>-->
          <el-table-column :label="$t('table.operate')" align="center" width="100">
            <template slot-scope="scope">
              <el-button
                @click="onUnbindClick(scope.row)"
                type="text"
                size="small"
                class="tab-btn"
              >{{ $t('button.ubind') }}</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      devSerialnum: "",
      list: [],
      btnWrapperHeight: 0,
      dataMsg: ""
    };
  },
  computed: {
    tableHeight() {
      const windowInnerHeight = window.innerHeight;
      return windowInnerHeight - windowInnerHeight * 0.24;
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.btnWrapperHeight = this.$refs.textareaRef.$el.offsetHeight;
    });
    this.dataMsg = this.$t("echartsTitle.loading");
  },
  methods: {
    i18n(value) {
      let langaugeVal = "pholder." + value;
      if (value == "allFloor") {
        return this.$t(langaugeVal);
      } else {
        return value;
      }
    },
    fetchList() {
      this.dataMsg = this.$t("echartsTitle.loading");
      this.list = [];
      const serialNumArr = this.devSerialnum
        .replace(/[\r\n]/g, ",")
        .replace(/\s+/g, "");
      this.$api.management
        .deviceList({
          serialnum_arr: serialNumArr
        })
        .then(res => {
          const { data } = res.data;
          this.list = data;
          this.list.length === 0 &&
            (this.dataMsg = this.$t("echartsTitle.noData"));
        })
        .catch(err => {
          console.log(err);
        });
    },
    onSearchClick() {
      this.fetchList();
    },
    onUnbindClick(row) {
      this.$confirm(
        this.$t("message.unbindPrompt"),
        this.$t("message.prompt"),
        {
          confirmButtonText: this.$t("message.confirm"),
          cancelButtonText: this.$t("message.cancel"),
          type: "warning"
        }
      )
        .then(() => {
          this.$api.management
            .unbindDevice(row.id, "3")
            .then(res => {
              this.fetchList();
              this.$message({
                type: "success",
                message: "success!"
              });
            })
            .catch(err => {
              console.log(err);
            });
        })
        .catch(() => {
          //
        });
    }
  }
};
</script>

<style scoped>
.manage-input-box {
  margin-right: 10px;
}

.search-wrapper {
  position: relative;
}

.search-wrapper .search-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.device-content {
  padding-top: 20px;
}
</style>