<template>
  <div class="main_root">
    <div class="search_header">
      <Input
        v-model="searchForm.name"
        placeholder="请输入学生姓名、账号"
        style="width: 200px"
      />
      <Input
        v-model="searchForm.title"
        placeholder="请输入学校名称"
        style="width: 150px; margin: 0 10px"
      />
      <Button type="primary" class="primary_btn" @click="searchList()">
        <Icon type="ios-search" :size="18" />
      </Button>
    </div>
    <div class="table_wrap">
      <Table :columns="columns" :data="searchForm.list">
        <template slot-scope="{ row }" slot="enabled">
          <div class="action_list">
            <div v-if="row.enabled === 1" class="action_success">启用</div>
            <div v-if="row.enabled === 2" class="action_del">禁用</div>
          </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 { search_list_user } from "@/api/region";
export default {
  data() {
    return {
      searchForm: {
        title: "",
        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: "登录名",
          key: "loginname",
          align: "center"
        },
        {
          title: "学生姓名",
          key: "username",
          width: 140,
          align: "center"
        },
        {
          title: "状态",
          slot: "enabled",
          width: 190,
          align: "center"
        },
        {
          title: "学校名称",
          key: "schoolName",
          width: 140,
          align: "center"
        },
        {
          title: "创建时间",
          key: "createtime",
          width: 220,
          align: "center"
        },
        {
          title: "最后登录时间",
          key: "lasttime",
          width: 220,
          align: "center"
        }
      ]
    };
  },
  computed: {
    powerParams() {
      return this.$store.getters.powerParams;
    }
  },
  created() {
    this.searchList();
  },
  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() {
      search_list_user({
        rtype: this.powerParams.rtype,
        objectid: this.powerParams.objectid,
        page: this.searchForm.page,
        size: this.searchForm.size,
        name: this.searchForm.name,
        title: this.searchForm.title
      }).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;
  align-items: center;
  margin: 16px 16px;
}
.view_title {
  margin-bottom: 16px;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
}
</style>
