<template>
  <ns-view-list-table v-bind="tableConfig" rowKey="uuid" />
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  export default defineComponent({
    name: 'NsViewUserList',
    setup() {
      const tableConfig = {
        title: '员工管理',
        api: '/api/parking_merchant/objs/person/pageList',
        params: {
          page: 0,
          pageSize: 10,
        },
        rowSelection: null,
        // scroll: { x: 1150 },
        columns: [
          {
            title: '姓名',
            dataIndex: 'personName',
            width: 200,
          },
          {
            title: '性别',
            dataIndex: 'sex',
            width: 100,
            customRender: (value) => {
              switch (value.text) {
                case 0:
                  return '女';
                case 1:
                  return '男';
                default:
                  return '-';
              }
            },
          },
          {
            title: '员工编号',
            dataIndex: 'personNum',
            width: 150,
          },
          {
            title: '手机号码',
            dataIndex: 'telNum',
            width: 150,
          },
          {
            title: '账号状态',
            dataIndex: 'accountState',
            width: 100,
            customRender: (value) => {
              switch (value.text) {
                case 1:
                  return '启用';
                case 0:
                  return '禁用';
                default:
                  return '-';
              }
            },
          },
          {
            title: '用户状态',
            width: 100,
            dataIndex: 'personStatus',
            customRender: (value) => {
              switch (value.text) {
                case 1:
                  return '在职';
                case 2:
                  return '离职';
                default:
                  return '-';
              }
            },
          },
        ],
        columnActions: {
          title: '操作',
          // width: 250,

          actions: [
            // {
            //   label: '查看',
            //   name: 'userDetail',
            //   dynamicParams: 'personUuid',
            //   route: '/userManage/user/detail',
            // },
            {
              label: '重置密码',
              dynamicParams: 'personUuid',
              name: 'UserReset',
              confirm: {
                title: '提示',
                content: `确认重置密码吗？`,
              },
              isReload: true,
              api: '/api/parking_merchant/objs/person/reset',
            },
            {
              label: '编辑',
              dynamicParams: 'personUuid',
              name: 'UserEdit',
              route: '/userManage/user/edit',
            },
            {
              label: '删除',
              dynamicParams: {
                personUuid: 'personUuid',
              },
              name: 'UserRemove',
              ifShow: (record: any) => {
                return record.personStatus !== 1;
              },
              confirm: true,
              isReload: true,
              api: '/api/parking_merchant/objs/person/delete',
            },
            {
              label: '删除',
              name: 'UserRemove',
              dynamicParams: {
                uuid: 'uuid',
              },
              ifShow: (record: any) => {
                return record.personStatus === 1;
              },
              confirm: {
                title: '警告',
                content: '在职员工不可删除！',
              },
            },
          ],
        },
        headerActions: [
          {
            label: '新增用户',
            name: 'UserAdd',
            type: 'primary',
            route: '/userManage/user/add',
          },
        ],
        formConfig: {
          schemas: [
            {
              field: 'accountState',
              label: '账号状态',
              component: 'NsSelect',
              componentProps: {
                placeholder: '请选择',
                options: [
                  {
                    label: '全部',
                    value: '',
                  },
                  {
                    label: '启用',
                    value: 1,
                  },
                  {
                    label: '禁用',
                    value: 0,
                  },
                ],
              },
            },
            {
              field: 'personStatus',
              label: '用户状态',
              component: 'NsSelect',
              componentProps: {
                placeholder: '请选择',
                options: [
                  {
                    label: '全部',
                    value: '',
                  },
                  {
                    label: '在职',
                    value: 1,
                  },
                  {
                    label: '离职',
                    value: 2,
                  },
                ],
              },
            },
            {
              field: 'telNum',
              label: '手机号码',
              component: 'NsInput',
              componentProps: {
                placeholder: '请输入手机号码',
              },
            },
            {
              field: 'personName',
              label: '用户姓名',
              component: 'NsInput',
              componentProps: {
                placeholder: '请输入用户姓名',
              },
            },
          ],
        },
        rowKey: 'personUuid',
      };

      return {
        tableConfig,
      };
    },
  });
</script>
<style lang="less" scoped></style>
