report.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <hc-sys class="hc-report-page" :isNavBar="false">
  3. <uni-card class="" :is-shadow="false" is-full>
  4. <text class="text-black text-df">{{formData.taskName ?? ''}}</text>
  5. </uni-card>
  6. <uni-section class="mt-2" title="上报审批表单" type="line">
  7. <view class="p-2">
  8. <uni-forms ref="formRef" :rules="formRules" :modelValue="formData" label-width="190rpx">
  9. <uni-forms-item label="上报说明" required name="taskContent">
  10. <uni-easyinput type="textarea" v-model="formData.taskContent" placeholder="请输入上报说明" />
  11. </uni-forms-item>
  12. <uni-forms-item label="上报流程" required name="fixedFlowId">
  13. <uni-data-select v-model="formData.fixedFlowId" :localdata="fixedFlowData" @change="fixedFlowChange"/>
  14. </uni-forms-item>
  15. <uni-forms-item class="hc-form-item" label="任务人" required name="userTasks" v-if="diyProcessUser">
  16. <view class="tasks-user-box" @click="userTasksClick">
  17. <view class="tag-user-list" v-if="formData.userTasks && formData.userTasks.length > 0">
  18. <template v-for="(item, index) in formData.userTasks">
  19. <uni-tag :text="item.userName" type="primary"/>
  20. <text class="i-ri-arrow-right-line arrow-icon-tag" v-if="(formData.userTasks.length - 1) > index"/>
  21. </template>
  22. </view>
  23. <view v-else class="tasks-placeholder">点击这里选择任务人</view>
  24. </view>
  25. </uni-forms-item>
  26. <uni-forms-item class="hc-form-item" label="任务人" v-else>
  27. <view class="form-item-div">{{ linkUserJoinString }}</view>
  28. </uni-forms-item>
  29. <uni-forms-item class="hc-form-item" label="上报批次">
  30. <uni-number-box v-model="formData.batch" :min="1"/>
  31. </uni-forms-item>
  32. <uni-forms-item class="hc-form-item" label="限定审批时间">
  33. <uni-number-box v-model="formData.restrictDay" :min="1"/>
  34. <text class="text ml-4">(天)</text>
  35. </uni-forms-item>
  36. </uni-forms>
  37. </view>
  38. </uni-section>
  39. <!--底部操作栏-->
  40. <HcTabbarBlock :height="77"/>
  41. <hc-tabbars>
  42. <button type="primary" class="action-bar-btn" :disabled="!isFixedFlow" @click="submitClick">确认上报</button>
  43. </hc-tabbars>
  44. </hc-sys>
  45. </template>
  46. <script setup>
  47. import {ref, nextTick, getCurrentInstance} from "vue";
  48. import {onLoad} from '@dcloudio/uni-app'
  49. import {ApprovalApi, queryFixedFlow} from '~api/other/index'
  50. import {arrIndex, getArrValue, getObjValue} from "js-fast-way";
  51. import {errorToast, successToast, formValidate} from "@/utils/tools";
  52. import flowApi from '~api/tasks/flow'
  53. //页面传参数据
  54. const instance = getCurrentInstance().proxy
  55. const props = ref({})
  56. //渲染完成
  57. onLoad(async () => {
  58. await getEventChannel();
  59. getFixedFlowDataApi().then();
  60. // 设置自定义表单校验规则,必须在节点渲染完毕后执行
  61. formRef.value?.setRules(formRules)
  62. })
  63. //页面传参数据
  64. let eventChannel = null;
  65. const getEventChannel = async () => {
  66. await nextTick();
  67. eventChannel = instance.getOpenerEventChannel();
  68. eventChannel.on('reportProps', (data) => {
  69. const res = getObjValue(data);
  70. const addition = getObjValue(res.addition)
  71. props.value = res
  72. //初始表单
  73. formData.value = {
  74. ids: res.ids,
  75. userTasks: [],
  76. taskName: res.taskName,
  77. taskContent: '',
  78. fixedFlowId: '',
  79. batch: 1,
  80. restrictDay: 1,
  81. trialSelfInspectionRecordId: res.trialSelfInspectionRecordId ?? '',
  82. ...addition,
  83. }
  84. })
  85. }
  86. //获取流程数据
  87. const fixedFlowData = ref([])
  88. const linkUserJoinString = ref('')
  89. const isFixedFlow = ref(false)
  90. const fixedFlowDefault = [{
  91. value: 0, text: '自定义流程', disable: false, linkUserJoinString: null
  92. }]
  93. const getFixedFlowDataApi = async () => {
  94. uni.showLoading({title: '获取数据中...', mask: true});
  95. const { type, typeData } = props.value
  96. if (type === 'first' || type === 'log' || type === 'wbs') {
  97. await queryFixedFlowApi(type, typeData)
  98. } else {
  99. await getProcessData()
  100. }
  101. }
  102. //获取流程数据
  103. const getProcessData = async () => {
  104. linkUserJoinString.value = ''
  105. fixedFlowData.value = fixedFlowDefault
  106. const { projectId, contractId } = props.value
  107. const { error, code, data, msg } = await flowApi.getPageData({
  108. projectId: projectId,
  109. contractId: contractId,
  110. current: 1, size: 100,
  111. })
  112. if (!error && code === 200) {
  113. const arr = getArrValue(data['records'])
  114. for (let i = 0; i < arr.length; i++) {
  115. fixedFlowData.value.push({
  116. value: arr[i].id,
  117. text: arr[i].fixedFlowName,
  118. disable: arr[i].disabled,
  119. linkUserJoinString: arr[i].linkUserJoinString
  120. })
  121. }
  122. uni.hideLoading();
  123. isFixedFlow.value = true
  124. } else {
  125. uni.hideLoading();
  126. isFixedFlow.value = false
  127. errorToast(msg ?? '任务流程异常');
  128. }
  129. }
  130. //获取符合条件的预设流程(三大填报页、日志列表的批量上报、首件列表的批量上报)
  131. const queryFixedFlowApi = async (type, datas) => {
  132. let flowJson = {}
  133. if (type === 'first') {
  134. flowJson['firstId'] = datas
  135. } else if (type === 'log') {
  136. flowJson['theLogPrimaryKeyId'] = datas
  137. } else if (type === 'wbs') {
  138. flowJson['privatePKeyId'] = datas
  139. }
  140. //请求数据
  141. linkUserJoinString.value = ''
  142. fixedFlowData.value = fixedFlowDefault
  143. const { projectId, contractId } = props.value
  144. const { error, code, data, msg } = await queryFixedFlow({
  145. projectId: projectId,
  146. contractId: contractId,
  147. ...flowJson,
  148. })
  149. if (!error && code === 200) {
  150. const arr = getArrValue(data['records'])
  151. for (let i = 0; i < arr.length; i++) {
  152. fixedFlowData.value.push({
  153. value: arr[i].id,
  154. text: arr[i].fixedFlowName,
  155. disable: arr[i].disabled,
  156. linkUserJoinString: arr[i].linkUserJoinString
  157. })
  158. }
  159. uni.hideLoading();
  160. isFixedFlow.value = true
  161. } else {
  162. uni.hideLoading();
  163. isFixedFlow.value = false
  164. errorToast(msg ?? '任务流程异常');
  165. }
  166. }
  167. //任务流程
  168. const diyProcessUser = ref(false)
  169. const fixedFlowChange = (val) => {
  170. if (val > 0) {
  171. diyProcessUser.value = false
  172. const list = fixedFlowData.value
  173. const index = arrIndex(list, 'value', val)
  174. linkUserJoinString.value = list[index]?.linkUserJoinString
  175. formData.value.userTasks = []
  176. } else {
  177. linkUserJoinString.value = ''
  178. formData.value.userTasks = []
  179. diyProcessUser.value = true
  180. }
  181. }
  182. //表单数据
  183. const formRef = ref(null)
  184. const formData = ref({
  185. userTasks: [],
  186. })
  187. const formRules = {
  188. taskContent: {
  189. rules: [{
  190. required: true,
  191. errorMessage: '上报说明不能为空'
  192. }]
  193. },
  194. fixedFlowId: {
  195. rules: [{
  196. required: true,
  197. errorMessage: '上报流程不能为空'
  198. }]
  199. },
  200. userTasks: {
  201. rules: [{
  202. required: true,
  203. errorMessage: '任务人不能为空'
  204. }]
  205. },
  206. }
  207. //选择任务人
  208. const userTasksClick = () => {
  209. uni.navigateTo({
  210. url: '/pages/report/tasks-user',
  211. events:{
  212. flowUserList: function(data) {
  213. formData.value.userTasks = data
  214. }
  215. },
  216. success: function(res){
  217. const { type, typeData, projectId, contractId } = props.value
  218. const {userTasks} = formData.value
  219. res.eventChannel.emit('flowUserData', {
  220. type: type,
  221. typeData: typeData,
  222. projectId: projectId,
  223. contractId: contractId,
  224. selectedData: userTasks
  225. })
  226. }
  227. });
  228. }
  229. //确认提交
  230. const submitClick = async () => {
  231. const res = await formValidate(formRef.value)
  232. if (!res) return false;
  233. //发起请求
  234. uni.showLoading({title: '上报审批中...', mask: true});
  235. const { projectId, contractId, url } = props.value
  236. const { error, code, msg } = await ApprovalApi(url, {
  237. projectId: projectId,
  238. contractId: contractId,
  239. ...formData.value,
  240. })
  241. uni.hideLoading();
  242. if (!error && code === 200) {
  243. successToast('上报成功', 3000);
  244. //eventChannel.emit('finish');
  245. setTimeout(() => {
  246. //跳转到任务列表
  247. uni.switchTab({
  248. url: '/pages/task/index'
  249. });
  250. //uni.navigateBack();
  251. }, 3000)
  252. } else {
  253. errorToast(msg);
  254. }
  255. }
  256. </script>
  257. <style lang="scss">
  258. @import "@/style/report/report.scss";
  259. </style>