<!-- @format -->

<template>
  <ns-view-list-table ref="nsTableRef" v-bind="tableConfig" :model="data" />
</template>

<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import moment from 'moment';
  import { useRouter } from 'vue-router';
  export default defineComponent({
    name: 'NsViewRoleType',
    setup() {
      const sonRef = ref(null);
      const nsTableRef = ref(null);
      const data = ref({});
      const router = useRouter();
      const tableConfig = {
        api: '/api/community/objs/Role',
        title: '角色列表',
        pagination: {
          page: 0,
          pageSize: 10,
        },
        rowSelection: null,
        // scroll: { x: 1100 },
        columns: [
          {
            title: '角色名称',
            // width: 200,
            dataIndex: 'roleName',
          },
          {
            title: '备注',
            // width: 200,
            dataIndex: 'describe',
          },
          {
            title: '操作时间',
            // width: 200,
            dataIndex: 'updateTime',
            customRender: (text: any) => {
              if (text.record.updateTime) {
                return moment(text.record.updateTime).format('YYYY-MM-DD HH:mm:ss');
              }
              return '--';
            },
          },
        ],
        headerActions: [
          {
            label: '新增',
            name: 'RoleTypeAdd',
            type: 'primary',
            handle: () => {
              router.push({
                name: 'RoleTypeAdd',
              });
            },
          },
        ],
        columnActions: {
          title: '操作',
          // width: 150,
          actions: [
            {
              label: '人员设置',
              name: 'SetRolePerson',
              handle: (record: any) => {
                router.push({
                  name: 'SetRolePerson',
                  query: {
                    roleUuid: record.roleUuid,
                  },
                });
              },
            },
            {
              label: '编辑',
              name: 'RoleTypeEdit',
              handle: (record: any) => {
                router.push({
                  name: 'RoleTypeEdit',
                  query: {
                    roleUuid: record.roleUuid,
                  },
                });
              },
            },
            {
              label: '删除',
              dynamicParams: ['roleUuid', 'roleUuid'],
              name: 'RoleTypeRemove',
              confirm: true,
              isReload: true,
              api: '/api/community/objs/Role/delete',
            },
          ],
        },

        formConfig: {
          schemas: [
            {
              field: 'roleName',
              label: '角色名称',
              component: 'NsInput',
              defaultValue: '',
            },
          ],
          params: {},
        },
        rowKey: 'roleUuid',
      };

      return {
        tableConfig,
        data,
        moment,
        sonRef,
        nsTableRef,
      };
    },
  });
</script>
