<template>
  <admin-layout>
    <admin-todo-list title="数据列表" icon="table">
      <template #options>
        <a-button type="primary" icon="plus" @click="handleAdd('字典新增')">新 增</a-button>
      </template>
      <a-table
        ref="table"
        bordered
        rowKey="id"
        size="small"
        :columns="columns"
        :dataSource="dataSource"
        :loading="tableLoading"
        :footer="null"
      >
        <template slot="icon" slot-scope="text">
          <a-icon :type="text" />
        </template>
        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record, '菜单编辑')"><a-icon type="edit" class="mr-1" />编辑</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="handleView(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="handleAddSub(record)">添加子菜单</a>
              </a-menu-item>
              <!--              <a-menu-item>-->
              <!--                <a href="javascript:;" @click="handleDataRule(record)">数据规则</a>-->
              <!--              </a-menu-item>-->
              <a-menu-item>
                <a-popconfirm placement="left" title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a style="color: #f5222d">删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
      </a-table>
    </admin-todo-list>

    <permission-modal ref="modalEditRef" @ok="handleOk"></permission-modal>
    <permission-modal ref="modalViewRef" @ok="handleOk"></permission-modal>
    <permission-data-rule-list ref="PermissionDataRuleList" @ok="handleOk"></permission-data-rule-list>
  </admin-layout>
</template>

<script>
import PermissionModal from './modules/menu/PermissionModal'
import { getPermissionList } from './api/services/menu'
import { PageListMixin } from '@/mixins/PageListMixin'
import PermissionDataRuleList from './modules/menu/PermissionDataRuleList'

export default {
  name: 'MenuManageList',
  components: {
    PermissionDataRuleList,
    PermissionModal
  },
  mixins: [PageListMixin],
  data() {
    return {
      columns: Object.freeze([
        {
          title: '菜单名称',
          dataIndex: 'name',
          ellipsis: true,
          key: 'name',
          width: 300
        },
        {
          title: '菜单类型',
          dataIndex: 'menuType',
          key: 'menuType',
          ellipsis: true,
          width: 120,
          align: 'center',
          customRender: function (text) {
            switch (text) {
              case 0:
              case 1:
                return '菜单'
              case 2:
                return '按钮/权限'
              default:
                return text
            }
          }
        },
        {
          title: 'icon',
          dataIndex: 'icon',
          key: 'icon',
          width: 100,
          align: 'center',
          scopedSlots: { customRender: 'icon' }
        },
        {
          title: '组件',
          dataIndex: 'component',
          key: 'component',
          scopedSlots: { customRender: 'component' }
        },
        {
          title: '路径',
          dataIndex: 'url',
          key: 'url',
          ellipsis: true,
          scopedSlots: { customRender: 'url' }
        },
        {
          title: '排序',
          dataIndex: 'sortNo',
          key: 'sortNo',
          width: 60
        },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          align: 'center',
          fixed: 'right',
          width: 150
        }
      ]),
      dataSource: [],
      isDisableMixin: true,
      interface: {
        list: '/sys/permission/list',
        delete: '/sys/permission/delete',
        deleteBatch: '/sys/permission/deleteBatch'
      }
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    loadData() {
      this.dataSource = []
      getPermissionList().then(res => {
        if (res.code === '200') {
          this.dataSource = res.value
        }
      })
    },
    // 打开数据规则编辑
    // handleDataRule(record) {
    //   this.$refs.PermissionDataRuleList.edit(record)
    // },
    handleAddSub(record) {
      this.$refs.modalEditRef.title = '添加子菜单'
      this.$refs.modalEditRef.localMenuType = 1
      this.$refs.modalEditRef.disableSubmit = false
      this.$refs.modalEditRef.handleEdit({ status: '1', permsType: '1', rouwwwwte: true, parentId: record.id })
    }
  }
}
</script>
<style>
.ant-drawer-left.ant-drawer-open,
.ant-drawer-right.ant-drawer-open {
  width: 100%;
  height: 100% !important;
  -webkit-transition: -webkit-transform 0.3s cubic-bezier(0.7, 0.3, 0.1, 1);
  transition: -webkit-transform 0.3s cubic-bezier(0.7, 0.3, 0.1, 1);
  transition: transform 0.3s cubic-bezier(0.7, 0.3, 0.1, 1);
  transition: transform 0.3s cubic-bezier(0.7, 0.3, 0.1, 1), -webkit-transform 0.3s cubic-bezier(0.7, 0.3, 0.1, 1);
}

.ant-drawer-wrapper-body {
  height: 100%;
  overflow: auto;
}
</style>
