report.vue 8.8 KB

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