|
|
@@ -109,7 +109,7 @@
|
|
|
<el-button type="primary" size="small" @click="handleImportData">
|
|
|
导入数据
|
|
|
</el-button>
|
|
|
- <el-button type="primary" size="small" @click="handleSaveTemplate">
|
|
|
+ <el-button type="primary" size="small" @click="handleSaveData">
|
|
|
保存核定数据
|
|
|
</el-button>
|
|
|
</div>
|
|
|
@@ -178,7 +178,8 @@
|
|
|
} from '@/api/costVerifyManage'
|
|
|
import { getDetail } from '@/api/auditInitiation'
|
|
|
import { catalogMixin } from '@/mixins/useDict'
|
|
|
- import { saveAs } from 'file-saver'
|
|
|
+ import { saveSingleRecordSurvey } from '@/api/audit/survey'
|
|
|
+
|
|
|
export default {
|
|
|
name: 'CostAudit',
|
|
|
mixins: [catalogMixin],
|
|
|
@@ -201,6 +202,7 @@
|
|
|
type: String,
|
|
|
default: '',
|
|
|
},
|
|
|
+ auditedUnitId: { type: String, default: '' },
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -631,8 +633,44 @@
|
|
|
this.costAuditData.push(rowData)
|
|
|
})
|
|
|
|
|
|
- // 表格排序,子项排在父项的后面
|
|
|
- this.sortItemsByHierarchy()
|
|
|
+ // 平铺顺序:父项在前、子项紧随其后
|
|
|
+ const sortFn = (a, b) =>
|
|
|
+ Number(a.orderNum || 0) - Number(b.orderNum || 0)
|
|
|
+ const byRowId = new Map()
|
|
|
+ const parents = []
|
|
|
+ const childGroups = new Map()
|
|
|
+ this.costAuditData.forEach((row) => {
|
|
|
+ if (row && row.children) delete row.children
|
|
|
+ const key = row.rowid != null ? String(row.rowid) : ''
|
|
|
+ if (key) byRowId.set(key, row)
|
|
|
+ const pid = row.parentid
|
|
|
+ const isParent =
|
|
|
+ pid === -1 || pid === '-1' || pid === null || pid === undefined
|
|
|
+ if (isParent) {
|
|
|
+ parents.push(row)
|
|
|
+ } else {
|
|
|
+ const pKey = pid != null ? String(pid) : ''
|
|
|
+ if (!childGroups.has(pKey)) childGroups.set(pKey, [])
|
|
|
+ childGroups.get(pKey).push(row)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ parents.sort(sortFn)
|
|
|
+ const flat = []
|
|
|
+ const seen = new Set()
|
|
|
+ parents.forEach((p) => {
|
|
|
+ flat.push(p)
|
|
|
+ seen.add(p)
|
|
|
+ const group = childGroups.get(String(p.rowid)) || []
|
|
|
+ group.sort(sortFn).forEach((c) => {
|
|
|
+ flat.push(c)
|
|
|
+ seen.add(c)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ // 处理找不到父项的子项:放在末尾
|
|
|
+ this.costAuditData.forEach((row) => {
|
|
|
+ if (!seen.has(row)) flat.push(row)
|
|
|
+ })
|
|
|
+ this.costAuditData = flat
|
|
|
}
|
|
|
},
|
|
|
handleSaveTemplate(type) {
|
|
|
@@ -669,7 +707,52 @@
|
|
|
this.$loading().close()
|
|
|
console.log(err)
|
|
|
})
|
|
|
- // this.$message({ type: 'success', message: '保存成功' })
|
|
|
+ },
|
|
|
+ async handleSaveData() {
|
|
|
+ const loading = this.$loading({
|
|
|
+ lock: true,
|
|
|
+ text: '保存数据中...',
|
|
|
+ spinner: 'el-icon-loading',
|
|
|
+ background: 'rgba(0, 0, 0, 0.7)',
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ // 1) 基于当前表格数据生成保存明细
|
|
|
+ const rawItems =
|
|
|
+ this.splitFixedTableDataForSave(this.costAuditData) || []
|
|
|
+ const auditedUnitId =
|
|
|
+ this.auditedUnitId || this.auditForm.auditedUnitId || ''
|
|
|
+ const surveyTemplateId =
|
|
|
+ this.auditForm.surveyTemplateId || this.auditForm.dataTable || ''
|
|
|
+ const catalogId = this.auditForm.catalogId || ''
|
|
|
+ const hasData = !!(this.auditForm && this.auditForm.uploadId)
|
|
|
+
|
|
|
+ const finalSaveData = rawItems.map((it) => {
|
|
|
+ const base = {
|
|
|
+ rowid: it.rowid,
|
|
|
+ rkey: it.rkey,
|
|
|
+ rvalue: it.rvalue != null ? String(it.rvalue) : '',
|
|
|
+ auditedUnitId,
|
|
|
+ surveyTemplateId,
|
|
|
+ catalogId,
|
|
|
+ }
|
|
|
+ if (hasData) base.uploadId = this.auditForm.uploadId
|
|
|
+ return base
|
|
|
+ })
|
|
|
+
|
|
|
+ // 2) 调用保存接口
|
|
|
+ const res = await saveSingleRecordSurvey(finalSaveData)
|
|
|
+ if (res && res.code === 200) {
|
|
|
+ this.$message.success('保存成功')
|
|
|
+ this.loadTemplateData && this.loadTemplateData()
|
|
|
+ } else {
|
|
|
+ this.$message.error((res && res.message) || '保存失败')
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ console.error(err)
|
|
|
+ // this.$message.error('保存失败')
|
|
|
+ } finally {
|
|
|
+ loading.close()
|
|
|
+ }
|
|
|
},
|
|
|
//分割字符串
|
|
|
stringToObjects(str) {
|
|
|
@@ -946,9 +1029,9 @@
|
|
|
this.$message({ type: 'info', message: '导出数据' })
|
|
|
},
|
|
|
|
|
|
- handleSaveData() {
|
|
|
- this.$message({ type: 'success', message: '成本审核数据已保存' })
|
|
|
- },
|
|
|
+ // handleSaveData() {
|
|
|
+ // this.$message({ type: 'success', message: '成本审核数据已保存' })
|
|
|
+ // },
|
|
|
|
|
|
handleRemark(row, field) {
|
|
|
this.$prompt('请输入说明', '提示', {
|