workflowTab.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <template>
  2. <div class="task-formulate">
  3. <div class="operation-bar">
  4. <span>预定的监审工作起止时间:</span>
  5. <el-date-picker
  6. v-model="formData.workflow.plannedAuditStartDate"
  7. type="date"
  8. placeholder="开始日期"
  9. style="width: 150px; margin: 0 10px"
  10. format="yyyy-MM-dd"
  11. value-format="yyyy-MM-dd"
  12. disabled
  13. ></el-date-picker>
  14. <span>至</span>
  15. <el-date-picker
  16. v-model="formData.workflow.plannedAuditEndDate"
  17. type="date"
  18. placeholder="结束日期"
  19. style="width: 150px; margin: 0 10px"
  20. format="yyyy-MM-dd"
  21. value-format="yyyy-MM-dd"
  22. disabled
  23. ></el-date-picker>
  24. </div>
  25. <div class="operation-bar">
  26. <el-button
  27. type="success"
  28. plain
  29. icon="el-icon-circle-plus"
  30. :disabled="isView"
  31. @click="handleSetWorkflow"
  32. >
  33. 工作环节设置
  34. </el-button>
  35. </div>
  36. <CostAuditTable
  37. :table-data="workflowData.list"
  38. :columns="workflowData.listColumns"
  39. :show-index="true"
  40. :show-action-column="true"
  41. >
  42. <template #action="{ row }">
  43. <!-- v-if="row.nodeType == 1" -->
  44. <el-button type="text" :disabled="isView" @click="handleSetStep(row)">
  45. 设置
  46. </el-button>
  47. </template>
  48. </CostAuditTable>
  49. <div class="table-description">
  50. 说明:为所有内部环节预置办理人员、流转操作按钮、环节截止时间;环节时限不能超过预定的工作流程起止时间。
  51. </div>
  52. <el-dialog
  53. title="工作环节设置"
  54. :visible.sync="dialogs.setStepDialogVisible"
  55. width="70%"
  56. >
  57. <div class="operation-bar">
  58. <span>请选择预定的监审工作起止时间:</span>
  59. <el-date-picker
  60. v-model="formData.workflow.plannedAuditStartDate"
  61. type="date"
  62. placeholder="开始日期"
  63. style="width: 150px; margin: 0 10px"
  64. format="yyyy-MM-dd"
  65. value-format="yyyy-MM-dd"
  66. :picker-options="dialogStartPickerOptions"
  67. ></el-date-picker>
  68. <span>至</span>
  69. <el-date-picker
  70. v-model="formData.workflow.plannedAuditEndDate"
  71. type="date"
  72. placeholder="结束日期"
  73. style="width: 150px; margin: 0 10px"
  74. format="yyyy-MM-dd"
  75. value-format="yyyy-MM-dd"
  76. :picker-options="dialogEndPickerOptions"
  77. ></el-date-picker>
  78. </div>
  79. <CostAuditTable
  80. :table-data="workflowData.stepList"
  81. :columns="workflowData.workflowColumns"
  82. :show-index="true"
  83. :show-pagination="true"
  84. :show-action-column="true"
  85. :table-props="{
  86. maxHeight: '500',
  87. }"
  88. :pagination="workflowData.pagination"
  89. @pagination-change="handlePaginationChange"
  90. >
  91. <template #mainUserId="{ row }">
  92. <el-select
  93. v-if="row.nodeType == 1"
  94. v-model="row.mainUserId"
  95. filterable
  96. allow-create
  97. default-first-option
  98. placeholder="请选择主办人员"
  99. style="width: 100%"
  100. >
  101. <el-option
  102. v-for="item in formatterMainUserList()"
  103. :key="item.userId"
  104. :label="item.fullname"
  105. :value="item.userId"
  106. />
  107. </el-select>
  108. </template>
  109. <template #userId="{ row }">
  110. <el-select
  111. v-if="row.nodeType == 1"
  112. v-model="row.userId"
  113. multiple
  114. filterable
  115. allow-create
  116. default-first-option
  117. placeholder="请选择从办人员"
  118. style="width: 100%"
  119. :disabled="!row.mainUserId"
  120. >
  121. <el-option
  122. v-for="item in formatterUserList(row.mainUserId)"
  123. :key="item.userId"
  124. :label="item.fullname"
  125. :value="item.userId"
  126. />
  127. </el-select>
  128. </template>
  129. <template #status="{ row }">
  130. <el-select
  131. v-if="row.nodeType == 1"
  132. v-model="row.status"
  133. multiple
  134. filterable
  135. allow-create
  136. default-first-option
  137. placeholder="请选择预置流转操作"
  138. style="width: 100%"
  139. >
  140. <el-option
  141. v-for="item in dictData['processStatus']"
  142. :key="item.key"
  143. :label="item.name"
  144. :value="item.key"
  145. />
  146. </el-select>
  147. </template>
  148. <template #endTime="{ row }">
  149. <el-date-picker
  150. v-model="row.endTime"
  151. type="date"
  152. placeholder="请选择截止时间"
  153. format="yyyy-MM-dd"
  154. value-format="yyyy-MM-dd"
  155. style="width: 100%"
  156. :picker-options="getPickerOptions(row)"
  157. ></el-date-picker>
  158. </template>
  159. </CostAuditTable>
  160. <div slot="footer" class="dialog-footer">
  161. <el-button
  162. type="primary"
  163. :loading="loading.saveStep"
  164. @click="handleSaveSetStep"
  165. >
  166. 确认
  167. </el-button>
  168. <el-button @click="dialogs.setStepDialogVisible = false">
  169. 取消
  170. </el-button>
  171. </div>
  172. </el-dialog>
  173. <!-- 设置流程环节弹窗 -->
  174. <el-dialog
  175. v-loading="loading.save"
  176. title="设置流程环节"
  177. :visible.sync="dialogs.stepDialogVisible"
  178. width="50%"
  179. :close-on-click-modal="false"
  180. >
  181. <el-form
  182. ref="currentStepForm"
  183. :model="formData.currentStep"
  184. label-width="120px"
  185. :rules="formData.currentStepRules"
  186. >
  187. <el-form-item label="流程环节:" prop="processNodeValue">
  188. <el-input
  189. v-model="formData.currentStep.processNodeValue"
  190. disabled
  191. ></el-input>
  192. </el-form-item>
  193. <el-form-item label="主办人员:" prop="mainUserId">
  194. <el-select
  195. v-model="formData.currentStep.mainUserId"
  196. filterable
  197. allow-create
  198. default-first-option
  199. placeholder="请选择主办人员"
  200. style="width: 100%"
  201. :disabled="formData.currentStep.nodeType == 0"
  202. >
  203. <el-option
  204. v-for="item in formatterMainUserList()"
  205. :key="item.userId"
  206. :label="item.fullname"
  207. :value="item.userId"
  208. ></el-option>
  209. </el-select>
  210. </el-form-item>
  211. <el-form-item label="从办人员:" prop="userId">
  212. <el-select
  213. v-model="formData.currentStep.userId"
  214. multiple
  215. filterable
  216. allow-create
  217. default-first-option
  218. placeholder="请选择从办人员"
  219. style="width: 100%"
  220. :disabled="
  221. !formData.currentStep.mainUserId ||
  222. formData.currentStep.nodeType == 0
  223. "
  224. >
  225. <el-option
  226. v-for="item in formatterUserList(formData.currentStep.mainUserId)"
  227. :key="item.userId"
  228. :label="item.fullname"
  229. :value="item.userId"
  230. ></el-option>
  231. </el-select>
  232. </el-form-item>
  233. <el-form-item label="预置流转操作:" prop="status">
  234. <el-select
  235. v-model="formData.currentStep.status"
  236. filterable
  237. multiple
  238. allow-create
  239. default-first-option
  240. placeholder="请选择预置流转操作"
  241. style="width: 100%"
  242. :disabled="formData.currentStep.nodeType == 0"
  243. >
  244. <el-option
  245. v-for="item in dictData['processStatus']"
  246. :key="item.key"
  247. :label="item.name"
  248. :value="item.key"
  249. />
  250. </el-select>
  251. </el-form-item>
  252. <el-form-item label="截止时间:" prop="endTime">
  253. <el-date-picker
  254. v-model="formData.currentStep.endTime"
  255. type="date"
  256. placeholder="请选择截止时间"
  257. format="yyyy-MM-dd"
  258. value-format="yyyy-MM-dd"
  259. style="width: 100%"
  260. :disabled="isTimePickerDisabled"
  261. :picker-options="getPickerOptions(formData.currentStep)"
  262. ></el-date-picker>
  263. </el-form-item>
  264. </el-form>
  265. <div slot="footer" class="dialog-footer">
  266. <el-button
  267. type="primary"
  268. :loading="loading.save"
  269. @click="handleSaveStep('currentStepForm', 'list')"
  270. >
  271. 确认
  272. </el-button>
  273. <el-button @click="dialogs.stepDialogVisible = false">取消</el-button>
  274. </div>
  275. </el-dialog>
  276. </div>
  277. </template>
  278. <script>
  279. import { taskMixin } from './index.js'
  280. import {
  281. getCostProjectNodeTmpletePageList,
  282. saveProcess,
  283. } from '@/api/taskCustomizedRelease.js'
  284. import CostAuditTable from '@/components/costAudit/CostAuditTable.vue'
  285. export default {
  286. components: { CostAuditTable },
  287. mixins: [taskMixin],
  288. props: {
  289. // 父组件传递的参数
  290. project: {
  291. type: Object,
  292. default: () => {},
  293. },
  294. isView: {
  295. type: Boolean,
  296. default: false,
  297. },
  298. },
  299. data() {
  300. return {
  301. formData: {
  302. currentStepRules: {
  303. endTime: [
  304. { required: true, message: '请选择截止时间', trigger: 'change' },
  305. {
  306. validator: (rule, value, callback) => {
  307. // 检查单个环节时间是否在总流程时间范围内
  308. if (
  309. !this.formData.workflow.plannedAuditStartDate ||
  310. !this.formData.workflow.plannedAuditEndDate
  311. ) {
  312. return callback()
  313. }
  314. if (value < this.formData.workflow.plannedAuditStartDate) {
  315. return callback(new Error('截止时间不能早于工作开始时间'))
  316. }
  317. if (value > this.formData.workflow.plannedAuditEndDate) {
  318. return callback(new Error('截止时间不能晚于工作结束时间'))
  319. }
  320. callback()
  321. },
  322. trigger: 'change',
  323. },
  324. ],
  325. },
  326. },
  327. // 对话框内“开始日期”不可选择今天之前的日期
  328. dialogStartPickerOptions: {
  329. disabledDate: (time) => {
  330. // 取今天 00:00:00 的时间戳
  331. const todayStart = new Date(new Date().toDateString()).getTime()
  332. return time.getTime() < todayStart
  333. },
  334. },
  335. // 对话框内“结束日期”必须大于开始日期
  336. dialogEndPickerOptions: {
  337. disabledDate: (time) => {
  338. const start = this.formData.workflow.plannedAuditStartDate
  339. ? new Date(this.formData.workflow.plannedAuditStartDate).getTime()
  340. : null
  341. if (start != null) {
  342. // 禁用 小于等于 开始日期 的日期,实现“之后”的严格要求
  343. return time.getTime() <= start
  344. }
  345. return false
  346. },
  347. },
  348. }
  349. },
  350. computed: {
  351. // 计算是否应该禁用当前步骤的时间选择器
  352. isTimePickerDisabled() {
  353. // 如果当前没有选中步骤,不禁用
  354. if (
  355. !this.formData.currentStep ||
  356. !this.formData.currentStep.processNodeKey
  357. ) {
  358. return false
  359. }
  360. // 获取当前步骤列表(优先使用已保存的列表)
  361. const stepList =
  362. this.workflowData.list.length > 0
  363. ? this.workflowData.list
  364. : this.workflowData.stepList
  365. if (!stepList || stepList.length <= 1) {
  366. return false
  367. }
  368. // 找到当前步骤在列表中的索引
  369. const currentIndex = stepList.findIndex(
  370. (item) =>
  371. item.processNodeKey === this.formData.currentStep.processNodeKey
  372. )
  373. // 如果是第一个步骤或找不到当前步骤,不禁用
  374. if (currentIndex <= 0) {
  375. return false
  376. }
  377. // 检查上一个步骤是否有设置时间
  378. const prevStep = stepList[currentIndex - 1]
  379. return !prevStep.endTime
  380. },
  381. },
  382. watch: {
  383. // 监听workflowData.stepList变化,动态更新下一个环节的最小可选时间
  384. 'workflowData.stepList': {
  385. handler(newList) {
  386. // 对步骤列表按顺序排序,确保时间验证的准确性
  387. if (newList && newList.length > 0) {
  388. // 这里可以根据需要添加排序逻辑,假设步骤已经按顺序排列
  389. }
  390. },
  391. deep: true,
  392. },
  393. },
  394. mounted() {
  395. this.getWorkflow()
  396. },
  397. methods: {
  398. // 获取“归档”的key
  399. getArchiveKey() {
  400. const list = (this.dictData && this.dictData['processStatus']) || []
  401. if (!Array.isArray(list)) return ''
  402. const item = list.find((it) => it && it.name === '归档')
  403. return item ? item.key : ''
  404. },
  405. // 获取除“归档”外的全部预置流转操作key数组
  406. getNonArchiveKeys() {
  407. const list = (this.dictData && this.dictData['processStatus']) || []
  408. if (!Array.isArray(list)) return []
  409. return list
  410. .filter((it) => it && it.name !== '归档')
  411. .map((it) => it.key)
  412. .filter((k) => k != null && k !== '')
  413. },
  414. // 获取所有预置流转操作的key数组(全选)
  415. getAllStatusKeys() {
  416. const list = (this.dictData && this.dictData['processStatus']) || []
  417. if (!Array.isArray(list)) return []
  418. return list
  419. .map((it) => (it ? it.key : undefined))
  420. .filter((k) => k != null && k !== '')
  421. },
  422. formatterUserList(userId) {
  423. // 筛选出除主办人员之外的人员
  424. return this.formatterMainUserList().filter(
  425. (item) => item.userId !== userId
  426. )
  427. },
  428. formatterMainUserList() {
  429. // 防御性编程,确保userList存在
  430. if (!this.userList || !Array.isArray(this.userList)) {
  431. return []
  432. }
  433. // 防御性编程,确保project.projectMembers存在且为字符串
  434. if (
  435. !this.project ||
  436. !this.project.projectMembers ||
  437. typeof this.project.projectMembers !== 'string'
  438. ) {
  439. return this.userList // 返回全部用户作为后备方案
  440. }
  441. try {
  442. // 分割项目组成员ID并过滤用户列表
  443. const projectMemberIds = this.project.projectMembers.split(',')
  444. const filteredUsers = this.userList.filter((item) =>
  445. projectMemberIds.includes(item.userId)
  446. )
  447. return filteredUsers
  448. } catch (error) {
  449. return this.userList // 出错时返回全部用户作为后备方案
  450. }
  451. },
  452. // 获取日期选择器的配置选项,动态设置最小可选日期
  453. getPickerOptions(row) {
  454. const stepList = this.workflowData.stepList
  455. const rowIndex = stepList.findIndex(
  456. (item) => item.processNodeKey === row.processNodeKey
  457. )
  458. let pickerOptions = {
  459. disabledDate: (time) => {
  460. // 基础限制:不能早于工作开始时间,不能晚于工作结束时间
  461. const startLimit = this.formData.workflow.plannedAuditStartDate
  462. ? new Date(this.formData.workflow.plannedAuditStartDate).getTime()
  463. : null
  464. const endLimit = this.formData.workflow.plannedAuditEndDate
  465. ? new Date(this.formData.workflow.plannedAuditEndDate).getTime()
  466. : null
  467. if (startLimit && time.getTime() < startLimit - 8.64e7) {
  468. return true // 禁用开始时间之前的日期
  469. }
  470. if (endLimit && time.getTime() > endLimit) {
  471. return true // 禁用结束时间之后的日期
  472. }
  473. // 如果不是第一个步骤,需要确保时间大于上一个步骤的时间
  474. if (rowIndex > 0) {
  475. const prevStep = stepList[rowIndex - 1]
  476. if (prevStep && prevStep.endTime) {
  477. const prevEndTime = new Date(prevStep.endTime).getTime()
  478. if (time.getTime() <= prevEndTime - 8.64e7) {
  479. return true // 禁用上一步骤结束时间之前的日期
  480. }
  481. }
  482. }
  483. return false
  484. },
  485. }
  486. return pickerOptions
  487. },
  488. handleSetWorkflow() {
  489. this.getUser()
  490. this.dialogs.setStepDialogVisible = true
  491. if (this.workflowData.list.length > 0) {
  492. this.workflowData.stepList = this.workflowData.list
  493. this.workflowData.stepList = this.workflowData.list.map((item) => {
  494. const mapped = {
  495. ...item,
  496. userId: item.userId ? item.userId.split(',') : [],
  497. status: item.status ? item.status.split(',') : [],
  498. }
  499. // 默认预置流转操作:归档环节默认“全部选中”,其他环节默认“除归档外全部选中”
  500. if (!mapped.status || mapped.status.length === 0) {
  501. if (this.isArchiveNode(mapped)) {
  502. mapped.status = this.getAllStatusKeys()
  503. } else {
  504. mapped.status = this.getNonArchiveKeys()
  505. }
  506. }
  507. return mapped
  508. })
  509. } else {
  510. getCostProjectNodeTmpletePageList({
  511. pageNum: this.workflowData.pagination.currentPage,
  512. pageSize: this.workflowData.pagination.pageSize,
  513. processId: '1',
  514. }).then((res) => {
  515. this.workflowData.stepList = res.value.records.map((item) => {
  516. const mapped = {
  517. ...item,
  518. userId: item.userId ? item.userId.split(',') : [],
  519. status: item.status ? item.status.split(',') : [],
  520. }
  521. if (!mapped.status || mapped.status.length === 0) {
  522. if (this.isArchiveNode(mapped)) {
  523. mapped.status = this.getAllStatusKeys()
  524. } else {
  525. mapped.status = this.getNonArchiveKeys()
  526. }
  527. }
  528. return mapped
  529. })
  530. this.workflowData.pagination.total = res.value.total
  531. })
  532. }
  533. },
  534. // 设置流程环节
  535. handleSetStep(row) {
  536. this.getUser()
  537. const statusArr = row.status ? row.status.split(',') : []
  538. let finalStatus = statusArr
  539. if (!finalStatus || finalStatus.length === 0) {
  540. finalStatus = this.isArchiveNode(row)
  541. ? this.getAllStatusKeys()
  542. : this.getNonArchiveKeys()
  543. }
  544. this.formData.currentStep = {
  545. ...row,
  546. userId: row.userId ? row.userId.split(',') : [],
  547. status: finalStatus,
  548. }
  549. this.dialogs.stepDialogVisible = true
  550. this.loading.save = false
  551. // 重置表单验证状态
  552. this.$nextTick(() => {
  553. if (this.$refs.currentStepForm) {
  554. this.$refs.currentStepForm.clearValidate()
  555. }
  556. })
  557. },
  558. // 保存流程环节设置
  559. handleSaveStep(formName, type) {
  560. this.$refs[formName].validate((valid) => {
  561. if (valid) {
  562. // 校验当前环节预置流转操作
  563. const needKey = this.isArchiveNode(this.formData.currentStep)
  564. ? this.getProcessStatusKeyByName('归档')
  565. : this.getProcessStatusKeyByName('通过')
  566. const needName = this.isArchiveNode(this.formData.currentStep)
  567. ? '归档'
  568. : '通过'
  569. const statusArr = Array.isArray(this.formData.currentStep.status)
  570. ? this.formData.currentStep.status
  571. : []
  572. if (needKey && !statusArr.includes(needKey)) {
  573. const stepName =
  574. this.formData.currentStep.processNodeValue ||
  575. this.formData.currentStep.processNodeKey ||
  576. ''
  577. this.$message.error(
  578. `流程环节【${stepName}】预置流转操作必须包含“${needName}”`
  579. )
  580. return
  581. }
  582. if (type == 'list') {
  583. this.workflowData.list = this.workflowData.list.map((item) => {
  584. if (
  585. item.processNodeKey ==
  586. this.formData.currentStep.processNodeKey
  587. ) {
  588. return {
  589. ...item,
  590. ...this.formData.currentStep,
  591. userId: this.formData.currentStep.userId.join(','),
  592. status: this.formData.currentStep.status.join(','),
  593. }
  594. }
  595. return item
  596. })
  597. // 触发自定义事件通知父组件数据已更新
  598. this.$emit('update:workflowData', { ...this.workflowData })
  599. this.handleSaveSetStep('list')
  600. }
  601. } else {
  602. return false
  603. }
  604. })
  605. },
  606. // 保存工作环节设置
  607. handleSaveSetStep(type) {
  608. if (!this.formData.workflow.plannedAuditStartDate) {
  609. this.$message.error('请选择预定的监审工作开始日期')
  610. return
  611. }
  612. if (!this.formData.workflow.plannedAuditEndDate) {
  613. this.$message.error('请选择预定的监审工作结束日期')
  614. return
  615. }
  616. // 验证环节时间顺序,确保下一个环节的时间大于上一个环节的时间
  617. let stepList =
  618. type === 'list' ? this.workflowData.list : this.workflowData.stepList
  619. if (stepList && stepList.length > 1) {
  620. // 按顺序排序步骤(假设存在排序字段或按数组顺序)
  621. const sortedSteps = [...stepList].sort((a, b) => {
  622. // 假设步骤有某种排序标识,这里简单按数组顺序处理
  623. return stepList.indexOf(a) - stepList.indexOf(b)
  624. })
  625. // 验证每个步骤的时间是否符合要求
  626. for (let i = 1; i < sortedSteps.length; i++) {
  627. const currentStep = sortedSteps[i]
  628. const prevStep = sortedSteps[i - 1]
  629. // 检查当前步骤和上一步骤是否都有时间设置
  630. if (currentStep.endTime && prevStep.endTime) {
  631. if (new Date(currentStep.endTime) <= new Date(prevStep.endTime)) {
  632. this.$message.error(
  633. `第${i + 1}个环节的截止时间必须大于第${i}个环节的截止时间`
  634. )
  635. return
  636. }
  637. } else if (currentStep.endTime && !prevStep.endTime) {
  638. this.$message.error(`请先设置第${i}个环节的截止时间`)
  639. return
  640. } else if (!currentStep.endTime && prevStep.endTime) {
  641. this.$message.error(`请设置第${i + 1}个环节的截止时间`)
  642. return
  643. }
  644. }
  645. }
  646. // 验证每个环节的预置流转操作(归档需“归档”,其余需“通过”)
  647. const listToCheck =
  648. type === 'list'
  649. ? this.workflowData.list.map((it) => ({
  650. ...it,
  651. statusArr:
  652. typeof it.status === 'string' && it.status
  653. ? it.status.split(',')
  654. : Array.isArray(it.status)
  655. ? it.status
  656. : [],
  657. }))
  658. : this.workflowData.stepList.map((it) => ({
  659. ...it,
  660. statusArr: Array.isArray(it.status) ? it.status : [],
  661. }))
  662. for (const it of listToCheck) {
  663. const needKey = this.isArchiveNode(it)
  664. ? this.getProcessStatusKeyByName('归档')
  665. : this.getProcessStatusKeyByName('通过')
  666. const needName = this.isArchiveNode(it) ? '归档' : '通过'
  667. if (needKey && !it.statusArr.includes(needKey)) {
  668. const stepName = it.processNodeValue || it.processNodeKey || ''
  669. this.$message.error(
  670. `流程环节【${stepName}】预置流转操作必须包含“${needName}”`
  671. )
  672. return
  673. }
  674. }
  675. this.loading.save = true
  676. let data = {
  677. nodeReqList: [
  678. {
  679. endTime: '',
  680. id: '',
  681. mainUserId: '',
  682. processNodeKey: '',
  683. status: '',
  684. userId: '',
  685. },
  686. ],
  687. plannedAuditEndDate: this.formData.workflow.plannedAuditEndDate,
  688. plannedAuditStartDate: this.formData.workflow.plannedAuditStartDate,
  689. processId: this.workflowData.detailInfo.processId || '1',
  690. projectId: this.project.projectId,
  691. }
  692. if (type == 'list') {
  693. data.nodeReqList = this.workflowData.list
  694. } else {
  695. data.nodeReqList = this.workflowData.stepList.map((item) => {
  696. return {
  697. ...item,
  698. userId: item.userId.join(','),
  699. status: item.status.join(','),
  700. }
  701. })
  702. }
  703. saveProcess(data)
  704. .then((res) => {
  705. if (res.code === 200) {
  706. this.$message.success('保存成功')
  707. this.loading.save = false
  708. if (type == 'list') {
  709. this.dialogs.stepDialogVisible = false
  710. } else {
  711. this.dialogs.setStepDialogVisible = false
  712. }
  713. this.getWorkflow()
  714. }
  715. })
  716. .catch(() => {
  717. this.loading.save = false
  718. })
  719. },
  720. // 判断是否归档环节
  721. isArchiveNode(row) {
  722. const key = (row && row.processNodeKey) || ''
  723. const val = (row && row.processNodeValue) || ''
  724. const keyLower = String(key).toLowerCase()
  725. return (
  726. String(val).includes('归档') ||
  727. keyLower === 'gd' ||
  728. keyLower === 'guidang' ||
  729. keyLower.includes('archive')
  730. )
  731. },
  732. // 根据字典名称获取预置流转操作key
  733. getProcessStatusKeyByName(name) {
  734. const list = (this.dictData && this.dictData['processStatus']) || []
  735. if (!Array.isArray(list)) return ''
  736. const item = list.find((it) => it.name === name)
  737. return item ? item.key : ''
  738. },
  739. },
  740. }
  741. </script>
  742. <style scoped lang="scss">
  743. @import '@/styles/costAudit.scss';
  744. </style>