materialTab.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <div class="material-tab">
  3. <span class="link-text">被监审单位需报送材料:</span>
  4. <el-button
  5. v-if="!isView"
  6. plain
  7. type="success"
  8. icon="el-icon-circle-plus"
  9. style="margin-bottom: 20px"
  10. @click="handleAddMaterial"
  11. >
  12. 添加材料
  13. </el-button>
  14. <CostAuditTable
  15. class="mt20"
  16. :table-data="materialList"
  17. :columns="materialColumns"
  18. :show-index="true"
  19. :show-pagination="true"
  20. :show-action-column="true"
  21. :pagination="pagination"
  22. @pagination-change="handlePaginationChange"
  23. >
  24. <template #orderNum="scope">
  25. <el-input
  26. v-model="scope.row.orderNum"
  27. size="mini"
  28. style="width: 60px"
  29. @blur="handleSortChange(scope.row)"
  30. ></el-input>
  31. </template>
  32. <template #action="scope">
  33. <el-button
  34. type="primary"
  35. size="mini"
  36. plain
  37. icon="el-icon-edit"
  38. :disabled="isView"
  39. @click="handleEditMaterial(scope.row)"
  40. >
  41. 修改
  42. </el-button>
  43. <el-button
  44. type="danger"
  45. size="mini"
  46. plain
  47. icon="el-icon-delete"
  48. :disabled="isView"
  49. @click="handleDeleteMaterial(scope.row)"
  50. >
  51. 删除
  52. </el-button>
  53. />
  54. </template>
  55. </CostAuditTable>
  56. <legal-dialog
  57. ref="legalDialog"
  58. :dialog-visible="materialDialogVisible"
  59. :dialog-title="materialDialogTitle"
  60. :template-data="templateData"
  61. :template-columns="templateColumns"
  62. :form-data="formData.material"
  63. @submit="handleMaterialSubmit"
  64. @cancel="handleMaterialCancel"
  65. />
  66. </div>
  67. </template>
  68. <script>
  69. import {
  70. addCostProjectMaterial,
  71. updateCostProjectMaterial,
  72. deleteCostProjectMaterial,
  73. getCostProjectMaterialPageList,
  74. } from '@/api/taskCustomizedRelease.js'
  75. import CostAuditTable from '@/components/costAudit/CostAuditTable.vue'
  76. import LegalDialog from '@/views/costAudit/baseInfo/catalogManage/legalDialog.vue'
  77. import { dictMixin } from '@/mixins/useDict'
  78. export default {
  79. components: {
  80. CostAuditTable,
  81. LegalDialog,
  82. },
  83. mixins: [dictMixin],
  84. props: {
  85. // 父组件传递的参数
  86. project: {
  87. type: Object,
  88. default: () => {},
  89. },
  90. isView: {
  91. type: Boolean,
  92. default: false,
  93. },
  94. },
  95. data() {
  96. return {
  97. dictData: {
  98. materialType: [], //资料类别
  99. formatAsk: [], //格式要求
  100. },
  101. // 模板相关数据
  102. templateData: [],
  103. templateColumns: [
  104. {
  105. prop: 'surveyTemplateName',
  106. label: '模板名称',
  107. align: 'center',
  108. },
  109. {
  110. prop: 'surveyTemplateCode',
  111. label: '模板编码',
  112. align: 'center',
  113. },
  114. {
  115. prop: 'createTime',
  116. label: '创建时间',
  117. align: 'center',
  118. },
  119. ],
  120. formData: {
  121. material: {},
  122. },
  123. addMaterial: false,
  124. materialDialogVisible: false,
  125. materialDialogTitle: '添加',
  126. // 简化数据结构,避免嵌套对象可能导致的数据绑定问题
  127. materialList: [],
  128. pagination: {
  129. currentPage: 1,
  130. pageSize: 50,
  131. total: 0,
  132. },
  133. materialColumns: [],
  134. }
  135. },
  136. computed: {},
  137. watch: {
  138. // 监听project变化,确保有项目ID时刷新数据
  139. project: {
  140. handler(newVal) {
  141. if (newVal && newVal.projectId) {
  142. this.loadMaterialData()
  143. }
  144. },
  145. deep: true,
  146. },
  147. },
  148. mounted() {
  149. // 组件挂载时先初始化表格列配置
  150. this.materialColumns = this.getMaterialColumns()
  151. // 然后加载数据
  152. if (this.project && this.project.projectId) {
  153. this.loadMaterialData()
  154. }
  155. },
  156. methods: {
  157. // 获取表格列配置
  158. getMaterialColumns() {
  159. return [
  160. {
  161. prop: 'informationType',
  162. label: '材料分类',
  163. width: 120,
  164. align: 'center',
  165. formatter: (row) => {
  166. return this.getDictName('materialType', row.informationType)
  167. },
  168. },
  169. {
  170. prop: 'informationName',
  171. label: '材料名称',
  172. minWidth: 200,
  173. align: 'left',
  174. },
  175. {
  176. prop: 'informationRequire',
  177. label: '材料要求说明',
  178. minWidth: 300,
  179. align: 'left',
  180. },
  181. {
  182. prop: 'formatRequired',
  183. label: '格式要求',
  184. width: 120,
  185. align: 'center',
  186. formatter: (row) => {
  187. return this.getDictName('formatAsk', row.formatRequired)
  188. },
  189. },
  190. {
  191. prop: 'orderNum',
  192. label: '排序',
  193. width: 120,
  194. align: 'center',
  195. slotName: 'orderNum',
  196. },
  197. {
  198. prop: 'action',
  199. label: '操作',
  200. align: 'center',
  201. width: 200,
  202. slotName: 'action',
  203. actions: [
  204. {
  205. name: 'edit',
  206. label: '修改',
  207. type: 'text',
  208. size: 'mini',
  209. onClick: this.handleEditMaterial,
  210. disabled: this.isView,
  211. },
  212. {
  213. name: 'delete',
  214. label: '删除',
  215. type: 'text',
  216. size: 'mini',
  217. className: 'delete-btn',
  218. onClick: this.handleDeleteMaterial,
  219. disabled: this.isView,
  220. },
  221. ],
  222. },
  223. ]
  224. },
  225. // 加载材料数据
  226. loadMaterialData() {
  227. // 确保project和projectId存在
  228. if (!this.project || !this.project.projectId) {
  229. console.warn('项目ID不存在,无法加载材料数据')
  230. return
  231. }
  232. const { currentPage, pageSize } = this.pagination
  233. const params = {
  234. projectId: this.project.projectId,
  235. page: currentPage,
  236. size: pageSize,
  237. }
  238. getCostProjectMaterialPageList(params)
  239. .then((res) => {
  240. if (res && res.value && res.value.value) {
  241. this.materialList = Array.isArray(res.value.value.records)
  242. ? res.value.value.records
  243. : []
  244. this.pagination.total = Number(res.value.value.total) || 0
  245. } else {
  246. this.materialList = []
  247. this.pagination.total = 0
  248. }
  249. })
  250. .catch((error) => {
  251. console.error('加载材料数据失败:', error)
  252. // 错误时清空数据避免显示异常
  253. this.materialList = []
  254. this.pagination.total = 0
  255. })
  256. },
  257. // 排序变更
  258. handleSortChange(row) {
  259. // 排序逻辑
  260. let data = {
  261. ...row,
  262. projectId: this.project.projectId,
  263. }
  264. updateCostProjectMaterial(data)
  265. .then(() => {
  266. this.$message.success('修改成功')
  267. this.loadMaterialData()
  268. })
  269. .catch(() => {})
  270. },
  271. // 新增材料
  272. handleAddMaterial() {
  273. this.formData.material = {
  274. informationType: '',
  275. informationName: '',
  276. informationRequire: '',
  277. formatRequired: '',
  278. templateId: '',
  279. surveyTemplateName: '',
  280. orderNum: 1,
  281. isRequired: '0',
  282. }
  283. this.materialDialogVisible = true
  284. this.materialDialogTitle = '添加'
  285. },
  286. // 编辑材料
  287. handleEditMaterial(row) {
  288. this.formData.material = { ...row }
  289. this.materialDialogVisible = true
  290. this.materialDialogTitle = '修改'
  291. },
  292. // 删除材料
  293. handleDeleteMaterial(row) {
  294. this.$confirm(
  295. `确定要删除资料名称为${row.informationName}的数据吗?`,
  296. '提示',
  297. {
  298. confirmButtonText: '确定',
  299. cancelButtonText: '取消',
  300. type: 'warning',
  301. }
  302. )
  303. .then(() => {
  304. try {
  305. deleteCostProjectMaterial(row.id).then(() => {
  306. this.$message.success('删除成功')
  307. this.loadMaterialData()
  308. })
  309. } catch (error) {
  310. console.error('删除失败:', error)
  311. }
  312. })
  313. .catch(() => {
  314. this.$message.info('已取消删除')
  315. })
  316. },
  317. // 保存材料
  318. handleMaterialSubmit(formData) {
  319. let data = {
  320. ...formData,
  321. projectId: this.project.projectId,
  322. }
  323. updateCostProjectMaterial(data)
  324. .then(() => {
  325. this.$message.success('保存成功')
  326. this.$refs.legalDialog.setSubmitting(false)
  327. this.materialDialogVisible = false
  328. this.loadMaterialData()
  329. })
  330. .catch(() => {
  331. this.$refs.legalDialog.setSubmitting(false)
  332. })
  333. },
  334. handleLegalSubmit() {},
  335. handleMaterialCancel() {
  336. this.formData.material = {
  337. informationType: '',
  338. informationName: '',
  339. informationRequire: '',
  340. formatRequired: '',
  341. templateId: '',
  342. surveyTemplateName: '',
  343. orderNum: 1,
  344. isRequired: '0',
  345. }
  346. this.materialDialogVisible = false
  347. },
  348. getTemplateOptions() {},
  349. templatePaginationChange() {},
  350. handlePaginationChange({ currentPage, pageSize }) {
  351. this.pagination.currentPage = currentPage
  352. this.pagination.pageSize = pageSize
  353. this.loadMaterialData()
  354. },
  355. },
  356. }
  357. </script>
  358. <style lang="scss" scoped>
  359. @import '@/styles/costAudit.scss';
  360. </style>