audit-cpm-project-group.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <sd-detail-form
  3. v-show="initialled"
  4. ref="docform"
  5. :page-id="this.$route.query.pageId"
  6. :record-id="this.$route.query.projectId ? this.$route.query.projectId : null"
  7. :class="$style.form"
  8. :read-only="false"
  9. @close="close(true)"
  10. @saved="saved"
  11. @actionBtnClick="actionBtnClick"
  12. >
  13. <template v-slot="{ formData, model, fields }">
  14. <table>
  15. <tr>
  16. <td style="border: none">
  17. <audit-advanced-group
  18. :expand="expand"
  19. expand-str="expand"
  20. group-label="分组信息"
  21. @changedClick="changedClick"
  22. ></audit-advanced-group>
  23. </td>
  24. </tr>
  25. </table>
  26. <table v-show="expand">
  27. <tr>
  28. <td colspan="4" :class="$style.subTable">
  29. <sd-form-by-builder
  30. v-if="initialled"
  31. :form-data="formData.pageFormData"
  32. ></sd-form-by-builder>
  33. </td>
  34. </tr>
  35. </table>
  36. </template>
  37. </sd-detail-form>
  38. </template>
  39. <script>
  40. import { message } from '@/common/one-ui'
  41. import auditAdvancedGroup from '@product/iam/components/audit-advanced-group.vue'
  42. import auditAdvancedGroupMixins from '@product/iam/components/audit-advanced-group-mixins'
  43. import CpmService from '../../cpm-service'
  44. import components from './_import-components/audit-cpm-project-group-import'
  45. import auditCpmProjectGroupService from './audit-cpm-project-group-service'
  46. export default {
  47. name: 'AuditCpmProjectGroup',
  48. metaInfo: {
  49. title: '项目分组',
  50. },
  51. components: {
  52. auditAdvancedGroup,
  53. ...components,
  54. },
  55. mixins: [auditAdvancedGroupMixins],
  56. data() {
  57. return {
  58. expand: true,
  59. initialled: false,
  60. deptFw: undefined,
  61. }
  62. },
  63. mounted() {
  64. const ini = setInterval(() => {
  65. if (
  66. this.$refs.docform &&
  67. (this.$refs.docform.$refs.form || this.$refs.docform.$refs.sdForm)
  68. ) {
  69. try {
  70. // 设置被检查单位选择范围
  71. this.setDeptData(this.$route.query.projectId)
  72. clearInterval(ini)
  73. } catch {}
  74. }
  75. }, 100)
  76. },
  77. methods: {
  78. // 设置被检查单位选择范围
  79. setDeptData(projectId) {
  80. if (projectId) {
  81. // 获取项目信息
  82. const childTableData = this.$refs.docform.getFieldValue('CPM_SUB_PROJECT')
  83. CpmService.getProjectData(projectId).then((res) => {
  84. const checkdeptnames = res.data[0].checkedDeptNames
  85. const checkdeptcodes = res.data[0].checkedDeptIds
  86. const names = checkdeptnames.split(',')
  87. const codes = checkdeptcodes.split(',')
  88. const deptFw = []
  89. names.forEach((n, index) => {
  90. deptFw.push({
  91. type: 'Group',
  92. name: n,
  93. code: codes[index],
  94. })
  95. })
  96. this.deptFw = deptFw
  97. childTableData.forEach((item) => {
  98. item.CHECKED_DEPT_OPT_FW = JSON.stringify(deptFw)
  99. })
  100. this.$refs.docform.setFieldValue('CPM_SUB_PROJECT', childTableData)
  101. this.filter(this.$refs.docform.formData.pageFormData)
  102. this.initialled = true
  103. })
  104. }
  105. },
  106. saved() {
  107. // 保存成功后
  108. message.success({ content: '保存成功', key: 'messagekey' })
  109. // 保存成功之后,更新分组数据
  110. auditCpmProjectGroupService.saveSubProjectLeader(this.$route.query.projectId)
  111. },
  112. close(flag) {
  113. window.close()
  114. },
  115. filter(pageFormData) {
  116. // 升级新加的参数,使用这个判断是否展示这个字段
  117. this.$refs.docform.$refs.form.displayExprResults.CPM_SUB_PROJECT = 'true'
  118. const formData = pageFormData
  119. formData.pageFieldInfos.forEach((item) => {
  120. if (item.name !== 'CPM_SUB_PROJECT') {
  121. item.attrFD.hidden = true
  122. } else {
  123. item.attrFD.hidden = false
  124. item.attr.dync?.forEach((item) => {
  125. if (item.name === 'CHECKED_DEPT_OPT_FW') {
  126. item.attr.defaultValue = JSON.stringify(this.deptFw)
  127. }
  128. })
  129. }
  130. })
  131. return formData
  132. },
  133. actionBtnClick(evt, btn) {
  134. if (btn.buttonId === 'save') {
  135. // 停止默认事件,走自己的保存
  136. evt.preventDefault()
  137. // 判断表中是否有重复
  138. let flag = true
  139. // 判断子表是否都已填完
  140. const btnList = document.querySelectorAll('.operation_sd-child-table_common')
  141. btnList.forEach((item) => {
  142. if (item.innerHTML.includes('保存')) {
  143. flag = false
  144. }
  145. })
  146. if (!flag) {
  147. message.warning('请保存编辑行,再执行此操作', 1)
  148. return
  149. }
  150. const ulist = this.$refs.docform.getFieldValue('CPM_SUB_PROJECT')
  151. let tsxx = ''
  152. ulist.forEach((i) => {
  153. if (
  154. ulist.filter((u) => u.CHECKED_DEPT_ID && u.CHECKED_DEPT_ID === i.CHECKED_DEPT_ID)
  155. .length > 1
  156. ) {
  157. flag = false
  158. tsxx = '分组表中被检查单位重复,请检查数据'
  159. }
  160. })
  161. if (!flag) {
  162. message.warning(tsxx, 1)
  163. } else {
  164. // 进行保存
  165. ulist.forEach((item) => {
  166. item.CHECKED_DEPT_OPT_FW = '[]'
  167. })
  168. this.$refs.docform.setFieldValue('CPM_SUB_PROJECT', ulist)
  169. this.$refs.docform.saveBtnClick()
  170. }
  171. }
  172. },
  173. },
  174. }
  175. </script>
  176. <style module lang="scss">
  177. @use '@/common/design' as *;
  178. .form {
  179. :global(.ant-form-item-control-wrapper) {
  180. margin: auto;
  181. width: 100% !important;
  182. text-align: center;
  183. }
  184. :global(.ant-form-item-control) {
  185. margin-top: 10px;
  186. }
  187. }
  188. .sub-table {
  189. table {
  190. width: 100%;
  191. }
  192. }
  193. </style>