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.
 
 
 
 
 
 

313 lines
11 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. console.log(this.type,this.currentTask);
  73. this.LOADING('加载表单中…')
  74. this.SET_TITLE(this.currentTask.F_Title)
  75. // 未完成的子流程,可以编辑
  76. if (get(this.currentTask, 'mark') !== 'maked' && this.type === 'child') {
  77. this.editMode = true
  78. }
  79. // 如果是代办任务是可编辑的
  80. if (get(this.currentTask, 'mark') === 'pre' ) {
  81. this.editMode = true
  82. }
  83. // 获得流程信息
  84. this.processId = this.currentTask.F_Id
  85. this.taskId = this.currentTask.F_TaskId
  86. this.processInfo = await this.fetchProcessInfo({
  87. processId: this.processId,
  88. taskId: this.taskId
  89. })
  90. console.log(this.processInfo)
  91. this.currentNode = this.getCurrentNode(this.processInfo)
  92. console.log(this.currentNode)
  93. this.processList = get(this.processInfo, 'info.TaskLogList', [])
  94. console.log(this.processList)
  95. // wfForms 的数组成员 t,表示表单数据项(TAB页)
  96. // t.formId 使用表单,根据这个 formId 来获取 scheme 等信息
  97. // t.appurl 使用移动页面,直接跳转到本地的页面;表单结构等均写死在页面里
  98. const { wfForms } = this.currentNode
  99. console.log(wfForms);
  100. // 处理没有有效表单的情况,停止加载
  101. //if (!wfForms || wfForms.every(t => !t.formId && !t.appurl)) {
  102. //this.HIDE_LOADING()
  103. //this.TOAST('移动表单数据(wfForms)中无有效表单')
  104. //return
  105. //}
  106. //2022-02-14修改
  107. if (this.type !== 'child') {
  108. if (!wfForms || wfForms.every(t => !t.formId && !t.appurl)) {
  109. this.HIDE_LOADING()
  110. this.TOAST('移动表单数据(wfForms)中无有效表单')
  111. //return
  112. }
  113. }
  114. //2022-02-14修改end
  115. // 处理移动端本地表单(也就是系统表单)的情况,直接跳转过去
  116. //const appSysPage = wfForms.find(t => t.appurl)
  117. //2022-02-14修改
  118. var appSysPage = null
  119. if(wfForms && wfForms.every(t => t.formId && t.appurl)){
  120. appSysPage = wfForms.find(t => t.appurl)
  121. }
  122. //2022-02-14修改end
  123. if (this.type !== 'child' && appSysPage) {
  124. this.sysFormJump(appSysPage.appurl, {
  125. currentNode: this.currentNode,
  126. currentTask: this.currentTask,
  127. logList: this.processList
  128. })
  129. return
  130. }
  131. if (this.type === 'child') {
  132. // 发起子流程的场合
  133. // 获取子流程的流程信息,提取出时间线和表单模板 code
  134. const childProcessInfo = await this.fetchProcessInfo({ processId: this.processId })
  135. this.processList = get(childProcessInfo, 'info.TaskLogList', [])
  136. this.code = this.currentNode.childFlow
  137. // 提取出子流程 Id;因为是发起新的流程,所以 processInfo 只传入表单模板 code
  138. const childProcessId = this.processInfo.info.childProcessId
  139. const childCurrentNode = this.getCurrentNode(await this.fetchProcessInfo({ code: this.code }))
  140. // 处理系统表单跳转,使用子流程相关信息
  141. if (appSysPage) {
  142. this.sysFormJump(appSysPage.appurl, {
  143. currentNode: this.currentNode,
  144. currentTask: this.currentTask,
  145. parentProcessId: this.processId,
  146. logList: this.processList
  147. })
  148. return
  149. }
  150. const schemeData = await this.fetchSchemeData(childCurrentNode)
  151. const formData = await this.fetchFormData(childCurrentNode, childProcessId)
  152. const { formValue, scheme, rel, options } = await this.getCustomForm({
  153. formData,
  154. schemeData,
  155. currentNode: childCurrentNode,
  156. processId: childProcessId,
  157. code: this.code,
  158. useDefault: true
  159. })
  160. this.scheme = scheme
  161. this.formValue = formValue
  162. this.rel = rel
  163. } else {
  164. // 不是子流程,可以直接渲染
  165. const schemeData = await this.fetchSchemeData(this.currentNode)
  166. const formData = await this.fetchFormData(this.currentNode, this.processId)
  167. console.log(schemeData)
  168. console.log(formData)
  169. const { formValue, scheme, rel } = await this.getCustomForm({
  170. formData,
  171. schemeData,
  172. currentNode: this.currentNode,
  173. processId: this.processId,
  174. code: null
  175. })
  176. this.scheme = scheme
  177. console.log(scheme)
  178. this.formValue = formValue
  179. this.rel = rel
  180. }
  181. this.ready = true
  182. this.HIDE_LOADING()
  183. },
  184. // 跳转到系统表单页面
  185. sysFormJump(url, param) {
  186. this.HIDE_LOADING()
  187. this.TOAST('跳转至移动端本地表单(即系统表单)')
  188. let pagePath = url || ''
  189. if (!pagePath.startsWith('/pages')) {
  190. pagePath = '/pages' + pagePath
  191. }
  192. this.JUMP_TO(`${pagePath}?type=${this.type}`, param, true)
  193. },
  194. // 点击操作按钮(非审批类按钮)
  195. async action(taskType) {
  196. switch (taskType) {
  197. // 点击「催办」/「撤销流程」/「标记已阅」按钮
  198. case 'urge':
  199. case 'revoke':
  200. case 'refer':
  201. const actionText = { urge: '催办', revoke: '撤销', refer: '已阅' }[taskType]
  202. const actionUrl = { urge: '/urge', revoke: '/revoke', refer: '/refer' }[taskType]
  203. let actionData = this.processId
  204. if (taskType === 'refer') {
  205. actionData = { processId: this.processId, taskId: this.taskId }
  206. }
  207. if (!(await this.CONFIRM(`${actionText}确认`, `确定要提交${actionText}吗?`, true))) {
  208. return
  209. }
  210. this.LOADING(`提交${actionText}中…`)
  211. this.HTTP_POST(`/learun/adms/newwf${actionUrl}`, actionData, `提交${actionText}失败`).then(success => {
  212. this.HIDE_LOADING()
  213. if (success) {
  214. this.EMIT('task-list-change')
  215. this.TOAST(`成功提交${actionText}`, 'success')
  216. if (taskType === 'revoke') {
  217. this.NAV_BACK()
  218. }
  219. }
  220. })
  221. break
  222. // 点击「提交草稿」按钮
  223. case 'draft':
  224. if (!(await this.CONFIRM('提交确认', '确定要提交草稿吗?', true))) {
  225. return
  226. }
  227. this.LOADING('正在提交…')
  228. const draftFormValue = this.$refs.form.getFormValue()
  229. const draftPostData = await this.getPostData(draftFormValue, this.scheme)
  230. this.HTTP_POST('learun/adms/newwf/draft', draftPostData, '提交草稿失败').then(success => {
  231. this.HIDE_LOADING()
  232. if (success) {
  233. this.EMIT('task-list-change')
  234. this.NAV_BACK()
  235. this.TOAST('草稿已保存', 'success')
  236. }
  237. })
  238. break
  239. // 点击「发起流程」按钮
  240. case 'submit':
  241. const verifyResult = this.$refs.form.verifyValue()
  242. if (verifyResult.length > 0) {
  243. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  244. return
  245. }
  246. if (!(await this.CONFIRM('提交确认', '确定要发起流程吗?', true))) {
  247. return
  248. }
  249. this.LOADING('正在提交…')
  250. const formValue = this.$refs.form.getFormValue()
  251. const postData = await this.getPostData(formValue, this.scheme)
  252. postData.auditors = JSON.stringify({})
  253. if (this.type === 'child') {
  254. postData.parentProcessId = this.processId
  255. postData.parentTaskId = this.taskId
  256. }
  257. const errorTips = '流程发起失败'
  258. this.HTTP_POST('learun/adms/newwf/childcreate', postData, errorTips).then(success => {
  259. this.HIDE_LOADING()
  260. if (success) {
  261. this.EMIT('task-list-change')
  262. this.NAV_BACK()
  263. this.TOAST('流程发起成功', 'success')
  264. }
  265. })
  266. break
  267. default:
  268. break
  269. }
  270. },
  271. // 点击审批相关按钮
  272. async audit(action) {
  273. this.LOADING('加载中…')
  274. const currentTask = this.processInfo.task.find(t => t.F_NodeId === this.currentNode.id)
  275. const postData = await this.getPostData(this.formValue, this.scheme)
  276. const pageParam = {
  277. type: 'sign',
  278. processId: currentTask.F_ProcessId,
  279. taskId: currentTask.F_Id,
  280. formreq: postData.formreq,
  281. taskName: this.currentTask.F_Title
  282. }
  283. // 不是加签
  284. if (action.code !== '__sign__') {
  285. Object.assign(pageParam, action)
  286. pageParam.type = 'verify'
  287. pageParam.auditors = JSON.stringify({})
  288. pageParam.isFromSignAudit = Number(this.currentTask.F_TaskType) === 3
  289. }
  290. this.HIDE_LOADING()
  291. this.NAV_TO('./sign', pageParam, true)
  292. }
  293. }
  294. }
  295. </script>