| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- <template>
- <div>
- <!-- 成本调查表(只读) -->
- <el-table border :data="rows" style="width: 100%">
- <el-table-column
- prop="index"
- label="序号"
- width="80"
- align="center"
- header-align="center"
- />
- <el-table-column
- prop="name"
- label="成本调查表"
- min-width="200"
- align="center"
- header-align="center"
- show-overflow-tooltip
- />
- <el-table-column
- prop="dataType"
- label="资料类型"
- width="120"
- align="center"
- header-align="center"
- />
- <!-- 表格类型 -->
- <el-table-column
- prop="tableType"
- label="表格类型"
- width="120"
- align="center"
- />
- <el-table-column
- prop="isRequired"
- label="是否必填"
- width="100"
- align="center"
- header-align="center"
- />
- <!-- 是否上传(只读显示) -->
- <el-table-column label="是否上传" width="100" align="center">
- <template slot-scope="scope">
- <span
- :style="{
- color: scope.row.isUploaded === true ? '#67c23a' : '#f56c6c',
- }"
- >
- {{ scope.row.isUploaded === true ? '已上传' : '未上传' }}
- </span>
- </template>
- </el-table-column>
- <el-table-column
- label="操作"
- width="120"
- align="center"
- header-align="center"
- >
- <template slot-scope="scope">
- <el-button type="text" @click="handleViewTemplate(scope.row)">
- 查看模板
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- <!-- 单记录弹窗(查看) -->
- <survey-form-dialog
- :visible.sync="singleDialogVisible"
- :survey-data="{ ...currentSurveyRow, ...surveyDetailData }"
- :is-view-mode="true"
- :request-type="1"
- :audited-unit-id="
- (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
- "
- :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
- :survey-template-id="
- (currentTemplateRow &&
- (currentTemplateRow.templateId ||
- currentTemplateRow.surveyTemplateId)) ||
- ''
- "
- :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
- />
- <!-- 固定表弹窗(查看) -->
- <fixed-table-dialog
- :visible.sync="fixedDialogVisible"
- :survey-data="surveyDetailData"
- :is-view-mode="true"
- :request-type="1"
- :audited-unit-id="
- (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
- "
- :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
- :survey-template-id="
- (currentTemplateRow &&
- (currentTemplateRow.templateId ||
- currentTemplateRow.surveyTemplateId)) ||
- ''
- "
- :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
- :table-items="tableItems"
- :audit-periods="auditPeriods"
- />
- <!-- 动态表弹窗(查看) -->
- <dynamic-table-dialog
- :visible.sync="dynamicDialogVisible"
- :table-data="dynamicTableData"
- :is-view-mode="true"
- :request-type="1"
- :audited-unit-id="
- (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
- "
- :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
- :survey-template-id="
- (currentTemplateRow &&
- (currentTemplateRow.templateId ||
- currentTemplateRow.surveyTemplateId)) ||
- ''
- "
- :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
- />
- </div>
- </template>
- <script>
- import taskMixins from './taskMixins.js'
- import {
- getSurveyList,
- getSurveyDetail,
- getSingleRecordSurveyList,
- getDynamicTableData,
- } from '@/api/audit/survey'
- import SurveyFormDialog from '@/views/EntDeclaration/auditTaskManagement/components/SurveyFormDialog.vue'
- import FixedTableDialog from '@/views/EntDeclaration/auditTaskManagement/components/FixedTableDialog.vue'
- import DynamicTableDialog from '@/views/EntDeclaration/auditTaskManagement/components/DynamicTableDialog.vue'
- export default {
- components: { SurveyFormDialog, FixedTableDialog, DynamicTableDialog },
- mixins: [taskMixins],
- props: {
- auditedUnitId: { type: String, default: '' },
- catalogId: { type: String, default: '' },
- taskId: { type: String, default: '' },
- },
- data() {
- return {
- loading: false,
- rows: [],
- currentTemplateRow: null,
- currentSurveyRow: null,
- surveyDetailData: {},
- tableItems: [],
- auditPeriods: [],
- dynamicTableData: [],
- singleDialogVisible: false,
- fixedDialogVisible: false,
- dynamicDialogVisible: false,
- }
- },
- watch: {
- taskId(newVal, oldVal) {
- if (newVal && newVal !== oldVal) {
- this.loadList()
- }
- },
- auditedUnitId(newVal, oldVal) {
- if (this.taskId && newVal !== oldVal) {
- this.loadList()
- }
- },
- },
- created() {
- console.log('auditedUnitId', this.auditedUnitId)
- console.log('taskId', this.taskId)
- if (this.taskId) {
- this.loadList()
- }
- },
- methods: {
- // 预取单记录详情作为回显
- async loadSingleRecordDetail() {
- this.surveyDetailData = {}
- const row = this.currentTemplateRow || {}
- const uploadId = row.uploadId || row.id || ''
- const auditedUnitId = row.auditedUnitId || this.auditedUnitId || ''
- if (!uploadId || !auditedUnitId) return
- try {
- const params = { uploadId, auditedUnitId, type: 1 }
- const res = await getSurveyDetail(params)
- if (res && res.code === 200 && res.value) {
- const detail = {}
- const val = res.value
- if (Array.isArray(val)) {
- val.forEach((item) => {
- if (!item || typeof item !== 'object') return
- const key =
- item.rowid !== undefined
- ? item.rowid
- : item.rowId !== undefined
- ? item.rowId
- : item.id !== undefined
- ? item.id
- : undefined
- const value =
- item.rvalue !== undefined
- ? item.rvalue
- : item.rValue !== undefined
- ? item.rValue
- : item.value !== undefined
- ? item.value
- : item.val !== undefined
- ? item.val
- : ''
- if (key !== undefined) {
- detail[key] = value
- }
- })
- } else if (val && typeof val === 'object') {
- // 兼容对象结构,直接合并
- Object.assign(detail, val)
- }
- this.surveyDetailData = detail
- }
- } catch (e) {
- this.surveyDetailData = {}
- }
- },
- async loadList() {
- try {
- const params = {
- taskId: this.taskId,
- pageNum: 1,
- pageSize: 100,
- type: 1,
- }
- if (this.auditedUnitId) params.auditedUnitId = this.auditedUnitId
- const resp = await getSurveyList(params)
- console.log(resp, 'resp')
- const raw =
- (resp &&
- ((resp.value && (resp.value.records || resp.value)) ||
- resp.data ||
- resp)) ||
- []
- const list = Array.isArray(raw)
- ? raw
- : Array.isArray(raw.records)
- ? raw.records
- : []
- this.rows = list.map((it, idx) => {
- const t = String(it.templateType || it.templatetype || '')
- const tableType =
- t === '1'
- ? '单记录'
- : t === '2'
- ? '固定表'
- : t === '3'
- ? '动态表'
- : ''
- return {
- index: idx + 1,
- id: it.uploadId || it.id || '',
- name:
- it.surveyTemplateName || it.informationName || it.name || '',
- dataType: it.dataType || '预置模板',
- tableType,
- isRequired: String(it.isRequired) === '1' ? '是' : '否',
- isUploaded: String(it.isUpload) === '1' || it.isUpload === true,
- uploadId: it.uploadId || it.id || '',
- surveyTemplateId: it.templateId || it.surveyTemplateId || '',
- catalogId: it.catalogId || this.catalogId || '',
- auditedUnitId: it.auditedUnitId || this.auditedUnitId || '',
- templateType: t,
- }
- })
- } catch (e) {
- this.rows = []
- }
- },
- async handleViewTemplate(row) {
- this.currentTemplateRow = row || null
- this.currentSurveyRow = row || null
- const t = String(
- (row && (row.templateType || row.templatetype)) || ''
- ).trim()
- if (t === '1') {
- // 单记录:清理并预取详情
- this.surveyDetailData = {}
- await this.loadSingleRecordDetail()
- this.singleDialogVisible = true
- } else if (t === '2') {
- // 预加载固定表配置(tableItems)并推断监审期间
- this.tableItems = []
- this.auditPeriods = []
- await this.initFixedTableData()
- this.fixedDialogVisible = true
- } else if (t === '3') {
- // 预加载动态表列表数据
- this.dynamicTableData = []
- await this.initDynamicTableData()
- this.dynamicDialogVisible = true
- } else {
- this.$message &&
- this.$message.warning &&
- this.$message.warning('未知的模板类型,无法打开预置模板')
- }
- },
- async initFixedTableData() {
- this.tableItems = []
- this.auditPeriods = []
- const row = this.currentTemplateRow || {}
- const surveyTemplateId = row.templateId || row.surveyTemplateId || ''
- if (!surveyTemplateId) return
- try {
- const params = { surveyTemplateId, type: 1 }
- const res = await getSingleRecordSurveyList(params)
- if (res && res.code === 200 && res.value) {
- const { itemlist } = res.value || {}
- if (Array.isArray(itemlist) && itemlist.length > 0) {
- this.tableItems = itemlist.map((item) => ({
- id: item.id || item.itemId || '',
- rowid: item.rowid || item.id || item.itemId || '',
- seq: item.序号,
- itemName: item.项目 || item.itemName || '',
- unit: item.unit || '',
- isCategory: item.isCategory || false,
- categorySeq: item.categorySeq || '',
- categoryId: item.categoryId || '',
- parentid:
- item.parentid !== undefined
- ? item.parentid
- : item.parentId !== undefined
- ? item.parentId
- : '-1',
- validateRules: item.validateRules || {},
- linkageRules: item.linkageRules || {},
- children: item.children || [],
- ...item,
- }))
- }
- // 尝试从当前行或配置中解析监审期间
- const periodStr =
- row.auditPeriod || (res.value && res.value.auditPeriod) || ''
- this.auditPeriods = this.parseAuditPeriod(periodStr)
- }
- } catch (e) {
- this.tableItems = []
- this.auditPeriods = []
- }
- },
- parseAuditPeriod(periodStr) {
- if (!periodStr) return []
- const str = String(periodStr)
- if (str.includes(',')) {
- return str.split(',').map((p) => String(p).trim())
- }
- if (str.includes('-')) {
- const parts = str.split('-')
- if (parts.length === 2) {
- const start = parseInt(parts[0].trim())
- const end = parseInt(parts[1].trim())
- const years = []
- for (let y = start; y <= end; y++) years.push(String(y))
- return years
- }
- }
- return [String(str)]
- },
- async initDynamicTableData() {
- this.dynamicTableData = []
- const row = this.currentTemplateRow || {}
- const uploadId = row.uploadId || row.id || ''
- const auditedUnitId = row.auditedUnitId || this.auditedUnitId || ''
- const catalogId = row.catalogId || this.catalogId || ''
- const surveyTemplateId = row.templateId || row.surveyTemplateId || ''
- // 动态表列表以 uploadId 为主键查询,auditedUnitId 可选
- if (!uploadId) return
- try {
- const params = {
- uploadId,
- ...(auditedUnitId ? { auditedUnitId } : {}),
- catalogId,
- surveyTemplateId,
- type: 1,
- }
- const res = await getDynamicTableData(params)
- if (res && res.code === 200) {
- const records = res.value?.records || res.value || []
- this.dynamicTableData = Array.isArray(records) ? records : []
- }
- } catch (e) {
- this.dynamicTableData = []
- }
- },
- },
- }
- </script>
|