<template>
  <div class="new-app-container layout-vertical">
    <!--    <YMTableSearch :loading="loading" :search-form="searchForm" @onValueChange="onValueChange" @submit="onSubmit" />-->
    <YMTable
      ref="table"
      :table-key="1"
      :index="true"
      :selection="false"
      :table-options="tableOptions"
      :edit-form="editForm"
      :edit-config="editConfig"
      :columns="columns"
      :rows-actions="rowsActions"
      :show-summary="false"
      :apis="apis"
      :custom-style="{ height: 'calc(100vh - 80px)' }"
    />
    <!-- 自定义弹窗 -->
    <Dialog ref="dialog">
      <template slot="content"/>
    </Dialog>
  </div>
</template>
<script>
import Dialog from '@/components/Dialog/index.vue'
import { roleall } from '@/api/data'

export default {
  components: {
    Dialog
  },
  data() {
    return {
      loading: false,
      visibleBasicDrawer: false,
      renderContent: '',
      searchForm: [],
      columns: [
        {
          label: '管理员账号',
          prop: 'username'
        },
        {
          label: '管理员名称',
          prop: 'nickname'
        },
        {
          label: '角色',
          prop: 'roles_names'
        },
        {
          label: '邮箱',
          prop: 'email'
        },
        {
          label: '手机号',
          prop: 'cellphone'
        },
        {
          label: '备注',
          prop: 'remarks'
        }
      ],
      rowsActions: [
        {
          key: 'edit',
          label: '编辑'
        },
        {
          key: 'delete',
          label: '删除',
          vIF: (row) => row.id === 1 ? false : true
        }
      ],
      apis: {
        list: {
          url: 'index',
          dataParam: 'data.data',
          resultParam: 'data',
          init: false
        },
        add: {
          url: 'submit'
        },
        edit: {
          url: 'submit'
        },
        delete: {
          url: 'delete',
          method: 'post'
        }
      },
      tableOptions: {
        add: {
          show: true,
          initData: () => {
            return {}
          }
        }
      },
      editForm: [
        {
          body: [
            {
              label: '管理员账号',
              prop: 'username',
              disabled: (row) => row.id === 1 ? true : false,
              type: 'input',
              required: true,
              placeholder: '请输入'
            },
            {
              label: '管理员名称',
              prop: 'nickname',
              type: 'input',
              required: true,
              placeholder: '请输入'
            },
            {
              label: '角色',
              prop: 'roles_ids',
              type: 'cascader',
              required: false,
              disabled: (row) => row.id === 1 ? true : false,
              checkStrictly: true,
              options: []
            },
            {
              label: '邮箱',
              prop: 'email',
              type: 'input',
              required: true,
              placeholder: '请输入'
            },
            {
              label: '手机号',
              prop: 'cellphone',
              type: 'input',
              required: true,
              placeholder: '请输入'
            },
            {
              label: '密码',
              prop: 'password',
              type: 'input',
              disabled: (row) => row.id === 1 ? true : false,
              required: false,
              placeholder: '请输入'
            },
            {
              label: '备注',
              prop: 'remarks',
              type: 'input',
              placeholder: '请输入'
            }
          ]
        }
      ],
      editConfig: {}
    }
  },
  created() {
  },
  mounted() {
    this.onSubmit()
    this.getroleall()
  },
  methods: {
    async getroleall() {
      const { data } = await roleall()
      data.forEach(item => {
        item.label = item.display_name
        item.value = item.id
      })
      this.editForm[0].body[2].options = data
    },
    onValueChange(val) {

    },
    onSubmit(params) {
      this.$refs.table.getList(params)
    }
  }
}
</script>
