|
|
@@ -13,10 +13,36 @@ import {
|
|
|
editProductApi,
|
|
|
getProductDetailApi,
|
|
|
} from '#/api/product';
|
|
|
+import { getCustomerListApi } from '#/api/user';
|
|
|
|
|
|
const emit = defineEmits(['finish']);
|
|
|
const data = ref();
|
|
|
const formType = ref<'create' | 'detail' | 'edit'>('create');
|
|
|
+const channelOptions = ref<{ label: string; value: string }[]>([]);
|
|
|
+
|
|
|
+// 获取渠道商列表
|
|
|
+const fetchChannelOptions = async () => {
|
|
|
+ try {
|
|
|
+ // 确保清空之前的选项
|
|
|
+ channelOptions.value = [];
|
|
|
+
|
|
|
+ const response = await getCustomerListApi({
|
|
|
+ 'usersnature.value': '渠道',
|
|
|
+ pageindex: 1,
|
|
|
+ rows: 100,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 从response.Data中获取数据
|
|
|
+ if (response && response.Data && Array.isArray(response.Data)) {
|
|
|
+ channelOptions.value = response.Data.map((item: any) => ({
|
|
|
+ label: item.usersname || '未命名渠道商',
|
|
|
+ value: item.usersid || '',
|
|
|
+ })).filter((item: any) => item.value);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取渠道商列表失败', error);
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
const titleMap = {
|
|
|
create: '新增产品',
|
|
|
@@ -123,6 +149,24 @@ const [BaseForm, baseFormApi] = useVbenForm({
|
|
|
rules: z.string().min(1, { message: '请输入品目' }),
|
|
|
},
|
|
|
{
|
|
|
+ component: 'Select',
|
|
|
+ fieldName: 'productsmerchantid',
|
|
|
+ label: '关联渠道商',
|
|
|
+ componentProps: {
|
|
|
+ placeholder: '请选择关联渠道商',
|
|
|
+ options: channelOptions,
|
|
|
+ multiple: true,
|
|
|
+ collapseTags: true,
|
|
|
+ collapseTagsTooltip: true,
|
|
|
+ clearable: true,
|
|
|
+ filterable: true,
|
|
|
+ noDataText: '暂无渠道商数据',
|
|
|
+ loading: false,
|
|
|
+ style: { width: '100%' },
|
|
|
+ },
|
|
|
+ rules: z.array(z.string()).min(1, { message: '请选择关联渠道商' }),
|
|
|
+ },
|
|
|
+ {
|
|
|
component: 'Input',
|
|
|
fieldName: 'productsfl1',
|
|
|
label: '一级分类',
|
|
|
@@ -200,12 +244,18 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
+ // 处理多选值的转换
|
|
|
+ const formValues = { ...validate.values };
|
|
|
+ if (Array.isArray(formValues.productsmerchantid)) {
|
|
|
+ formValues.productsmerchantid = formValues.productsmerchantid.join(',');
|
|
|
+ }
|
|
|
+
|
|
|
// 调用新增或编辑接口
|
|
|
const apiMap = {
|
|
|
- create: () => addProductApi(validate.values as ProductEntity),
|
|
|
+ create: () => addProductApi(formValues as ProductEntity),
|
|
|
edit: () =>
|
|
|
editProductApi({
|
|
|
- ...validate.values,
|
|
|
+ ...formValues,
|
|
|
'productsid.value': data.value.row.productsid,
|
|
|
} as any),
|
|
|
};
|
|
|
@@ -225,13 +275,15 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
async onOpenChange(isOpen) {
|
|
|
if (isOpen) {
|
|
|
data.value = modalApi.getData();
|
|
|
-
|
|
|
formType.value = data.value.formType;
|
|
|
|
|
|
baseFormApi.setState({
|
|
|
commonConfig: { disabled: formType.value === 'detail' },
|
|
|
});
|
|
|
|
|
|
+ // 获取渠道商列表
|
|
|
+ await fetchChannelOptions();
|
|
|
+
|
|
|
if (data.value.formType === 'create') {
|
|
|
return;
|
|
|
}
|
|
|
@@ -242,9 +294,15 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
productsid: data.value.row.productsid,
|
|
|
});
|
|
|
|
|
|
+ // 处理多选值的转换
|
|
|
+ if (detailData.productsmerchantid) {
|
|
|
+ detailData.productsmerchantid =
|
|
|
+ detailData.productsmerchantid.split(',');
|
|
|
+ }
|
|
|
+
|
|
|
baseFormApi.setValues(detailData);
|
|
|
- } catch {
|
|
|
- // console.log(error);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取产品详情失败', error);
|
|
|
}
|
|
|
|
|
|
modalApi.setState({ loading: false });
|