<script lang="ts" setup>
|
import type { BasicColumn } from '@jnpf/ui/vxeTable';
|
|
import { computed, nextTick, reactive, ref, watch } from 'vue';
|
|
import { useMessage } from '@jnpf/hooks';
|
import { ModalClose } from '@jnpf/ui/modal';
|
import { BasicVxeTable, useVxeTable } from '@jnpf/ui/vxeTable';
|
|
import { Modal as AModal, Form } from 'ant-design-vue';
|
import { pick } from 'lodash-es';
|
|
import { getConfigList } from '#/api/msgCenter/accountConfig';
|
import { getMsgTemplateList } from '#/api/msgCenter/msgTemplate';
|
import { $t } from '#/locales';
|
|
defineOptions({ inheritAttrs: false });
|
const props = defineProps({
|
value: { default: '' },
|
title: { type: String, default: '' },
|
messageType: { type: [String, Number], default: 0 },
|
type: { type: Number, default: 1 },
|
placeholder: { type: String, default: '请选择' },
|
messageSource: { type: [String, Number], default: '' },
|
});
|
const emit = defineEmits(['update:value', 'change']);
|
const formItemContext = Form.useInjectFormItemContext();
|
const innerValue = ref(undefined);
|
const visible = ref(false);
|
const options = ref<any[]>([]);
|
const { createMessage } = useMessage();
|
const columns: BasicColumn[] = [
|
{ title: '名称', dataIndex: 'fullName' },
|
{ title: '编码', dataIndex: 'enCode', width: 180 },
|
];
|
const searchInfo: any = reactive({
|
enabledMark: 1,
|
});
|
const [registerTable, { getForm, getSelectRows, setSelectedRowKeys, getSelectRowKeys }] = useVxeTable({
|
api: props.type === 1 ? getMsgTemplateList : getConfigList,
|
columns,
|
immediate: false,
|
useSearchForm: true,
|
formConfig: {
|
baseColProps: { span: 8 },
|
schemas: [
|
{
|
field: 'keyword',
|
label: $t('common.keyword'),
|
component: 'Input',
|
componentProps: {
|
placeholder: $t('common.enterKeyword'),
|
submitOnPressEnter: true,
|
},
|
},
|
],
|
},
|
tableSetting: { size: false, setting: false },
|
rowSelection: { type: 'radio' },
|
afterFetch: (data) => {
|
if (data) {
|
setTimeout(() => {
|
setSelectedRowKeys(innerValue.value ? [innerValue.value] : []);
|
}, 100);
|
}
|
},
|
});
|
|
const getSelectBindValue = computed(() => {
|
return {
|
...pick(props, ['disabled', 'size', 'allowClear']),
|
fieldNames: { label: 'fullName', value: 'id' },
|
placeholder: props.placeholder,
|
open: false,
|
showSearch: false,
|
showArrow: true,
|
};
|
});
|
|
watch(
|
() => props.value,
|
(val) => {
|
setValue(val);
|
},
|
{ immediate: true },
|
);
|
|
function setValue(value) {
|
options.value = [{ id: value, fullName: props.title }];
|
innerValue.value = value || undefined;
|
}
|
function onChange(_val, option) {
|
options.value = option ?? [];
|
const selectValue = options.value.length ? options.value[0] : {};
|
emit('change', innerValue.value, selectValue);
|
}
|
async function openSelectModal() {
|
if (!props.messageType) return createMessage.warning('请选择消息类型');
|
if (props.type == 1) {
|
searchInfo.messageType = props.messageType;
|
searchInfo.messageSource = props.messageSource;
|
}
|
if (props.type == 2) searchInfo.type = props.messageType;
|
visible.value = true;
|
nextTick(() => {
|
getForm().resetFields();
|
});
|
}
|
function handleCancel() {
|
visible.value = false;
|
}
|
function handleSubmit() {
|
if (!getSelectRowKeys().length && !getSelectRows().length) return;
|
if (!getSelectRows().length) {
|
emit('update:value', innerValue.value);
|
emit('change', innerValue.value, options.value[0]);
|
formItemContext.onFieldChange();
|
handleCancel();
|
return;
|
}
|
const selectRow = getSelectRows();
|
options.value = selectRow;
|
innerValue.value = selectRow[0]?.id;
|
emit('update:value', innerValue.value);
|
emit('change', innerValue.value, options.value[0]);
|
formItemContext.onFieldChange();
|
handleCancel();
|
}
|
</script>
|
|
<template>
|
<div class="common-container">
|
<a-select v-model:value="innerValue" v-bind="getSelectBindValue" :options="options" @change="onChange" @click="openSelectModal" />
|
<AModal
|
v-model:open="visible"
|
:title="props.type == 1 ? '选择模板' : '选择账号'"
|
:width="600"
|
class="jnpf-list-modal"
|
@ok="handleSubmit"
|
@cancel="handleCancel"
|
destroy-on-close>
|
<template #closeIcon>
|
<ModalClose :can-fullscreen="false" @cancel="handleCancel" />
|
</template>
|
<div class="jnpf-content-wrapper">
|
<div class="jnpf-content-wrapper-center">
|
<div class="jnpf-content-wrapper-content">
|
<BasicVxeTable @register="registerTable" :search-info="searchInfo" class="jnpf-sub-table" />
|
</div>
|
</div>
|
</div>
|
</AModal>
|
</div>
|
</template>
|