flow.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="hc-layout-box">
  3. <HcCard :scrollbar="false" action-size="lg">
  4. <template #header>
  5. <HcTooltip keys="tasks_flow_add">
  6. <el-button hc-btn type="primary" @click="addFlowData">
  7. <HcIcon name="add-circle" />
  8. <span>新建流程</span>
  9. </el-button>
  10. </HcTooltip>
  11. </template>
  12. <template #extra>
  13. <el-alert
  14. :closable="false"
  15. title="同一合同段内,只需要设置重复岗位的流程即可,其他任务岗位,系统将自动推送,无需创建更多任务流" type="error"
  16. />
  17. </template>
  18. <HcTable :column="tableListColumn" :datas="tableListData" :loading="tableLoading" border>
  19. <template #action="{ row }">
  20. <HcTooltip keys="tasks_flow_edit">
  21. <el-button plain size="small" type="primary" @click="handleTableEdit(row)">编辑</el-button>
  22. </HcTooltip>
  23. <HcTooltip keys="tasks_flow_del">
  24. <el-button plain size="small" type="danger" @click="handleTableDel(row)">删除</el-button>
  25. </HcTooltip>
  26. </template>
  27. </HcTable>
  28. <template #action>
  29. <HcPages :pages="searchForm" @change="pageChange" />
  30. </template>
  31. </HcCard>
  32. <!-- 新增/编辑流程 弹框 -->
  33. <el-dialog
  34. v-model="showEditModal" :title="`${flowFormData.id ? '编辑' : '新增'}流程`" class="hc-modal-border"
  35. width="47rem"
  36. >
  37. <el-form ref="formFlowRef" :model="flowFormData" :rules="formFlowRules" label-width="auto" size="large">
  38. <el-form-item label="流程名称" prop="fixedFlowName">
  39. <el-input v-model="flowFormData.fixedFlowName" placeholder="请输入流程名称" />
  40. </el-form-item>
  41. <el-form-item label="任务人" prop="linkUserJoinString">
  42. <HcTasksUser
  43. :contract-id="contractId" :project-id="projectId" :users="flowFormData.linkUserJoinString"
  44. ui="w-full" @change="tasksUserChange"
  45. />
  46. </el-form-item>
  47. </el-form>
  48. <template #footer>
  49. <div class="dialog-footer">
  50. <el-button size="large" @click="showEditModal = false">取消</el-button>
  51. <el-button :loading="sevaLoading" hc-btn type="primary" @click="saveFormClick">保存</el-button>
  52. </div>
  53. </template>
  54. </el-dialog>
  55. </div>
  56. </template>
  57. <script setup>
  58. import { onMounted, ref } from 'vue'
  59. import { useAppStore } from '~src/store'
  60. import { getArrValue, getObjValue } from 'js-fast-way'
  61. import tasksFlowApi from '~api/tasks/flow'
  62. import { delMessageV2 } from '~com/message/index.js'
  63. //变量
  64. const useAppState = useAppStore()
  65. const projectId = ref(useAppState.getProjectId)
  66. const contractId = ref(useAppState.getContractId)
  67. //渲染完成
  68. onMounted(() => {
  69. getTableData()
  70. })
  71. //搜索表单
  72. const searchForm = ref({ current: 1, size: 20, total: 0 })
  73. //分页被点击
  74. const pageChange = ({ current, size }) => {
  75. searchForm.value.current = current
  76. searchForm.value.size = size
  77. getTableData()
  78. }
  79. //获取数据
  80. const tableLoading = ref(false)
  81. const tableListData = ref([])
  82. const tableListColumn = ref([
  83. { key: 'fixedFlowName', name: '流程名称' },
  84. { key: 'linkUserJoinString', name: '流程详情' },
  85. { key: 'action', name: '操作', width: '200', align: 'center' },
  86. ])
  87. const getTableData = async () => {
  88. tableLoading.value = true
  89. const { error, code, data } = await tasksFlowApi.getPageData({
  90. projectId: projectId.value,
  91. contractId: contractId.value,
  92. ...searchForm.value,
  93. })
  94. //处理数据
  95. tableLoading.value = false
  96. if (!error && code === 200) {
  97. tableListData.value = getArrValue(data['records'])
  98. searchForm.value.total = data.total || 0
  99. } else {
  100. tableListData.value = []
  101. searchForm.value.total = 0
  102. }
  103. }
  104. //新增编辑数据
  105. const showEditModal = ref(false)
  106. const formFlowRef = ref(null)
  107. const flowFormData = ref({ id: '', fixedFlowName: '', linkUserJoinString: '' })
  108. const formFlowRules = {
  109. fixedFlowName: {
  110. required: true,
  111. trigger: 'blur',
  112. message: '请输入流程名称',
  113. },
  114. linkUserJoinString: {
  115. required: true,
  116. trigger: 'blur',
  117. message: '请选择任务人',
  118. },
  119. }
  120. //任务人选择改变
  121. const tasksUserChange = (a, b, users) => {
  122. flowFormData.value.linkUserJoinString = users
  123. }
  124. //新建流程
  125. const addFlowData = () => {
  126. flowFormData.value = { id: '', fixedFlowName: '', linkUserJoinString: '' }
  127. showEditModal.value = true
  128. }
  129. //编辑流程
  130. const handleTableEdit = async (row) => {
  131. flowFormData.value = { id: '', fixedFlowName: '', linkUserJoinString: '' }
  132. showEditModal.value = true
  133. const { error, code, data } = await tasksFlowApi.queryFixedFlowDetail({
  134. id: row?.id,
  135. })
  136. if (!error && code === 200) {
  137. let users = '', res = getObjValue(data)
  138. const list = getArrValue(res['fixedFlowLinkList'])
  139. for (let i = 0; i < list.length; i++) {
  140. const item = getObjValue(list[i])
  141. if (users) {
  142. users += `,${item['fixedFlowLinkUserName']}-${item['fixedFlowLinkUser']}`
  143. } else {
  144. users = `${item['fixedFlowLinkUserName']}-${item['fixedFlowLinkUser']}`
  145. }
  146. }
  147. flowFormData.value = { id: res.id, fixedFlowName: res.fixedFlowName, linkUserJoinString: users }
  148. } else {
  149. flowFormData.value = { id: '', fixedFlowName: '', linkUserJoinString: '' }
  150. }
  151. }
  152. //提交保存
  153. const sevaLoading = ref(false)
  154. const saveFormClick = async () => {
  155. const form = flowFormData.value
  156. if (!form.id) {
  157. sevaLoading.value = true
  158. const { error, code } = await tasksFlowApi.addFixedFlowData({
  159. ...form,
  160. projectId: projectId.value,
  161. contractId: contractId.value,
  162. })
  163. //处理数据
  164. sevaLoading.value = false
  165. if (!error && code === 200) {
  166. showEditModal.value = false
  167. window?.$message?.success('保存成功')
  168. getTableData()
  169. }
  170. } else {
  171. sevaLoading.value = true
  172. const { error, code } = await tasksFlowApi.updateFixedFlowData({
  173. ...form,
  174. projectId: projectId.value,
  175. contractId: contractId.value,
  176. })
  177. //处理数据
  178. sevaLoading.value = false
  179. if (!error && code === 200) {
  180. showEditModal.value = false
  181. window?.$message?.success('保存成功')
  182. getTableData()
  183. }
  184. }
  185. }
  186. //删除
  187. const handleTableDel = (row) => {
  188. delMessageV2(async (action, instance, done) => {
  189. if (action === 'confirm') {
  190. instance.confirmButtonLoading = true
  191. removeFixedFlowData(row)
  192. instance.confirmButtonLoading = false
  193. done()
  194. } else {
  195. done()
  196. }
  197. })
  198. }
  199. //确认删除
  200. const removeFixedFlowData = async (row) => {
  201. const { error, code } = await tasksFlowApi.removeFixedFlowData({
  202. ids: row?.id || '',
  203. projectId: projectId.value,
  204. contractId: contractId.value,
  205. })
  206. //处理数据
  207. if (!error && code === 200) {
  208. window.$message?.success('删除成功')
  209. getTableData()
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .hc-layout-box {
  215. position: relative;
  216. height: 100%;
  217. }
  218. </style>