您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

204 行
6.7 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 表单 -->
  4. <l-customform v-if="ready" :initFormValue="formValue" :scheme="scheme" :rel="rel" ref="form" />
  5. <!-- 设置标题和优先级 -->
  6. <view v-if="ready && type !== 'again'">
  7. <view style="height:15px"></view>
  8. <l-input v-if="needTitle" v-model="title" title="流程标题" placeholder="请为流程设置一个标题" required />
  9. <l-select v-model="level" :range="levelRange" title="流程优先级" placeholder="请选择一个优先级" required />
  10. </view>
  11. <!-- 发起流程/重新发起流程按钮 -->
  12. <view v-if="ready" class="padding margin-top bg-white" style="padding-top: 0; overflow: hidden;">
  13. <l-button v-if="type !== 'again'" @click="draft" size="lg" color="orange" class="block margin-top" block>
  14. 保存草稿
  15. </l-button>
  16. <l-button @click="submit" size="lg" color="green" class="block margin-top" block>
  17. {{ type === 'again' ? `重新发起流程` : `发起流程` }}
  18. </l-button>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import get from 'lodash/get'
  24. import workflowFormMixins from '../workflow.js'
  25. export default {
  26. mixins: [workflowFormMixins],
  27. data() {
  28. return {
  29. ready: false,
  30. type: 'create',
  31. code: null,
  32. processId: '',
  33. formValue: {},
  34. scheme: [],
  35. rel: {},
  36. level: '0',
  37. levelRange: [{ value: '0', text: '普通' }, { value: '1', text: '重要' }, { value: '2', text: '紧急' }],
  38. title: '',
  39. needTitle: false
  40. }
  41. },
  42. async onLoad({ type }) {
  43. await this.init(type)
  44. },
  45. methods: {
  46. // 初始化页面
  47. async init(type = 'create') {
  48. // type 表示打开页面的方式,create=新建,draft=编辑草稿,again=重新发起
  49. // 新建的场合最简单,直接渲染出空的表单即可;
  50. // 重新发起流程/编辑草稿的场合,比新建多出一个拉取表单已经输入的内容的步骤,把内容填充到表单中;
  51. this.LOADING('加载表单中…')
  52. this.type = type
  53. const currentTask = this.GET_PARAM()
  54. const { F_Code: code, F_Id: pid } = currentTask
  55. // 设置页面标题
  56. const title = {
  57. create: `创建[${currentTask.F_Name}]流程`,
  58. draft: `编辑[${currentTask.F_Title || currentTask.F_SchemeName}]流程草稿`,
  59. again: `重新发起[${currentTask.F_Title}]流程`
  60. }[this.type]
  61. this.SET_TITLE(title)
  62. // 拉取流程信息,提取出当前节点;如果是新建表单则生成 processId
  63. const processId = this.type === 'create' ? this.GUID('-') : pid
  64. const processInfo = await this.fetchProcessInfo({ code, processId: this.type === 'create' ? null : processId })
  65. const currentNode = this.getCurrentNode(processInfo)
  66. // wfForms 的数组成员 t,表示表单数据项(TAB页),t.type 表示类别,注意它是字符串型,用 Number(t.type) 转换
  67. // 为 1 则使用工作流表单,依据它的 .formId
  68. // 不为 1 则使用系统表单,依据它的 .appurl
  69. const { wfForms } = currentNode
  70. // 处理没有有效表单的情况,停止加载
  71. if (!wfForms || wfForms.length <= 0) {
  72. this.HIDE_LOADING()
  73. this.TOAST('移动表单数据(wfForms)中无有效表单')
  74. return
  75. }
  76. // 处理移动端本地表单(也就是系统表单)的情况,直接跳转过去
  77. const appSysPage = wfForms.find(t => Number(t.type) !== 1)
  78. if (appSysPage) {
  79. this.HIDE_LOADING()
  80. this.TOAST('跳转至移动端本地表单(即系统表单)')
  81. let pagePath = appSysPage.appurl || ''
  82. if (!pagePath.startsWith('/pages')) {
  83. pagePath = '/pages' + pagePath
  84. }
  85. this.JUMP_TO(
  86. `${pagePath}?type=${this.type}`,
  87. { currentNode, currentTask, logList: get(processInfo, 'info.TaskLogList', []) },
  88. true
  89. )
  90. return
  91. }
  92. this.needTitle = this.type !== 'again' && Number(currentNode.isTitle) === 1
  93. const formData = await this.fetchFormData(currentNode, processId)
  94. const schemeData = await this.fetchSchemeData(currentNode)
  95. const { formValue, scheme, rel } = await this.getCustomForm({
  96. schemeData,
  97. processId,
  98. formData,
  99. currentNode: currentNode,
  100. code: this.type === 'again' ? null : code,
  101. useDefault: true
  102. })
  103. this.rel = rel
  104. this.scheme = scheme
  105. this.formValue = formValue
  106. this.code = code
  107. this.processId = processId
  108. this.ready = true
  109. this.HIDE_LOADING()
  110. },
  111. // 提交草稿按钮
  112. async draft() {
  113. if (!(await this.CONFIRM('提交确认', '确定要提交草稿吗?', true))) {
  114. return
  115. }
  116. this.LOADING('正在提交…')
  117. const formValue = this.$refs.form.getFormValue()
  118. const postData = await this.getPostData(formValue, this.scheme)
  119. this.HTTP_POST('learun/adms/newwf/draft', postData, '提交草稿时发生失败,未能成功保存').then(success => {
  120. this.HIDE_LOADING()
  121. if (!success) {
  122. return
  123. }
  124. this.EMIT('task-list-change')
  125. this.NAV_BACK()
  126. this.TOAST('草稿已保存', 'success')
  127. })
  128. },
  129. // 发起流程按钮
  130. async submit() {
  131. const isAgain = this.type === 'again'
  132. // 先验证表单,验证不通过则提示
  133. const verifyResult = this.verifyValue()
  134. if (verifyResult.length > 0) {
  135. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  136. return
  137. }
  138. if (!(await this.CONFIRM('提交确认', `确定要${isAgain ? '重新' : ''}发起流程吗?`, true))) {
  139. return
  140. }
  141. this.LOADING('正在提交…')
  142. const formValue = this.$refs.form.getFormValue()
  143. const postData = await this.getPostData(formValue, this.scheme)
  144. if (this.needTitle) {
  145. postData.title = this.title
  146. }
  147. postData.level = this.level
  148. postData.auditors = JSON.stringify({})
  149. const url = isAgain ? 'learun/adms/newwf/againcreate' : 'learun/adms/newwf/create'
  150. const tips = `流程${isAgain ? '重新' : ''}发起失败`
  151. this.HTTP_POST(url, postData, tips).then(success => {
  152. this.HIDE_LOADING()
  153. if (!success) {
  154. return
  155. }
  156. this.EMIT('task-list-change')
  157. this.NAV_BACK()
  158. this.TOAST(`流程${isAgain ? '重新' : ''}发起成功`, 'success')
  159. })
  160. },
  161. // 获取表单验证结果,是一个包含错误信息的数组,长度为 0 则没有错误
  162. verifyValue() {
  163. const errList = this.$refs.form.verifyValue()
  164. if (this.needTitle && !this.title) {
  165. errList.push(`流程的标题不能为空`)
  166. }
  167. return errList
  168. }
  169. }
  170. }
  171. </script>