Commit 23d235e0 authored by 郝聪敏's avatar 郝聪敏

fix: 修改优惠券选择bug

parent e43c6d4e
......@@ -24,12 +24,10 @@ export default class DynamicForm extends Mixins(DynamicFormMixin) {
tableData: object[] = [];
get idsLength() {
if (validateType(this.value) === 'object') {
return this.value?.ids?.length;
}
return this.value?.length;
return this.getLength('value');
}
// 获取除本页之外的默认值
getDefaultIds() {
let defaultIds = this.value;
if (validateType(this.value) === 'object') {
......@@ -47,6 +45,7 @@ export default class DynamicForm extends Mixins(DynamicFormMixin) {
return rs;
}
// 获取本页的选中值
getSelectionsIds() {
if (this.table.length > 1) {
return this.selections.map(v => v[this.table[this.activeName].key]);
......@@ -55,6 +54,42 @@ export default class DynamicForm extends Mixins(DynamicFormMixin) {
}
}
// 获取本页之外的临时值
getTemplateIds() {
let filterIds = [];
let templates = [];
if (this.table.length > 1) {
filterIds = this.tableData.map(v => v[this.table[this.activeName].key]);
templates = this.templates.ids;
} else {
filterIds = this.tableData.map(v => v.id);
templates = this.templates;
}
const rs = templates.filter(v => !filterIds.includes(v));
return rs;
}
getLength(type) {
const rs = type === 'templates' ? this.templates : this.value;
if (validateType(this.templates) === 'object') {
return this.templates?.ids?.length;
}
return this.templates?.length;
}
// 当table取消全选时的默认值
getDefaultSelections() {
let rs = [];
if (this.table.length > 1) {
const key = this.table[this.activeName].key;
rs = [{ [key]: -1 }];
} else {
rs = [{ id: -1 }];
}
return rs;
}
@Watch('curEleIndex', { immediate: true })
onElementChange(newVal) {
this.formControl.forEach(schame => {
......@@ -83,37 +118,35 @@ export default class DynamicForm extends Mixins(DynamicFormMixin) {
title: '商品组只能单选'
});
}
this.selections = uniqBy([...this.selections, ...selection], 'id');
console.log('selectionChange', this.selections, selection);
this.selections = selection.length ? selection : this.getDefaultSelections();
const ids = [...this.getSelectionsIds(), ...(this.getLength('templates') ? this.getTemplateIds() : this.getDefaultIds())];
console.log('selectionChange', ids, selection);
let rs = null;
if (this.table.length > 1) {
rs = {
type: this.table[this.activeName].type,
ids: this.selections.map(v => v[this.table[this.activeName].key])
ids
};
} else {
rs = this.selections.map(v => v.id);
rs = ids;
}
return rs;
}
selectionCancel(_, row) {
const index = this.selections.findIndex(v => v.id === row.id);
this.selections.splice(index, 1);
console.log('selectionCancel', this.selections, row, index);
}
ok() {
const ids = [...this.getSelectionsIds(), ...this.getDefaultIds()];
const ids = [...this.getSelectionsIds(), ...(this.getLength('templates') ? this.getTemplateIds() : this.getDefaultIds())].filter(v => v !== -1);
if (!ids.length) { return; }
this.selections = [];
// console.log('commit', selections);
if (this.table.length > 1) {
this.$emit('update:templates', {});
this.$emit('input', {
type: this.table[this.activeName].type,
ids
});
} else {
this.$emit('update:templates', []);
this.$emit('input', ids);
}
}
......
......@@ -35,7 +35,6 @@
:height="500"
:tableData.sync="tableData"
@on-selection-change="selectionChange"
@on-select-cancel="selectionCancel"
>
</QGTable>
</div>
......
......@@ -1479,9 +1479,9 @@
}
},
"@qg/citrus-ui": {
"version": "0.0.43",
"resolved": "http://npmprivate.quantgroups.com/@qg%2fcitrus-ui/-/citrus-ui-0.0.43.tgz",
"integrity": "sha512-7DEd3h0m/aCQK5Dgc/QthYdi/CipT9H9l+GfkZy5HSi+2VuRkQFmPqbKdF3l6/gKjQt4++iKP6TexLbjsB2lWw==",
"version": "0.0.45",
"resolved": "http://npmprivate.quantgroups.com/@qg%2fcitrus-ui/-/citrus-ui-0.0.45.tgz",
"integrity": "sha512-quO3sk+I9YbqtPLhRRNGvcBrSSTVZT4GK0upMKH4jFyaXQDSKfkUoi1LD1R9Avs0UXvvUZ2A+bY7X3yuXKjViA==",
"requires": {
"@better-scroll/core": "^2.1.1",
"@qg/cherry-ui": "^2.20.5",
......@@ -19921,9 +19921,9 @@
"integrity": "sha1-8z/pz7Urv9UgqhgyO8ZdsRCht2w="
},
"rollup": {
"version": "2.42.4",
"resolved": "http://npmprivate.quantgroups.com/rollup/-/rollup-2.42.4.tgz",
"integrity": "sha512-Zqv3EvNfcllBHyyEUM754npqsZw82VIjK34cDQMwrQ1d6aqxzeYu5yFb7smGkPU4C1Bj7HupIMeT6WU7uIdnMw==",
"version": "2.43.0",
"resolved": "http://npmprivate.quantgroups.com/rollup/-/rollup-2.43.0.tgz",
"integrity": "sha512-FRsYGqlo1iF/w3bv319iStAK0hyhhwon35Cbo7sGUoXaOpsZFy6Lel7UoGb5bNDE4OsoWjMH94WiVvpOM26l3g==",
"requires": {
"fsevents": "~2.3.1"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment