index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="yd-page-container">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="加签任务"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. />
  9. <!-- 操作表单 -->
  10. <view class="p-24rpx">
  11. <wd-form ref="formRef" :model="formData" :rules="formRules">
  12. <wd-cell-group border>
  13. <!-- 加签处理人 -->
  14. <UserPicker
  15. v-model="formData.userIds"
  16. prop="userIds"
  17. type="checkbox"
  18. label="加签处理人:"
  19. label-width="200rpx"
  20. placeholder="请选择加签处理人"
  21. :rules="formRules.userIds"
  22. />
  23. <!-- 审批意见 -->
  24. <wd-textarea
  25. v-model="formData.reason"
  26. prop="reason"
  27. label="审批意见:"
  28. label-width="200rpx"
  29. placeholder="请输入审批意见"
  30. :maxlength="500"
  31. show-word-limit
  32. clearable
  33. />
  34. </wd-cell-group>
  35. <!-- 提交按钮 -->
  36. <view class="mt-48rpx flex gap-16rpx">
  37. <wd-button
  38. type="primary"
  39. class="flex-1"
  40. plain
  41. :loading="submitting"
  42. :disabled="submitting"
  43. @click="handleSubmit('before')"
  44. >
  45. 向前加签
  46. </wd-button>
  47. <wd-button
  48. type="primary"
  49. class="flex-1"
  50. :loading="submitting"
  51. :disabled="submitting"
  52. @click="handleSubmit('after')"
  53. >
  54. 向后加签
  55. </wd-button>
  56. </view>
  57. </wd-form>
  58. </view>
  59. </view>
  60. </template>
  61. <script lang="ts" setup>
  62. import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
  63. import { computed, reactive, ref } from 'vue'
  64. import { useToast } from 'wot-design-uni'
  65. import { signCreateTask } from '@/api/bpm/task'
  66. import UserPicker from '@/components/system-select/user-picker.vue'
  67. import { navigateBackPlus } from '@/utils'
  68. const props = defineProps<{
  69. processInstanceId: string
  70. taskId: string
  71. }>()
  72. definePage({
  73. style: {
  74. navigationBarTitleText: '',
  75. navigationStyle: 'custom',
  76. },
  77. })
  78. const taskId = computed(() => props.taskId)
  79. const processInstanceId = computed(() => props.processInstanceId)
  80. const toast = useToast()
  81. const submitting = ref(false)
  82. const formData = reactive({
  83. userIds: [] as number[],
  84. reason: '',
  85. })
  86. const formRules = {
  87. userIds: [
  88. { required: true, message: '加签处理人不能为空', validator: (value: number[]) => value.length > 0 },
  89. ],
  90. reason: [
  91. { required: true, message: '审批意见不能为空' },
  92. ],
  93. }
  94. const formRef = ref<FormInstance>()
  95. /** 返回上一页 */
  96. function handleBack() {
  97. navigateBackPlus(`/pages-bpm/processInstance/detail/index?id=${processInstanceId.value}&taskId=${taskId.value}`)
  98. }
  99. // TODO @jason:最好放在 onMounted 里?或者其他地方,有个入口方法。
  100. /** 初始化校验 */
  101. if (!props.taskId || !props.processInstanceId) {
  102. toast.show('参数错误')
  103. }
  104. /** 提交操作 */
  105. async function handleSubmit(type: 'before' | 'after') {
  106. if (submitting.value) {
  107. return
  108. }
  109. const { valid } = await formRef.value!.validate()
  110. if (!valid) {
  111. return
  112. }
  113. // TODO @jason:submitting 改成 formLoading 哇?统一代码风格哈;
  114. submitting.value = true
  115. try {
  116. // TODO @jason:这里是不是不用判断 result 哈?
  117. const result = await signCreateTask({
  118. id: taskId.value as string,
  119. type,
  120. userIds: formData.userIds,
  121. reason: formData.reason,
  122. })
  123. if (result) {
  124. const actionText = type === 'before' ? '向前加签' : '向后加签'
  125. toast.success(`${actionText}成功`)
  126. setTimeout(() => {
  127. uni.redirectTo({
  128. url: `/pages-bpm/processInstance/detail/index?id=${processInstanceId.value}&taskId=${taskId.value}`,
  129. })
  130. }, 500)
  131. }
  132. } catch (error) {
  133. // TODO @jason:可以不用这里的 catch 哈?
  134. const actionText = type === 'before' ? '向前加签' : '向后加签'
  135. console.error(`[add-sign] ${actionText}失败:`, error)
  136. toast.error(`${actionText}失败`)
  137. } finally {
  138. submitting.value = false
  139. }
  140. }
  141. </script>