start-work.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // pages/progress/start-work.js
  2. const api = require('../../utils/o2Api.js');
  3. const util = require('../../utils/util.js');
  4. Page({
  5. /**
  6. * Page initial data
  7. */
  8. data: {
  9. navTitle: '创建工作',
  10. currentAppId: '',
  11. applicationList: [],
  12. processList: [],
  13. currentProcess: null,
  14. showChooseIdentityDialog: false,
  15. identityList: [],
  16. selectedIdentity: ''
  17. },
  18. /**
  19. * Lifecycle function--Called when page load
  20. */
  21. onLoad: function (options) {
  22. },
  23. /**
  24. * Lifecycle function--Called when page is initially rendered
  25. */
  26. onReady: function () {
  27. },
  28. /**
  29. * Lifecycle function--Called when page show
  30. */
  31. onShow: function () {
  32. this.loadApplication()
  33. },
  34. /**
  35. * Lifecycle function--Called when page hide
  36. */
  37. onHide: function () {
  38. },
  39. /**
  40. * Lifecycle function--Called when page unload
  41. */
  42. onUnload: function () {
  43. },
  44. /**
  45. * Page event handler function--Called when user drop down
  46. */
  47. onPullDownRefresh: function () {
  48. },
  49. /**
  50. * Called when page reach bottom
  51. */
  52. onReachBottom: function () {
  53. },
  54. /**
  55. * Called when user click on the top right corner to share
  56. */
  57. onShareAppMessage: function () {
  58. },
  59. /**
  60. * 获取流程应用列表
  61. */
  62. loadApplication: function () {
  63. util.showLoading()
  64. api.applicationList().then(list => {
  65. var pList = []
  66. var cid = ''
  67. if (list && list.length > 0) {
  68. pList = list[0].processList
  69. cid = list[0].id
  70. }
  71. this.setData({
  72. applicationList: list,
  73. processList: pList,
  74. currentAppId: cid
  75. });
  76. util.hideLoading()
  77. }).catch(err => {
  78. util.hideLoading()
  79. api.o2Error(err);
  80. })
  81. },
  82. /**
  83. * 选择身份
  84. */
  85. showChooseIdentityDialog: function(identityList){
  86. this.setData({
  87. showChooseIdentityDialog: true,
  88. identityList: identityList
  89. })
  90. },
  91. /**
  92. * 启动流程实例
  93. * @param {*} identityDn
  94. */
  95. startProcess: function(identityDn) {
  96. let body = {"identity": identityDn}
  97. api.createWork(this.data.currentProcess.id, body).then(result => {
  98. util.hideLoading()
  99. let work = result[0].taskList[0].work
  100. let activityName = result[0].taskList[0].activityName
  101. if (work) {
  102. wx.navigateBack({
  103. delta: 1,
  104. complete: function() {
  105. wx.navigateTo({
  106. url: '../progress/work-web?work=' +work + '&title=' + encodeURIComponent(activityName)
  107. });
  108. }
  109. })
  110. }
  111. }).catch(err => {
  112. util.hideLoading()
  113. api.o2Error(err);
  114. })
  115. },
  116. /**
  117. * 启动草稿
  118. * @param {*} identityDn
  119. */
  120. startDraft: function(identityDn) {
  121. let body = {"identity": identityDn}
  122. api.createDraft(this.data.currentProcess.id, body).then(result => {
  123. console.log(result)
  124. console.log(result.work)
  125. util.hideLoading()
  126. if (result.work) {
  127. let draft = JSON.stringify(result.work)
  128. wx.navigateBack({
  129. delta: 1,
  130. complete: function() {
  131. wx.navigateTo({
  132. url: '../progress/work-web?draft=' + encodeURIComponent(draft)
  133. });
  134. }
  135. })
  136. }
  137. }).catch(err => {
  138. util.hideLoading()
  139. api.o2Error(err);
  140. })
  141. },
  142. /**
  143. * 启动
  144. * @param {*} identityDn
  145. */
  146. start: function(identityDn) {
  147. util.showLoading()
  148. if(this.data.currentProcess && this.data.currentProcess.defaultStartMode && this.data.currentProcess.defaultStartMode === 'draft') {
  149. this.startDraft(identityDn)
  150. }else {
  151. this.startProcess(identityDn)
  152. }
  153. },
  154. bindTapApplication: function(e) {
  155. let index = e.currentTarget.dataset.index
  156. let app = this.data.applicationList[index]
  157. this.setData({
  158. processList: app.processList,
  159. currentAppId: app.id
  160. })
  161. },
  162. bindTapProcess: function(e) {
  163. let index = e.currentTarget.dataset.index
  164. let process = this.data.processList[index]
  165. this.data.currentProcess = process
  166. util.showLoading()
  167. api.listAvailableIdentityWithProcess(process.id).then(list => {
  168. if (list && list.length > 0) {
  169. if (list.length > 1) {
  170. this.showChooseIdentityDialog(list)
  171. }else {
  172. this.start(list[0].distinguishedName)
  173. }
  174. } else {
  175. util.toast('没有获取到当前用户的身份,无法启动流程!')
  176. }
  177. }).catch(err => {
  178. util.hideLoading()
  179. api.o2Error(err);
  180. })
  181. },
  182. tapDialogButton: function(e) {
  183. this.setData({
  184. showChooseIdentityDialog: false
  185. });
  186. if (e.detail.index == 1) {
  187. this.start(this.data.selectedIdentity)
  188. }
  189. },
  190. identityRadioChange: function(e) {
  191. this.data.selectedIdentity = e.detail.value
  192. }
  193. })