flow.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <hc-new-card>
  3. <template #header>
  4. <el-button hc-btn type="primary" @click="addFlowData">新建流程</el-button>
  5. </template>
  6. <template #extra>
  7. <el-alert :closable="false" title="同一合同段内,只需要设置重复岗位的流程即可,其他任务岗位,系统将自动推送,无需创建更多任务流" type="error" />
  8. </template>
  9. <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" is-new :index-style="{ width: 60 }">
  10. <template #action="{ row }">
  11. <el-link type="success" @click="handleTableEdit(row)">修改</el-link>
  12. <el-link type="danger" @click="handleTableDel(row)">删除</el-link>
  13. </template>
  14. </hc-table>
  15. <template #action>
  16. <hc-pages :pages="searchForm" @change="pageChange" />
  17. </template>
  18. <!-- 新增/编辑流程 弹框 -->
  19. <hc-new-dialog v-model="showEditModal" :title="`${flowFormData.id ? '编辑' : '新增'}流程`" widths="40rem">
  20. <el-form ref="formFlowRef" class="p-4" :model="flowFormData" :rules="formFlowRules" label-width="auto" size="large">
  21. <el-form-item label="流程名称" prop="fixedName">
  22. <el-input v-model="flowFormData.fixedName" placeholder="请输入流程名称" />
  23. </el-form-item>
  24. <el-form-item label="任务名称" prop="fixedBranchList">
  25. <hc-tasks-user :id="changeId" :contract-id="contractId" :project-id="projectId" :users="linkUserJoinString" ui="w-full" :is-show-task-name="true" :fixed-branch-list="flowFormData.fixedBranchList" @change="tasksUserChange" />
  26. </el-form-item>
  27. </el-form>
  28. <template #footer>
  29. <div class="dialog-footer">
  30. <el-button size="large" @click="showEditModal = false">取消</el-button>
  31. <el-button :loading="sevaLoading" hc-btn type="primary" @click="saveFormClick">保存</el-button>
  32. </div>
  33. </template>
  34. </hc-new-dialog>
  35. </hc-new-card>
  36. </template>
  37. <script setup>
  38. import { onActivated, onMounted, ref } from 'vue'
  39. import { useAppStore } from '~src/store'
  40. import { getArrValue, getObjValue } from 'js-fast-way'
  41. import tasksFlowApi from '~api/tasks/flow'
  42. import { delMessage } from '~uti/tools'
  43. //变量
  44. const store = useAppStore()
  45. const projectId = ref(store.getProjectId)
  46. const contractId = ref(store.getContractId)
  47. //渲染完成
  48. onActivated(() => {
  49. getTableData()
  50. })
  51. //搜索表单
  52. const searchForm = ref({ current: 1, size: 20, total: 0 })
  53. //分页
  54. const pageChange = ({ current, size }) => {
  55. searchForm.value.current = current
  56. searchForm.value.size = size
  57. }
  58. //表格数据
  59. const tableLoading = ref(false)
  60. const tableColumn = ref([
  61. { key: 'fixedFlowName', name: '流程名称' },
  62. { key: 'linkUserJoinString', name: '流程详情' },
  63. { key: 'action', name: '操作', width: 94 },
  64. ])
  65. const tableData = ref([])
  66. const getTableData = async () => {
  67. tableLoading.value = true
  68. const { error, code, data } = await tasksFlowApi.getPageData({
  69. projectId: projectId.value,
  70. contractId: contractId.value,
  71. ...searchForm.value,
  72. })
  73. //处理数据
  74. tableLoading.value = false
  75. if (!error && code === 200) {
  76. tableData.value = getArrValue(data['records'])
  77. searchForm.value.total = data.total || 0
  78. } else {
  79. tableData.value = []
  80. searchForm.value.total = 0
  81. }
  82. }
  83. //新建流程
  84. const addFlowData = () => {
  85. flowFormData.value = { id: '', fixedName: '', fixedBranchList: [] }
  86. linkUserJoinString.value = ''
  87. showEditModal.value = true
  88. }
  89. //编辑流程
  90. const linkUserJoinString = ref(null)
  91. const changeId = ref('')
  92. const handleTableEdit = async (row) => {
  93. changeId.value = row.id
  94. flowFormData.value = { id: '', fixedName: '', fixedBranchList: [] }
  95. showEditModal.value = true
  96. const { error, code, data } = await tasksFlowApi.queryFixedFlowDetail({ id: row?.id })
  97. if (!error && code === 200) {
  98. let users = '', res = getObjValue(data)
  99. const list = getArrValue(res['fixedBranchVOList'])
  100. const item = getObjValue(list[0])['userList']
  101. for (let index = 0; index < item.length; index++) {
  102. const element = item[index]
  103. if (users) {
  104. users += `,${element['userName']}-${element['userId']}`
  105. } else {
  106. users = `${element['userName']}-${element['userId']}`
  107. }
  108. console.log(users, 'users')
  109. }
  110. flowFormData.value = { id: res.fixedFlowId, fixedName: res.fixedFlowName, fixedBranchList:res.fixedBranchVOList }
  111. linkUserJoinString.value = users
  112. } else {
  113. flowFormData.value = { id: '', fixedName: '', fixedBranchList: [] }
  114. }
  115. }
  116. //新增编辑数据
  117. const showEditModal = ref(false)
  118. const formFlowRef = ref(null)
  119. const flowFormData = ref({ id: '', fixedName: '', fixedBranchList: [] })
  120. const formFlowRules = {
  121. fixedName: {
  122. required: true,
  123. trigger: 'blur',
  124. message: '请输入流程名称',
  125. },
  126. fixedBranchList: {
  127. required: true,
  128. trigger: 'blur',
  129. message: '请选择任务人',
  130. },
  131. }
  132. //任务人选择改变
  133. const tasksUserChange = ( fixedBranchList) => {
  134. flowFormData.value.fixedBranchList = fixedBranchList
  135. }
  136. //提交保存
  137. const sevaLoading = ref(false)
  138. const saveFormClick = async () => {
  139. const form = flowFormData.value
  140. console.log(form, 'form')
  141. const fixedBranchList = form.fixedBranchList
  142. fixedBranchList.forEach((ele)=>{
  143. delete ele.users
  144. })
  145. form.fixedBranchList = fixedBranchList
  146. if (!form.id) {
  147. sevaLoading.value = true
  148. const { error, code } = await tasksFlowApi.saveFixedFlow({
  149. ...form,
  150. projectId: projectId.value,
  151. contractId: contractId.value,
  152. })
  153. //处理数据
  154. sevaLoading.value = false
  155. if (!error && code === 200) {
  156. showEditModal.value = false
  157. window?.$message?.success('保存成功')
  158. getTableData().then()
  159. }
  160. } else {
  161. sevaLoading.value = true
  162. form.fixedFlowId = form.id
  163. delete form.id
  164. const { error, code } = await tasksFlowApi.updateFixedFlowData({
  165. ...form,
  166. projectId: projectId.value,
  167. contractId: contractId.value,
  168. })
  169. //处理数据
  170. sevaLoading.value = false
  171. if (!error && code === 200) {
  172. showEditModal.value = false
  173. window?.$message?.success('保存成功')
  174. getTableData().then()
  175. }
  176. }
  177. }
  178. //删除
  179. const handleTableDel = (row) => {
  180. delMessage(async () => {
  181. const { error, code } = await tasksFlowApi.removeFixedFlowData({
  182. id:row?.id || '',
  183. name: row?.fixedFlowName,
  184. })
  185. //处理数据
  186. if (!error && code === 200) {
  187. window.$message?.success('删除成功')
  188. getTableData().then()
  189. }
  190. })
  191. }
  192. </script>