Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

203 linhas
6.7 KiB

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