|
|
|
@ -160,8 +160,12 @@ |
|
|
|
import HandleFormItem from "./HandleFormItem.vue"; |
|
|
|
import { isEqual } from "@/utils/index.js"; |
|
|
|
import { isShowOther } from "@/utils/formPackageCommon.js"; |
|
|
|
import { EventBus } from "@/utils/eventBus"; |
|
|
|
import { getuuid } from "@/utils/index.js"; |
|
|
|
import moment from "moment"; |
|
|
|
import _ from "lodash"; |
|
|
|
export default { |
|
|
|
inject: ['templateFillType'], |
|
|
|
inject: ['templateFillType', 'getZdxgjl'], |
|
|
|
name: 'CustomTable', |
|
|
|
components: { |
|
|
|
HandleFormItem |
|
|
|
@ -217,6 +221,7 @@ export default { |
|
|
|
orangeBgCells: {}, // 存储需要橙色背景的单元格 {rowIndex-colIndex: true/false} |
|
|
|
isShowOther, |
|
|
|
oldLocalDataSource: [], |
|
|
|
uuid: getuuid(), |
|
|
|
} |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
@ -226,7 +231,6 @@ export default { |
|
|
|
const { stepTableFormData = [], headerSelectFields = {} } = newData; |
|
|
|
this.updateDataSource(stepTableFormData); |
|
|
|
this.headerSelectFields = JSON.parse(JSON.stringify(headerSelectFields)); |
|
|
|
console.log(stepTableFormData,"stepTableFormData") |
|
|
|
// 在数据加载后检查 compareTo 逻辑 |
|
|
|
this.checkCompareToOnDataLoad(); |
|
|
|
} |
|
|
|
@ -242,10 +246,123 @@ export default { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
// this.initHeaderSelectValues(); |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
EventBus.$on('onEditSignCallback', this.handleEditSignCallback); |
|
|
|
EventBus.$on('onFormEditSignCancel', this.handleEditSignCancel); |
|
|
|
}, |
|
|
|
unmounted() { |
|
|
|
this.oldLocalDataSource = []; |
|
|
|
EventBus.$off('onEditSignCallback', this.handleEditSignCallback); |
|
|
|
EventBus.$off('onFormEditSignCancel', this.handleEditSignCancel); |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
handleEditSignCancel(data) { |
|
|
|
if (data.uuid === this.uuid) { |
|
|
|
this.resetRecord(); |
|
|
|
} |
|
|
|
}, |
|
|
|
handleEditSignCallback(data) { |
|
|
|
if (data.uuid === this.uuid) { |
|
|
|
this.updateRecord(); |
|
|
|
} |
|
|
|
}, |
|
|
|
getRecords() { |
|
|
|
const records = []; |
|
|
|
const { nickName, name } = this.$store.getters; |
|
|
|
const { oldLocalDataSource, localDataSource, columns, prefixKey, fieldItemLabel } = this; |
|
|
|
|
|
|
|
localDataSource.forEach((row, rowIndex) => { |
|
|
|
const oldRow = oldLocalDataSource[rowIndex]; |
|
|
|
if (!oldRow) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
columns.forEach((col, colIndex) => { |
|
|
|
const oldValue = oldRow[col.prop]; |
|
|
|
const newValue = row[col.prop]; |
|
|
|
|
|
|
|
if (!isEqual(oldValue, newValue)) { |
|
|
|
const fieldLabelCn = this.$i18n.t(col.label, "zh_CN"); |
|
|
|
const fieldLabelEn = this.$i18n.t(col.label, "en_US"); |
|
|
|
const record = { |
|
|
|
userNameCn: nickName, |
|
|
|
userNameEn: name, |
|
|
|
key: prefixKey + '_' + col.prop + '_' + rowIndex, |
|
|
|
fieldCn: `${this.$i18n.t(fieldItemLabel, "zh_CN")}-${fieldLabelCn}`, |
|
|
|
fieldEn: `${this.$i18n.t(fieldItemLabel, "en_US")}-${fieldLabelEn}`, |
|
|
|
oldValue: oldValue, |
|
|
|
value: newValue, |
|
|
|
title: oldValue ? "修改" : "提交", |
|
|
|
time: moment().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
}; |
|
|
|
this.getZdxgjl().unshift(record); |
|
|
|
records.push(record); |
|
|
|
} |
|
|
|
|
|
|
|
if (col.bodySubKey) { |
|
|
|
const oldSubValue = oldRow[col.bodySubKey]; |
|
|
|
const newSubValue = row[col.bodySubKey]; |
|
|
|
|
|
|
|
if (!isEqual(oldSubValue, newSubValue)) { |
|
|
|
const fieldLabelCn = this.$i18n.t(col.label, "zh_CN"); |
|
|
|
const fieldLabelEn = this.$i18n.t(col.label, "en_US"); |
|
|
|
const record = { |
|
|
|
userNameCn: nickName, |
|
|
|
userNameEn: name, |
|
|
|
key: prefixKey + '_' + col.bodySubKey + '_' + rowIndex, |
|
|
|
fieldCn: `${this.$i18n.t(fieldItemLabel, "zh_CN")}-${fieldLabelCn}单位`, |
|
|
|
fieldEn: `${this.$i18n.t(fieldItemLabel, "en_US")}-${fieldLabelEn}单位`, |
|
|
|
oldValue: oldSubValue, |
|
|
|
value: newSubValue, |
|
|
|
title: oldSubValue ? "修改" : "提交", |
|
|
|
time: moment().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
}; |
|
|
|
this.getZdxgjl().unshift(record); |
|
|
|
records.push(record); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (col.otherCode) { |
|
|
|
const oldOtherValue = oldRow[col.otherCode]; |
|
|
|
const newOtherValue = row[col.otherCode]; |
|
|
|
|
|
|
|
if (!isEqual(oldOtherValue, newOtherValue)) { |
|
|
|
const fieldLabelCn = this.$i18n.t(col.label, "zh_CN"); |
|
|
|
const fieldLabelEn = this.$i18n.t(col.label, "en_US"); |
|
|
|
const otherLabelCn = col.otherLabel ? this.$i18n.t(col.otherLabel, "zh_CN") : this.$i18n.t("template.common.other", "zh_CN"); |
|
|
|
const otherLabelEn = col.otherLabel ? this.$i18n.t(col.otherLabel, "en_US") : this.$i18n.t("template.common.other", "en_US"); |
|
|
|
const record = { |
|
|
|
userNameCn: nickName, |
|
|
|
userNameEn: name, |
|
|
|
key: prefixKey + '_' + col.otherCode + '_' + rowIndex, |
|
|
|
fieldCn: `${this.$i18n.t(fieldItemLabel, "zh_CN")}-${fieldLabelCn}${otherLabelCn}`, |
|
|
|
fieldEn: `${this.$i18n.t(fieldItemLabel, "en_US")}-${fieldLabelEn}${otherLabelEn}`, |
|
|
|
oldValue: oldOtherValue, |
|
|
|
value: newOtherValue, |
|
|
|
title: oldOtherValue ? "修改" : "提交", |
|
|
|
time: moment().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
}; |
|
|
|
this.getZdxgjl().unshift(record); |
|
|
|
records.push(record); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
return records; |
|
|
|
}, |
|
|
|
updateRecord() { |
|
|
|
const records = this.getRecords(); |
|
|
|
const params = { |
|
|
|
type: "fieldChanged", |
|
|
|
newRecord: records, |
|
|
|
resourceList: this.getZdxgjl(), |
|
|
|
} |
|
|
|
setTimeout(() => { |
|
|
|
EventBus.$emit('onModifyRecord', params); |
|
|
|
}, 0); |
|
|
|
this.oldLocalDataSource = JSON.parse(JSON.stringify(this.localDataSource)); |
|
|
|
}, |
|
|
|
//取消按钮 重置记录 |
|
|
|
resetRecord(rowIndex, colIndex,) { |
|
|
|
if(this.localDataSource.length){ |
|
|
|
@ -596,12 +713,27 @@ export default { |
|
|
|
this.$emit('row-delete', rowIndex); |
|
|
|
}, |
|
|
|
// 更新数据方法,可在formData变更时调用,也可由父组件调用 |
|
|
|
updateDataSource(dataSource = []) { |
|
|
|
updateDataSource(dataSource = [],autoUpdateRecord = true) { |
|
|
|
this.oldLocalDataSource = JSON.parse(JSON.stringify(this.localDataSource)); |
|
|
|
if(autoUpdateRecord){ |
|
|
|
this.showEditSignDialog(); |
|
|
|
} |
|
|
|
console.log(this.oldLocalDataSource, "oldLocalDataSource") |
|
|
|
// 深拷贝数据以避免直接修改原始数据 |
|
|
|
this.localDataSource = JSON.parse(JSON.stringify(dataSource || [])); |
|
|
|
}, |
|
|
|
// 根据行索引更新数据 autoUpdateRecord 是否自动更新记录 |
|
|
|
updateDataSourceByRowIndex(rowIndex, data,autoUpdateRecord = true) { |
|
|
|
this.oldLocalDataSource = JSON.parse(JSON.stringify(this.localDataSource)); |
|
|
|
if(autoUpdateRecord){ |
|
|
|
this.showEditSignDialog(); |
|
|
|
} |
|
|
|
this.localDataSource[rowIndex] = { ...this.localDataSource[rowIndex], ...data }; |
|
|
|
this.localDataSource = [...this.localDataSource]; |
|
|
|
}, |
|
|
|
showEditSignDialog: _.debounce(()=>{ |
|
|
|
|
|
|
|
}, 100), |
|
|
|
onAddRow() { |
|
|
|
this.addRow({ |
|
|
|
actSolutionVolumePrecision: 3,//小数点精度默认为3 |
|
|
|
@ -617,12 +749,7 @@ export default { |
|
|
|
getDataSource() { |
|
|
|
return this.localDataSource; |
|
|
|
}, |
|
|
|
// 根据行索引更新数据 |
|
|
|
updateDataSourceByRowIndex(rowIndex, data) { |
|
|
|
this.oldLocalDataSource = JSON.parse(JSON.stringify(this.localDataSource)); |
|
|
|
this.localDataSource[rowIndex] = { ...this.localDataSource[rowIndex], ...data }; |
|
|
|
this.localDataSource = [...this.localDataSource]; |
|
|
|
}, |
|
|
|
|
|
|
|
// 判断表单项是否有错误 |
|
|
|
hasError(rowIndex, colIndex, field) { |
|
|
|
return this.formErrors.some(error => |
|
|
|
|