<template>
|
<LoadingLayout :loading="state.loading">
|
<AppContainer>
|
<ProTableQueryFilterBar @on-reset="reset">
|
<template #query>
|
<QueryFilterItem>
|
<FieldSelect
|
v-model="extraParamState.searchType"
|
@change="getList()"
|
:value-enum="SearchTypeText"
|
placeholder="请选择所属类别"
|
></FieldSelect>
|
</QueryFilterItem>
|
<QueryFilterItem v-if="extraParamState.searchType === SearchType.Position">
|
<FieldSelect
|
v-model="extraParamState.parentId"
|
@change="getList()"
|
:value-enum="typeList"
|
enum-label-key="name"
|
enum-value-key="id"
|
placeholder="请选择行业类型"
|
clearable
|
></FieldSelect>
|
</QueryFilterItem>
|
<QueryFilterItem>
|
<SearchInput
|
v-model="extraParamState.name"
|
style="width: 200px"
|
placeholder="请输入名称"
|
@on-click-search="getList"
|
@keyup.enter="getList()"
|
>
|
</SearchInput>
|
</QueryFilterItem>
|
</template>
|
<template #btn>
|
<el-button
|
v-if="checkSubModuleItemShow('pageButton', 'addBtn')"
|
@click="openDialog()"
|
icon="Plus"
|
type="primary"
|
>新增</el-button
|
>
|
</template>
|
</ProTableQueryFilterBar>
|
<ProTableV2 v-bind="proTableProps" :columns="column" :operationBtns="operationBtns">
|
<template #columns="{ row, column }">
|
<template v-if="column.property === 'status'">
|
<FieldSwitch
|
v-model="row.status"
|
active-text="显示"
|
inactive-text="隐藏"
|
:before-change="() => setCategoryVis(row)"
|
/>
|
</template>
|
</template>
|
</ProTableV2>
|
</AppContainer>
|
<AddOrEditSearchSetting v-bind="dialogProps" :typeList="typeList" />
|
</LoadingLayout>
|
</template>
|
|
<script setup lang="ts">
|
import {
|
ProTableQueryFilterBar,
|
OperationBtnType,
|
ProTableV2,
|
SearchInput,
|
LoadingLayout,
|
AppContainer,
|
QueryFilterItem,
|
useTable,
|
useFormDialog,
|
UploadUserFile,
|
FieldSwitch,
|
FieldSelect,
|
FieldRadio,
|
} from '@bole-core/components';
|
import { useAccess } from '@/hooks';
|
import * as searchSettingServices from '@/services/api/SearchSetting';
|
import {
|
SearchType,
|
SearchTypeText,
|
// BelongType,
|
// BelongTypeText,
|
BooleanOptions,
|
} from '@/constants';
|
import { OrderInputType, Message } from '@bole-core/core';
|
import AddOrEditSearchSetting from './components/AddOrEditSearchSetting.vue';
|
import { convertApi2FormUrl } from '@/utils';
|
import { useQueryClient } from '@tanstack/vue-query';
|
import { useSearchSettingType } from '@/hooks';
|
|
defineOptions({
|
name: 'SearchSetting',
|
});
|
|
const operationBtnMap: Record<string, OperationBtnType> = {
|
editBtn: { emits: { onClick: (role) => openDialog(role) } },
|
};
|
|
const { checkSubModuleItemShow, column, operationBtns } = useAccess({
|
operationBtnMap,
|
});
|
|
const BaseState = {
|
loading: true,
|
};
|
const queryClient = useQueryClient();
|
const { searchSettingTypeList: typeList } = useSearchSettingType({
|
searchType: SearchType.IndustryCategory,
|
});
|
const state = reactive({ ...BaseState });
|
|
onMounted(async () => {
|
await getList();
|
state.loading = false;
|
});
|
|
const {
|
getDataSource: getList,
|
proTableProps,
|
paginationState,
|
extraParamState,
|
reset,
|
} = useTable(
|
async ({ pageIndex, pageSize }, extraParamState) => {
|
try {
|
let params: API.GetSearchSettingListInput = {
|
pageModel: {
|
rows: pageSize,
|
page: pageIndex,
|
orderInput: extraParamState.orderInput,
|
},
|
name: extraParamState.name,
|
// belongType: Number(extraParamState.belongType),
|
searchType: Number(extraParamState.searchType),
|
status: extraParamState.status,
|
};
|
|
if (extraParamState.searchType === SearchType.Position) {
|
params.isRecommend = extraParamState.isRecommend;
|
params.parentId = extraParamState.parentId;
|
}
|
let res = await searchSettingServices.getSearchSettingList(params, {
|
showLoading: !state.loading,
|
});
|
return res;
|
} catch (error) {
|
console.log('error: ', error);
|
}
|
},
|
{
|
defaultExtraParams: {
|
name: '',
|
searchType: SearchType.Identity,
|
orderInput: [{ property: 'sort', order: OrderInputType.Asc }],
|
status: '' as any as boolean,
|
isRecommend: '' as any as boolean,
|
parentId: '',
|
},
|
queryKey: ['searchSettingServices/getSearchSettingList'],
|
columnsRenderProps: {
|
searchType: { type: 'enum', valueEnum: SearchTypeText },
|
},
|
}
|
);
|
|
function openDialog(row?: API.GetSearchSettingList) {
|
if (row) {
|
handleEdit({
|
id: row.id,
|
searchType: extraParamState.searchType,
|
name: row.name,
|
sort: row.sort,
|
status: row.status,
|
src: row.src?.length ? [convertApi2FormUrl(row.src)] : [],
|
parentId: row.parentId ?? '',
|
});
|
} else {
|
handleAdd({
|
searchType: extraParamState.searchType,
|
});
|
}
|
}
|
|
const { dialogProps, handleAdd, handleEdit, editForm, dialogState } = useFormDialog({
|
onConfirm: handleAddOrEdit,
|
defaultFormParams: {
|
id: '',
|
searchType: SearchType.Identity,
|
name: '',
|
sort: 0,
|
status: true,
|
src: [] as UploadUserFile[],
|
parentId: '',
|
},
|
});
|
|
async function handleAddOrEdit() {
|
try {
|
let params: API.CreateOrEditSearchInput = {
|
searchType: extraParamState.searchType,
|
name: editForm.name,
|
sort: editForm.sort,
|
status: editForm.status,
|
src: editForm.src?.[0]?.path ?? '',
|
parentId: editForm.parentId ?? '',
|
};
|
if (editForm.id) {
|
params.id = editForm.id;
|
}
|
let res = await searchSettingServices.createOrEditSearchSetting(params);
|
if (res) {
|
Message.successMessage('操作成功');
|
getList(paginationState.pageIndex);
|
dialogState.dialogVisible = false;
|
updateCategoryMenu();
|
}
|
} catch (error) {}
|
}
|
|
function updateCategoryMenu() {
|
queryClient.invalidateQueries({
|
queryKey: [
|
'searchSettingServices/getTypeSearchSettingList',
|
{ searchType: extraParamState.searchType, belongType: null },
|
],
|
});
|
}
|
|
async function setCategoryVis(row: API.GetSearchSettingList) {
|
try {
|
let params: API.EnableSearchSettingInput = {
|
id: row.id,
|
status: !row.status,
|
};
|
let res = await searchSettingServices.enableSearchSetting(params);
|
updateCategoryMenu();
|
getList(paginationState.pageIndex);
|
return !!res;
|
} catch (error) {}
|
}
|
</script>
|