Skip to content

Commit f871781

Browse files
committed
fix: price repeat line
1 parent 5dd94d1 commit f871781

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

frontend/packages/web/src/components/business/crm-form-create/index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@
270270
currentFieldValues.forEach((fieldValue, index) => {
271271
if ([FieldTypeEnum.DATA_SOURCE].includes(item.type) && Array.isArray(fieldValue)) {
272272
// 处理数据源字段,单选传单个值
273-
result[index][item.businessKey || item.id] = fieldValue?.[0];
273+
result[index][item.businessKey || item.id] = result[index].price_sub
274+
? fieldValue?.filter((e) => e !== result[index].price_sub)[0] // 价格表子表格特殊处理,price_sub是行号,这里不填充到fieldValue中
275+
: fieldValue?.[0];
274276
}
275277
if (item.type === FieldTypeEnum.PHONE) {
276278
// 去空格

frontend/packages/web/src/components/business/crm-sub-table/index.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</template>
1616

1717
<script setup lang="ts">
18-
import { DataTableCreateSummary, NButton, NDataTable, NImage, NImageGroup, NTooltip } from 'naive-ui';
18+
import { DataTableCreateSummary, NButton, NDataTable, NImage, NImageGroup, NTooltip, useMessage } from 'naive-ui';
1919
import { isEqual } from 'lodash-es';
2020
2121
import { PreviewPictureUrl } from '@lib/shared/api/requrls/system/module';
@@ -54,6 +54,7 @@
5454
}>();
5555
5656
const { t } = useI18n();
57+
const Message = useMessage();
5758
5859
const data = defineModel<Record<string, any>[]>('value', {
5960
required: true,
@@ -277,6 +278,9 @@
277278
const children = source.filter(
278279
(s) => s.parentId && data.value.every((r) => r.price_sub !== s.id) // 过滤已存在的行
279280
);
281+
if (children.length === 0 && val.length > 0) {
282+
Message.warning(t('crm.subTable.repeatAdd'));
283+
}
280284
if (children.length === 0 || !source.some((s) => s.parentId)) {
281285
// 没有选中子项或没有选中父项,都表示当前为清空
282286
row[key] = [];
@@ -291,7 +295,7 @@
291295
if (children.length > 1) {
292296
// 多选行时,新增多行且选中值为子项的父项信息
293297
row.price_sub = children[0]?.id;
294-
row[key] = [children[0].parentId, row.price_sub];
298+
row[key] = [children[0].parentId, row.price_sub]; // 价格表 id 在第一位,因为当前是单选数据源,提交表单时只会保存第一个值
295299
applyDataSourceShowFields(field, row[key], row, source, row.price_sub); // 数据源显示字段读取值并显示
296300
for (let i = 1; i < children.length; i++) {
297301
// 补充新增行
@@ -309,7 +313,16 @@
309313
} else {
310314
// 单选行只有一个父级
311315
row.price_sub = children[0]?.id;
312-
row[key] = val;
316+
row[key] = val.sort((a, b) => {
317+
// 保证父项在前,子项在后
318+
if (a === children[0].parentId) {
319+
return -1;
320+
}
321+
if (b === children[0].parentId) {
322+
return 1;
323+
}
324+
return 0;
325+
});
313326
applyDataSourceShowFields(field, row[key], row, source, row.price_sub);
314327
}
315328
} else {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export default {
22
'crm.subTable.addLine': 'Add a line',
3+
'crm.subTable.repeatAdd': 'The current row is already in the table, please do not add it repeatedly',
34
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export default {
22
'crm.subTable.addLine': '添加一行',
3+
'crm.subTable.repeatAdd': '当前行已在表格中,请勿重复添加',
34
};

0 commit comments

Comments
 (0)