| | |
| | | |
| | | import type { TrainModeItem } from './types'; |
| | | |
| | | import { onMounted, ref } from 'vue'; |
| | | |
| | | import { useMessage } from '@jnpf/hooks'; |
| | | import { useModal } from '@jnpf/ui/modal'; |
| | | import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable'; |
| | | |
| | | import { deleteTrainMode, getTrainModeList, setTrainModeEnabled } from '#/api/x/tms/trainMode'; |
| | | import { useBaseStore } from '#/store'; |
| | | |
| | | import Form from './Form.vue'; |
| | | import { |
| | | ENABLE_OPTIONS, |
| | | labelOfEnabled, |
| | | labelOfSignRule, |
| | | labelOfYesNo, |
| | | } from './constants'; |
| | | TMS_DIC, |
| | | TMS_DIC_FIELD_NAMES, |
| | | labelOfDic, |
| | | loadTmsDic, |
| | | type TmsDicOpt, |
| | | } from '#/views/x/tms/shared/dic'; |
| | | |
| | | defineOptions({ name: 'TmsTrainMode' }); |
| | | |
| | | const { createMessage } = useMessage(); |
| | | const baseStore = useBaseStore(); |
| | | const [registerForm, { openModal: openFormModal }] = useModal(); |
| | | |
| | | const signRuleOpts = ref<TmsDicOpt[]>([]); |
| | | const yesNoOpts = ref<TmsDicOpt[]>([]); |
| | | const enableOpts = ref<TmsDicOpt[]>([]); |
| | | |
| | | const columns: BasicColumn[] = [ |
| | | { title: '方式编码', dataIndex: 'modeCode', width: 120 }, |
| | |
| | | title: '签到规则', |
| | | dataIndex: 'signRule', |
| | | width: 120, |
| | | customRender: ({ record }) => labelOfSignRule((record as TrainModeItem).signRule), |
| | | customRender: ({ record }) => labelOfDic(signRuleOpts.value, (record as TrainModeItem).signRule), |
| | | }, |
| | | { |
| | | title: '允许名单外签到', |
| | | dataIndex: 'allowGuestSign', |
| | | width: 130, |
| | | align: 'center', |
| | | customRender: ({ record }) => labelOfYesNo((record as TrainModeItem).allowGuestSign), |
| | | customRender: ({ record }) => labelOfDic(yesNoOpts.value, (record as TrainModeItem).allowGuestSign), |
| | | }, |
| | | { |
| | | title: '起止须同一天', |
| | | dataIndex: 'sameDayRequired', |
| | | width: 120, |
| | | align: 'center', |
| | | customRender: ({ record }) => labelOfYesNo((record as TrainModeItem).sameDayRequired), |
| | | customRender: ({ record }) => labelOfDic(yesNoOpts.value, (record as TrainModeItem).sameDayRequired), |
| | | }, |
| | | { |
| | | title: '地点必填', |
| | | dataIndex: 'placeRequired', |
| | | width: 100, |
| | | align: 'center', |
| | | customRender: ({ record }) => labelOfYesNo((record as TrainModeItem).placeRequired), |
| | | customRender: ({ record }) => labelOfDic(yesNoOpts.value, (record as TrainModeItem).placeRequired), |
| | | }, |
| | | { title: '排序', dataIndex: 'sortNo', width: 80, align: 'center' }, |
| | | { |
| | |
| | | { title: '备注', dataIndex: 'remark', minWidth: 180 }, |
| | | ]; |
| | | |
| | | const [registerTable, { reload }] = useVxeTable({ |
| | | const [registerTable, { reload, getForm }] = useVxeTable({ |
| | | api: fetchList, |
| | | columns, |
| | | immediate: true, |
| | | immediate: false, |
| | | rowKey: 'id', |
| | | useSearchForm: true, |
| | | formConfig: { |
| | |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: ENABLE_OPTIONS, |
| | | options: enableOpts.value, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | ], |
| | |
| | | dataIndex: 'action', |
| | | fixed: 'right', |
| | | }, |
| | | }); |
| | | |
| | | async function loadDic() { |
| | | const [signRule, yesNo, enable] = await Promise.all([ |
| | | loadTmsDic(baseStore, TMS_DIC.signRule), |
| | | loadTmsDic(baseStore, TMS_DIC.yesNo), |
| | | loadTmsDic(baseStore, TMS_DIC.enableStatus), |
| | | ]); |
| | | signRuleOpts.value = signRule; |
| | | yesNoOpts.value = yesNo; |
| | | enableOpts.value = enable; |
| | | |
| | | getForm()?.updateSchema?.({ |
| | | field: 'enabled', |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: enableOpts.value, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }); |
| | | } |
| | | |
| | | onMounted(async () => { |
| | | await loadDic(); |
| | | reload(); |
| | | }); |
| | | |
| | | async function fetchList(params: Record<string, any>) { |
| | |
| | | } |
| | | |
| | | async function handleDelete(record: TrainModeItem) { |
| | | if (record.enabled !== '0') { |
| | | createMessage.warning('请先停用后再删除'); |
| | | return; |
| | | } |
| | | try { |
| | | await deleteTrainMode(record.id); |
| | | createMessage.success('删除成功'); |
| | |
| | | |
| | | function getTableActions(record: TrainModeItem): ActionItem[] { |
| | | const enableLabel = record.enabled === '1' ? '停用' : '启用'; |
| | | return [ |
| | | const actions: ActionItem[] = [ |
| | | { label: '编辑', onClick: handleEdit.bind(null, record) }, |
| | | { |
| | | label: enableLabel, |
| | |
| | | onOk: handleToggleEnabled.bind(null, record), |
| | | }, |
| | | }, |
| | | { |
| | | ]; |
| | | if (record.enabled === '0') { |
| | | actions.push({ |
| | | label: '删除', |
| | | color: 'error', |
| | | modelConfirm: { |
| | | content: `确定删除培训方式「${record.modeName}」吗?`, |
| | | onOk: handleDelete.bind(null, record), |
| | | }, |
| | | }, |
| | | ]; |
| | | }); |
| | | } |
| | | return actions; |
| | | } |
| | | </script> |
| | | |
| | |
| | | </template> |
| | | <template #enabled="{ record }"> |
| | | <a-tag :color="record.enabled === '1' ? 'success' : 'default'"> |
| | | {{ labelOfEnabled(record.enabled) }} |
| | | {{ labelOfDic(enableOpts, record.enabled) }} |
| | | </a-tag> |
| | | </template> |
| | | <template #action="{ record }"> |