<template>
  <div class="main_root">
    <div class="search_header">
      <div class="search_left">
        <Input
          v-model="searchForm.name"
          placeholder="请输入登录账号、姓名、设备型号、设备号"
          search
          @on-search="searchList()"
          style="width: 310px"
        />
      </div>
    </div>
    <div class="table_wrap">
      <Table :columns="columns" :data="searchForm.list">
        <template slot-scope="{ row }" slot="controlSlot">
          <div>
            {{
              row.control === 1 ? "管控中" : row.control === 2 ? "解除管控" : ""
            }}
          </div>
        </template>
      </Table>
    </div>
    <div class="page_wrap">
      <Page
        :transfer="true"
        :total="searchForm.total"
        :current="searchForm.page"
        :page-size="searchForm.size"
        :page-size-opts="[10, 20, 40, 60]"
        @on-change="pageChange"
        @on-page-size-change="pageSizeChange"
        show-total
        show-sizer
      ></Page>
    </div>
  </div>
</template>

<script>
import { device_manager_list_od } from "@/api/device_manager";
export default {
  data() {
    return {
      searchForm: {
        pushType: 2,
        name: "",
        page: 1,
        size: 10,
        list: [],
        total: 0
      },
      columns: [
        {
          title: "序号",
          align: "center",
          width: 70,
          render: (h, params) => {
            return h(
              "span",
              params.index +
                (this.searchForm.page - 1) * this.searchForm.size +
                1
            );
          }
        },
        {
          title: "登录账号",
          minWidth: 100,
          key: "loginname",
          align: "center"
        },
        {
          title: "姓名",
          minWidth: 80,
          key: "username",
          align: "center"
        },
        {
          title: "设备名称",
          minWidth: 100,
          key: "device",
          align: "center"
        },
        {
          title: "管控状态",
          width: 100,
          slot: "controlSlot",
          align: "center"
        },
        {
          title: "设备型号",
          width: 150,
          key: "deviceModel",
          align: "center"
        },
        {
          title: "设备号",
          minWidth: 170,
          key: "sn",
          align: "center"
        },
        {
          title: "Rom版本",
          minWidth: 200,
          key: "romVersion",
          align: "center"
        },
        {
          title: "更新时间",
          key: "updatetime",
          width: 190,
          align: "center"
        }
      ]
    };
  },
  created() {
    this.searchList();
  },
  computed: {
    powerParams() {
      return this.$store.getters.powerParams;
    }
  },
  methods: {
    // 搜索
    searchList() {
      this.searchForm.page = 1;
      this.getList();
    },
    // 页码改变
    pageChange(page) {
      this.searchForm.page = page;
      this.getList();
    },
    // 每页显示数量改变
    pageSizeChange(size) {
      this.searchForm.size = size;
      this.searchForm.page = 1;
      this.getList();
    },
    // 获取列表
    getList() {
      device_manager_list_od({
        rtype: this.powerParams.rtype,
        objectid: this.powerParams.objectid,
        page: this.searchForm.page,
        size: this.searchForm.size,
        schoolid: this.powerParams.objectid,
        doEvent: this.searchForm.doEvent,
        name: this.searchForm.name,
        pushType: 2
      }).then((data) => {
        if (data.code === 0) {
          this.searchForm.list = data.obj.data;
          this.searchForm.total = data.obj.total;
        } else {
          this.$Message.error(data.msg);
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
.search_header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 16px;
  .search_left {
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
}
</style>
