You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

321 lines
10 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 顶部页签 -->
  4. <l-nav v-model="tab" :items="['表单信息', '流程信息']" type="flex" class="solid-bottom" />
  5. <!-- Tab #1:表单页 -->
  6. <view v-if="ready && tab === 0" class="form">
  7. <!-- 表单 -->
  8. <l-customform :initFormValue="formValue" :editMode="editMode" :scheme="scheme" rel="rel" ref="form" />
  9. <!-- 操作区按钮 -->
  10. <l-workflow-action
  11. @audit="audit"
  12. @action="action"
  13. :type="type"
  14. :currentNode="currentNode"
  15. :currentTask="currentTask"
  16. />
  17. </view>
  18. <!-- Tab #2:流程图页 -->
  19. <view v-if="ready && tab === 1" class="progress"><l-workflow-timeline :processList="processList" /></view>
  20. </view>
  21. </template>
  22. <script>
  23. import get from 'lodash/get'
  24. import pick from 'lodash/pick'
  25. import workflowFormMixins from '../workflow.js'
  26. export default {
  27. data() {
  28. return {
  29. tab: 0,
  30. editMode: false,
  31. type: 'view',
  32. ready: false,
  33. code: null,
  34. currentTask: null,
  35. taskId: null,
  36. processList: [],
  37. processId: null,
  38. processInfo: null,
  39. currentNode: null,
  40. scheme: [],
  41. formValue: {},
  42. rel: {}
  43. }
  44. },
  45. mixins: [workflowFormMixins],
  46. async onLoad({ type }) {
  47. await this.init(type)
  48. },
  49. // 小程序专有,分享任务到聊天
  50. // #ifdef MP
  51. onShareAppMessage() {
  52. const props = ['F_Id', 'F_Title', 'F_TaskId', 'F_ProcessId', 'F_IsStart', 'F_IsFinished', 'F_EnabledMark']
  53. const taskInfo = { ...pick(this.currentTask, props), mark: 'pre' }
  54. // 获取页面参数
  55. const queryString = this.MP_SHARE_ENCODE(taskInfo, { type: this.type })
  56. return {
  57. title: `${this.GET_GLOBAL('loginUser').realName}发起的${this.currentTask.F_Title}工作流程`,
  58. desc: '我发起了一个工作流程,快来看看吧',
  59. path: `pages/home?${queryString}`
  60. }
  61. },
  62. // #endif
  63. methods: {
  64. // 页面初始化
  65. async init(type = 'view') {
  66. // type 表示打开方式:view=查看普通流程,child=子流程,refer=审阅
  67. // 当前任务相关信息用 GET_PARAM 获取
  68. // 需要字段: F_Title、F_Id、F_TaskId、F_ProcessId、F_IsFinished、F_IsStart、F_EnabledMark
  69. // 需要字段: mark (是 my 或者不是,表示是否自「我的」列打开)
  70. this.type = type
  71. this.currentTask = this.GET_PARAM()
  72. this.LOADING('加载表单中…')
  73. this.SET_TITLE(this.currentTask.F_Title)
  74. // 未完成的子流程,可以编辑
  75. if (get(this.currentTask, 'mark') !== 'maked' && this.type === 'child') {
  76. this.editMode = true
  77. }
  78. // 获得流程信息
  79. this.processId = this.currentTask.F_Id
  80. this.taskId = this.currentTask.F_TaskId
  81. this.processInfo = await this.fetchProcessInfo({
  82. processId: this.processId,
  83. taskId: this.taskId
  84. })
  85. this.currentNode = this.getCurrentNode(this.processInfo)
  86. this.processList = get(this.processInfo, 'info.TaskLogList', [])
  87. // wfForms 的数组成员 t,表示表单数据项(TAB页)
  88. // t.formId 使用表单,根据这个 formId 来获取 scheme 等信息
  89. // t.appurl 使用移动页面,直接跳转到本地的页面;表单结构等均写死在页面里
  90. const { wfForms } = this.currentNode
  91. // 处理没有有效表单的情况,停止加载
  92. if (!wfForms || wfForms.every(t => !t.formId && !t.appurl)) {
  93. this.HIDE_LOADING()
  94. this.TOAST('移动表单数据(wfForms)中无有效表单')
  95. return
  96. }
  97. // 处理移动端本地表单(也就是系统表单)的情况,直接跳转过去
  98. const appSysPage = wfForms.find(t => t.appurl)
  99. if (this.type !== 'child' && appSysPage) {
  100. this.sysFormJump(appSysPage.appurl, {
  101. currentNode: this.currentNode,
  102. currentTask: this.currentTask,
  103. logList: this.processList
  104. })
  105. return
  106. }
  107. if (this.type === 'child') {
  108. // 发起子流程的场合
  109. // 获取子流程的流程信息,提取出时间线和表单模板 code
  110. const childProcessInfo = await this.fetchProcessInfo({ processId: this.processId })
  111. this.processList = get(childProcessInfo, 'info.TaskLogList', [])
  112. this.code = this.currentNode.childFlow
  113. // 提取出子流程 Id;因为是发起新的流程,所以 processInfo 只传入表单模板 code
  114. const childProcessId = this.processInfo.info.childProcessId
  115. const childCurrentNode = this.getCurrentNode(await this.fetchProcessInfo({ code: this.code }))
  116. // 处理系统表单跳转,使用子流程相关信息
  117. if (appSysPage) {
  118. this.sysFormJump(appSysPage.appurl, {
  119. currentNode: this.currentNode,
  120. currentTask: this.currentTask,
  121. parentProcessId: this.processId,
  122. logList: this.processList
  123. })
  124. return
  125. }
  126. const schemeData = await this.fetchSchemeData(childCurrentNode)
  127. const formData = await this.fetchFormData(childCurrentNode, childProcessId)
  128. const { formValue, scheme, rel, options } = await this.getCustomForm({
  129. formData,
  130. schemeData,
  131. currentNode: childCurrentNode,
  132. processId: childProcessId,
  133. code: this.code,
  134. useDefault: true
  135. })
  136. this.scheme = scheme
  137. this.formValue = formValue
  138. this.rel = rel
  139. } else {
  140. // 不是子流程,可以直接渲染
  141. const schemeData = await this.fetchSchemeData(this.currentNode)
  142. const formData = await this.fetchFormData(this.currentNode, this.processId)
  143. const { formValue, scheme, rel } = await this.getCustomForm({
  144. formData,
  145. schemeData,
  146. currentNode: this.currentNode,
  147. processId: this.processId,
  148. code: null
  149. })
  150. this.scheme = scheme
  151. this.formValue = formValue
  152. this.rel = rel
  153. }
  154. this.ready = true
  155. this.HIDE_LOADING()
  156. },
  157. // 跳转到系统表单页面
  158. sysFormJump(url, param) {
  159. this.HIDE_LOADING()
  160. this.TOAST('跳转至移动端本地表单(即系统表单)')
  161. let pagePath = url || ''
  162. if (!pagePath.startsWith('/pages')) {
  163. pagePath = '/pages' + pagePath
  164. }
  165. this.JUMP_TO(`${pagePath}?type=${this.type}`, param, true)
  166. },
  167. // 点击操作按钮(非审批类按钮)
  168. async atcion(taskType) {
  169. switch (actionType) {
  170. // 点击「催办」/「撤销流程」/「标记已阅」按钮
  171. case 'urge':
  172. case 'revoke':
  173. case 'refer':
  174. const actionText = { urge: '催办', revoke: '撤销', refer: '已阅' }[actionType]
  175. const actionUrl = { urge: '/urge', revoke: '/revoke', refer: '/refer' }[actionType]
  176. let actionData = this.processId
  177. if (actionType === 'refer') {
  178. actionData = { processId: this.processId, taskId: this.taskId }
  179. }
  180. if (!(await this.CONFIRM(`${actionText}确认`, `确定要提交${actionText}吗?`, true))) {
  181. return
  182. }
  183. this.LOADING(`提交${actionText}中…`)
  184. this.HTTP_POST(`/newwf${actionUrl}`, actionData, `提交${actionText}失败`).then(success => {
  185. this.HIDE_LOADING()
  186. if (success) {
  187. this.EMIT('task-list-change')
  188. this.TOAST(`成功提交${actionText}`, 'success')
  189. if (actionType === 'revoke') {
  190. this.NAV_BACK()
  191. }
  192. }
  193. })
  194. break
  195. // 点击「提交草稿」按钮
  196. case 'draft':
  197. if (!(await this.CONFIRM('提交确认', '确定要提交草稿吗?', true))) {
  198. return
  199. }
  200. this.LOADING('正在提交…')
  201. const draftFormValue = this.$refs.form.getFormValue()
  202. const draftPostData = await this.getPostData(draftFormValue, this.scheme)
  203. this.HTTP_POST('/newwf​/draft', draftPostData, '提交草稿失败').then(success => {
  204. this.HIDE_LOADING()
  205. if (success) {
  206. this.EMIT('task-list-change')
  207. this.NAV_BACK()
  208. this.TOAST('草稿已保存', 'success')
  209. }
  210. })
  211. break
  212. // 点击「发起流程」按钮
  213. case 'submit':
  214. const verifyResult = this.$refs.form.verifyValue()
  215. if (verifyResult.length > 0) {
  216. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  217. return
  218. }
  219. if (!(await this.CONFIRM('提交确认', '确定要发起流程吗?', true))) {
  220. return
  221. }
  222. this.LOADING('正在提交…')
  223. const formValue = this.$refs.form.getFormValue()
  224. const postData = await this.getPostData(formValue, this.scheme)
  225. postData.auditors = JSON.stringify({})
  226. if (this.type === 'child') {
  227. postData.parentProcessId = this.processId
  228. postData.parentTaskId = this.taskId
  229. }
  230. const errorTips = '流程发起失败'
  231. this.HTTP_POST('/newwf/createchildflow', postData, errorTips).then(success => {
  232. this.HIDE_LOADING()
  233. if (success) {
  234. this.EMIT('task-list-change')
  235. this.NAV_BACK()
  236. this.TOAST('流程发起成功', 'success')
  237. }
  238. })
  239. break
  240. default:
  241. break
  242. }
  243. },
  244. // 点击审批相关按钮
  245. async audit(action) {
  246. this.LOADING('加载中…')
  247. const currentTask = this.processInfo.task.find(t => t.F_NodeId === this.currentNode.id)
  248. const postData = await this.getPostData(this.formValue, this.scheme)
  249. const pageParam = {
  250. type: 'sign',
  251. processId: currentTask.F_ProcessId,
  252. taskId: currentTask.F_Id,
  253. formreq: postData.formreq,
  254. taskName: this.currentTask.F_Title
  255. }
  256. // 不是加签
  257. if (action.code !== '__sign__') {
  258. Object.assign(pageParam, action)
  259. pageParam.type = 'verify'
  260. pageParam.auditors = JSON.stringify({})
  261. pageParam.isFromSignAudit = Number(this.currentTask.F_TaskType) === 3
  262. }
  263. this.HIDE_LOADING()
  264. this.NAV_TO('./sign', pageParam, true)
  265. }
  266. }
  267. }
  268. </script>