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.

single.vue 10 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. <l-modal v-model="modal" @close="reviewer = ''" title="指派审核人">
  13. <l-checkbox-picker @input="(e)=>{reviewer = e}" :value="reviewer" :readonly="false" :range="reviewerList"
  14. required title="审核人" />
  15. <l-button @click="userAssign" color="blue" class="block" block>确定指派</l-button>
  16. <l-button @click="()=>{modal = false;reviewer = ''}" line="blue" class="block margin-top-sm" block>取消</l-button>
  17. </l-modal>
  18. <!-- 发起流程/重新发起流程按钮 -->
  19. <view v-if="ready" class="padding margin-top bg-white" style="padding-top: 0; overflow: hidden;">
  20. <l-button v-if="type !== 'again'" @click="draft" size="lg" color="orange" class="block margin-top" block>
  21. 保存草稿
  22. </l-button>
  23. <l-button @click="submit" size="lg" color="green" class="block margin-top" block>
  24. {{ type === 'again' ? `重新发起流程` : `发起流程` }}
  25. </l-button>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import get from 'lodash/get'
  31. import workflowFormMixins from '../workflow.js'
  32. export default {
  33. mixins: [workflowFormMixins],
  34. data() {
  35. return {
  36. ready: false,
  37. type: 'create',
  38. code: null,
  39. processId: '',
  40. formValue: {},
  41. scheme: [],
  42. rel: {},
  43. level: '0',
  44. levelRange: [{ value: '0', text: '普通' }, { value: '1', text: '重要' }, { value: '2', text: '紧急' }],
  45. title: '',
  46. needTitle: false,
  47. // 指派审核人数据
  48. modal: false,
  49. userAssignData:{},//收集数据用来判断是否需要审核人
  50. reviewerListId:'',
  51. reviewerList:[],
  52. submitPostData:{},
  53. reviewer: [],
  54. }
  55. },
  56. async onLoad({ type }) {
  57. await this.init(type)
  58. },
  59. methods: {
  60. // 初始化页面
  61. async init(type = 'create') {
  62. // type 表示打开页面的方式,create=新建,draft=编辑草稿,again=重新发起
  63. // 新建的场合最简单,直接渲染出空的表单即可;
  64. // 重新发起流程/编辑草稿的场合,比新建多出一个拉取表单已经输入的内容的步骤,把内容填充到表单中;
  65. this.LOADING('加载表单中…')
  66. this.type = type
  67. const currentTask = this.GET_PARAM()
  68. this.userAssignData.currentTask = currentTask
  69. const { F_Code: code, F_Id: pid } = currentTask
  70. // 设置页面标题
  71. const title = {
  72. create: `创建[${currentTask.F_Name}]流程`,
  73. draft: `编辑[${currentTask.F_Title || currentTask.F_SchemeName}]流程草稿`,
  74. again: `重新发起[${currentTask.F_Title}]流程`
  75. }[this.type]
  76. this.SET_TITLE(title)
  77. // 拉取流程信息,提取出当前节点;如果是新建表单则生成 processId
  78. const processId = this.type === 'create' ? this.GUID('-') : pid
  79. const processInfo = await this.fetchProcessInfo({ code, processId: this.type === 'create' ? null : processId })
  80. const currentNode = this.getCurrentNode(processInfo)
  81. console.log(processInfo)
  82. this.userAssignData.currentNode =currentNode
  83. // wfForms 的数组成员 t,表示表单数据项(TAB页),t.type 表示类别,注意它是字符串型,用 Number(t.type) 转换
  84. // 为 1 则使用工作流表单,依据它的 .formId
  85. // 不为 1 则使用系统表单,依据它的 .appurl
  86. const { wfForms } = currentNode
  87. // 处理没有有效表单的情况,停止加载
  88. if (!wfForms || wfForms.length <= 0) {
  89. this.HIDE_LOADING()
  90. this.TOAST('移动表单数据(wfForms)中无有效表单')
  91. return
  92. }
  93. // 处理移动端本地表单(也就是系统表单)的情况,直接跳转过去
  94. const appSysPage = wfForms.find(t => Number(t.type) !== 1)
  95. if (appSysPage) {
  96. this.HIDE_LOADING()
  97. this.TOAST('跳转至移动端本地表单(即系统表单)')
  98. let pagePath = appSysPage.appurl || ''
  99. if (!pagePath.startsWith('/pages')) {
  100. pagePath = '/pages' + pagePath
  101. }
  102. this.JUMP_TO(
  103. `${pagePath}?type=${this.type}`,
  104. { currentNode, currentTask, logList: get(processInfo, 'info.TaskLogList', []) },
  105. true
  106. )
  107. return
  108. }
  109. this.needTitle = this.type !== 'again' && Number(currentNode.isTitle) === 1
  110. const formData = await this.fetchFormData(currentNode, processId)
  111. const schemeData = await this.fetchSchemeData(currentNode);
  112. const fetchFolderkeyData=await this.fetchFolderkeyData(currentNode, processId);
  113. uni.setStorageSync('guids',JSON.stringify(fetchFolderkeyData));
  114. const { formValue, scheme, rel } = await this.getCustomForm({
  115. schemeData,
  116. processId,
  117. formData,
  118. currentNode: currentNode,
  119. code: this.type === 'again' ? null : code,
  120. useDefault: true
  121. })
  122. this.rel = rel
  123. this.scheme = scheme
  124. this.formValue = formValue
  125. this.code = code
  126. this.processId = processId
  127. this.ready = true
  128. this.HIDE_LOADING()
  129. },
  130. // 提交草稿按钮
  131. async draft() {
  132. if (!(await this.CONFIRM('提交确认', '确定要提交草稿吗?', true))) {
  133. return
  134. }
  135. this.LOADING('正在提交…')
  136. const formValue = this.$refs.form.getFormValue()
  137. const postData = await this.getPostData(formValue, this.scheme)
  138. this.HTTP_POST('learun/adms/newwf/draft', postData, '提交草稿时发生失败,未能成功保存').then(success => {
  139. this.HIDE_LOADING()
  140. if (!success) {
  141. return
  142. }
  143. this.EMIT('task-list-change')
  144. this.NAV_BACK()
  145. this.TOAST('草稿已保存', 'success')
  146. })
  147. },
  148. // 指派审核人
  149. async userAssign() {
  150. this.modal = false
  151. if(!this.reviewer.length){
  152. this.TOAST('请选择审核人')
  153. return
  154. }
  155. // const res = await this.HTTP_POST('learun/adms/newwf/instance', this.submitPostData.formreq, `指派审核人时发生错误`)
  156. // if(!res){
  157. // return
  158. // }
  159. // delete this.submitPostData.formreq
  160. const isAgain = this.type === 'again'
  161. // if (!(await this.CONFIRM('提交确认', `确定要${isAgain ? '重新' : ''}发起流程吗?`, true))) {
  162. // return
  163. // }
  164. this.LOADING('正在提交…')
  165. // this.submitPostData.schemeCode = this.submitPostData.code
  166. // delete this.submitPostData.code
  167. // this.submitPostData.title = ''
  168. // this.submitPostData.createUserId = ''
  169. if (this.needTitle) {
  170. this.submitPostData.title = this.title
  171. }
  172. this.submitPostData.level = this.level
  173. this.submitPostData.auditors = JSON.stringify({[this.reviewerListId]:this.reviewer.toString()})
  174. const url = isAgain ? 'learun/adms/newwf/againcreate' : 'learun/adms/newwf/create'
  175. const tips = `流程${isAgain ? '重新' : ''}发起失败`
  176. this.HTTP_POST(url, this.submitPostData, tips).then(success => {
  177. this.HIDE_LOADING()
  178. if (!success) {
  179. return
  180. }
  181. this.EMIT('task-list-change')
  182. this.NAV_BACK()
  183. this.TOAST(`流程${isAgain ? '重新' : ''}发起成功`, 'success')
  184. })
  185. },
  186. // 发起流程按钮
  187. async submit() {
  188. const isAgain = this.type === 'again'
  189. // 先验证表单,验证不通过则提示
  190. const verifyResult = this.verifyValue()
  191. if (verifyResult.length > 0) {
  192. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  193. return
  194. }
  195. const formValue = this.$refs.form.getFormValue()
  196. const postData = await this.getPostData(this.formValue, this.scheme)
  197. // 判断是否指派审核人
  198. let isNext = this.userAssignData.currentNode.isNext
  199. Object.assign(this.userAssignData,{ code: 'agree' })
  200. if (this.userAssignData.next == '2') {
  201. isNext = '1';
  202. }
  203. if (isNext == '1') {
  204. let params = {
  205. code: this.code,
  206. processId: this.processId,
  207. taskId: this.userAssignData.currentTask.taskId,
  208. nodeId: this.userAssignData.currentNode.id,
  209. operationCode: this.userAssignData.code,
  210. }
  211. this.LOADING('正在获取审核人…')
  212. const userList = await this.HTTP_GET('learun/adms/newwf/auditer', params, `获取审核人时发生错误`)
  213. this.HIDE_LOADING()
  214. if (!userList) {
  215. return
  216. }
  217. let arr = Object.entries(userList)
  218. this.reviewerListId = arr[0][0]
  219. this.reviewerList = arr[0][1].map(item => {
  220. return {
  221. text: item.Name,
  222. value: item.Id
  223. }
  224. })
  225. this.submitPostData = postData
  226. if(this.reviewerList.length>1){
  227. this.modal = true
  228. return
  229. }
  230. }
  231. if (!(await this.CONFIRM('提交确认', `确定要${isAgain ? '重新' : ''}发起流程吗?`, true))) {
  232. return
  233. }
  234. this.LOADING('正在提交…')
  235. // const formValue = this.$refs.form.getFormValue()
  236. // const postData = await this.getPostData(formValue, this.scheme)
  237. if (this.needTitle) {
  238. postData.title = this.title
  239. }
  240. postData.level = this.level
  241. postData.auditors = JSON.stringify({})
  242. const url = isAgain ? 'learun/adms/newwf/againcreate' : 'learun/adms/newwf/create'
  243. const tips = `流程${isAgain ? '重新' : ''}发起失败`
  244. this.HTTP_POST(url, postData, tips).then(success => {
  245. this.HIDE_LOADING()
  246. if (!success) {
  247. return
  248. }
  249. this.EMIT('task-list-change')
  250. this.NAV_BACK()
  251. this.TOAST(`流程${isAgain ? '重新' : ''}发起成功`, 'success')
  252. })
  253. },
  254. // 获取表单验证结果,是一个包含错误信息的数组,长度为 0 则没有错误
  255. verifyValue() {
  256. const errList = this.$refs.form.verifyValue()
  257. if (this.needTitle && !this.title) {
  258. errList.push(`流程的标题不能为空`)
  259. }
  260. return errList
  261. }
  262. }
  263. }
  264. </script>