<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search-form :items="formItems" v-model="queryParam" @search="searchQuery">
      <a-space style="float: right" class="btn-group" slot="additional">
        <a-button @click="handleAdd" type="primary">
          <img src="@/assets/images/global/add.png" alt="" />
          Add
        </a-button>
        <a-button @click="handleAdd" type="primary">
          <img src="@/assets/images/global/edit.png" alt="" />
          Edit
        </a-button>
        <a-button @click="handleAdd" type="primary">
          <img src="@/assets/images/global/delete.png" alt="" />
          Delete
        </a-button>
        <a-button @click="handleAdd" type="primary">
          <img src="@/assets/images/global/reset-pwd.png" alt="" />
          Reset pwd
        </a-button>
      </a-space>
    </search-form>

    <div>
      <a-table
        ref="table"
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="index" slot-scope="text, record, index">
          {{ index + 1 }}
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />

          <a-dropdown>
            <a class="ant-dropdown-link"> 更多 <a-icon type="down" /> </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
              </a-menu-item>

              <a-menu-item>
                <a href="javascript:;" @click="handleChangePassword(record.username)">密码</a>
              </a-menu-item>

              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>

              <a-menu-item v-if="record.status == 1">
                <a-popconfirm title="确定冻结吗?" @confirm="() => handleFrozen(record.id, 2, record.username)">
                  <a>冻结</a>
                </a-popconfirm>
              </a-menu-item>

              <a-menu-item v-if="record.status == 2">
                <a-popconfirm title="确定解冻吗?" @confirm="() => handleFrozen(record.id, 1, record.username)">
                  <a>解冻</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SearchForm from '@/components/SearchForm'

const formItems = [
  {
    type: 'a-input',
    label: 'User',
    name: 'username',
    span: 4
  },
  {
    type: 'a-input',
    label: 'Name',
    name: 'realname',
    span: 4
  },
  {
    type: 'custom-select',
    label: 'Role',
    name: 'role',
    span: 4,
    props: {
      options: [
        {
          label: 'test',
          value: '1'
        },
        {
          label: 'test2',
          value: '2'
        }
      ]
    }
  }
]

export default {
  name: 'UserList',
  mixins: [JeecgListMixin],
  components: {
    SearchForm
  },
  data() {
    this.formItems = formItems
    return {
      queryParam: {},
      columns: [
        {
          title: 'NO',
          align: 'center',
          width: 100,
          scopedSlots: {
            customRender: 'index'
          }
        },
        {
          title: 'USER',
          align: 'center',
          dataIndex: 'username',
          width: 100
        },
        {
          title: 'NAME',
          align: 'center',
          width: 100,
          dataIndex: 'realname'
        },
        {
          title: 'ROLE',
          align: 'center',
          width: 100,
          dataIndex: 'roleCode'
        },
        {
          title: 'PHONE',
          align: 'center',
          width: 100,
          dataIndex: 'phone'
        }
      ],
      url: {
        list: '/sys/user/list',
        delete: '/sys/user/delete'
      }
    }
  },
  methods: {}
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
.btn-group {
  img {
    margin-right: 12px;
    height: 18px;
  }
}
</style>
