surveyTab.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div>
  3. <!-- 表格组件 -->
  4. <CostAuditTable
  5. v-loading="loading"
  6. :table-data="surveyData.list"
  7. :columns="getSurveyColumns()"
  8. :show-action-column="true"
  9. :show-pagination="true"
  10. :pagination="costSurveyPagination"
  11. style="width: 100%"
  12. @pagination-change="handlePaginationChange"
  13. ></CostAuditTable>
  14. <!-- 成本调查表查看弹窗 -->
  15. <SurveyDialog
  16. :dialog-visible="contentEditDialogVisible"
  17. :dialog-title="contentEditDialogTitle"
  18. :form-data="contentEditForm"
  19. :audit-period-from-parent="auditPeriodFromProject"
  20. :disabled="contentEditDisabled"
  21. @cancel="handleContentEditCancel"
  22. />
  23. </div>
  24. </template>
  25. <script>
  26. import CostAuditTable from '@/components/costAudit/CostAuditTable.vue'
  27. import SurveyDialog from '@/views/costAudit/baseInfo/catalogManage/surveyDialog.vue'
  28. import { getCostSurveyForms } from '@/api/catalogManage.js'
  29. export default {
  30. components: {
  31. CostAuditTable,
  32. SurveyDialog,
  33. },
  34. props: {
  35. // 父组件传递的参数
  36. project: {
  37. type: Object,
  38. default: () => {},
  39. },
  40. isView: {
  41. type: Boolean,
  42. default: false,
  43. },
  44. },
  45. data() {
  46. return {
  47. loading: false,
  48. // 内容编辑弹窗相关
  49. contentEditDialogVisible: false,
  50. contentEditDialogTitle: '内容维护',
  51. contentEditDisabled: true,
  52. contentEditForm: {
  53. surveyTemplateName: '',
  54. templateType: '1',
  55. // 单记录列表
  56. tableHeaders: [],
  57. // 固定表列表
  58. fixedTable: [],
  59. // 动态表列表
  60. dynamicTable: [],
  61. },
  62. // 内部管理调查数据
  63. surveyData: {
  64. list: [],
  65. },
  66. costSurveyPagination: {
  67. currentPage: 1,
  68. pageSize: 10,
  69. total: 0,
  70. },
  71. }
  72. },
  73. computed: {
  74. // 从项目中提取监审期间(字符串或数组),优先 basicInfo.auditPeriod
  75. auditPeriodFromProject() {
  76. const p = this.project || {}
  77. if (p.basicInfo && p.basicInfo.auditPeriod)
  78. return p.basicInfo.auditPeriod
  79. if (p.auditPeriod) return p.auditPeriod
  80. if (p.data && p.data.basicInfo && p.data.basicInfo.auditPeriod) {
  81. return p.data.basicInfo.auditPeriod
  82. }
  83. return ''
  84. },
  85. },
  86. watch: {
  87. // 监听project变化,确保有项目ID时刷新数据
  88. project: {
  89. handler(newVal) {
  90. if (newVal && newVal.projectId) {
  91. this.loadSurveyData()
  92. }
  93. },
  94. deep: true,
  95. immediate: true,
  96. },
  97. },
  98. mounted() {
  99. // 组件挂载时加载数据
  100. if (this.project && this.project.projectId) {
  101. this.loadSurveyData()
  102. }
  103. },
  104. methods: {
  105. // 加载调查模板数据
  106. loadSurveyData() {
  107. if (!this.project || !this.project.projectId) {
  108. console.warn('项目ID不存在,无法加载调查模板数据')
  109. return
  110. }
  111. this.loading = true
  112. const params = {
  113. catalogId:
  114. this.project.catalogId ||
  115. this.project.catalogid ||
  116. this.project.catalogID ||
  117. '',
  118. pageNum: this.costSurveyPagination.currentPage,
  119. pageSize: this.costSurveyPagination.pageSize,
  120. }
  121. getCostSurveyForms(params)
  122. .then((res) => {
  123. const value = res?.value || {}
  124. const records = Array.isArray(value.records)
  125. ? value.records
  126. : Array.isArray(value?.value?.records)
  127. ? value.value.records
  128. : []
  129. // 直接用 records;若无 records 则尝试把 value 视作数组
  130. this.surveyData.list =
  131. Array.isArray(records) && records.length > 0
  132. ? records
  133. : Array.isArray(value)
  134. ? value
  135. : []
  136. const total =
  137. value.total ??
  138. value?.value?.total ??
  139. (Array.isArray(records) ? records.length : 0)
  140. this.costSurveyPagination.total = Number(total) || 0
  141. })
  142. .catch((error) => {
  143. console.error('加载调查模板数据失败:', error)
  144. this.surveyData.list = []
  145. })
  146. .finally(() => {
  147. this.loading = false
  148. })
  149. },
  150. // 获取带操作按钮的表格列配置
  151. getSurveyColumns() {
  152. return [
  153. {
  154. prop: 'surveyTemplateName',
  155. label: '模板名称',
  156. minWidth: 220,
  157. align: 'left',
  158. headerAlign: 'center',
  159. showOverflowTooltip: true,
  160. },
  161. {
  162. prop: 'templateType',
  163. label: '模板类型',
  164. width: 120,
  165. align: 'center',
  166. headerAlign: 'center',
  167. formatter: (row) => {
  168. return row.templateType == '1'
  169. ? '单记录'
  170. : row.templateType == '2'
  171. ? '固定表'
  172. : '动态表'
  173. },
  174. },
  175. {
  176. prop: 'action',
  177. label: '操作',
  178. align: 'center',
  179. headerAlign: 'center',
  180. width: 140,
  181. actions: [
  182. {
  183. name: 'view',
  184. label: '查看模板',
  185. type: 'text',
  186. onClick: this.handleViewTemplate,
  187. },
  188. ],
  189. },
  190. ]
  191. },
  192. // 查看成本调查表内容弹窗
  193. handleViewTemplate(data) {
  194. this.contentEditForm = {
  195. surveyTemplateName: data.surveyTemplateName || '',
  196. templateType: data.templateType || '1',
  197. data: {
  198. ...data,
  199. surveyId: data.surveyId,
  200. },
  201. tableHeaders: [],
  202. fixedTable: {
  203. tableHeaders: [],
  204. fixedTables: [],
  205. fixedTablesTitle: [],
  206. fixedTableHeaders: [],
  207. },
  208. dynamicTable: {
  209. tableHeaders: [],
  210. dynamicTables: [],
  211. dynamicTablesTitle: [],
  212. dynamicTableHeaders: [],
  213. },
  214. isDynamicTables: false,
  215. isFixedTables: false,
  216. }
  217. this.contentEditDialogTitle = '查看'
  218. this.contentEditDialogVisible = true
  219. },
  220. handlePaginationChange({ currentPage, pageSize }) {
  221. this.costSurveyPagination.currentPage = currentPage
  222. this.costSurveyPagination.pageSize = pageSize
  223. this.loadSurveyData()
  224. },
  225. // 关闭内容编辑弹窗
  226. handleContentEditCancel() {
  227. this.contentEditDialogVisible = false
  228. this.contentEditForm = {
  229. surveyTemplateName: '',
  230. templateType: '1',
  231. tableHeaders: [],
  232. fixedTable: [],
  233. dynamicTable: [],
  234. }
  235. },
  236. },
  237. }
  238. </script>
  239. <style lang="scss" scoped></style>