report.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 = [{value: 0, text: '自定义流程', disable: false, linkUserJoinString: null}]
  91. const getFixedFlowDataApi = async () => {
  92. uni.showLoading({title: '获取数据中...', mask: true});
  93. const { type, typeData } = props.value
  94. if (type === 'first' || type === 'log' || type === 'wbs') {
  95. await queryFixedFlowApi(type, typeData)
  96. } else {
  97. await getProcessData()
  98. }
  99. }
  100. //获取流程数据
  101. const getProcessData = async () => {
  102. linkUserJoinString.value = ''
  103. fixedFlowData.value = fixedFlowDefault
  104. const { projectId, contractId } = props.value
  105. const { error, code, data, msg } = await flowApi.getPageData({
  106. projectId: projectId,
  107. contractId: contractId,
  108. current: 1, size: 100,
  109. })
  110. if (!error && code === 200) {
  111. const arr = getArrValue(data['records'])
  112. for (let i = 0; i < arr.length; i++) {
  113. fixedFlowData.value.push({
  114. value: arr[i].id,
  115. text: arr[i].fixedFlowName,
  116. disable: arr[i].disabled,
  117. linkUserJoinString: arr[i].linkUserJoinString
  118. })
  119. }
  120. uni.hideLoading();
  121. isFixedFlow.value = true
  122. } else {
  123. uni.hideLoading();
  124. isFixedFlow.value = false
  125. errorToast(msg ?? '任务流程异常');
  126. }
  127. }
  128. //获取符合条件的预设流程(三大填报页、日志列表的批量上报、首件列表的批量上报)
  129. const queryFixedFlowApi = async (type, datas) => {
  130. let flowJson = {}
  131. if (type === 'first') {
  132. flowJson['firstId'] = datas
  133. } else if (type === 'log') {
  134. flowJson['theLogPrimaryKeyId'] = datas
  135. } else if (type === 'wbs') {
  136. flowJson['privatePKeyId'] = datas
  137. }
  138. //请求数据
  139. linkUserJoinString.value = ''
  140. fixedFlowData.value = fixedFlowDefault
  141. const { projectId, contractId } = props.value
  142. const {ids, classify} = formData.value
  143. const { error, code, data, msg } = await queryFixedFlow({
  144. projectId: projectId,
  145. contractId: contractId,
  146. classifyType: classify,
  147. nodeId: ids,
  148. tableOwner: "1",
  149. ...flowJson,
  150. })
  151. if (!error && code === 200) {
  152. const arr = getArrValue(data['records'])
  153. for (let i = 0; i < arr.length; i++) {
  154. fixedFlowData.value.push({
  155. value: arr[i].id,
  156. text: arr[i].fixedFlowName,
  157. disable: arr[i].disabled,
  158. linkUserJoinString: arr[i].linkUserJoinString
  159. })
  160. }
  161. uni.hideLoading();
  162. isFixedFlow.value = true
  163. } else {
  164. uni.hideLoading();
  165. isFixedFlow.value = false
  166. errorToast(msg ?? '任务流程异常');
  167. }
  168. }
  169. //任务流程
  170. const diyProcessUser = ref(false)
  171. const fixedFlowChange = (val) => {
  172. if (val > 0) {
  173. diyProcessUser.value = false
  174. const list = fixedFlowData.value
  175. const index = arrIndex(list, 'value', val)
  176. linkUserJoinString.value = list[index]?.linkUserJoinString
  177. formData.value.userTasks = []
  178. } else {
  179. linkUserJoinString.value = ''
  180. formData.value.userTasks = []
  181. diyProcessUser.value = true
  182. }
  183. }
  184. //表单数据
  185. const formRef = ref(null)
  186. const formData = ref({
  187. userTasks: [],
  188. })
  189. const formRules = {
  190. taskContent: {
  191. rules: [{
  192. required: true,
  193. errorMessage: '上报说明不能为空'
  194. }]
  195. },
  196. fixedFlowId: {
  197. rules: [{
  198. required: true,
  199. errorMessage: '上报流程不能为空'
  200. }]
  201. },
  202. userTasks: {
  203. rules: [{
  204. required: true,
  205. errorMessage: '任务人不能为空'
  206. }]
  207. },
  208. }
  209. //选择任务人
  210. const userTasksClick = () => {
  211. uni.navigateTo({
  212. url: '/pages/report/tasks-user',
  213. events:{
  214. flowUserList: function(data) {
  215. formData.value.userTasks = data
  216. }
  217. },
  218. success: function(res){
  219. const { type, typeData, projectId, contractId } = props.value
  220. const {ids, userTasks, classify} = formData.value
  221. res.eventChannel.emit('flowUserData', {
  222. type: type,
  223. typeData: typeData,
  224. projectId: projectId,
  225. contractId: contractId,
  226. selectedData: userTasks,
  227. classifyType: classify,
  228. nodeId: ids,
  229. tableOwner: "1",
  230. })
  231. }
  232. });
  233. }
  234. //确认提交
  235. const submitClick = async () => {
  236. const res = await formValidate(formRef.value)
  237. if (!res) return false;
  238. //发起请求
  239. uni.showLoading({title: '上报审批中...', mask: true});
  240. const { projectId, contractId, url } = props.value
  241. const { error, code, msg } = await ApprovalApi(url, {
  242. projectId: projectId,
  243. contractId: contractId,
  244. ...formData.value,
  245. })
  246. uni.hideLoading();
  247. if (!error && code === 200) {
  248. successToast('上报成功', 3000);
  249. //eventChannel.emit('finish');
  250. setTimeout(() => {
  251. //跳转到任务列表
  252. uni.switchTab({
  253. url: '/pages/task/index'
  254. });
  255. //uni.navigateBack();
  256. }, 3000)
  257. } else {
  258. errorToast(msg);
  259. }
  260. }
  261. </script>
  262. <style lang="scss">
  263. @import "@/style/report/report.scss";
  264. </style>