<template>
|
<LoadingLayout :loading="isEdit && isLoading">
|
<AppScrollContainer>
|
<ChunkCell title="基本信息">
|
<ProForm :model="form" ref="formRef" label-width="140px" :is-read="isDetail">
|
<ProFormCol>
|
<ProFormColItem :span="12">
|
<ProFormItemV2
|
label="行业类别:"
|
prop="industryCategoryCode"
|
:check-rules="[{ message: '请选择行业类别' }]"
|
>
|
<ProFormSelect
|
v-model="form.industryCategoryCode"
|
placeholder="请选择行业类别"
|
:value-enum="dictionaryDataList"
|
clearable
|
@change="industryCategoryCodeChange"
|
></ProFormSelect>
|
</ProFormItemV2>
|
</ProFormColItem>
|
</ProFormCol>
|
<ProFormCol>
|
<ProFormColItem :span="12">
|
<ProFormItemV2
|
label="岗位:"
|
prop="jobCode"
|
:check-rules="[{ message: '请选择岗位' }]"
|
>
|
<ProFormSelect
|
v-model="form.jobCode"
|
placeholder="请选择岗位"
|
:value-enum="positionList"
|
clearable
|
></ProFormSelect>
|
</ProFormItemV2>
|
</ProFormColItem>
|
</ProFormCol>
|
<ProFormCol>
|
<ProFormColItem :span="12">
|
<ProFormItemV2
|
label="服务名:"
|
prop="name"
|
:check-rules="[{ message: '请输入服务名' }]"
|
>
|
<ProFormText v-model.trim="form.name" :maxlength="30" placeholder="请输入服务名" />
|
</ProFormItemV2>
|
</ProFormColItem>
|
</ProFormCol>
|
<ProFormCol>
|
<ProFormColItem :span="12">
|
<ProFormItemV2
|
label="规格:"
|
prop="specs"
|
:check-rules="[
|
{
|
validator: (rule, value, callback) => {
|
if (specProTableProps.tableData?.length) {
|
console.log(123);
|
specProTableProps.tableData.forEach((item, index) => {
|
if (!item?.name) callback(new Error(`请输入第${index + 1}个规格名称`));
|
if (!item?.price) callback(new Error(`请输入第${index + 1}个规格价格`));
|
});
|
} else {
|
callback(new Error(`请添加规格`));
|
}
|
callback();
|
},
|
},
|
]"
|
class="form-item-specs"
|
>
|
<ProTableV2
|
v-bind="specProTableProps"
|
:columns="specificationsColumn"
|
:operationBtns="specificationsOperationBtns"
|
:show-pagination="false"
|
:auto-height="false"
|
ref="proTable"
|
:tableProps="{
|
maxHeight: '200px',
|
}"
|
>
|
<template #name="{ row }">
|
<el-input v-model="row.name" placeholder="请输入规格名称" />
|
</template>
|
<template #price="{ row }">
|
<el-input-number
|
v-model="row.price"
|
:controls="false"
|
:precision="2"
|
placeholder="请输入价格"
|
/>
|
</template>
|
</ProTableV2>
|
<el-button class="add-spec-btn" type="primary" link @click="handleSpecAdd()"
|
>添加</el-button
|
>
|
</ProFormItemV2>
|
</ProFormColItem>
|
</ProFormCol>
|
|
<ProFormCol>
|
<ProFormColItem :span="12">
|
<ProFormItemV2
|
label="图片:"
|
prop="files"
|
:check-rules="[{ type: 'array', message: '请上传图片' }]"
|
>
|
<ProFormUpload
|
v-model:file-url="form.files"
|
:limit="10"
|
:limitFileSize="10"
|
accept="jpg/jpeg,png,pdf"
|
></ProFormUpload>
|
</ProFormItemV2>
|
</ProFormColItem>
|
</ProFormCol>
|
|
<ProFormCol>
|
<ProFormColItem :span="24">
|
<ProFormItemV2
|
label="服务描述:"
|
prop="description"
|
required
|
:check-rules="[{ message: '请输入服务描述' }]"
|
>
|
<RichEditor v-model="form.description" :editorConfig="{ readOnly: isDetail }" />
|
</ProFormItemV2>
|
</ProFormColItem>
|
</ProFormCol>
|
</ProForm>
|
</ChunkCell>
|
<ChunkCell title="供应商">
|
<ProTableQueryFilterBar :show-reset-btn="false">
|
<template #btn>
|
<el-button type="primary" link @click="openSupplierDialog()">添加</el-button>
|
</template>
|
</ProTableQueryFilterBar>
|
<ProTableV2
|
v-bind="proTableProps"
|
:columns="column"
|
:operationBtns="operationBtns"
|
:auto-height="false"
|
ref="proTable"
|
:tableProps="{
|
maxHeight: '400px',
|
}"
|
>
|
</ProTableV2>
|
<div class="chuck-add-or-edit-actions">
|
<el-button class="chuck-add-or-edit-actions" @click="handleBack">取消</el-button>
|
<el-button type="primary" class="chuck-add-or-edit-actions" @click="handleSubmit"
|
>保存</el-button
|
>
|
</div>
|
</ChunkCell>
|
</AppScrollContainer>
|
<AddSupplierDialog v-bind="dialogProps"></AddSupplierDialog>
|
</LoadingLayout>
|
</template>
|
<script setup lang="ts">
|
import {
|
LoadingLayout,
|
AppScrollContainer,
|
ProForm,
|
ProFormItemV2,
|
ChunkCell,
|
ProFormText,
|
ProFormSelect,
|
ProFormCol,
|
ProFormColItem,
|
UploadUserFile,
|
ProTableQueryFilterBar,
|
ProFormUpload,
|
useFormDialog,
|
useTable,
|
ProTableV2,
|
defineColumns,
|
defineOperationBtns,
|
} from '@bole-core/components';
|
import { FormInstance } from 'element-plus';
|
import * as standardService from '@/services/api/standardService';
|
import { useRouteView, useGlobalEventContext, GlobalEvent } from '@/hooks';
|
import _ from 'lodash';
|
import { convertApi2FormUrl, Message, paginateList } from '@/utils';
|
import { useQuery } from '@tanstack/vue-query';
|
import AddSupplierDialog from './AddSupplierDialog.vue';
|
|
defineOptions({ name: 'AddOrEditServicesManageView' });
|
|
type Props = {
|
isDetail: boolean;
|
emitAddEvent?: keyof GlobalEvent;
|
emitEditEvent?: keyof GlobalEvent;
|
backRouteName?: string;
|
};
|
|
const props = withDefaults(defineProps<Props>(), {
|
emitAddEvent: 'servicesManage:add',
|
emitEditEvent: 'servicesManage:edit',
|
backRouteName: 'ServicesManage',
|
});
|
|
const eventContext = useGlobalEventContext();
|
|
const route = useRoute();
|
const id = route.params.id as string;
|
const isEdit = computed(() => !!id);
|
const { dictionaryDataList } = useDictionaryDataSelect({
|
categoryCode: computed(() => CategoryCode.IndustryCategory),
|
});
|
|
const { closeViewPush } = useRouteView();
|
|
const specificationsColumn = defineColumns([
|
{
|
id: '1',
|
enCode: 'name',
|
name: '规格名称',
|
},
|
{
|
id: '2',
|
enCode: 'price',
|
name: '价格',
|
},
|
]);
|
|
const specificationsOperationBtns = defineOperationBtns([
|
{
|
data: {
|
enCode: 'deleteBtn',
|
name: '删除',
|
},
|
emits: {
|
onClick: (role) => handleSpecificationsDelete(role),
|
},
|
},
|
]);
|
|
const operationBtnMap: Record<string, OperationBtnType> = {
|
deleteBtn: {
|
emits: {
|
onClick: (role) => handleDelete(role),
|
},
|
},
|
};
|
const { column, operationBtns, checkSubModuleItemShow } = useAccess({
|
operationBtnMap,
|
});
|
|
const { proTableProps: enterpriseProTableProps } = useGetEnterprises();
|
|
const form = reactive({
|
id: '',
|
industryCategoryCode: '',
|
jobCode: '',
|
name: '',
|
specs: [] as API.GetStandardServiceQueryResultSpec[],
|
files: [] as UploadUserFile[],
|
description: '',
|
field1: '',
|
|
suppliers: [] as API.GetStandardServiceQueryResultSupplier[],
|
});
|
|
const { dictionaryDataList: positionList, refetch } = useDictionaryDataSelect({
|
categoryCode: computed(() => CategoryCode.Position),
|
field1: computed(() => form.field1),
|
});
|
|
const { isLoading } = useQuery({
|
queryKey: ['standardService/getStandardService', id],
|
queryFn: async () => {
|
return await standardService.getStandardService(
|
{ id: id },
|
{
|
showLoading: false,
|
}
|
);
|
},
|
onSuccess(data) {
|
form.industryCategoryCode = data.industryCategoryCode;
|
form.jobCode = data.jobCode;
|
form.name = data.name;
|
form.specs = data.specs;
|
form.files = data.files?.length ? data.files.map(convertApi2FormUrl) : [];
|
form.description = data.description;
|
form.suppliers = data.suppliers;
|
|
getSpecList();
|
getList();
|
},
|
enabled: computed(() => !!id),
|
});
|
|
const {
|
getDataSource: getSpecList,
|
proTableProps: specProTableProps,
|
paginationState: specPaginationState,
|
extraParamState: specExtraParamState,
|
} = useTable(
|
async ({ pageIndex, pageSize }, extraParamState) => {
|
try {
|
let list = [...form.specs];
|
return Promise.resolve({
|
pageModel: {
|
rows: pageSize,
|
page: pageIndex,
|
totalCount: list.length,
|
},
|
data: paginateList(list, pageIndex, pageSize),
|
});
|
} catch (error) {
|
console.log('error: ', error);
|
}
|
},
|
{
|
defaultExtraParams: {
|
orderInput: [{ property: 'id', order: EnumPagedListOrder.Desc }],
|
},
|
queryKey: ['standardService/getStandardService'],
|
}
|
);
|
|
const {
|
getDataSource: getList,
|
proTableProps,
|
paginationState,
|
extraParamState,
|
reset,
|
} = useTable(
|
async ({ pageIndex, pageSize }, extraParamState) => {
|
try {
|
let list = [...form.suppliers];
|
return Promise.resolve({
|
pageModel: {
|
rows: pageSize,
|
page: pageIndex,
|
totalCount: list.length,
|
},
|
data: paginateList(list, pageIndex, pageSize),
|
});
|
} catch (error) {
|
console.log('error: ', error);
|
}
|
},
|
{
|
defaultExtraParams: {
|
orderInput: [{ property: 'id', order: EnumPagedListOrder.Desc }],
|
},
|
queryKey: ['standardService/getStandardService'],
|
columnsRenderProps: {
|
isReal: {
|
formatter: (row: API.GetPersonalUserInfosQueryResultItem) => {
|
return row.isReal ? '已实名' : '未实名';
|
},
|
},
|
},
|
}
|
);
|
|
function industryCategoryCodeChange() {
|
form.jobCode = '';
|
form.field1 = dictionaryDataList.value.find(
|
(item) => item.code === form.industryCategoryCode
|
)?.data?.code;
|
|
refetch({
|
type: 'inactive',
|
});
|
}
|
|
function handleSpecAdd() {
|
form.specs.push({
|
name: '',
|
price: null,
|
});
|
getSpecList();
|
}
|
|
function handleSpecificationsDelete(row: API.GetStandardServiceQueryResultSpec) {
|
if (form.specs.length <= 1) {
|
Message.errorMessage('至少保留一个规格');
|
return;
|
}
|
form.specs.splice(form.specs.indexOf(row), 1);
|
getSpecList();
|
}
|
|
const { dialogProps, handleAdd, dialogState, editForm } = useFormDialog({
|
onConfirm: handleAddSupplier,
|
defaultFormParams: {
|
ids: [] as string[],
|
},
|
});
|
|
function openSupplierDialog() {
|
handleAdd({
|
ids: form.suppliers?.map((item) => item.id),
|
});
|
}
|
|
async function handleAddSupplier() {
|
console.log(editForm.ids, 'editForm.ids');
|
form.suppliers = enterpriseProTableProps.value?.tableData.filter((item) =>
|
editForm.ids.includes(item.id)
|
);
|
getList();
|
}
|
|
function handleDelete(row: any) {
|
form.suppliers.splice(form.suppliers.indexOf(row), 1);
|
getList();
|
}
|
|
const formRef = ref<FormInstance>();
|
|
function handleSubmit() {
|
if (!formRef.value) return;
|
formRef.value.validate((valid) => {
|
if (valid) {
|
saveStandardService();
|
} else {
|
return;
|
}
|
});
|
}
|
|
async function saveStandardService() {
|
try {
|
if (form.suppliers?.length <= 0) {
|
Message.errorMessage('至少选择一个供应商');
|
return;
|
}
|
let params: API.SaveStandardServiceCommand = {
|
industryCategoryCode: form.industryCategoryCode,
|
jobCode: form.jobCode,
|
name: form.name,
|
specs: form.specs,
|
files: form.files?.length > 0 ? form.files.map((item) => item.path) : [],
|
description: form.description,
|
supplierIds: form.suppliers?.length > 0 ? form.suppliers.map((item) => item.id) : [],
|
};
|
if (isEdit.value) {
|
params.id = id;
|
}
|
let res = await standardService.saveStandardService(params);
|
if (res) {
|
Message.successMessage(isEdit.value ? '编辑成功' : '发布成功');
|
eventContext.emit(isEdit.value ? 'servicesManage:edit' : 'servicesManage:add');
|
handleBack();
|
}
|
} catch (error) {}
|
}
|
|
function handleBack() {
|
closeViewPush(route, {
|
name: 'ServicesManage',
|
});
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
@use '@/style/common.scss' as *;
|
|
.form-item-specs {
|
:deep() {
|
.el-form-item__content {
|
flex-direction: column;
|
|
.pro-table-wrapper {
|
width: 100%;
|
}
|
}
|
}
|
|
.add-spec-btn {
|
place-self: flex-end;
|
}
|
}
|
</style>
|