costAudit.vue 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. <template>
  2. <div class="app-container">
  3. <div class="audit-controls">
  4. <el-form
  5. ref="auditForm"
  6. :model="auditForm"
  7. :rules="rules"
  8. :disabled="auditForm.surveyTemplateId !== ''"
  9. >
  10. <el-row>
  11. <el-col :span="6">
  12. <el-form-item label="" prop="catalogId">
  13. <div
  14. style="display: flex; justify-self: start; align-items: center"
  15. >
  16. <div style="width: 120px">监审类别:</div>
  17. <el-cascader
  18. v-model="auditForm.catalogId"
  19. :options="catalogListOptions"
  20. v-bind="props"
  21. style="width: 200px"
  22. clearable
  23. ></el-cascader>
  24. </div>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="6">
  28. <el-form-item label="核定模板名称:" prop="surveyTemplateName">
  29. <el-input
  30. v-model="auditForm.surveyTemplateName"
  31. style="width: 200px"
  32. clearable
  33. placeholder="请输入核定模板名称"
  34. ></el-input>
  35. </el-form-item>
  36. </el-col>
  37. </el-row>
  38. <el-row :gutter="20">
  39. <el-col :span="6">
  40. <el-form-item label="" prop="templateType">
  41. <div
  42. style="display: flex; justify-self: start; align-items: center"
  43. >
  44. <el-radio
  45. v-model="auditForm.templateType"
  46. label="1"
  47. @change="handleTemplateTypeChange"
  48. >
  49. 选择调查表修改核定表
  50. </el-radio>
  51. <el-select
  52. v-model="auditForm.dataTable"
  53. placeholder="请选择"
  54. :disabled="auditForm.templateType !== '1'"
  55. >
  56. <el-option
  57. v-for="item in surveyFormList"
  58. :key="item.id"
  59. :label="item.surveyTemplateName"
  60. :value="item.surveyTemplateId"
  61. ></el-option>
  62. </el-select>
  63. </div>
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="6">
  67. <el-form-item label="" prop="">
  68. <div
  69. style="display: flex; justify-self: start; align-items: center"
  70. >
  71. <el-radio
  72. v-model="auditForm.templateType"
  73. label="2"
  74. @change="handleTemplateTypeChange"
  75. >
  76. 选择核定表历史版本
  77. </el-radio>
  78. <el-select
  79. v-model="auditForm.historyTemplate"
  80. placeholder="请选择"
  81. :disabled="auditForm.templateType !== '2'"
  82. >
  83. <el-option
  84. v-for="item in auditFormList"
  85. :key="item.id"
  86. :label="item.surveyTemplateName"
  87. :value="item.surveyTemplateId"
  88. ></el-option>
  89. </el-select>
  90. </div>
  91. </el-form-item>
  92. </el-col>
  93. </el-row>
  94. </el-form>
  95. <el-button
  96. v-if="!auditForm.surveyTemplateId"
  97. type="primary"
  98. size="small"
  99. @click="handleGenerateTemplate"
  100. >
  101. 生成核定表
  102. </el-button>
  103. <el-button type="primary" size="small" @click="handleSaveTemplate">
  104. 保存核定模版
  105. </el-button>
  106. <el-button type="primary" size="small" @click="handleExportTemplate">
  107. 导出模版
  108. </el-button>
  109. <el-button type="primary" size="small" @click="handleImportData">
  110. 导入数据
  111. </el-button>
  112. <el-button type="primary" size="small" @click="handleSaveData">
  113. 保存核定数据
  114. </el-button>
  115. </div>
  116. <el-table :data="costAuditData" style="width: 100%" border>
  117. <el-table-column
  118. v-for="item in costAuditcolumn"
  119. :key="item.prop"
  120. :prop="item.prop"
  121. :label="item.label"
  122. :width="item.width"
  123. :align="item.align"
  124. :fixed="item.fixed"
  125. >
  126. <template slot-scope="scope">
  127. <el-input
  128. v-model="scope.row[item.prop]"
  129. :placeholder="item.label"
  130. :disabled="item.disabled"
  131. style="width: 80%"
  132. ></el-input>
  133. </template>
  134. </el-table-column>
  135. <el-table-column
  136. prop="action"
  137. label="操作"
  138. width="100"
  139. align="center"
  140. fixed="right"
  141. >
  142. <template slot-scope="scope">
  143. <el-button
  144. type="text"
  145. title="添加行"
  146. @click="handleAddItem(scope.row)"
  147. >
  148. <i class="el-icon el-icon-circle-plus"></i>
  149. </el-button>
  150. <el-button
  151. type="text"
  152. title="删除行"
  153. @click="handleDeleteItem(scope.row)"
  154. >
  155. <i class="el-icon el-icon-remove"></i>
  156. </el-button>
  157. </template>
  158. </el-table-column>
  159. </el-table>
  160. </div>
  161. </template>
  162. <script>
  163. import {
  164. generateCostVerifyForm,
  165. generateCostVerifyFormData,
  166. getActiveCostVerifyFormList,
  167. getActiveCostVerifyFormListByType,
  168. getCostFormVersionsByTemplateId,
  169. batchSaveOrUpdate,
  170. } from '@/api/costFormManage'
  171. import {
  172. getlistBySurveyTemplateId,
  173. getVerifyTemplateDetail,
  174. importExcel,
  175. exportExcel,
  176. } from '@/api/costVerifyManage'
  177. import { getDetail } from '@/api/auditInitiation'
  178. import { catalogMixin } from '@/mixins/useDict'
  179. import { saveSingleRecordSurvey, getSurveyDetail } from '@/api/audit/survey'
  180. export default {
  181. name: 'CostAudit',
  182. mixins: [catalogMixin],
  183. props: {
  184. id: {
  185. type: [String, Number],
  186. default: null,
  187. },
  188. selectedProject: {
  189. type: Object,
  190. default: () => {
  191. return {}
  192. },
  193. },
  194. currentNode: {
  195. type: String,
  196. default: '',
  197. },
  198. currentStatus: {
  199. type: String,
  200. default: '',
  201. },
  202. auditedUnitId: { type: String, default: '' },
  203. },
  204. data() {
  205. return {
  206. props: {
  207. filterable: true,
  208. placeholder: '请选择监审类别',
  209. style: 'width: 100%',
  210. showAllLevels: false,
  211. props: {
  212. multiple: false,
  213. children: 'children',
  214. checkStrictly: false,
  215. label: 'catalogName',
  216. value: 'id',
  217. emitPath: false,
  218. },
  219. },
  220. // 成本核定表模板列表
  221. auditFormList: [],
  222. // 成本调查表模板列表
  223. surveyFormList: [],
  224. auditForm: {
  225. surveyTemplateName: '',
  226. surveyTemplateId: '',
  227. templateType: '',
  228. dataTable: '',
  229. historyTemplate: '',
  230. catalogId: '',
  231. },
  232. rules: {
  233. catalogId: [
  234. { required: true, message: '请输选择监审类别', trigger: 'change' },
  235. ],
  236. surveyTemplateName: [
  237. { required: true, message: '请输入模版名称', trigger: 'blur' },
  238. ],
  239. },
  240. tableHeadersRes: [],
  241. tableDataRes: [],
  242. // 成本审核表格列配置
  243. costAuditcolumn: [],
  244. // 成本审核数据
  245. costAuditData: [],
  246. project: {},
  247. }
  248. },
  249. watch: {
  250. // 监听id变化
  251. // id(newVal) {
  252. // if (newVal) {
  253. // this.$nextTick(() => {
  254. // })
  255. // }
  256. // },
  257. selectedProject(newVal) {
  258. if (newVal) {
  259. this.$nextTick(() => {
  260. // 获取项目的详情数据
  261. this.getDetail()
  262. })
  263. }
  264. },
  265. },
  266. created() {
  267. if (this.selectedProject && this.selectedProject.projectId) {
  268. // 获取项目的详情数据
  269. this.getDetail()
  270. }
  271. this.getActiveCostVerifyFormListByType()
  272. this.getActiveCostVerifyFormList()
  273. // this.handleGenerateTemplate1()
  274. },
  275. methods: {
  276. getDetail() {
  277. // 获取项目的详情数据
  278. getDetail({ id: this.selectedProject.projectId }).then((res) => {
  279. if (res.code === 200) {
  280. this.project = res.value
  281. this.auditForm.catalogId = res.value.catalogId
  282. // this.auditForm.surveyTemplateId = '9368f1cf-77e7-49fe-8502-4a7a2da99668'
  283. this.loadTemplateData()
  284. }
  285. })
  286. },
  287. // 获取所有模板类型为固定表的所有启用成本调查表数据
  288. getActiveCostVerifyFormListByType() {
  289. getActiveCostVerifyFormListByType().then((res) => {
  290. if (res.code === 200) {
  291. this.surveyFormList = res.value
  292. }
  293. })
  294. },
  295. // 获取所有状态为启用的成本核定表模板数据
  296. getActiveCostVerifyFormList() {
  297. getActiveCostVerifyFormList().then((res) => {
  298. if (res.code === 200) {
  299. this.auditFormList = res.value
  300. }
  301. })
  302. },
  303. // TemplateTypeChange
  304. handleTemplateTypeChange(val) {
  305. if (this.auditForm.templateType == '1') {
  306. this.historyTemplate = ''
  307. } else if (this.auditForm.templateType == '2') {
  308. this.dataTable = ''
  309. }
  310. },
  311. // 模板生成操作
  312. handleGenerateTemplate() {
  313. // 提示生成后不能修改
  314. this.$confirm(
  315. '生成后不能修改根据调查表生成还是根据历史核定模板生成,确定生成模板吗?',
  316. '提示',
  317. {
  318. confirmButtonText: '确定',
  319. cancelButtonText: '取消',
  320. type: 'warning',
  321. }
  322. ).then(() => {
  323. // 校验表单
  324. this.$refs['auditForm'].validate((valid) => {
  325. if (valid) {
  326. if (this.auditForm.templateType == '1') {
  327. if (!this.auditForm.dataTable) {
  328. this.$message.error('请选择成本调查表模板')
  329. return
  330. }
  331. this.generateFromSurveyTemplate()
  332. } else if (this.auditForm.templateType == '2') {
  333. if (!this.auditForm.historyTemplate) {
  334. this.$message.error('请选择历史核定模板')
  335. return
  336. }
  337. this.generateFromHistoryTemplate()
  338. }
  339. // this.$message({ type: 'success', message: '模板生成成功' })
  340. } else {
  341. this.$message.error('请填写表单数据')
  342. return
  343. }
  344. })
  345. })
  346. },
  347. // 根据调查表生成模板
  348. async generateFromSurveyTemplate() {
  349. try {
  350. // 保存模板基本信息
  351. let data = await generateCostVerifyForm({
  352. catalogId: this.auditForm.catalogId,
  353. templatename: this.auditForm.surveyTemplateName,
  354. templateId: this.auditForm.dataTable,
  355. taskId: this.selectedProject.taskId,
  356. })
  357. this.auditForm.surveyTemplateId = data.value
  358. ? data.value.surveyTemplateId
  359. : ''
  360. this.loadTemplateDataForEdit(this.auditForm.surveyTemplateId)
  361. } catch (error) {
  362. console.error('生成模板失败:', error)
  363. } finally {
  364. }
  365. },
  366. // 根据历史核定模板生成
  367. async generateFromHistoryTemplate() {
  368. // 保存模板基本信息
  369. let data = await generateCostVerifyFormData({
  370. catalogId: this.auditForm.catalogId,
  371. templatename: this.auditForm.surveyTemplateName,
  372. templateId: this.auditForm.historyTemplate,
  373. taskId: this.selectedProject.taskId,
  374. })
  375. this.auditForm.surveyTemplateId = data.value
  376. ? data.value.surveyTemplateId
  377. : ''
  378. this.loadTemplateDataForEdit(this.auditForm.surveyTemplateId)
  379. },
  380. // 回显数据用
  381. async loadTemplateData(surveyTemplateId) {
  382. // 先获取表格数据
  383. const tableDataRes = await getCostFormVersionsByTemplateId({
  384. taskId: this.selectedProject.taskId,
  385. // surveyTemplateId: '',
  386. })
  387. // 处理表格数据
  388. if (tableDataRes.code == 200) {
  389. this.auditForm.surveyTemplateId =
  390. tableDataRes.value.itemlist[0].surveyTemplateId
  391. // 有数据后再获取表头数据
  392. const tableHeadersRes = await getlistBySurveyTemplateId({
  393. // taskId: this.selectedProject.taskId,
  394. surveyTemplateId: this.auditForm.surveyTemplateId,
  395. })
  396. getVerifyTemplateDetail({
  397. id: this.auditForm.surveyTemplateId,
  398. }).then((res) => {
  399. this.auditForm.surveyTemplateName = res.value.surveyTemplateName
  400. this.auditForm.catalogId = res.value.catalogId
  401. this.auditForm.templateType = res.value.createmode
  402. if (res.value.createmode == '1') {
  403. this.auditForm.dataTable = res.value.createtemplateid
  404. } else if (res.value.createmode == '2') {
  405. this.auditForm.historyTemplate = res.value.createtemplateid
  406. }
  407. })
  408. // 处理表头数据
  409. if (tableHeadersRes.code == 200) {
  410. this.parseAndDisplayTableHeaders(tableHeadersRes)
  411. this.parseAndDisplayTableData(tableDataRes)
  412. await this.tryEchoUploadData()
  413. }
  414. }
  415. },
  416. async loadTemplateDataForEdit(surveyTemplateId) {
  417. // 并行获取表头和表格数据
  418. const [tableHeadersRes, tableDataRes] = await Promise.all([
  419. getlistBySurveyTemplateId({
  420. taskId: this.selectedProject.taskId,
  421. surveyTemplateId: this.auditForm.surveyTemplateId,
  422. }),
  423. getCostFormVersionsByTemplateId({
  424. taskId: this.selectedProject.taskId,
  425. surveyTemplateId: '',
  426. }),
  427. ])
  428. // 处理表头数据
  429. if (tableHeadersRes.code == 200) {
  430. this.parseAndDisplayTableHeaders(tableHeadersRes)
  431. }
  432. // 处理表格数据
  433. if (tableDataRes.code == 200) {
  434. this.parseAndDisplayTableData(tableDataRes)
  435. await this.tryEchoUploadData()
  436. }
  437. },
  438. // 根据已存在的上传数据进行回显(若有)
  439. async tryEchoUploadData() {
  440. try {
  441. const uploadId = (this.auditForm && this.auditForm.uploadId) || ''
  442. const auditedUnitId = this.auditedUnitId || ''
  443. const taskId =
  444. (this.selectedProject && this.selectedProject.taskId) || ''
  445. // if (!uploadId || !auditedUnitId) return
  446. const params = {
  447. // uploadId,
  448. // auditedUnitId,
  449. type: '3',
  450. taskId: taskId,
  451. }
  452. const res = await getSurveyDetail(params)
  453. if (res && res.code === 200 && res.value) {
  454. const triplets = Array.isArray(res.value)
  455. ? res.value
  456. : res.value.items || res.value.records || []
  457. if (!Array.isArray(triplets) || triplets.length === 0) return
  458. // 建立字段名映射:rkey(中文列名) -> fieldEname(表格prop)
  459. const headerMap = {}
  460. ;(this.tableHeadersRes || []).forEach((h) => {
  461. if (h && h.fieldName && h.fieldEname)
  462. headerMap[h.fieldName] = h.fieldEname
  463. })
  464. // 行索引:rowid -> 行对象
  465. const rowMap = new Map()
  466. ;(this.costAuditData || []).forEach((row) => {
  467. if (row && row.rowid !== undefined && row.rowid !== null) {
  468. rowMap.set(String(row.rowid), row)
  469. }
  470. })
  471. // 应用回显
  472. triplets.forEach((item) => {
  473. const rowid = item.rowid || item.rowId || item.ROWID
  474. const rkey = item.rkey || item.rKey || item.RKEY
  475. const rvalue = item.rvalue || item.rValue || item.RVALUE
  476. if (!rowid || !rkey) return
  477. const row = rowMap.get(String(rowid))
  478. const prop = headerMap[rkey]
  479. if (row && prop) {
  480. row[prop] = rvalue != null ? String(rvalue) : ''
  481. }
  482. })
  483. // 强制刷新
  484. this.costAuditData = [...this.costAuditData]
  485. }
  486. } catch (e) {
  487. // 静默失败即可
  488. console.warn('回显上传数据失败: ', e)
  489. }
  490. },
  491. parseAndDisplayTableHeaders(res) {
  492. this.tableHeadersRes = Array.isArray(res.value) ? res.value : []
  493. if (this.tableHeadersRes.length > 0) {
  494. this.auditForm.surveyTemplateId = res.value[0].surveyTemplateId
  495. // 表头按照orderNum重新排序
  496. this.tableHeadersRes.sort((a, b) => a.orderNum - b.orderNum)
  497. this.costAuditcolumn = [] // 清空现有列配置
  498. this.tableHeadersRes.forEach((item) => {
  499. let column = {
  500. ...item,
  501. prop: item.fieldEname,
  502. label: item.fieldName,
  503. width: item.fieldName == '序号' ? '80px' : '150px',
  504. align: 'center',
  505. }
  506. this.costAuditcolumn.push(column)
  507. })
  508. this.costAuditcolumn.push({
  509. prop: 'unit',
  510. label: '单位',
  511. width: '80px',
  512. })
  513. // 检查tableHeadersRes数组是否包含年账面值
  514. const hasBookValueColumn = this.checkHasBookValueColumn()
  515. if (!hasBookValueColumn && this.selectedProject.auditPeriod) {
  516. // 获取审计期间并按年份排序
  517. let auditPeriod = this.selectedProject.auditPeriod
  518. .split(',')
  519. .map((year) => parseInt(year))
  520. .sort((a, b) => a - b)
  521. .map((year) => year.toString())
  522. let num = this.tableHeadersRes.length
  523. // 按年份顺序生成三个字段
  524. auditPeriod.forEach((item) => {
  525. // 账面价值字段
  526. let bookValueColumn = {
  527. prop: 'year' + item + 'BookValue',
  528. label: item + '年账面值',
  529. width: '120px',
  530. align: 'right',
  531. fieldName: item + '年账面值',
  532. fieldType: 'integer',
  533. format: '',
  534. fieldTypelen: '255',
  535. fieldTypenointlen: '',
  536. isAuditPeriod: 'true',
  537. isRequired: 'true',
  538. showVisible: '1',
  539. isDict: 'false',
  540. dictid: '',
  541. dictValue: '',
  542. tabtype: this.tableHeadersRes[0].tabtype,
  543. surveyTemplateId: this.tableHeadersRes[0].surveyTemplateId,
  544. versionId: this.tableHeadersRes[0].versionId,
  545. orderNum: this.getMaxOrderNum() + 1,
  546. }
  547. this.costAuditcolumn.push(bookValueColumn)
  548. this.tableHeadersRes.push(bookValueColumn)
  549. // 审核字段
  550. let auditColumn = {
  551. prop: 'year' + item + 'Audit',
  552. label: item + '年审核调整值',
  553. width: '150px',
  554. align: 'center',
  555. fieldName: item + '年审核调整值',
  556. fieldType: 'integer',
  557. format: '',
  558. fieldTypelen: '9',
  559. fieldTypenointlen: '',
  560. isRequired: 'true',
  561. isAuditPeriod: 'true',
  562. showVisible: '1',
  563. isDict: 'false',
  564. dictid: '',
  565. dictValue: '',
  566. tabtype: this.tableHeadersRes[0].tabtype,
  567. surveyTemplateId: this.tableHeadersRes[0].surveyTemplateId,
  568. versionId: this.tableHeadersRes[0].versionId,
  569. orderNum: this.getMaxOrderNum() + num + 1,
  570. }
  571. this.costAuditcolumn.push(auditColumn)
  572. this.tableHeadersRes.push(auditColumn)
  573. // 核定值字段
  574. let approvedValueColumn = {
  575. prop: 'year' + item + 'ApprovedValue',
  576. label: item + '年核定值',
  577. width: '120px',
  578. align: 'right',
  579. fieldName: item + '年核定值',
  580. fieldType: 'integer',
  581. format: '',
  582. fieldTypelen: '255',
  583. fieldTypenointlen: '',
  584. isRequired: 'true',
  585. isAuditPeriod: 'true',
  586. showVisible: '1',
  587. isDict: 'false',
  588. dictid: '',
  589. dictValue: '',
  590. tabtype: this.tableHeadersRes[0].tabtype,
  591. surveyTemplateId: this.tableHeadersRes[0].surveyTemplateId,
  592. versionId: this.tableHeadersRes[0].versionId,
  593. orderNum: this.getMaxOrderNum() + num + 1,
  594. }
  595. this.costAuditcolumn.push(approvedValueColumn)
  596. this.tableHeadersRes.push(approvedValueColumn)
  597. })
  598. }
  599. }
  600. },
  601. getMaxOrderNum() {
  602. if (!this.tableHeadersRes || this.tableHeadersRes.length === 0) {
  603. return 0
  604. }
  605. const maxOrderNum = Math.max(
  606. ...this.tableHeadersRes.map((item) => item.orderNum || 0)
  607. )
  608. return maxOrderNum
  609. },
  610. // 检查tableHeadersRes数组是否包含年账面值列
  611. checkHasBookValueColumn() {
  612. if (!this.tableHeadersRes || this.tableHeadersRes.length === 0) {
  613. return false
  614. }
  615. // 检查是否有列的label或fieldName包含'年账面值'字样
  616. return this.tableHeadersRes.some((item) => {
  617. return (
  618. (item.label && item.label.includes('年账面值')) ||
  619. (item.fieldName && item.fieldName.includes('年账面值'))
  620. )
  621. })
  622. },
  623. parseAndDisplayTableData(res) {
  624. // 清空现有数据
  625. this.costAuditData = []
  626. if (
  627. res &&
  628. res.value &&
  629. res.value.itemlist &&
  630. res.value.itemlist.length > 0
  631. ) {
  632. let headers = this.tableHeadersRes
  633. let itemlist = res.value.itemlist
  634. // 遍历每个数据项
  635. itemlist.forEach((item, index) => {
  636. // 为每个数据项创建一个完整的对象
  637. // 判断是否为子项(parentid不为-1且不为"-1")
  638. const isSubItem =
  639. item.parentid && item.parentid !== -1 && item.parentid !== '-1'
  640. let rowData = {
  641. ...item,
  642. isChild: isSubItem,
  643. isSubItem: isSubItem,
  644. }
  645. // 遍历表头,将字段值映射到对应的列
  646. headers.forEach((header) => {
  647. if (header && header.fieldEname && header.fieldName) {
  648. let fieldEname = header.fieldEname
  649. let fieldName = header.fieldName
  650. let fieldValue = item[fieldName] || ''
  651. // 将字段值添加到行数据中
  652. rowData[fieldEname] = fieldValue
  653. rowData.rkey = fieldName
  654. rowData.rvalue = fieldValue
  655. }
  656. })
  657. // if (this.selectedProject && this.selectedProject.auditPeriod) {
  658. // // 为审计期间的三个字段添加初始值
  659. // // 获取审计期间并按年份排序
  660. // let auditPeriod = this.selectedProject.auditPeriod
  661. // .split(',')
  662. // .map((year) => parseInt(year))
  663. // .sort((a, b) => a - b)
  664. // .map((year) => year.toString())
  665. // // 为每个年份添加三个字段的初始值,使用与表头定义一致的属性名
  666. // auditPeriod.forEach((year) => {
  667. // rowData[`year${year}BookValue`] = '' // 账面值
  668. // rowData[`year${year}Audit`] = '' // 审核调整值
  669. // rowData[`year${year}ApprovedValue`] = '' // 核定值
  670. // })
  671. // }
  672. // 添加完整的行数据到表格数据中
  673. this.costAuditData.push(rowData)
  674. })
  675. // 平铺顺序:父项在前、子项紧随其后
  676. const sortFn = (a, b) =>
  677. Number(a.orderNum || 0) - Number(b.orderNum || 0)
  678. const byRowId = new Map()
  679. const parents = []
  680. const childGroups = new Map()
  681. this.costAuditData.forEach((row) => {
  682. if (row && row.children) delete row.children
  683. const key = row.rowid != null ? String(row.rowid) : ''
  684. if (key) byRowId.set(key, row)
  685. const pid = row.parentid
  686. const isParent =
  687. pid === -1 || pid === '-1' || pid === null || pid === undefined
  688. if (isParent) {
  689. parents.push(row)
  690. } else {
  691. const pKey = pid != null ? String(pid) : ''
  692. if (!childGroups.has(pKey)) childGroups.set(pKey, [])
  693. childGroups.get(pKey).push(row)
  694. }
  695. })
  696. parents.sort(sortFn)
  697. const flat = []
  698. const seen = new Set()
  699. parents.forEach((p) => {
  700. flat.push(p)
  701. seen.add(p)
  702. const group = childGroups.get(String(p.rowid)) || []
  703. group.sort(sortFn).forEach((c) => {
  704. flat.push(c)
  705. seen.add(c)
  706. })
  707. })
  708. // 处理找不到父项的子项:放在末尾
  709. this.costAuditData.forEach((row) => {
  710. if (!seen.has(row)) flat.push(row)
  711. })
  712. this.costAuditData = flat
  713. }
  714. },
  715. handleSaveTemplate(type) {
  716. // 显示加载状态
  717. this.$loading({
  718. lock: true,
  719. text: '保存数据中...',
  720. spinner: 'el-icon-loading',
  721. background: 'rgba(0, 0, 0, 0.7)',
  722. })
  723. // 加上遮罩层
  724. const headersList = this.tableHeadersRes.map((header, index) => ({
  725. ...header,
  726. orderNum: header.orderNum || index + 1,
  727. }))
  728. let splitData = this.splitFixedTableDataForSave(this.costAuditData)
  729. let data = {
  730. costVerifyTemplateId: this.auditForm.surveyTemplateId,
  731. headersList: headersList,
  732. itemsList: splitData,
  733. }
  734. batchSaveOrUpdate(data)
  735. .then((data) => {
  736. // 关闭加载状态
  737. this.$loading().close()
  738. if (type != 'delete') {
  739. this.$message.success('保存成功')
  740. this.loadTemplateData()
  741. }
  742. })
  743. .catch((err) => {
  744. // 关闭加载状态
  745. this.$loading().close()
  746. console.log(err)
  747. })
  748. },
  749. async handleSaveData() {
  750. const loading = this.$loading({
  751. lock: true,
  752. text: '保存数据中...',
  753. spinner: 'el-icon-loading',
  754. background: 'rgba(0, 0, 0, 0.7)',
  755. })
  756. try {
  757. // 1) 基于当前表格数据生成保存明细
  758. const rawItems =
  759. this.splitFixedTableDataForSave(this.costAuditData) || []
  760. const auditedUnitId =
  761. this.auditedUnitId || this.auditForm.auditedUnitId || ''
  762. const surveyTemplateId =
  763. this.auditForm.surveyTemplateId || this.auditForm.dataTable || ''
  764. const catalogId = this.auditForm.catalogId || ''
  765. const hasData = !!(this.auditForm && this.auditForm.uploadId)
  766. const taskId =
  767. (this.selectedProject && this.selectedProject.taskId) || ''
  768. console.log('rawItems', rawItems)
  769. const finalSaveData = rawItems.map((it) => {
  770. const base = {
  771. rowid: it.rowid,
  772. rkey: it.rkey,
  773. rvalue: it.rvalue != null ? String(it.rvalue) : '',
  774. auditedUnitId,
  775. surveyTemplateId,
  776. catalogId,
  777. taskId,
  778. // id: it.id,
  779. parentId: it.parentid || '-1',
  780. // refId: taskId,
  781. type: '3',
  782. // uploadId: '',
  783. }
  784. if (hasData) base.uploadId = this.auditForm.uploadId
  785. return base
  786. })
  787. // 2) 调用保存接口
  788. const res = await saveSingleRecordSurvey(finalSaveData)
  789. if (res && res.code === 200) {
  790. this.$message.success('保存成功')
  791. this.loadTemplateData && this.loadTemplateData()
  792. await this.tryEchoUploadData()
  793. } else {
  794. this.$message.error((res && res.message) || '保存失败')
  795. }
  796. } catch (err) {
  797. console.error(err)
  798. // this.$message.error('保存失败')
  799. } finally {
  800. loading.close()
  801. }
  802. },
  803. //分割字符串
  804. stringToObjects(str) {
  805. const items = str.split(',')
  806. return items.map((item) => ({
  807. rkey: item,
  808. rvalue: '',
  809. }))
  810. },
  811. splitFixedTableDataForSave() {
  812. let fixedHeaders = this.tableHeadersRes
  813. let fixedTables = this.costAuditData
  814. let fixedFields = fixedHeaders
  815. .map((header) => header.fieldName)
  816. .join(',')
  817. let fixedTitles = this.stringToObjects(fixedFields || '')
  818. // 结果数组
  819. const result = []
  820. const processNode = (node, parentRowIndex = 0) => {
  821. // 确保node和fixedValues存在
  822. if (!node) {
  823. console.warn('遇到空节点,跳过处理')
  824. return
  825. }
  826. // 确保fixedValues属性存在,如果不存在则初始化为空对象
  827. if (!node.fixedValues) {
  828. node.fixedValues = {}
  829. }
  830. // 为每个固定列创建一条记录
  831. fixedTitles.forEach((title) => {
  832. // 找到对应的表头信息
  833. const correspondingHeader = fixedHeaders.find(
  834. (header) => header.fieldName === title.rkey
  835. )
  836. const newItem = {
  837. rkey: title.rkey,
  838. rvalue:
  839. node[correspondingHeader.prop] ||
  840. node[correspondingHeader.fieldEname] ||
  841. '',
  842. [correspondingHeader.fieldName]:
  843. node[correspondingHeader.fieldEname] || '',
  844. surveyTemplateId:
  845. node.surveyTemplateId || correspondingHeader.surveyTemplateId,
  846. versionId: node.versionId || correspondingHeader.versionId,
  847. tabtype: node.tabtype || correspondingHeader.templateType,
  848. // 添加 headersId 字段(表头的id)
  849. headersId: correspondingHeader ? correspondingHeader.id : null,
  850. // 添加记录的id(itemlist中每条记录的id)
  851. id: node.id || null,
  852. // 添加父子关系字段
  853. parentid: node.parentid || -1, // 父项ID,默认为-1表示无父项
  854. isChild: node.isChild || false, // 是否为子项
  855. // 添加 rowid 字段
  856. rowid: node.rowid || null,
  857. // 添加计算公式相关字段
  858. calculationFormula: node.calculationFormula || null,
  859. jsonstr: node.jsonstr || null,
  860. orderNum:
  861. typeof node.orderNum === 'number'
  862. ? node.orderNum
  863. : parseInt(node.orderNum, 10) || 0,
  864. // 添加用户需要的其他字段
  865. orderText: node.orderText || '',
  866. percentage: node.percentage || '',
  867. unit: node.unit || '',
  868. }
  869. // 添加其他固定表特有的字段
  870. if (!node.isSubItem) {
  871. newItem.cellCode = node.cellCode || ''
  872. newItem.unit = node.unit || ''
  873. }
  874. // 添加其他可能需要的字段,但排除特定字段
  875. Object.keys(node).forEach((key) => {
  876. if (
  877. !(key in newItem) &&
  878. key !== 'fixedValues' &&
  879. key !== 'itemId' &&
  880. key !== 'id' &&
  881. key !== 'parentid' &&
  882. key !== 'isChild' &&
  883. key !== 'isSubItem' &&
  884. key !== 'rowid' &&
  885. key !== 'jsonstr' &&
  886. key !== 'calculationFormula' &&
  887. key !== 'children' // 排除children字段
  888. ) {
  889. newItem[key] = node[key]
  890. }
  891. })
  892. result.push(newItem)
  893. })
  894. }
  895. fixedTables.forEach((row) => {
  896. processNode(row)
  897. })
  898. // 首先收集所有父节点的orderNum,确保不与子节点冲突
  899. const parentOrderNums = new Set()
  900. // 第一次遍历:识别父节点并收集它们的orderNum
  901. result.forEach((item) => {
  902. // 假设isChild为false或parentid为-1的是父节点
  903. if (!item.isChild || item.parentid === -1) {
  904. parentOrderNums.add(item.orderNum)
  905. }
  906. })
  907. // 创建映射来跟踪已使用的orderNum
  908. const usedOrderNums = new Set([...parentOrderNums])
  909. let nextAvailableOrderNum = 1
  910. // 找到当前最大的orderNum,作为新orderNum的起点
  911. const allOrderNums = result
  912. .map((item) => item.orderNum)
  913. .filter((num) => typeof num === 'number' && !isNaN(num))
  914. if (allOrderNums.length > 0) {
  915. nextAvailableOrderNum = Math.max(...allOrderNums) + 1
  916. }
  917. // 第二次遍历:为子节点分配唯一的orderNum
  918. result.forEach((item) => {
  919. // 只为子节点重新分配orderNum
  920. if (item.isChild && item.parentid !== -1) {
  921. // 找到下一个未使用的orderNum
  922. while (usedOrderNums.has(nextAvailableOrderNum)) {
  923. nextAvailableOrderNum++
  924. }
  925. // 分配新的orderNum并标记为已使用
  926. item.orderNum = nextAvailableOrderNum
  927. usedOrderNums.add(nextAvailableOrderNum)
  928. nextAvailableOrderNum++
  929. }
  930. })
  931. return result
  932. },
  933. //
  934. handleImportData() {
  935. let loading = null
  936. // 第一步:创建文件选择器
  937. const input = document.createElement('input')
  938. input.type = 'file'
  939. input.accept = '.xls,.xlsx,.csv' // 允许的文件类型
  940. input.onchange = async (event) => {
  941. const file = event.target.files[0]
  942. if (!file) return
  943. try {
  944. // 校验文件大小(50MB)
  945. const maxSize = 50 * 1024 * 1024 // 50MB
  946. if (file.size > maxSize) {
  947. this.$message.error('文件大小不能超过50MB!')
  948. return
  949. }
  950. // 校验文件格式
  951. const allowedFormats = ['.xls', '.xlsx', 'csv']
  952. const fileName = file.name.toLowerCase()
  953. const isValidFormat = allowedFormats.some((format) =>
  954. fileName.endsWith(format)
  955. )
  956. if (!isValidFormat) {
  957. this.$message.error('只允许上传.xls,.xlsx,.csv格式的文件!')
  958. return
  959. }
  960. // 显示遮罩层
  961. loading = this.$baseLoading(1, '文件上传中...')
  962. // 第三步:创建FormData并上传文件
  963. const formData = new FormData()
  964. formData.append('file', file)
  965. // 其他参数作为query参数传递
  966. const queryParams = {
  967. surveyTemplateId: this.auditForm.surveyTemplateId,
  968. taskId: this.selectedProject.taskId,
  969. materialId: '', // 根据API文档,此参数为必填,但当前没有值,保留空字符串
  970. periodRecordId: '', // 非必填参数
  971. }
  972. // 先调用上传API,将参数作为query传递
  973. const uploadRes = await importExcel(formData, queryParams)
  974. // 第四步:检查上传结果
  975. if (!uploadRes.state) {
  976. this.$message.error('导入失败!')
  977. return
  978. }
  979. this.$message.success('导入成功')
  980. this.loadTemplateData()
  981. // this.$emit('refresh', this.project.projectId) // 通知父组件刷新
  982. } catch (error) {
  983. // 错误处理
  984. // this.$message.error('操作失败:' + (error.message || '未知错误'))
  985. } finally {
  986. // 关闭遮罩层
  987. loading.close()
  988. }
  989. }
  990. // 触发文件选择
  991. input.click()
  992. },
  993. handleExportTemplate() {
  994. if (this.costAuditData.length === 0) {
  995. return
  996. }
  997. // 显示加载状态
  998. const loading = this.$loading({
  999. lock: true,
  1000. text: '文件下载中...',
  1001. spinner: 'el-icon-loading',
  1002. background: 'rgba(0, 0, 0, 0.7)',
  1003. })
  1004. // 调用导出API
  1005. exportExcel({
  1006. // surveyTemplateId: '1985224388517109760', // 测试用 1989165590455066624
  1007. surveyTemplateId: this.auditForm.surveyTemplateId,
  1008. versionId: this.tableHeadersRes[0].versionId || '',
  1009. })
  1010. .then((res) => {
  1011. // 从响应头获取文件名(如果有)
  1012. let fileName = `成本审核模板_${new Date()
  1013. .toLocaleString()
  1014. .replace(/[:\s]/g, '_')}.xlsx`
  1015. if (res.headers && res.headers['content-disposition']) {
  1016. const contentDisposition = res.headers['content-disposition']
  1017. const match = contentDisposition.match(/filename=([^;]+)/i)
  1018. if (match && match[1]) {
  1019. fileName = decodeURIComponent(match[1].replace(/['"]/g, ''))
  1020. }
  1021. }
  1022. // 使用a标签方式下载文件
  1023. const blobData = new Blob([res.data], {
  1024. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  1025. })
  1026. // 创建URL对象
  1027. const url = window.URL.createObjectURL(blobData)
  1028. // 创建a标签
  1029. const a = document.createElement('a')
  1030. a.style.display = 'none'
  1031. a.href = url
  1032. a.download = fileName // 设置下载文件名
  1033. // 添加到DOM并触发点击
  1034. document.body.appendChild(a)
  1035. a.click()
  1036. // 关闭加载状态
  1037. loading.close()
  1038. // 清理
  1039. setTimeout(() => {
  1040. document.body.removeChild(a)
  1041. window.URL.revokeObjectURL(url) // 释放URL对象,避免内存泄漏
  1042. }, 100)
  1043. })
  1044. .catch((error) => {
  1045. // 关闭加载状态
  1046. loading.close()
  1047. console.error('文件下载失败:', error)
  1048. })
  1049. },
  1050. handleExportData() {
  1051. this.$message({ type: 'info', message: '导出数据' })
  1052. },
  1053. // handleSaveData() {
  1054. // this.$message({ type: 'success', message: '成本审核数据已保存' })
  1055. // },
  1056. handleRemark(row, field) {
  1057. this.$prompt('请输入说明', '提示', {
  1058. confirmButtonText: '确定',
  1059. cancelButtonText: '取消',
  1060. inputValue: row[field],
  1061. })
  1062. .then(({ value }) => {
  1063. row[field] = value
  1064. this.$message({ type: 'success', message: '说明已保存' })
  1065. })
  1066. .catch(() => {
  1067. this.$message({ type: 'info', message: '已取消' })
  1068. })
  1069. },
  1070. // 按层级关系排序表格数据,子项排在父项后面
  1071. sortItemsByHierarchy() {
  1072. if (!this.costAuditData || this.costAuditData.length === 0) {
  1073. return
  1074. }
  1075. // 构建父子关系映射
  1076. const itemMap = new Map()
  1077. const rootItems = []
  1078. const childrenMap = new Map()
  1079. const processedItems = new Set() // 用于避免循环引用
  1080. // 初始化映射和找出根节点
  1081. this.costAuditData.forEach((item) => {
  1082. const currentId = item.id || item.itemId
  1083. if (currentId !== undefined) {
  1084. itemMap.set(currentId, item)
  1085. }
  1086. // 检查是否有有效父ID
  1087. const parentId = item.parentId || item.parentItemId
  1088. const hasValidParent =
  1089. parentId !== undefined &&
  1090. parentId !== null &&
  1091. parentId !== '' &&
  1092. parentId !== -1
  1093. if (!hasValidParent) {
  1094. // 没有有效父ID的是根节点
  1095. rootItems.push(item)
  1096. } else {
  1097. // 有父ID的添加到子节点映射中
  1098. if (!childrenMap.has(parentId)) {
  1099. childrenMap.set(parentId, [])
  1100. }
  1101. childrenMap.get(parentId).push(item)
  1102. }
  1103. })
  1104. // 深度优先遍历生成排序后的数据
  1105. const sortedData = []
  1106. function traverse(item) {
  1107. const currentId = item.id || item.itemId
  1108. // 避免循环引用
  1109. if (processedItems.has(currentId)) {
  1110. return
  1111. }
  1112. // 标记为已处理
  1113. processedItems.add(currentId)
  1114. // 添加当前项
  1115. sortedData.push(item)
  1116. // 获取当前项的子项并递归遍历
  1117. const children = childrenMap.get(currentId) || []
  1118. // 对子项按照orderNum或id进行排序
  1119. children.sort((a, b) => {
  1120. if (a.orderNum !== undefined && b.orderNum !== undefined) {
  1121. return a.orderNum - b.orderNum
  1122. }
  1123. const aId = a.id || a.itemId || 0
  1124. const bId = b.id || b.itemId || 0
  1125. return aId - bId
  1126. })
  1127. // 递归处理每个子项
  1128. children.forEach((child) => {
  1129. traverse(child)
  1130. })
  1131. }
  1132. // 对根节点按照orderNum或id进行排序
  1133. rootItems.sort((a, b) => {
  1134. if (a.orderNum !== undefined && b.orderNum !== undefined) {
  1135. return a.orderNum - b.orderNum
  1136. }
  1137. const aId = a.id || a.itemId || 0
  1138. const bId = b.id || b.itemId || 0
  1139. return aId - bId
  1140. })
  1141. // 从根节点开始遍历
  1142. rootItems.forEach((root) => {
  1143. traverse(root)
  1144. })
  1145. // 如果有未被包含的项目(可能没有正确的父子关系),直接添加到末尾
  1146. if (sortedData.length < this.costAuditData.length) {
  1147. this.costAuditData.forEach((item) => {
  1148. const currentId = item.id || item.itemId
  1149. if (currentId !== undefined && !processedItems.has(currentId)) {
  1150. sortedData.push(item)
  1151. processedItems.add(currentId)
  1152. }
  1153. })
  1154. }
  1155. // 更新表格数据为排序后的数据
  1156. this.costAuditData = sortedData
  1157. // 更新序号字段而非覆盖原始ID
  1158. // this.costAuditData.forEach((item, index) => {
  1159. // // 创建或更新序号字段,保留原始ID不变
  1160. // item.index = index + 1
  1161. // })
  1162. },
  1163. handleAddItem(row) {
  1164. // 判断parentId是否为空,是就添加父项,否则添加子项
  1165. const rowIndex = this.costAuditData.indexOf(row)
  1166. if (rowIndex === -1) {
  1167. this.$message.error('未找到指定行')
  1168. return
  1169. }
  1170. // 确定新行的parentId
  1171. let parentId = row.parentId || '-1'
  1172. // 计算新行的orderNum(当前行的orderNum + 1)
  1173. const newOrderNum = row.orderNum + 1
  1174. // 整体后移逻辑:将所有orderNum大于等于新orderNum的行,其orderNum加1
  1175. // 根据父项和子项关系判断是否需要移动
  1176. this.costAuditData.forEach((item) => {
  1177. // 如果是相同父项的子项,或者都是父项(parentId为'-1'),则需要移动
  1178. if (
  1179. (item.parentId === parentId ||
  1180. (item.parentId === '-1' && parentId === '-1')) &&
  1181. item.orderNum >= newOrderNum
  1182. ) {
  1183. item.orderNum += 1
  1184. }
  1185. })
  1186. // 创建新元素
  1187. const newItem = {
  1188. ...row,
  1189. parentId,
  1190. orderNum: newOrderNum,
  1191. rowid: this.generateUUID(),
  1192. id: null,
  1193. rvalue: '',
  1194. }
  1195. // 循环表头,把值置空
  1196. this.costAuditcolumn.forEach((item) => {
  1197. newItem[item.label] = ''
  1198. newItem[item.prop] = ''
  1199. })
  1200. // 在当前行后面插入新元素
  1201. this.costAuditData.splice(rowIndex + 1, 0, newItem)
  1202. this.$message.success('行添加成功')
  1203. },
  1204. handleDeleteItem(row) {
  1205. // 显示确认对话框
  1206. this.$confirm(
  1207. '确定要删除此行数据吗?如果删除的是父项,将同时删除其所有子项。',
  1208. '确认删除',
  1209. {
  1210. confirmButtonText: '确定',
  1211. cancelButtonText: '取消',
  1212. type: 'warning',
  1213. }
  1214. )
  1215. .then(() => {
  1216. // 获取要删除的行ID
  1217. const rowId = row.rowId || row.id
  1218. // 收集要删除的行索引
  1219. const indicesToDelete = []
  1220. // 查找要删除的行及其子项
  1221. for (let i = 0; i < this.costAuditData.length; i++) {
  1222. const item = this.costAuditData[i]
  1223. // 如果是要删除的行本身,或者是其子项
  1224. if (
  1225. item.rowId === rowId ||
  1226. item.id === rowId ||
  1227. (item.parentId !== '-1' &&
  1228. (item.parentId === rowId || item.parentId === row.id))
  1229. ) {
  1230. indicesToDelete.push(i)
  1231. }
  1232. }
  1233. // 从后往前删除,避免索引偏移
  1234. indicesToDelete
  1235. .sort((a, b) => b - a)
  1236. .forEach((index) => {
  1237. this.costAuditData.splice(index, 1)
  1238. })
  1239. // 更新剩余行的orderNum
  1240. this.updateOrderNumbersAfterDelete(row)
  1241. // 删除行后调用保存模板方法
  1242. this.handleSaveTemplate('delete')
  1243. this.$message.success('行删除成功')
  1244. })
  1245. .catch(() => {
  1246. // 用户取消删除
  1247. this.$message.info('已取消删除操作')
  1248. })
  1249. },
  1250. // 删除行后更新orderNum的方法
  1251. updateOrderNumbersAfterDelete(deletedRow) {
  1252. const deletedOrderNum = deletedRow.orderNum
  1253. const deletedParentId = deletedRow.parentId || '-1'
  1254. // 遍历所有行,更新orderNum
  1255. this.costAuditData.forEach((item) => {
  1256. // 如果是相同父项的子项,或者都是父项(parentId为'-1'),且orderNum大于删除行的orderNum
  1257. if (
  1258. (item.parentId === deletedParentId ||
  1259. (item.parentId === '-1' && deletedParentId === '-1')) &&
  1260. item.orderNum > deletedOrderNum
  1261. ) {
  1262. // 将orderNum减1,保持连续性
  1263. item.orderNum -= 1
  1264. }
  1265. })
  1266. },
  1267. // 生成唯一ID
  1268. generateUUID() {
  1269. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
  1270. /[xy]/g,
  1271. function (c) {
  1272. const r = (Math.random() * 16) | 0,
  1273. v = c === 'x' ? r : (r & 0x3) | 0x8
  1274. return v.toString(16)
  1275. }
  1276. )
  1277. },
  1278. },
  1279. }
  1280. </script>
  1281. <style scoped>
  1282. /* .app-container {
  1283. padding: 20px;
  1284. } */
  1285. .audit-controls {
  1286. margin-bottom: 20px;
  1287. }
  1288. .audit-controls .el-select {
  1289. margin-right: 10px;
  1290. width: 150px;
  1291. }
  1292. .el-icon {
  1293. font-size: 24px;
  1294. }
  1295. </style>