<template>
  <div class="content">
    <div class="topSearch">
      <div class="left">
        管理员搜索：
        <Input
          v-model="keyword"
          style="width:200px"
          enter-button
          placeholder="请输入"
        />
        <Button type="primary" @click="goDetail">查 询</Button>
        <Button type="primary" ghost>重 置</Button>
        <Button type="primary" @click="goAdd">新增管理员</Button>
      </div>
    </div>
    <Table
      :loading="$store.state.app.isLoading"
      border
      ref="selection"
      :columns="columns"
      :data="data"
    >
      <template slot-scope="{ row }" slot="action">
        <a @click="edit(row)">编辑</a>
        <a style="margin-left:10px" @click="del(row.uuid)">删除</a>
      </template>
    </Table>
    <Pager
      class="margin-top-10"
      :config="config"
      @on-change="handlePager"
    ></Pager>
  </div>
</template>

<script>
import { admins, delAdmins } from "@/api/clock/activityClocks";
import Pager from "@/view/common/Pager.vue";
export default {
  name: "categories",
  components: {
    Pager
  },
  data() {
    return {
      keyword: "",
      config: { total: 0, size: 10, current: 1 },
      pageIndex: 1,
      pageSize: 10,
      data: [],
      columns: [
        {
          title: "管理员姓名",
          key: "name"
        },
        {
          title: "联系方式",
          key: "mobile"
        },
        {
          title: "管理员账号",
          key: "account"
        },
        {
          title: "操作",
          slot: "action"
        }
      ]
    };
  },
  methods: {
    search() {
      let params = {
        keyword: this.keyword,
        language: "cn",
        page_index: this.pageIndex,
        page_size: this.pageSize
      };
      admins(params).then(res => {
        this.config.total = res.total;
        this.data = res.data;
      });
    },
    handlePager(pager) {
      this.pageIndex = pager.current;
      this.pageSize = pager.size;
      this.search();
    },
    del(id) {
      delAdmins(id).then(res => {
        this.$Message.success("删除成功");
        this.search();
      });
    },
    edit(p) {
      this.$router.push({ path: "/admin/add", query: { id: p.uuid } });
    },
    goAdd() {
      this.$router.push({ path: "/admin/add" });
    }
  },
  mounted() {
    this.search();
  }
};
</script>

<style lang="less"></style>
