/*
 * @Author: Mm
 * @Date: 2025-05-09 10:56:48
 * @LastEditors: Mm
 * @LastEditTime: 2025-06-11 11:28:31
 * 不写bug的程序员不是一个好程序员!
 */

import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';
import { getPopupContainer } from '@vben/utils';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';
import { getDeptTree } from '#/api/system/user';
import select from './select.vue';
import { markRaw } from 'vue';
// 使用 markRaw 标记组件为“原始”对象，避免被响应式追踪
const SelectComponent = markRaw(select);
export const querySchema: FormSchemaGetter = () => [
  {
    component: SelectComponent,
    fieldName: 'status',
    formItemClass: 'col-span-4 hide-label',
    defaultValue: 1,
  },

  {
    component: 'Input',
    fieldName: 'title',
    label: '任务标题',
  },
  {
    component: 'ApiTreeSelect',
    componentProps: {
      api: getDeptTree,
      fieldNames: { label: 'label', value: 'id', children: 'children' },
      treeLine: { showLeafIcon: false },
      // 默认展开的节点
      // treeDefaultExpandedKeys: [340100000000],
      showSearch: true,
      treeNodeFilterProp: 'label',
    },
    fieldName: 'deptId',
    label: '发起单位',
  },

  {
    component: 'Select',
    componentProps: {
      options: getDictOptions('tasks_type'),
    },
    fieldName: 'taskType',
    label: '任务类型',
  },
  {
    component: 'Select',
    componentProps: {
      options: getDictOptions('task_level'),
    },
    fieldName: 'level',
    label: '任务级别',
  },
  {
    component: 'RangePicker',
    fieldName: 'startTimes',
    label: '发起时间',
    componentProps: {
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '任务标题',
    field: 'missionTitle',
  },
  {
    title: '状态',
    field: 'missionStatus',
    slots: { default: 'missionStatus' },
  },

  {
    title: '任务级别',
    field: 'missionLevel',
  },
  {
    title: '任务类型',
    field: 'missionTyle',
    slots: {
      default: ({ row }) => {
        return renderDict(row.missionTyle, 'tasks_type');
      },
    },
  },
  {
    title: '发起时间',
    field: 'startTime',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 200,
  },
];
export const queryDwspSchema: FormSchemaGetter = () => [
  // {
  //   component: SelectComponent,
  //   fieldName: 'status',
  //   formItemClass: 'col-span-4 hide-label',
  //   defaultValue: 1,
  // },

  {
    component: 'Input',
    fieldName: 'title',
    label: '任务标题',
  },
  {
    component: 'Input',
    fieldName: 'startUserName',
    label: '发起人',
  },
  {
    component: 'ApiTreeSelect',
    componentProps: {
      api: getDeptTree,
      fieldNames: { label: 'label', value: 'id', children: 'children' },
      treeLine: { showLeafIcon: false },
      // 默认展开的节点
      // treeDefaultExpandedKeys: [340100000000],
      showSearch: true,
      treeNodeFilterProp: 'label',
    },
    fieldName: 'deptId',
    label: '发起单位',
  },

  {
    component: 'Select',
    componentProps: {
      options: getDictOptions('tasks_type'),
    },
    fieldName: 'taskType',
    label: '任务类型',
  },
  {
    component: 'Select',
    componentProps: {
      options: getDictOptions('task_level'),
    },
    fieldName: 'level',
    label: '任务级别',
  },
  {
    component: 'RangePicker',
    fieldName: 'startTimes',
    label: '发起时间',
    componentProps: {
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
  },
];
export const dwspColumns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '任务标题',
    field: 'missionTitle',
  },
  {
    title: '状态',
    field: 'missionStatus',
    slots: { default: 'missionStatus' },
  },
  {
    title: '任务级别',
    field: 'missionLevel',
  },

  {
    title: '发起人',
    field: 'startUser',
    slots: { default: 'startUser' },
  },
  {
    title: '发起单位',
    field: 'owerDeptName',
  },
  {
    title: '任务类型',
    field: 'missionTyle',
    slots: {
      default: ({ row }) => {
        return renderDict(row.missionTyle, 'tasks_type');
      },
    },
    width: 120,
  },
  {
    title: '发起时间',
    field: 'startTime',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
];

export const dwblColumns: VxeGridProps['columns'] = [
  // { type: 'checkbox', width: 60 },
  {
    type: 'expand',
    width: 40,
    slots: { content: 'expand_content' },
  },

  {
    title: '任务标题',
    field: 'title',
  },
  {
    title: '任务级别',
    field: 'level',
  },
  {
    title: '状态',
    field: 'status',
    slots: {
      default: ({ row }) => {
        return renderDict(row.status, 'biz_task_status');
      },
    },
  },
  {
    title: '发起人',
    field: 'applyUserName',
  },
  {
    title: '发起单位',
    field: 'applyDeptName',
  },
  {
    title: '任务类型',
    field: 'type',
    slots: {
      default: ({ row }) => {
        return renderDict(row.type, 'tasks_type');
      },
    },
    width: 120,
  },
  {
    title: '发起时间',
    field: 'createTime',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 220,
  },
];
export const ycldColumns: VxeGridProps['columns'] = [
  // { type: 'checkbox', width: 60 },
  {
    type: 'expand',
    width: 40,
    slots: { content: 'expand_content' },
  },
  {
    title: '任务标题',
    field: 'title',
  },
  {
    title: '任务级别',
    field: 'level',
  },
  {
    title: '状态',
    field: 'status',
    slots: {
      default: ({ row }) => {
        return renderDict(row.status, 'biz_task_status');
      },
    },
  },
  {
    title: '发起人',
    field: 'applyUserName',
  },
  {
    title: '发起单位',
    field: 'applyDeptName',
  },
  {
    title: '任务类型',
    field: 'type',
    slots: {
      default: ({ row }) => {
        return renderDict(row.type, 'tasks_type');
      },
    },
    width: 120,
  },
  {
    title: '发起时间',
    field: 'createTime',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 120,
  },
];
export const modalSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'postId',
    label: 'postId',
  },
  {
    component: 'TreeSelect',
    componentProps: {
      getPopupContainer,
    },
    fieldName: 'deptId',
    label: '所属部门',
    rules: 'selectRequired',
  },
  {
    component: 'Input',
    fieldName: 'postName',
    label: '岗位名称',
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'postCode',
    label: '岗位编码',
    rules: 'required',
  },
  // {
  //   component: 'Input',
  //   fieldName: 'postCategory',
  //   label: '类别编码',
  // },
  {
    component: 'InputNumber',
    fieldName: 'postSort',
    label: '岗位排序',
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
      optionType: 'button',
    },
    defaultValue: '0',
    fieldName: 'status',
    label: '岗位状态',
    rules: 'required',
  },
  {
    component: 'Textarea',
    fieldName: 'remark',
    formItemClass: 'items-baseline',
    label: '备注',
  },
];
