<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: 150px"
        />
      </div>
      <Button type="primary" class="primary_btn" @click="toAdd()">新建</Button>
    </div>
    <div class="table_wrap">
      <Table :columns="columns" :data="searchForm.list">
        <template slot-scope="{ row }" slot="actionSlot">
          <div class="action_list">
            <div @click="toView(row)">查看</div>
            <div @click="toEdit(row)">编辑</div>
            <div class="action_del" @click="toDel(row)">删除</div>
            <div @click="toEmpower(row)">授权</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 { stPad_list } from "@/api/stPad";
export default {
  data() {
    return {
      searchForm: {
        name: "",
        page: 1,
        size: 10,
        list: [],
        total: 0
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入名称",
            trigger: "change"
          }
        ]
      },
      columns: [
        {
          title: "序号",
          align: "center",
          width: 70,
          render: (h, params) => {
            return h(
              "span",
              params.index +
                (this.searchForm.page - 1) * this.searchForm.size +
                1
            );
          }
        },
        {
          title: "策略名称",
          key: "name",
          align: "center"
        },
        {
          title: "操作人",
          key: "updatename",
          width: 140,
          align: "center"
        },
        {
          title: "操作时间",
          key: "updatetime",
          width: 190,
          align: "center"
        },
        {
          title: "操作",
          slot: "actionSlot",
          width: 200,
          align: "center"
        }
      ]
    };
  },
  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() {},
    // 新建
    toAdd() {},
    // 保存新建
    saveAddInfo() {},
    // 查看
    toView() {},
    // 编辑
    toEdit() {},
    // 删除
    toDel() {
      this.$Modal.confirm({
        title: "提示",
        content: `您确定删除选中数据吗？`,
        onOk: () => {},
        onCancel: () => {}
      });
    },
    toEmpower() {}
  }
};
</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;
  }
}
.view_title {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  .public {
    margin-left: 10px;
    padding: 0 10px;
    line-height: 20px;
    color: #fff;
    font-weight: normal;
    font-size: 12px;
    border-radius: 4px;
    background: #52c41a;
  }
}
.name_slot {
  display: flex;
  justify-content: center;
  align-items: center;
  .name_content {
    max-width: calc(100% - 38px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .public_tag {
    margin-left: 4px;
    width: 32px;
    text-align: center;
    color: #fff;
    line-height: 1.6;
    font-size: 12px;
    border-radius: 5px;
    background-color: #7854f6;
  }
}
.white_address {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
