costSurvey.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. <template>
  2. <div>
  3. <!-- 调查表填报弹窗(单记录类型,只读) -->
  4. <survey-form-dialog
  5. :visible.sync="surveyFormDialogVisible"
  6. :survey-data="{ ...currentSurveyRow, ...surveyDetailData }"
  7. :form-fields="formFields"
  8. :is-view-mode="true"
  9. :audited-unit-id="auditedUnitId"
  10. :upload-id="
  11. currentSurveyRow && currentSurveyRow.id ? currentSurveyRow.id : uploadId
  12. "
  13. :survey-template-id="
  14. currentSurveyRow && currentSurveyRow.surveyTemplateId
  15. ? currentSurveyRow.surveyTemplateId
  16. : surveyTemplateId
  17. "
  18. :catalog-id="catalogId"
  19. @save="noop"
  20. @refresh="noop"
  21. />
  22. <!-- 固定表填报弹窗(只读) -->
  23. <fixed-table-dialog
  24. :visible.sync="fixedTableDialogVisible"
  25. :survey-data="{ ...currentSurveyRow, fixedHeaders }"
  26. :table-items="tableItems"
  27. :audit-periods="auditPeriods"
  28. :is-view-mode="true"
  29. :audited-unit-id="auditedUnitId"
  30. :upload-id="
  31. currentSurveyRow && currentSurveyRow.id ? currentSurveyRow.id : uploadId
  32. "
  33. :survey-template-id="
  34. currentSurveyRow && currentSurveyRow.surveyTemplateId
  35. ? currentSurveyRow.surveyTemplateId
  36. : surveyTemplateId
  37. "
  38. :catalog-id="catalogId"
  39. @save="noop"
  40. @refresh="noop"
  41. />
  42. <!-- 动态表填报弹窗(只读) -->
  43. <dynamic-table-dialog
  44. :key="dynamicDialogKey"
  45. :visible.sync="dynamicTableDialogVisible"
  46. :survey-data="currentSurveyRow"
  47. :table-data="dynamicTableData"
  48. :table-items="tableItems"
  49. :is-view-mode="true"
  50. :audited-unit-id="auditedUnitId"
  51. :upload-id="
  52. currentSurveyRow && (currentSurveyRow.uploadId || currentSurveyRow.id)
  53. ? currentSurveyRow.uploadId || currentSurveyRow.id
  54. : uploadId
  55. "
  56. :catalog-id="catalogId"
  57. :survey-template-id="
  58. currentSurveyRow && currentSurveyRow.surveyTemplateId
  59. ? currentSurveyRow.surveyTemplateId
  60. : surveyTemplateId
  61. "
  62. @save="noop"
  63. @refresh="noop"
  64. />
  65. <el-table
  66. style="width: 100%; margin-top: 20px"
  67. :data="paginatedData"
  68. border
  69. size="medium"
  70. >
  71. <!-- 序号列 -->
  72. <el-table-column prop="index" label="序号" width="60" align="center">
  73. <template slot-scope="scope">{{ scope.$index + 1 }}</template>
  74. </el-table-column>
  75. <!-- 成本调查表名称(点击查看) -->
  76. <el-table-column label="成本调查表" min-width="220">
  77. <template slot-scope="scope">
  78. <span
  79. :style="{
  80. color: scope.row.isDisabled ? '#909399' : '#409EFF',
  81. cursor: scope.row.isDisabled ? 'default' : 'pointer',
  82. }"
  83. @click="!scope.row.isDisabled && handleOnlineFillClick(scope.row)"
  84. >
  85. {{ scope.row.name }}
  86. </span>
  87. </template>
  88. </el-table-column>
  89. <!-- 资料类型 -->
  90. <el-table-column
  91. prop="dataType"
  92. label="资料类型"
  93. width="120"
  94. align="center"
  95. />
  96. <!-- 表格类型 -->
  97. <el-table-column
  98. prop="tableType"
  99. label="表格类型"
  100. width="120"
  101. align="center"
  102. />
  103. <!-- 是否必填 -->
  104. <el-table-column
  105. prop="isRequired"
  106. label="是否必填"
  107. width="100"
  108. align="center"
  109. >
  110. <template slot-scope="scope">
  111. <span>
  112. {{
  113. scope.row.isRequired === '是' ||
  114. scope.row.isRequired === '1' ||
  115. scope.row.isRequired === 1
  116. ? '是'
  117. : '否'
  118. }}
  119. </span>
  120. </template>
  121. </el-table-column>
  122. <!-- 是否上传(只读显示) -->
  123. <el-table-column label="是否上传" width="100" align="center">
  124. <template slot-scope="scope">
  125. <span
  126. :style="{
  127. color: scope.row.isUploaded === true ? '#67c23a' : '#f56c6c',
  128. }"
  129. >
  130. {{ scope.row.isUploaded === true ? '已上传' : '未上传' }}
  131. </span>
  132. </template>
  133. </el-table-column>
  134. <!-- 操作列(只保留查看) -->
  135. <el-table-column label="操作" width="160" align="center">
  136. <template slot-scope="scope">
  137. <el-button
  138. type="text"
  139. size="small"
  140. @click="handleOnlineFillClick(scope.row)"
  141. >
  142. 查看
  143. </el-button>
  144. </template>
  145. </el-table-column>
  146. </el-table>
  147. <el-pagination
  148. background
  149. layout="total, sizes, prev, pager, next"
  150. :current-page="pagination.currentPage"
  151. :page-sizes="[10, 20, 30, 50]"
  152. :page-size="pagination.pageSize"
  153. :total="pagination.total"
  154. style="margin-top: 20px; text-align: right"
  155. @current-change="handlePageChange"
  156. @size-change="handleSizeChange"
  157. />
  158. </div>
  159. </template>
  160. <script>
  161. import SurveyFormDialog from '@/views/EntDeclaration/auditTaskManagement/components/SurveyFormDialog.vue'
  162. import FixedTableDialog from '@/views/EntDeclaration/auditTaskManagement/components/FixedTableDialog.vue'
  163. import DynamicTableDialog from '@/views/EntDeclaration/auditTaskManagement/components/DynamicTableDialog.vue'
  164. import {
  165. getSingleRecordSurveyList,
  166. getSurveyDetail,
  167. getDynamicTableData,
  168. } from '@/api/audit/survey'
  169. import { getListBySurveyTemplateIdAndVersion } from '@/api/costSurveyTemplateHeaders'
  170. export default {
  171. name: 'CostSurveyViewOnly',
  172. components: { SurveyFormDialog, FixedTableDialog, DynamicTableDialog },
  173. props: {
  174. paginatedData: { type: Array, default: () => [] },
  175. pagination: {
  176. type: Object,
  177. default: () => ({ currentPage: 1, pageSize: 10, total: 0 }),
  178. },
  179. auditedUnitId: { type: String, default: '' },
  180. uploadId: { type: String, default: '' },
  181. surveyTemplateId: { type: String, default: '' },
  182. catalogId: { type: String, default: '' },
  183. },
  184. data() {
  185. return {
  186. surveyFormDialogVisible: false,
  187. fixedTableDialogVisible: false,
  188. dynamicTableDialogVisible: false,
  189. currentSurveyRow: null,
  190. formFields: [],
  191. surveyDetailData: {},
  192. tableItems: [],
  193. auditPeriods: [],
  194. dynamicTableData: [],
  195. dynamicDialogKey: 0,
  196. dynamicTableLoading: false,
  197. fixedHeaders: null,
  198. }
  199. },
  200. methods: {
  201. // 查看(只读)
  202. async handleOnlineFillClick(row) {
  203. this.currentSurveyRow = row
  204. this.surveyDetailData = {}
  205. if (row.tableType === '单记录') {
  206. if (row.id && this.auditedUnitId) {
  207. try {
  208. const params = {
  209. uploadId: row.id,
  210. auditedUnitId: this.auditedUnitId,
  211. }
  212. const res = await getSurveyDetail(params)
  213. if (res && res.code === 200 && res.value) {
  214. const detailData = {}
  215. if (Array.isArray(res.value)) {
  216. res.value.forEach((item) => {
  217. if (item.rowid && item.rvalue !== undefined)
  218. detailData[item.rowid] = item.rvalue
  219. })
  220. } else if (res.value) {
  221. Object.assign(detailData, res.value)
  222. }
  223. this.surveyDetailData = detailData
  224. }
  225. } catch (err) {}
  226. }
  227. await this.initFormFields()
  228. } else if (row.tableType === '固定表') {
  229. await this.initFixedTableData()
  230. } else if (row.tableType === '动态表') {
  231. this.resetDynamicDialogState()
  232. await this.initDynamicTableData()
  233. }
  234. },
  235. handlePageChange(page) {
  236. this.$emit('handle-page-change', page)
  237. },
  238. handleSizeChange(size) {
  239. this.$emit('handle-size-change', size)
  240. },
  241. async initDynamicTableData() {
  242. try {
  243. this.dynamicTableLoading = true
  244. const uploadId =
  245. (this.currentSurveyRow &&
  246. (this.currentSurveyRow.uploadId || this.currentSurveyRow.id)) ||
  247. this.uploadId ||
  248. ''
  249. const auditedUnitId =
  250. this.auditedUnitId ||
  251. (this.currentSurveyRow && this.currentSurveyRow.auditedUnitId) ||
  252. ''
  253. const catalogId =
  254. (this.currentSurveyRow && this.currentSurveyRow.catalogId) ||
  255. this.catalogId ||
  256. ''
  257. const surveyTemplateId =
  258. (this.currentSurveyRow && this.currentSurveyRow.surveyTemplateId) ||
  259. this.surveyTemplateId ||
  260. ''
  261. const params = {
  262. uploadId,
  263. auditedUnitId,
  264. catalogId,
  265. surveyTemplateId,
  266. }
  267. const res = await getDynamicTableData(params)
  268. if (res && res.code === 200) {
  269. const records =
  270. (res.value && (res.value.records || res.value)) || []
  271. this.dynamicTableData = Array.isArray(records) ? records : []
  272. } else {
  273. this.dynamicTableData =
  274. (this.currentSurveyRow &&
  275. this.currentSurveyRow.dynamicTableData) ||
  276. []
  277. }
  278. if (
  279. this.currentSurveyRow &&
  280. this.currentSurveyRow.tableItems &&
  281. this.currentSurveyRow.tableItems.length > 0
  282. ) {
  283. this.tableItems = this.currentSurveyRow.tableItems
  284. } else {
  285. this.tableItems = this.getMockTableItems()
  286. }
  287. this.dynamicTableDialogVisible = true
  288. } catch (error) {
  289. this.dynamicTableData =
  290. (this.currentSurveyRow && this.currentSurveyRow.dynamicTableData) ||
  291. []
  292. this.tableItems =
  293. (this.currentSurveyRow && this.currentSurveyRow.tableItems) ||
  294. this.getMockTableItems()
  295. this.dynamicTableDialogVisible = true
  296. } finally {
  297. this.dynamicTableLoading = false
  298. }
  299. },
  300. async initFormFields() {
  301. if (
  302. this.currentSurveyRow &&
  303. this.currentSurveyRow.tableType === '单记录' &&
  304. this.currentSurveyRow.surveyTemplateId
  305. ) {
  306. try {
  307. const params = {
  308. surveyTemplateId: this.currentSurveyRow.surveyTemplateId,
  309. }
  310. const res = await getListBySurveyTemplateIdAndVersion(params)
  311. if (res && res.code === 200) {
  312. let mapped = []
  313. if (Array.isArray(res.value)) {
  314. mapped = res.value
  315. .map((item, index) =>
  316. this.mapApiFieldToFormField(item, index)
  317. )
  318. .filter(Boolean)
  319. } else if (res.value && typeof res.value === 'object') {
  320. const { fixedFields, fixedFieldids } = res.value
  321. if (fixedFields && fixedFieldids) {
  322. const labels = fixedFields.split(',').map((i) => i.trim())
  323. const ids = fixedFieldids.split(',').map((i) => i.trim())
  324. mapped = labels.map((label, index) => ({
  325. prop: ids[index] || `field_${index}`,
  326. label,
  327. type: 'input',
  328. colSpan: 12,
  329. placeholder: `请输入${label}`,
  330. rules: [],
  331. defaultValue: '',
  332. disabled: true,
  333. clearable: true,
  334. multiple: false,
  335. required: false,
  336. }))
  337. }
  338. }
  339. this.formFields =
  340. mapped.length > 0 ? mapped : this.getMockFormFields()
  341. } else {
  342. this.formFields = this.getMockFormFields()
  343. }
  344. this.surveyFormDialogVisible = true
  345. } catch (err) {
  346. this.formFields = this.getMockFormFields()
  347. this.surveyFormDialogVisible = true
  348. }
  349. } else if (this.currentSurveyRow && this.currentSurveyRow.formFields) {
  350. this.formFields = this.currentSurveyRow.formFields
  351. this.surveyFormDialogVisible = true
  352. } else {
  353. this.formFields = this.getMockFormFields()
  354. this.surveyFormDialogVisible = true
  355. }
  356. },
  357. mapApiFieldToFormField(item, index = 0) {
  358. if (!item) return null
  359. const getVal = (keys, fallback) => {
  360. for (const key of keys) {
  361. if (
  362. key &&
  363. item[key] !== undefined &&
  364. item[key] !== null &&
  365. item[key] !== ''
  366. ) {
  367. return item[key]
  368. }
  369. }
  370. return fallback
  371. }
  372. const toBool = (value) => {
  373. if (value === undefined || value === null) return false
  374. if (typeof value === 'boolean') return value
  375. if (typeof value === 'number') return value === 1
  376. const str = String(value).trim().toLowerCase()
  377. return ['1', 'true', 'y', 'yes', '是'].includes(str)
  378. }
  379. const toNumber = (value) => {
  380. if (value === undefined || value === null || value === '')
  381. return undefined
  382. const num = Number(value)
  383. return Number.isNaN(num) ? undefined : num
  384. }
  385. const prop =
  386. getVal(
  387. [
  388. 'fieldName',
  389. 'field_name',
  390. 'columnName',
  391. 'column_name',
  392. 'fieldCode',
  393. ],
  394. undefined
  395. ) || `field_${index}`
  396. const label =
  397. getVal(
  398. [
  399. 'columnComment',
  400. 'column_comment',
  401. 'fieldCname',
  402. 'field_cname',
  403. 'fieldLabel',
  404. 'field_label',
  405. ],
  406. prop
  407. ) || prop
  408. const columnType =
  409. (getVal(
  410. ['columnType', 'column_type', 'fieldType', 'field_type'],
  411. ''
  412. ) || '') + ''
  413. const columnTypeLower = columnType.toLowerCase()
  414. const totalLength = toNumber(
  415. getVal(
  416. ['fieldTypeLen', 'field_typelen', 'length', 'fieldLength'],
  417. undefined
  418. )
  419. )
  420. const decimalLength = toNumber(
  421. getVal(
  422. ['fieldTypeNointLen', 'field_typenointlen', 'scale'],
  423. undefined
  424. )
  425. )
  426. const isAuditPeriod = toBool(
  427. getVal(['isAuditPeriod', 'is_audit_period'], false)
  428. )
  429. const dictCode =
  430. getVal(
  431. [
  432. 'dictCode',
  433. 'dict_code',
  434. 'dictId',
  435. 'dictid',
  436. 'dictType',
  437. 'dict_type',
  438. ],
  439. ''
  440. ) || ''
  441. const optionsRaw = getVal(['options'], [])
  442. let options = []
  443. if (Array.isArray(optionsRaw)) options = optionsRaw
  444. else if (typeof optionsRaw === 'string' && optionsRaw.trim() !== '') {
  445. options = optionsRaw
  446. .split(',')
  447. .map((value) => ({ label: value.trim(), value: value.trim() }))
  448. }
  449. let type = getVal(['componentType', 'type'], '')
  450. if (!type) {
  451. if (dictCode || options.length > 0) type = 'select'
  452. else if (
  453. columnTypeLower.includes('datetime') ||
  454. columnTypeLower.includes('timestamp') ||
  455. columnTypeLower.includes('date time')
  456. )
  457. type = 'datetime'
  458. else if (columnTypeLower.includes('date')) type = 'date'
  459. else if (columnTypeLower.includes('year')) type = 'year'
  460. else if (
  461. columnTypeLower.includes('int') ||
  462. columnTypeLower.includes('number') ||
  463. columnTypeLower.includes('decimal') ||
  464. columnTypeLower.includes('float') ||
  465. columnTypeLower.includes('double')
  466. )
  467. type = 'number'
  468. else type = 'input'
  469. }
  470. const required = toBool(
  471. getVal(['isRequired', 'is_required', 'required'], false)
  472. )
  473. const multiple = toBool(
  474. getVal(['isMultiple', 'is_multiple', 'multiple'], false)
  475. )
  476. const colSpan =
  477. toNumber(
  478. getVal(['colSpan', 'colspan', 'columnSpan', 'column_span'], 12)
  479. ) || 12
  480. const placeholder =
  481. getVal(
  482. ['placeholder', 'columnComment', 'column_comment'],
  483. undefined
  484. ) || (type === 'select' ? `请选择${label}` : `请输入${label}`)
  485. const defaultValue = getVal(
  486. ['defaultValue', 'default_value', 'defaultVal', 'default_val'],
  487. undefined
  488. )
  489. const precision = toNumber(
  490. getVal(
  491. ['fieldTypeNointLen', 'field_typenointlen', 'precision'],
  492. undefined
  493. )
  494. )
  495. const min = toNumber(getVal(['min'], undefined))
  496. const max = toNumber(getVal(['max'], undefined))
  497. const format = getVal(['format'], undefined)
  498. const valueFormat =
  499. getVal(['valueFormat', 'value_format'], undefined) ||
  500. (type === 'datetime'
  501. ? 'yyyy-MM-dd HH:mm:ss'
  502. : type === 'date'
  503. ? 'yyyy-MM-dd'
  504. : type === 'year'
  505. ? 'yyyy'
  506. : undefined)
  507. const formatLength = this.extractLengthFromFormat(format)
  508. const rules = this.buildFieldRules({
  509. type,
  510. label,
  511. required,
  512. totalLength,
  513. decimalLength,
  514. formatLength,
  515. format,
  516. isAuditPeriod,
  517. })
  518. return {
  519. prop,
  520. label,
  521. type,
  522. colSpan,
  523. placeholder,
  524. dictCode,
  525. dictType: dictCode,
  526. options,
  527. required,
  528. defaultValue,
  529. multiple,
  530. precision,
  531. min,
  532. max,
  533. format,
  534. valueFormat,
  535. totalLength,
  536. decimalLength,
  537. formatLength,
  538. rules,
  539. }
  540. },
  541. extractLengthFromFormat(format) {
  542. if (!format) return undefined
  543. const str = String(format).trim()
  544. if (!str) return undefined
  545. const match = str.match(/\d+/)
  546. if (match && match[0]) {
  547. const len = Number(match[0])
  548. return Number.isNaN(len) ? undefined : len
  549. }
  550. return undefined
  551. },
  552. buildFieldRules(meta) {
  553. const {
  554. type,
  555. label,
  556. required,
  557. totalLength,
  558. decimalLength,
  559. formatLength,
  560. format,
  561. isAuditPeriod,
  562. } = meta || {}
  563. const rules = []
  564. const trigger = type === 'select' ? 'change' : 'blur'
  565. if (required) {
  566. rules.push({
  567. required: true,
  568. message: `${type === 'select' ? '请选择' : '请输入'}${label}`,
  569. trigger,
  570. })
  571. }
  572. const inputMaxLength = formatLength || totalLength
  573. if (type === 'input' && inputMaxLength) {
  574. rules.push({
  575. validator: (_, _value, callback) => {
  576. const value = _value
  577. if (value === undefined || value === null || value === '') {
  578. callback()
  579. return
  580. }
  581. const str = String(value)
  582. if (str.length > inputMaxLength) {
  583. callback(
  584. new Error(`${label}长度不能超过${inputMaxLength}个字符`)
  585. )
  586. } else {
  587. callback()
  588. }
  589. },
  590. trigger: 'blur',
  591. })
  592. }
  593. const numberTotal = totalLength || formatLength
  594. if (type === 'number') {
  595. rules.push({
  596. validator: (_, _value, callback) => {
  597. const value = _value
  598. if (value === undefined || value === null || value === '') {
  599. callback()
  600. return
  601. }
  602. if (Number.isNaN(Number(value))) {
  603. callback(new Error(`${label}必须为数字`))
  604. return
  605. }
  606. const pure = String(value).replace('-', '')
  607. if (numberTotal && pure.replace('.', '').length > numberTotal) {
  608. callback(new Error(`${label}总位数不能超过${numberTotal}`))
  609. return
  610. }
  611. if (decimalLength !== undefined && decimalLength !== null) {
  612. const decimals = pure.split('.')[1] || ''
  613. if (decimals.length > decimalLength) {
  614. callback(
  615. new Error(`${label}小数位不能超过${decimalLength}位`)
  616. )
  617. return
  618. }
  619. }
  620. callback()
  621. },
  622. trigger: 'blur',
  623. })
  624. }
  625. if (type === 'datetime' || type === 'date') {
  626. if (format) {
  627. rules.push({
  628. validator: (_, _value, callback) => {
  629. callback()
  630. },
  631. trigger: 'change',
  632. })
  633. }
  634. }
  635. if (type === 'year' || isAuditPeriod) {
  636. rules.push({
  637. validator: (_, _value, callback) => {
  638. const value = _value
  639. if (value === undefined || value === null || value === '') {
  640. callback()
  641. return
  642. }
  643. const pattern = /^\d{4}$/
  644. if (!pattern.test(String(value))) {
  645. callback(new Error(`${label}必须是四位年份`))
  646. } else {
  647. callback()
  648. }
  649. },
  650. trigger: 'change',
  651. })
  652. }
  653. return rules
  654. },
  655. getMockTableItems() {
  656. return []
  657. },
  658. // 解析监审期间字符串(如 "2022,2023,2024" 或 "2022-2024")
  659. parseAuditPeriod(periodStr) {
  660. if (!periodStr) return []
  661. const str = String(periodStr)
  662. if (str.includes(',')) {
  663. return str.split(',').map((p) => String(p).trim())
  664. }
  665. if (str.includes('-')) {
  666. const parts = str.split('-')
  667. if (parts.length === 2) {
  668. const start = parseInt(parts[0].trim())
  669. const end = parseInt(parts[1].trim())
  670. const years = []
  671. for (let y = start; y <= end; y++) years.push(String(y))
  672. return years
  673. }
  674. }
  675. return [String(str)]
  676. },
  677. // 初始化固定表数据(只读)
  678. async initFixedTableData() {
  679. // 仅当当前行为固定表且包含模板ID时调用
  680. if (
  681. this.currentSurveyRow &&
  682. this.currentSurveyRow.tableType === '固定表' &&
  683. this.currentSurveyRow.surveyTemplateId
  684. ) {
  685. try {
  686. // 1) 获取固定表项配置(itemlist)
  687. const params = {
  688. surveyTemplateId: this.currentSurveyRow.surveyTemplateId,
  689. }
  690. const res = await getSingleRecordSurveyList(params)
  691. if (res && res.code === 200 && res.value) {
  692. const { itemlist } = res.value || {}
  693. if (Array.isArray(itemlist) && itemlist.length > 0) {
  694. this.tableItems = itemlist.map((item) => ({
  695. id: item.id || item.itemId || '',
  696. rowid: item.rowid || item.id || item.itemId || '',
  697. seq: item.序号,
  698. itemName: item.项目 || '',
  699. unit: item.unit || '',
  700. isCategory: item.isCategory || false,
  701. categorySeq: item.categorySeq || '',
  702. categoryId: item.categoryId || '',
  703. parentid:
  704. item.parentid !== undefined
  705. ? item.parentid
  706. : item.parentId !== undefined
  707. ? item.parentId
  708. : '-1',
  709. validateRules: item.validateRules || {},
  710. linkageRules: item.linkageRules || {},
  711. children: item.children || [],
  712. ...item,
  713. }))
  714. } else {
  715. this.tableItems = this.getMockTableItems()
  716. }
  717. } else {
  718. this.tableItems = this.getMockTableItems()
  719. }
  720. } catch (err) {
  721. this.tableItems = this.getMockTableItems()
  722. }
  723. // 2) 初始化监审期间:优先当前行,其次默认最近3年
  724. if (this.currentSurveyRow && this.currentSurveyRow.auditPeriod) {
  725. this.auditPeriods = this.parseAuditPeriod(
  726. this.currentSurveyRow.auditPeriod
  727. )
  728. } else {
  729. const currentYear = new Date().getFullYear()
  730. this.auditPeriods = [
  731. String(currentYear - 2),
  732. String(currentYear - 1),
  733. String(currentYear),
  734. ]
  735. }
  736. // 3) 额外拉取表头/规则信息,并透传给弹窗
  737. try {
  738. const headerRes = await getListBySurveyTemplateIdAndVersion({
  739. surveyTemplateId: this.currentSurveyRow.surveyTemplateId,
  740. })
  741. if (headerRes && headerRes.code === 200) {
  742. this.fixedHeaders = headerRes.value || null
  743. } else {
  744. this.fixedHeaders = null
  745. }
  746. } catch (e) {
  747. this.fixedHeaders = null
  748. }
  749. // 4) 打开固定表弹窗
  750. this.fixedTableDialogVisible = true
  751. return
  752. }
  753. // 兜底:没有条件则使用当前行自带配置或空
  754. this.tableItems =
  755. (this.currentSurveyRow && this.currentSurveyRow.tableItems) ||
  756. this.getMockTableItems()
  757. this.fixedHeaders = null
  758. this.fixedTableDialogVisible = true
  759. },
  760. resetDynamicDialogState() {
  761. this.dynamicDialogKey += 1
  762. },
  763. noop() {},
  764. },
  765. }
  766. </script>