<template>
  <div class="manage-container">
    <vab-query-form>
      <el-button type="primary" @click="handleAdd()">添加触发器规则</el-button>
      <el-button type="primary" @click="deletes">
        {{ $t('defalult.plsc') }}
      </el-button>
      <el-button type="primary" @click="triggerRuleUse">
        {{ $t('trigger.plyy') }}
      </el-button>
    </vab-query-form>
    <el-table
      v-loading="listLoading"
      :data="sensorData"
      border
      stripe
      style="width: 100%"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column
        prop="name"
        :label="$t('sensor.cgqmc')"
        width="120"
        align="center"
      ></el-table-column>
      <el-table-column fixed="right" :label="$t('defalult.cz')" align="center">
        <template #default="{ row }">
          <el-button type="text" @click="handleEdit(row)">规则</el-button>
        </template>
      </el-table-column>
    </el-table>
    <vab-query-form>
      <vab-query-form-right-panel>
        <el-pagination
          :background="background"
          :current-page="queryForm.page"
          :layout="layout"
          :page-size="queryForm.size"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        ></el-pagination>
      </vab-query-form-right-panel>
    </vab-query-form>
    <rule-edit ref="edit"></rule-edit>
  </div>
</template>
<script>
import { getSensorsData } from '@/api/triggerRule';
import ruleEdit from './ruleEdit';
export default {
  name: 'Index',
  components: {
    ruleEdit,
  },
  data() {
    return {
      ruleData: [],
      deviceId: '',
      projectId: '',
      lazy: true,
      layout: 'total, sizes, prev, pager, next, jumper',
      total: 0,
      ids: [],
      background: true,
      listLoading: true,
      elementLoadingText: '正在加载...',
      queryForm: {
        projectId: '',
      },
    };
  },
  computed: {
    height() {
      return 500;
    },
  },
  created() {
    this.queryForm.projectId = sessionStorage.getItem('projectId');
    this.fetchData();
  },
  methods: {
    async fetchData() {
      this.listLoading = true;
      const { data } = await getSensorsData(this.queryForm);
      var list = [];
      for (var i = 0; i < data.length; i++) {
        list.push({ name: data[i] });
      }
      console.log(list);
      this.sensorData = data;
      this.total = data.total;
      setTimeout(() => {
        this.listLoading = false;
      }, 500);
    },
  },
};
</script>

<style lang="scss" scoped>
.manage-container {
  width: 100%;
  .vab-query-form {
    margin-bottom: 30px;
    .el-input {
      width: 180px;
      margin-right: 20px;
    }
  }
}
</style>
