| | |
| | | |
| | | import type { SignModeItem } 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 { deleteSignMode, getSignModeList, setSignModeEnabled } from '#/api/x/tms/signMode'; |
| | | import { useBaseStore } from '#/store'; |
| | | import { |
| | | TMS_DIC, |
| | | TMS_DIC_FIELD_NAMES, |
| | | labelOfDic, |
| | | loadTmsDic, |
| | | type TmsDicOpt, |
| | | } from '#/views/x/tms/shared/dic'; |
| | | |
| | | import Form from './Form.vue'; |
| | | import { ENABLE_OPTIONS, labelOfEnabled, labelOfYesNo } from './constants'; |
| | | |
| | | defineOptions({ name: 'TmsSignMode' }); |
| | | |
| | | const { createMessage } = useMessage(); |
| | | const baseStore = useBaseStore(); |
| | | const [registerForm, { openModal: openFormModal }] = useModal(); |
| | | |
| | | const yesNoOpts = ref<TmsDicOpt[]>([]); |
| | | const enableOpts = ref<TmsDicOpt[]>([]); |
| | | |
| | | const columns: BasicColumn[] = [ |
| | | { title: '方式编码', dataIndex: 'modeCode', width: 140 }, |
| | |
| | | dataIndex: 'matchRoster', |
| | | width: 120, |
| | | align: 'center', |
| | | customRender: ({ record }) => labelOfYesNo((record as SignModeItem).matchRoster), |
| | | customRender: ({ record }) => labelOfDic(yesNoOpts.value, (record as SignModeItem).matchRoster), |
| | | }, |
| | | { |
| | | title: '状态', |
| | |
| | | { title: '备注', dataIndex: 'remark', minWidth: 220 }, |
| | | ]; |
| | | |
| | | const [registerTable, { reload }] = useVxeTable({ |
| | | const [registerTable, { reload, getForm }] = useVxeTable({ |
| | | api: fetchList, |
| | | columns, |
| | | immediate: true, |
| | | immediate: false, |
| | | rowKey: 'id', |
| | | useSearchForm: true, |
| | | formConfig: { |
| | |
| | | field: 'enabled', |
| | | label: '状态', |
| | | component: 'Select', |
| | | componentProps: { allowClear: true, placeholder: '请选择', options: ENABLE_OPTIONS }, |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: enableOpts.value, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }, |
| | | ], |
| | | }, |
| | |
| | | dataIndex: 'action', |
| | | fixed: 'right', |
| | | }, |
| | | }); |
| | | |
| | | onMounted(async () => { |
| | | yesNoOpts.value = await loadTmsDic(baseStore, TMS_DIC.yesNo); |
| | | enableOpts.value = await loadTmsDic(baseStore, TMS_DIC.enableStatus); |
| | | getForm()?.updateSchema?.({ |
| | | field: 'enabled', |
| | | componentProps: { |
| | | allowClear: true, |
| | | placeholder: '请选择', |
| | | options: enableOpts.value, |
| | | fieldNames: TMS_DIC_FIELD_NAMES, |
| | | }, |
| | | }); |
| | | reload(); |
| | | }); |
| | | |
| | | async function fetchList(params: Record<string, any>) { |
| | |
| | | } |
| | | |
| | | async function handleDelete(record: SignModeItem) { |
| | | if (record.enabled !== '0') { |
| | | createMessage.warning('请先停用后再删除'); |
| | | return; |
| | | } |
| | | try { |
| | | await deleteSignMode(record.id); |
| | | createMessage.success('删除成功'); |
| | |
| | | |
| | | function getTableActions(record: SignModeItem): 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 }"> |