costSurvey.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <div>
  3. <!-- 成本调查表(只读) -->
  4. <el-table border :data="rows" style="width: 100%">
  5. <el-table-column
  6. prop="index"
  7. label="序号"
  8. width="80"
  9. align="center"
  10. header-align="center"
  11. />
  12. <el-table-column
  13. prop="name"
  14. label="成本调查表"
  15. min-width="200"
  16. align="center"
  17. header-align="center"
  18. show-overflow-tooltip
  19. />
  20. <el-table-column
  21. prop="dataType"
  22. label="资料类型"
  23. width="120"
  24. align="center"
  25. header-align="center"
  26. />
  27. <!-- 表格类型 -->
  28. <el-table-column
  29. prop="tableType"
  30. label="表格类型"
  31. width="120"
  32. align="center"
  33. />
  34. <el-table-column
  35. prop="isRequired"
  36. label="是否必填"
  37. width="100"
  38. align="center"
  39. header-align="center"
  40. />
  41. <!-- 是否上传(只读显示) -->
  42. <el-table-column label="是否上传" width="100" align="center">
  43. <template slot-scope="scope">
  44. <span
  45. :style="{
  46. color: scope.row.isUploaded === true ? '#67c23a' : '#f56c6c',
  47. }"
  48. >
  49. {{ scope.row.isUploaded === true ? '已上传' : '未上传' }}
  50. </span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column
  54. label="操作"
  55. width="120"
  56. align="center"
  57. header-align="center"
  58. >
  59. <template slot-scope="scope">
  60. <el-button type="text" @click="handleViewTemplate(scope.row)">
  61. 查看模板
  62. </el-button>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <!-- 单记录弹窗(查看) -->
  67. <survey-form-dialog
  68. :visible.sync="singleDialogVisible"
  69. :survey-data="{ ...currentSurveyRow, ...surveyDetailData }"
  70. :is-view-mode="true"
  71. :request-type="1"
  72. :audited-unit-id="
  73. (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
  74. "
  75. :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
  76. :survey-template-id="
  77. (currentTemplateRow &&
  78. (currentTemplateRow.templateId ||
  79. currentTemplateRow.surveyTemplateId)) ||
  80. ''
  81. "
  82. :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
  83. />
  84. <!-- 固定表弹窗(查看) -->
  85. <fixed-table-dialog
  86. :visible.sync="fixedDialogVisible"
  87. :survey-data="surveyDetailData"
  88. :is-view-mode="true"
  89. :request-type="1"
  90. :audited-unit-id="
  91. (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
  92. "
  93. :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
  94. :survey-template-id="
  95. (currentTemplateRow &&
  96. (currentTemplateRow.templateId ||
  97. currentTemplateRow.surveyTemplateId)) ||
  98. ''
  99. "
  100. :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
  101. :table-items="tableItems"
  102. :audit-periods="auditPeriods"
  103. />
  104. <!-- 动态表弹窗(查看) -->
  105. <dynamic-table-dialog
  106. :visible.sync="dynamicDialogVisible"
  107. :table-data="dynamicTableData"
  108. :is-view-mode="true"
  109. :request-type="1"
  110. :audited-unit-id="
  111. (currentTemplateRow && currentTemplateRow.auditedUnitId) || ''
  112. "
  113. :upload-id="(currentTemplateRow && currentTemplateRow.uploadId) || ''"
  114. :survey-template-id="
  115. (currentTemplateRow &&
  116. (currentTemplateRow.templateId ||
  117. currentTemplateRow.surveyTemplateId)) ||
  118. ''
  119. "
  120. :catalog-id="(currentTemplateRow && currentTemplateRow.catalogId) || ''"
  121. />
  122. </div>
  123. </template>
  124. <script>
  125. import taskMixins from './taskMixins.js'
  126. import {
  127. getSurveyList,
  128. getSurveyDetail,
  129. getSingleRecordSurveyList,
  130. getDynamicTableData,
  131. } from '@/api/audit/survey'
  132. import SurveyFormDialog from '@/views/EntDeclaration/auditTaskManagement/components/SurveyFormDialog.vue'
  133. import FixedTableDialog from '@/views/EntDeclaration/auditTaskManagement/components/FixedTableDialog.vue'
  134. import DynamicTableDialog from '@/views/EntDeclaration/auditTaskManagement/components/DynamicTableDialog.vue'
  135. export default {
  136. components: { SurveyFormDialog, FixedTableDialog, DynamicTableDialog },
  137. mixins: [taskMixins],
  138. props: {
  139. auditedUnitId: { type: String, default: '' },
  140. catalogId: { type: String, default: '' },
  141. taskId: { type: String, default: '' },
  142. },
  143. data() {
  144. return {
  145. loading: false,
  146. rows: [],
  147. currentTemplateRow: null,
  148. currentSurveyRow: null,
  149. surveyDetailData: {},
  150. tableItems: [],
  151. auditPeriods: [],
  152. dynamicTableData: [],
  153. singleDialogVisible: false,
  154. fixedDialogVisible: false,
  155. dynamicDialogVisible: false,
  156. }
  157. },
  158. watch: {
  159. taskId(newVal, oldVal) {
  160. if (newVal && newVal !== oldVal) {
  161. this.loadList()
  162. }
  163. },
  164. auditedUnitId(newVal, oldVal) {
  165. if (this.taskId && newVal !== oldVal) {
  166. this.loadList()
  167. }
  168. },
  169. },
  170. created() {
  171. console.log('auditedUnitId', this.auditedUnitId)
  172. console.log('taskId', this.taskId)
  173. if (this.taskId) {
  174. this.loadList()
  175. }
  176. },
  177. methods: {
  178. // 预取单记录详情作为回显
  179. async loadSingleRecordDetail() {
  180. this.surveyDetailData = {}
  181. const row = this.currentTemplateRow || {}
  182. const uploadId = row.uploadId || row.id || ''
  183. const auditedUnitId = row.auditedUnitId || this.auditedUnitId || ''
  184. if (!uploadId || !auditedUnitId) return
  185. try {
  186. const params = { uploadId, auditedUnitId, type: 1 }
  187. const res = await getSurveyDetail(params)
  188. if (res && res.code === 200 && res.value) {
  189. const detail = {}
  190. const val = res.value
  191. if (Array.isArray(val)) {
  192. val.forEach((item) => {
  193. if (!item || typeof item !== 'object') return
  194. const key =
  195. item.rowid !== undefined
  196. ? item.rowid
  197. : item.rowId !== undefined
  198. ? item.rowId
  199. : item.id !== undefined
  200. ? item.id
  201. : undefined
  202. const value =
  203. item.rvalue !== undefined
  204. ? item.rvalue
  205. : item.rValue !== undefined
  206. ? item.rValue
  207. : item.value !== undefined
  208. ? item.value
  209. : item.val !== undefined
  210. ? item.val
  211. : ''
  212. if (key !== undefined) {
  213. detail[key] = value
  214. }
  215. })
  216. } else if (val && typeof val === 'object') {
  217. // 兼容对象结构,直接合并
  218. Object.assign(detail, val)
  219. }
  220. this.surveyDetailData = detail
  221. }
  222. } catch (e) {
  223. this.surveyDetailData = {}
  224. }
  225. },
  226. async loadList() {
  227. try {
  228. const params = {
  229. taskId: this.taskId,
  230. pageNum: 1,
  231. pageSize: 100,
  232. type: 1,
  233. }
  234. if (this.auditedUnitId) params.auditedUnitId = this.auditedUnitId
  235. const resp = await getSurveyList(params)
  236. console.log(resp, 'resp')
  237. const raw =
  238. (resp &&
  239. ((resp.value && (resp.value.records || resp.value)) ||
  240. resp.data ||
  241. resp)) ||
  242. []
  243. const list = Array.isArray(raw)
  244. ? raw
  245. : Array.isArray(raw.records)
  246. ? raw.records
  247. : []
  248. this.rows = list.map((it, idx) => {
  249. const t = String(it.templateType || it.templatetype || '')
  250. const tableType =
  251. t === '1'
  252. ? '单记录'
  253. : t === '2'
  254. ? '固定表'
  255. : t === '3'
  256. ? '动态表'
  257. : ''
  258. return {
  259. index: idx + 1,
  260. id: it.uploadId || it.id || '',
  261. name:
  262. it.surveyTemplateName || it.informationName || it.name || '',
  263. dataType: it.dataType || '预置模板',
  264. tableType,
  265. isRequired: String(it.isRequired) === '1' ? '是' : '否',
  266. isUploaded: String(it.isUpload) === '1' || it.isUpload === true,
  267. uploadId: it.uploadId || it.id || '',
  268. surveyTemplateId: it.templateId || it.surveyTemplateId || '',
  269. catalogId: it.catalogId || this.catalogId || '',
  270. auditedUnitId: it.auditedUnitId || this.auditedUnitId || '',
  271. templateType: t,
  272. }
  273. })
  274. } catch (e) {
  275. this.rows = []
  276. }
  277. },
  278. async handleViewTemplate(row) {
  279. this.currentTemplateRow = row || null
  280. this.currentSurveyRow = row || null
  281. const t = String(
  282. (row && (row.templateType || row.templatetype)) || ''
  283. ).trim()
  284. if (t === '1') {
  285. // 单记录:清理并预取详情
  286. this.surveyDetailData = {}
  287. await this.loadSingleRecordDetail()
  288. this.singleDialogVisible = true
  289. } else if (t === '2') {
  290. // 预加载固定表配置(tableItems)并推断监审期间
  291. this.tableItems = []
  292. this.auditPeriods = []
  293. await this.initFixedTableData()
  294. this.fixedDialogVisible = true
  295. } else if (t === '3') {
  296. // 预加载动态表列表数据
  297. this.dynamicTableData = []
  298. await this.initDynamicTableData()
  299. this.dynamicDialogVisible = true
  300. } else {
  301. this.$message &&
  302. this.$message.warning &&
  303. this.$message.warning('未知的模板类型,无法打开预置模板')
  304. }
  305. },
  306. async initFixedTableData() {
  307. this.tableItems = []
  308. this.auditPeriods = []
  309. const row = this.currentTemplateRow || {}
  310. const surveyTemplateId = row.templateId || row.surveyTemplateId || ''
  311. if (!surveyTemplateId) return
  312. try {
  313. const params = { surveyTemplateId, type: 1 }
  314. const res = await getSingleRecordSurveyList(params)
  315. if (res && res.code === 200 && res.value) {
  316. const { itemlist } = res.value || {}
  317. if (Array.isArray(itemlist) && itemlist.length > 0) {
  318. this.tableItems = itemlist.map((item) => ({
  319. id: item.id || item.itemId || '',
  320. rowid: item.rowid || item.id || item.itemId || '',
  321. seq: item.序号,
  322. itemName: item.项目 || item.itemName || '',
  323. unit: item.unit || '',
  324. isCategory: item.isCategory || false,
  325. categorySeq: item.categorySeq || '',
  326. categoryId: item.categoryId || '',
  327. parentid:
  328. item.parentid !== undefined
  329. ? item.parentid
  330. : item.parentId !== undefined
  331. ? item.parentId
  332. : '-1',
  333. validateRules: item.validateRules || {},
  334. linkageRules: item.linkageRules || {},
  335. children: item.children || [],
  336. ...item,
  337. }))
  338. }
  339. // 尝试从当前行或配置中解析监审期间
  340. const periodStr =
  341. row.auditPeriod || (res.value && res.value.auditPeriod) || ''
  342. this.auditPeriods = this.parseAuditPeriod(periodStr)
  343. }
  344. } catch (e) {
  345. this.tableItems = []
  346. this.auditPeriods = []
  347. }
  348. },
  349. parseAuditPeriod(periodStr) {
  350. if (!periodStr) return []
  351. const str = String(periodStr)
  352. if (str.includes(',')) {
  353. return str.split(',').map((p) => String(p).trim())
  354. }
  355. if (str.includes('-')) {
  356. const parts = str.split('-')
  357. if (parts.length === 2) {
  358. const start = parseInt(parts[0].trim())
  359. const end = parseInt(parts[1].trim())
  360. const years = []
  361. for (let y = start; y <= end; y++) years.push(String(y))
  362. return years
  363. }
  364. }
  365. return [String(str)]
  366. },
  367. async initDynamicTableData() {
  368. this.dynamicTableData = []
  369. const row = this.currentTemplateRow || {}
  370. const uploadId = row.uploadId || row.id || ''
  371. const auditedUnitId = row.auditedUnitId || this.auditedUnitId || ''
  372. const catalogId = row.catalogId || this.catalogId || ''
  373. const surveyTemplateId = row.templateId || row.surveyTemplateId || ''
  374. // 动态表列表以 uploadId 为主键查询,auditedUnitId 可选
  375. if (!uploadId) return
  376. try {
  377. const params = {
  378. uploadId,
  379. ...(auditedUnitId ? { auditedUnitId } : {}),
  380. catalogId,
  381. surveyTemplateId,
  382. type: 1,
  383. }
  384. const res = await getDynamicTableData(params)
  385. if (res && res.code === 200) {
  386. const records = res.value?.records || res.value || []
  387. this.dynamicTableData = Array.isArray(records) ? records : []
  388. }
  389. } catch (e) {
  390. this.dynamicTableData = []
  391. }
  392. },
  393. },
  394. }
  395. </script>