workflowTab.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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="actualWorkflowData.list"
  38. :columns="actualWorkflowData.listColumns"
  39. :show-index="true"
  40. :show-action-column="false"
  41. ></CostAuditTable>
  42. <div class="table-description">
  43. 说明:为所有内部环节预置办理人员、流转操作按钮、环节截止时间;环节时限不能超过预定的工作流程起止时间。
  44. </div>
  45. <el-dialog
  46. title="工作环节设置"
  47. :visible.sync="dialogs.setStepDialogVisible"
  48. width="70%"
  49. >
  50. <div class="operation-bar">
  51. <span>请选择预定的监审工作起止时间:</span>
  52. <el-date-picker
  53. v-model="formData.workflow.plannedAuditStartDate"
  54. type="date"
  55. placeholder="开始日期"
  56. style="width: 150px; margin: 0 10px"
  57. format="yyyy-MM-dd"
  58. value-format="yyyy-MM-dd"
  59. ></el-date-picker>
  60. <span>至</span>
  61. <el-date-picker
  62. v-model="formData.workflow.plannedAuditEndDate"
  63. type="date"
  64. placeholder="结束日期"
  65. style="width: 150px; margin: 0 10px"
  66. format="yyyy-MM-dd"
  67. value-format="yyyy-MM-dd"
  68. ></el-date-picker>
  69. </div>
  70. <CostAuditTable
  71. :table-data="actualWorkflowData.stepList"
  72. :columns="actualWorkflowData.workflowColumns"
  73. :show-index="true"
  74. :show-pagination="true"
  75. :show-action-column="true"
  76. :table-props="{
  77. maxHeight: '500',
  78. }"
  79. :pagination="actualWorkflowData.pagination"
  80. @pagination-change="handlePaginationChange"
  81. >
  82. <template #mainUserId="{ row }">
  83. <el-select
  84. v-if="row.nodeType == 1"
  85. v-model="row.mainUserId"
  86. filterable
  87. allow-create
  88. default-first-option
  89. placeholder="请选择主办人员"
  90. style="width: 100%"
  91. >
  92. <el-option
  93. v-for="item in formatterMainUserList()"
  94. :key="item.userId"
  95. :label="item.fullname"
  96. :value="item.userId"
  97. />
  98. </el-select>
  99. </template>
  100. <template #userId="{ row }">
  101. <el-select
  102. v-if="row.nodeType == 1"
  103. v-model="row.userId"
  104. multiple
  105. filterable
  106. allow-create
  107. default-first-option
  108. placeholder="请选择从办人员"
  109. style="width: 100%"
  110. :disabled="!row.mainUserId"
  111. >
  112. <el-option
  113. v-for="item in formatterUserList(row.mainUserId)"
  114. :key="item.userId"
  115. :label="item.fullname"
  116. :value="item.userId"
  117. />
  118. </el-select>
  119. </template>
  120. <template #status="{ row }">
  121. <el-select
  122. v-if="row.nodeType == 1"
  123. v-model="row.status"
  124. multiple
  125. filterable
  126. allow-create
  127. default-first-option
  128. placeholder="请选择预置流转操作"
  129. style="width: 100%"
  130. >
  131. <el-option
  132. v-for="item in dictData['processStatus']"
  133. :key="item.key"
  134. :label="item.name"
  135. :value="item.key"
  136. />
  137. </el-select>
  138. </template>
  139. <template #endTime="{ row }">
  140. <el-date-picker
  141. v-model="row.endTime"
  142. type="date"
  143. placeholder="请选择截止时间"
  144. format="yyyy-MM-dd"
  145. value-format="yyyy-MM-dd"
  146. style="width: 100%"
  147. :picker-options="getPickerOptions(row)"
  148. ></el-date-picker>
  149. </template>
  150. </CostAuditTable>
  151. <div slot="footer" class="dialog-footer">
  152. <el-button
  153. type="primary"
  154. :loading="loading.saveStep"
  155. @click="handleSaveSetStep"
  156. >
  157. 确认
  158. </el-button>
  159. <el-button @click="dialogs.setStepDialogVisible = false">
  160. 取消
  161. </el-button>
  162. </div>
  163. </el-dialog>
  164. <!-- 设置流程环节弹窗 -->
  165. <el-dialog
  166. v-loading="loading.save"
  167. title="设置流程环节"
  168. :visible.sync="dialogs.stepDialogVisible"
  169. width="50%"
  170. :close-on-click-modal="false"
  171. >
  172. <el-form
  173. ref="currentStepForm"
  174. :model="formData.currentStep"
  175. label-width="120px"
  176. :rules="formData.currentStepRules"
  177. >
  178. <el-form-item label="流程环节:" prop="processNodeValue">
  179. <el-input
  180. v-model="formData.currentStep.processNodeValue"
  181. disabled
  182. ></el-input>
  183. </el-form-item>
  184. <el-form-item label="主办人员:" prop="mainUserId">
  185. <el-select
  186. v-model="formData.currentStep.mainUserId"
  187. filterable
  188. allow-create
  189. default-first-option
  190. placeholder="请选择主办人员"
  191. style="width: 100%"
  192. :disabled="formData.currentStep.nodeType == 0"
  193. >
  194. <el-option
  195. v-for="item in formatterMainUserList()"
  196. :key="item.userId"
  197. :label="item.fullname"
  198. :value="item.userId"
  199. ></el-option>
  200. </el-select>
  201. </el-form-item>
  202. <el-form-item label="从办人员:" prop="userId">
  203. <el-select
  204. v-model="formData.currentStep.userId"
  205. multiple
  206. filterable
  207. allow-create
  208. default-first-option
  209. placeholder="请选择从办人员"
  210. style="width: 100%"
  211. :disabled="
  212. !formData.currentStep.mainUserId ||
  213. formData.currentStep.nodeType == 0
  214. "
  215. >
  216. <el-option
  217. v-for="item in formatterUserList(formData.currentStep.mainUserId)"
  218. :key="item.userId"
  219. :label="item.fullname"
  220. :value="item.userId"
  221. ></el-option>
  222. </el-select>
  223. </el-form-item>
  224. <el-form-item label="预置流转操作:" prop="status">
  225. <el-select
  226. v-model="formData.currentStep.status"
  227. filterable
  228. multiple
  229. allow-create
  230. default-first-option
  231. placeholder="请选择预置流转操作"
  232. style="width: 100%"
  233. :disabled="formData.currentStep.nodeType == 0"
  234. >
  235. <el-option
  236. v-for="item in dictData['processStatus']"
  237. :key="item.key"
  238. :label="item.name"
  239. :value="item.key"
  240. />
  241. </el-select>
  242. </el-form-item>
  243. <el-form-item label="截止时间:" prop="endTime">
  244. <el-date-picker
  245. v-model="formData.currentStep.endTime"
  246. type="date"
  247. placeholder="请选择截止时间"
  248. format="yyyy-MM-dd"
  249. value-format="yyyy-MM-dd"
  250. style="width: 100%"
  251. :disabled="isTimePickerDisabled"
  252. :picker-options="getPickerOptions(formData.currentStep)"
  253. ></el-date-picker>
  254. </el-form-item>
  255. </el-form>
  256. <div slot="footer" class="dialog-footer">
  257. <el-button
  258. type="primary"
  259. :loading="loading.save"
  260. @click="handleSaveStep('currentStepForm', 'list')"
  261. >
  262. 确认
  263. </el-button>
  264. <el-button @click="dialogs.stepDialogVisible = false">取消</el-button>
  265. </div>
  266. </el-dialog>
  267. </div>
  268. </template>
  269. <script>
  270. import { taskMixin } from '@/views/costAudit/projectInfo/auditTaskManage/taskCustomizedRelease/index.js'
  271. import {
  272. getCostProjectNodeTmpletePageList,
  273. saveProcess,
  274. } from '@/api/taskCustomizedRelease.js'
  275. import CostAuditTable from '@/components/costAudit/CostAuditTable.vue'
  276. export default {
  277. components: { CostAuditTable },
  278. mixins: [taskMixin],
  279. props: {
  280. project: {
  281. type: Object,
  282. default: () => {},
  283. },
  284. isView: {
  285. type: Boolean,
  286. default: false,
  287. },
  288. workflowData: {
  289. type: Object,
  290. default: () => {},
  291. },
  292. },
  293. data() {
  294. return {
  295. formData: {
  296. currentStepRules: {
  297. endTime: [
  298. { required: true, message: '请选择截止时间', trigger: 'change' },
  299. {
  300. validator: (rule, value, callback) => {
  301. if (
  302. !this.formData.workflow.plannedAuditStartDate ||
  303. !this.formData.workflow.plannedAuditEndDate
  304. ) {
  305. return callback()
  306. }
  307. if (value < this.formData.workflow.plannedAuditStartDate) {
  308. return callback(new Error('截止时间不能早于工作开始时间'))
  309. }
  310. if (value > this.formData.workflow.plannedAuditEndDate) {
  311. return callback(new Error('截止时间不能晚于工作结束时间'))
  312. }
  313. callback()
  314. },
  315. trigger: 'change',
  316. },
  317. ],
  318. },
  319. },
  320. // 内部工作流数据,避免直接修改 prop
  321. localWorkflowData: {
  322. list: [],
  323. stepList: [],
  324. pagination: {
  325. currentPage: 1,
  326. pageSize: 10,
  327. total: 0,
  328. },
  329. },
  330. }
  331. },
  332. computed: {
  333. // 合并外部 workflowData 和内部数据
  334. actualWorkflowData() {
  335. return {
  336. ...this.workflowData,
  337. list:
  338. this.localWorkflowData.list.length > 0
  339. ? this.localWorkflowData.list
  340. : this.workflowData.list || [],
  341. stepList:
  342. this.localWorkflowData.stepList.length > 0
  343. ? this.localWorkflowData.stepList
  344. : this.workflowData.stepList || [],
  345. pagination: {
  346. ...(this.workflowData.pagination || {}),
  347. ...this.localWorkflowData.pagination,
  348. },
  349. }
  350. },
  351. isTimePickerDisabled() {
  352. if (
  353. !this.formData.currentStep ||
  354. !this.formData.currentStep.processNodeKey
  355. ) {
  356. return false
  357. }
  358. const stepList =
  359. this.actualWorkflowData.list.length > 0
  360. ? this.actualWorkflowData.list
  361. : this.actualWorkflowData.stepList
  362. if (!stepList || stepList.length <= 1) {
  363. return false
  364. }
  365. const currentIndex = stepList.findIndex(
  366. (item) =>
  367. item.processNodeKey === this.formData.currentStep.processNodeKey
  368. )
  369. if (currentIndex <= 0) {
  370. return false
  371. }
  372. const prevStep = stepList[currentIndex - 1]
  373. return !prevStep.endTime
  374. },
  375. },
  376. watch: {
  377. // 监听 workflowData prop 变化,同步到内部数据
  378. workflowData: {
  379. handler(newVal) {
  380. if (newVal) {
  381. this.localWorkflowData.list = newVal.list || []
  382. this.localWorkflowData.stepList = newVal.stepList || []
  383. if (newVal.pagination) {
  384. this.localWorkflowData.pagination = {
  385. ...this.localWorkflowData.pagination,
  386. ...newVal.pagination,
  387. }
  388. }
  389. }
  390. },
  391. deep: true,
  392. immediate: true,
  393. },
  394. 'workflowData.stepList': {
  395. handler(newList) {
  396. if (newList && newList.length > 0) {
  397. }
  398. },
  399. deep: true,
  400. },
  401. },
  402. mounted() {
  403. this.getWorkflow()
  404. },
  405. methods: {
  406. formatterUserList(userId) {
  407. return this.formatterMainUserList().filter(
  408. (item) => item.userId !== userId
  409. )
  410. },
  411. formatterMainUserList() {
  412. if (!this.userList || !Array.isArray(this.userList)) {
  413. return []
  414. }
  415. if (
  416. !this.project ||
  417. !this.project.projectMembers ||
  418. typeof this.project.projectMembers !== 'string'
  419. ) {
  420. return this.userList
  421. }
  422. try {
  423. const projectMemberIds = this.project.projectMembers.split(',')
  424. const filteredUsers = this.userList.filter((item) =>
  425. projectMemberIds.includes(item.userId)
  426. )
  427. return filteredUsers
  428. } catch (error) {
  429. return this.userList
  430. }
  431. },
  432. getPickerOptions(row) {
  433. const stepList = this.actualWorkflowData.stepList
  434. const rowIndex = stepList.findIndex(
  435. (item) => item.processNodeKey === row.processNodeKey
  436. )
  437. let pickerOptions = {
  438. disabledDate: (time) => {
  439. const startLimit = this.formData.workflow.plannedAuditStartDate
  440. ? new Date(this.formData.workflow.plannedAuditStartDate).getTime()
  441. : null
  442. const endLimit = this.formData.workflow.plannedAuditEndDate
  443. ? new Date(this.formData.workflow.plannedAuditEndDate).getTime()
  444. : null
  445. if (startLimit && time.getTime() < startLimit - 8.64e7) {
  446. return true
  447. }
  448. if (endLimit && time.getTime() > endLimit) {
  449. return true
  450. }
  451. if (rowIndex > 0) {
  452. const prevStep = stepList[rowIndex - 1]
  453. if (prevStep && prevStep.endTime) {
  454. const prevEndTime = new Date(prevStep.endTime).getTime()
  455. if (time.getTime() <= prevEndTime - 8.64e7) {
  456. return true
  457. }
  458. }
  459. }
  460. return false
  461. },
  462. }
  463. return pickerOptions
  464. },
  465. handleSetWorkflow() {
  466. this.getUser()
  467. this.dialogs.setStepDialogVisible = true
  468. if (this.actualWorkflowData.list.length > 0) {
  469. this.localWorkflowData.stepList = this.actualWorkflowData.list.map(
  470. (item) => ({
  471. ...item,
  472. userId: item.userId ? item.userId.split(',') : [],
  473. status: item.status ? item.status.split(',') : [],
  474. })
  475. )
  476. this.notifyWorkflowDataUpdate()
  477. } else {
  478. getCostProjectNodeTmpletePageList({
  479. pageNum: this.actualWorkflowData.pagination.currentPage,
  480. pageSize: this.actualWorkflowData.pagination.pageSize,
  481. processId: '1',
  482. }).then((res) => {
  483. this.localWorkflowData.stepList = res.value.records.map((item) => ({
  484. ...item,
  485. userId: item.userId ? item.userId.split(',') : [],
  486. status: item.status ? item.status.split(',') : [],
  487. }))
  488. this.localWorkflowData.pagination.total = res.value.total
  489. this.notifyWorkflowDataUpdate()
  490. })
  491. }
  492. },
  493. // 通知父组件更新 workflowData
  494. notifyWorkflowDataUpdate() {
  495. this.$emit('update:workflowData', { ...this.actualWorkflowData })
  496. },
  497. handleSetStep(row) {
  498. this.getUser()
  499. this.formData.currentStep = {
  500. ...row,
  501. userId: row.userId ? row.userId.split(',') : [],
  502. status: row.status ? row.status.split(',') : [],
  503. }
  504. this.dialogs.stepDialogVisible = true
  505. this.loading.save = false
  506. this.$nextTick(() => {
  507. if (this.$refs.currentStepForm) {
  508. this.$refs.currentStepForm.clearValidate()
  509. }
  510. })
  511. },
  512. handleSaveStep(formName, type) {
  513. this.$refs[formName].validate((valid) => {
  514. if (valid) {
  515. if (type == 'list') {
  516. this.localWorkflowData.list = this.actualWorkflowData.list.map(
  517. (item) => {
  518. if (
  519. item.processNodeKey ==
  520. this.formData.currentStep.processNodeKey
  521. ) {
  522. return {
  523. ...item,
  524. ...this.formData.currentStep,
  525. userId: this.formData.currentStep.userId.join(','),
  526. status: this.formData.currentStep.status.join(','),
  527. }
  528. }
  529. return item
  530. }
  531. )
  532. this.notifyWorkflowDataUpdate()
  533. this.handleSaveSetStep('list')
  534. }
  535. } else {
  536. return false
  537. }
  538. })
  539. },
  540. handleSaveSetStep(type) {
  541. if (!this.formData.workflow.plannedAuditStartDate) {
  542. this.$message.error('请选择预定的监审工作开始日期')
  543. return
  544. }
  545. if (!this.formData.workflow.plannedAuditEndDate) {
  546. this.$message.error('请选择预定的监审工作结束日期')
  547. return
  548. }
  549. let stepList =
  550. type === 'list'
  551. ? this.actualWorkflowData.list
  552. : this.actualWorkflowData.stepList
  553. if (stepList && stepList.length > 1) {
  554. const sortedSteps = [...stepList].sort((a, b) => {
  555. return stepList.indexOf(a) - stepList.indexOf(b)
  556. })
  557. for (let i = 1; i < sortedSteps.length; i++) {
  558. const currentStep = sortedSteps[i]
  559. const prevStep = sortedSteps[i - 1]
  560. if (currentStep.endTime && prevStep.endTime) {
  561. if (new Date(currentStep.endTime) <= new Date(prevStep.endTime)) {
  562. this.$message.error(
  563. `第${i + 1}个环节的截止时间必须大于第${i}个环节的截止时间`
  564. )
  565. return
  566. }
  567. } else if (currentStep.endTime && !prevStep.endTime) {
  568. this.$message.error(`请先设置第${i}个环节的截止时间`)
  569. return
  570. } else if (!currentStep.endTime && prevStep.endTime) {
  571. this.$message.error(`请设置第${i + 1}个环节的截止时间`)
  572. return
  573. }
  574. }
  575. }
  576. this.loading.save = true
  577. let data = {
  578. nodeReqList: [
  579. {
  580. endTime: '',
  581. id: '',
  582. mainUserId: '',
  583. processNodeKey: '',
  584. status: '',
  585. userId: '',
  586. },
  587. ],
  588. plannedAuditEndDate: this.formData.workflow.plannedAuditEndDate,
  589. plannedAuditStartDate: this.formData.workflow.plannedAuditStartDate,
  590. processId: this.actualWorkflowData.detailInfo?.processId || '1',
  591. projectId: this.project.projectId,
  592. }
  593. if (type == 'list') {
  594. data.nodeReqList = this.actualWorkflowData.list
  595. } else {
  596. data.nodeReqList = this.actualWorkflowData.stepList.map((item) => {
  597. return {
  598. ...item,
  599. userId: item.userId.join(','),
  600. status: item.status.join(','),
  601. }
  602. })
  603. }
  604. saveProcess(data)
  605. .then((res) => {
  606. if (res.code === 200) {
  607. this.$message.success('保存成功')
  608. this.loading.save = false
  609. if (type == 'list') {
  610. this.dialogs.stepDialogVisible = false
  611. } else {
  612. this.dialogs.setStepDialogVisible = false
  613. }
  614. this.getWorkflow()
  615. }
  616. })
  617. .catch(() => {
  618. this.loading.save = false
  619. })
  620. },
  621. },
  622. }
  623. </script>
  624. <style scoped lang="scss">
  625. @import '@/styles/costAudit.scss';
  626. </style>