case-mixins.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { Message, Modal } from 'ant-design-vue'
  2. import LawService from '../law-service'
  3. import FlowService from '@/webflow/flow-service'
  4. import crossWindowWatcher from '@/common/services/cross-window-watcher'
  5. function at(n) {
  6. n = Math.trunc(n) || 0
  7. if (n < 0) n += this.length
  8. if (n < 0 || n >= this.length) return undefined
  9. return this[n]
  10. }
  11. const TypedArray = Reflect.getPrototypeOf(Int8Array)
  12. for (const C of [Array, String, TypedArray]) {
  13. Object.defineProperty(C.prototype, 'at', {
  14. value: at,
  15. writable: true,
  16. enumerable: false,
  17. configurable: true,
  18. })
  19. }
  20. const CaseMixins = {
  21. data() {
  22. return {
  23. stage: [],
  24. parentstage: [],
  25. flag: true,
  26. create: false,
  27. type: '',
  28. caseStage: '',
  29. caseType: '',
  30. }
  31. },
  32. created() {
  33. this.caseStage = this.$route.query?.cs
  34. this.caseType = this.$route.query?.ct
  35. if (this.$route.params.id && this.$route.params.id === '0') {
  36. this.create = true
  37. }
  38. },
  39. methods: {
  40. initData() {
  41. if (this.create) {
  42. if (this.type === 'progress') {
  43. LawService.getCaseTree(this.caseType, '').then((r) => {
  44. LawService.getCaseTree(this.caseType, this.caseStage).then((res) => {
  45. this.parentstage = [...r.data]
  46. this.stage = [...res.data]
  47. LawService.getProgressData(this.$route.query.id).then((res) => {
  48. const obj = res.data.find((d) => d.props.stepType === 'progress')
  49. const sn = this.stage.find((i) => i.id === this.$route.query?.stage).text
  50. const psn = this.parentstage.find((i) => i.id === this.$route.query?.cs).text
  51. const ini = setInterval(() => {
  52. if (this.$refs.webflow) {
  53. clearInterval(ini)
  54. this.$refs.webflow.setFieldValue('CASE_ID', this.$route.query.id)
  55. this.$refs.webflow.setFieldValue('CASE_STAGE', this.$route.query?.stage)
  56. this.$refs.webflow.setFieldValue('CASE_STAGE_NAME', psn)
  57. this.$refs.webflow.setFieldValue('PROGRESS_CODE', this.$route.query?.stage)
  58. this.$refs.webflow.setFieldValue('STEP_NAME', sn)
  59. this.$refs.webflow.setFieldValue('CASE_NAME', res.data[0].text)
  60. if (
  61. this.$route.query.parentid !== '' &&
  62. this.$route.query.parentid !== 'progress'
  63. ) {
  64. this.$refs.webflow.setFieldValue('PARENT_STEP_ID', this.$route.query.parentid)
  65. }
  66. if (!(this.$route.query.flag && this.$route.query.flag === '1')) {
  67. const stageinfo = {
  68. stagecode: this.$route.query.cs,
  69. parentstagecode: this.$route.query.ct,
  70. parentstagename: psn,
  71. }
  72. this.$refs.webflow.setFieldValue('STAGE_INFO', JSON.stringify(stageinfo))
  73. }
  74. }
  75. }, 100)
  76. })
  77. })
  78. })
  79. } else {
  80. LawService.getAllcaseproStage().then((res) => {
  81. const stage = []
  82. res.data.forEach((d) => {
  83. stage.push({
  84. name: d.EXECUTE_NAME,
  85. code: d.EXECUTE_CODE,
  86. businessTypeId: d.businessTypeId,
  87. })
  88. })
  89. this.zxstage = stage
  90. LawService.getProgressData(this.$route.query.id).then((res) => {
  91. const sn = this.zxstage.find((i) => i.code === this.$route.query?.stage)?.name
  92. this.$refs.webflow.setFieldValue('CASE_ID', this.$route.query.id)
  93. this.$refs.webflow.setFieldValue('PROGRESS_CODE', this.$route.query?.stage)
  94. this.$refs.webflow.setFieldValue('STEP_NAME', sn)
  95. this.$refs.webflow.setFieldValue('CASE_NAME', res.data[0].text)
  96. if (this.$route.query.parentid !== '' && this.$route.query.parentid !== 'execute') {
  97. this.$refs.webflow.setFieldValue('PARENT_STEP_ID', this.$route.query.parentid)
  98. }
  99. LawService.getCaseData(this.$route.query.id).then((res) => {
  100. this.$refs.webflow.setFieldValue('CASE_TYPE', res.data.caseType)
  101. })
  102. })
  103. })
  104. }
  105. }
  106. },
  107. /**
  108. * 提交后事件
  109. */
  110. afterDispatch(obj) {
  111. // 提交也认为是保存
  112. obj.defaultPrevented = true
  113. Message.success({ content: `提交成功`, duration: 1 }).then(() => {
  114. const e = false
  115. const t = true
  116. const snap = this.$refs.webflow.getFormSnap()
  117. if (
  118. e &&
  119. this.$refs.webflow.FlowData.mode === 'EDIT' &&
  120. (this.$refs.webflow.getFormSnap() !== snap || this.$refs.webflow.disableActionAlert)
  121. )
  122. if (!window.confirm('正在编辑文档或正文附件,确认是否离开此网站')) return
  123. crossWindowWatcher.notifyChange(t)
  124. return FlowService.unLock(this.$refs.webflow.FlowData.instId).finally(() => {
  125. crossWindowWatcher.notifyChange(true)
  126. this.$refs.webflow.close()
  127. const url = window.location.href
  128. const obj = { url: url, type: this.type + 'close' }
  129. window.parent.postMessage(obj, '*')
  130. })
  131. })
  132. return obj
  133. },
  134. save() {
  135. if (this.create) {
  136. if (window.location.href.indexOf('draft/0') === -1) {
  137. if (window.parent) {
  138. const obj = { url: window.location.href, type: this.type }
  139. window.parent.postMessage(obj, '*')
  140. }
  141. this.create = false
  142. }
  143. }
  144. },
  145. actionBtnClick(evt, { button, FlowData }) {
  146. if (button.fakeId === 'we-doc$close') {
  147. this.$refs.webflow.close()
  148. window.parent.opener = null
  149. window.parent.open('', '_self')
  150. window.parent.close()
  151. } else {
  152. if (this.create) {
  153. if (button.fakeId === 'save' || button.fakeId === 'workflow-push') {
  154. evt.waitUntil(
  155. new Promise((resolve, reject) => {
  156. this.validForm().then((res) => {
  157. if (!res) {
  158. evt.preventDefault()
  159. }
  160. resolve()
  161. })
  162. })
  163. )
  164. }
  165. }
  166. }
  167. },
  168. validForm() {
  169. const validForm = new Promise((resolve) => {
  170. // 校验最新的上级节点是否是当前 if (this.type === 'progress') {
  171. LawService.getProgressData(this.$route.query.id).then((res) => {
  172. const objsz = res.data.filter((r) => r.props.stepType === this.type)
  173. const obj = objsz[objsz.length - 1]
  174. let flag = true
  175. if (this.type === 'progress') {
  176. if (obj && obj.children && obj.children.length > 0) {
  177. const sobj = obj.children.at(-1)
  178. if (sobj.children && sobj.children.length > 0) {
  179. const scobj = sobj.children.at(-1)
  180. if (scobj.props.stepStatus === '0') {
  181. flag = false
  182. }
  183. }
  184. }
  185. if (flag) {
  186. if (this.$route.query.parentid === 'progress') {
  187. if (obj && res.data.at(-1).props.stepType === 'progress') {
  188. // 需要创建进展阶段时,但是已有,则有问题
  189. flag = false
  190. }
  191. } else {
  192. if (res.data.at(-1).props.stepType !== 'progress' || !obj) {
  193. // 不需要创建进展阶段时,但是没有,则有问题
  194. flag = false
  195. } else {
  196. // 当前创建的父节点id 不是当前需要创建的节点
  197. if (
  198. obj &&
  199. this.$route.query.parentid !== obj.id &&
  200. this.$route.query.parentid !== obj.children.at(-1).id
  201. ) {
  202. flag = false
  203. }
  204. }
  205. }
  206. }
  207. } else if (this.type === 'execute') {
  208. if (obj && obj.children && obj.children.length > 0) {
  209. const sobj = obj.children.at(-1)
  210. if (sobj.props.stepStatus === '0') {
  211. flag = false
  212. }
  213. }
  214. if (flag) {
  215. if (this.$route.query.parentid === 'execute') {
  216. if (obj && res.data.at(-1).props.stepType === 'execute') {
  217. // 需要创建进展阶段时,但是已有,则有问题
  218. flag = false
  219. }
  220. } else {
  221. if (res.data.at(-1).props.stepType !== 'execute' || !obj) {
  222. // 不需要创建进展阶段时,但是没有,则有问题
  223. flag = false
  224. } else {
  225. // 当前创建的父节点id 不是当前需要创建的节点
  226. if (obj && this.$route.query.parentid !== obj.id) {
  227. flag = false
  228. }
  229. }
  230. }
  231. }
  232. } else {
  233. }
  234. if (!flag) {
  235. Modal.warning({
  236. title: '提示',
  237. content: '当前案件信息已变动,请关闭后重新进入!',
  238. })
  239. }
  240. resolve(flag)
  241. })
  242. })
  243. return validForm
  244. },
  245. },
  246. }
  247. export default CaseMixins