<template>
|
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
|
<BasicForm @register="registerForm">
|
<template #org="{ model, field }">
|
<BasicTree
|
v-model:value="model[field]"
|
:treeData="treeDataOrg"
|
:renderIcon="createIconOrg"
|
:fieldNames="{ title: 'deptName', key: 'id' }"
|
@gethalfCheckedKeys="gethalfCheckedKeysOrg"
|
:expanded-keys="expandedKeysOrg"
|
checkable
|
toolbar
|
title="分配组织"
|
/>
|
</template>
|
</BasicForm>
|
</BasicModal>
|
</template>
|
<script lang="ts" setup>
|
import { ref, computed, unref } from 'vue';
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
import { accountFormSchema } from './account.data';
|
import { getTreeList } from '/@/api/tigerapi/dept';
|
import { BasicTree, TreeItem } from '/@/components/Tree';
|
import { SaveUser } from '/@/api/tigerapi/account';
|
|
type CheckKeys = KeyType[] | { checked: string[] | number[]; halfChecked: string[] | number[] };
|
type _expandAll = KeyType[] | undefined;
|
const emits = defineEmits(['success', 'register']);
|
|
const isUpdate = ref(true);
|
const rowId = ref('');
|
const treeDataOrg = ref<TreeItem[]>([]);
|
const expandedKeysOrg = ref<_expandAll>([]);
|
const halfCheckedKeysOrg = ref<CheckKeys>([]);
|
|
const gethalfCheckedKeysOrg = (obj) => {
|
halfCheckedKeysOrg.value = obj;
|
console.log(obj);
|
};
|
|
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
|
labelWidth: 100,
|
schemas: accountFormSchema,
|
showActionButtonGroup: false,
|
actionColOptions: {
|
span: 24,
|
},
|
});
|
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
resetFields();
|
setModalProps({ confirmLoading: false });
|
isUpdate.value = !!data?.isUpdate;
|
|
if (unref(isUpdate)) {
|
rowId.value = data.record.id;
|
setFieldsValue({
|
...data.record,
|
});
|
}
|
if (unref(treeDataOrg).length === 0) {
|
treeDataOrg.value = (await getTreeList()) as any as TreeItem[];
|
}
|
// const treeData = await getTreeList();
|
// updateSchema([
|
// {
|
// field: 'USER_PWD',
|
// show: !unref(isUpdate),
|
// },
|
// {
|
// field: 'ORG_CODE',
|
// componentProps: { treeDataOrg },
|
// },
|
// ]);
|
});
|
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增账号' : '编辑账号'));
|
|
async function handleSubmit() {
|
try {
|
const values = await validate();
|
console.log('提交4', values.STATUS_CODE == true ? 'ENABLE' : 'DISABLEDS');
|
|
// return
|
|
console.log('提交', values.STATUS_CODE);
|
setModalProps({ confirmLoading: true });
|
// TODO custom api
|
//保存用户
|
const apiAction = SaveUser(values, unref(isUpdate));
|
console.log('保存', values);
|
// values.STATUS_CODE = values.STATUS_CODE == true?'ENABLE':'DISABLEDS'
|
apiAction.then((action) => {
|
if (action.IsSuccessed) {
|
closeModal();
|
emits('success', {
|
isUpdate: unref(isUpdate),
|
values: { ...values, id: rowId.value },
|
});
|
}
|
});
|
} finally {
|
setModalProps({ confirmLoading: false });
|
}
|
}
|
</script>
|