index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <hc-new-dialog :show="isShow" :title="title" widths="47rem" @close="cancelReportClick">
  3. <el-form ref="formRef" :model="formModel" :rules="formRules" label-width="auto" size="large">
  4. <el-form-item label="任务名称" prop="taskName">
  5. <el-input v-model="formModel.taskName" disabled />
  6. </el-form-item>
  7. <el-form-item v-if="isDatas && reportDatas.length > 0" label="审批内容">
  8. <div class="task-tag-data-box">
  9. <template v-for="(item, index) in reportDatas" :key="item.id">
  10. <el-tag closable size="default" type="info" @close="taskTagClose(index)">{{ item.name }}</el-tag>
  11. </template>
  12. </div>
  13. </el-form-item>
  14. <el-form-item label="任务描述" prop="taskContent">
  15. <el-input v-model="formModel.taskContent" :autosize="{ minRows: 3, maxRows: 5 }" placeholder="请输入任务描述" type="textarea" />
  16. </el-form-item>
  17. <el-form-item label="任务流程" prop="fixedFlowId">
  18. <el-select v-model="formModel.fixedFlowId" block @change="handleProcessValue">
  19. <el-option v-for="item in processData" :key="item.id" :disabled="item.disabled" :value="item.id" :label="item.fixedFlowName">
  20. <el-tooltip
  21. v-if="item.tips && item.disabled"
  22. class="box-item"
  23. effect="light"
  24. :content="item.tips "
  25. placement="right-end"
  26. >
  27. {{ item.fixedFlowName }}
  28. </el-tooltip>
  29. </el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item v-if="diyProcessUser" label="任务人" prop="userTasks">
  33. <HcTasksUser
  34. :contract-id="contractId" :project-id="projectId" :type="type" :type-data="typeData"
  35. ui="w-full" :classify-type="classifyType" :table-owner="tableOwner" :node-id="formModel.ids ? formModel.ids : nodeId "
  36. :info-ids="infoIds" @change="diyProcessUserChange"
  37. />
  38. </el-form-item>
  39. <el-form-item v-else label="任务人">
  40. <div class="form-item-div">{{ linkUserJoinString }}</div>
  41. </el-form-item>
  42. <el-form-item label="上报批次">
  43. <HcCounter v-model="formModel.batch" />
  44. </el-form-item>
  45. <el-form-item label="限定审批时间">
  46. <HcCounter v-model="formModel.restrictDay" text="(天)" />
  47. </el-form-item>
  48. </el-form>
  49. <template #footer>
  50. <div class="dialog-footer text-center">
  51. <el-button size="large" @click="cancelReportClick">取消</el-button>
  52. <el-button :loading="formReportLoading" hc-btn type="primary" @click="formReportClick">提交</el-button>
  53. </div>
  54. </template>
  55. </hc-new-dialog>
  56. </template>
  57. <script setup>
  58. import { onMounted, ref, watch } from 'vue'
  59. //import tasksFlowApi from '~api/tasks/flow'
  60. import { ApprovalApi, queryFixedFlow, queryFixedFlow1, queryFixedFlow3 } from '~api/other'
  61. import { arrIndex, arrToId, formValidate, getArrValue } from 'js-fast-way'
  62. const props = defineProps({
  63. show: {
  64. type: Boolean,
  65. default: false,
  66. },
  67. title: {
  68. type: String,
  69. default: '上报审批',
  70. },
  71. taskName: {
  72. type: String,
  73. default: '',
  74. },
  75. ids: {
  76. type: String,
  77. default: null,
  78. },
  79. projectId: {
  80. type: [String, Number],
  81. default: '',
  82. },
  83. contractId: {
  84. type: [String, Number],
  85. default: '',
  86. },
  87. flowContractId: {
  88. type: [String, Number],
  89. default: '',
  90. },
  91. classifyType: {
  92. type: [String, Number],
  93. default: '',
  94. },
  95. tableOwner: {
  96. type: [String, Number],
  97. default: '',
  98. },
  99. url: {
  100. type: [String, Number],
  101. default: '',
  102. },
  103. datas: {
  104. type: Array,
  105. default: () => ([]),
  106. },
  107. isDatas: {
  108. type: Boolean,
  109. default: false,
  110. },
  111. addition: {
  112. type: Object,
  113. default: () => ({}),
  114. },
  115. type: { //first,log,wbs
  116. type: [String, Number],
  117. default: '',
  118. },
  119. typeData: {
  120. type: [String, Number, Array, Object],
  121. default: '',
  122. },
  123. trialSelfInspectionRecordId: {
  124. type: [String, Number],
  125. default: '',
  126. },
  127. nodeId:{
  128. type: [String, Number],
  129. default: '',
  130. },
  131. reportArr: {
  132. type: Array,
  133. default: () => ([]),
  134. },
  135. })
  136. const emit = defineEmits(['hide', 'finish', 'tagClose'])
  137. //变量
  138. const isShow = ref(props.show)
  139. const projectId = ref(props.projectId)
  140. const contractId = ref(props.contractId)
  141. const flowContractId = ref(props.flowContractId)
  142. const classifyType = ref(props.classifyType)
  143. const tableOwner = ref(props.tableOwner)
  144. const ApiUrl = ref(props.url)
  145. const isTypes = ref(props.type)
  146. const typeDatas = ref(props.typeData)
  147. const reportDatas = ref(props.datas)
  148. const nodeId = ref(props.nodeId)
  149. //表单
  150. const formRef = ref(null)
  151. const processData = ref([])
  152. const formModel = ref({
  153. projectId: projectId.value,
  154. contractId: contractId.value,
  155. ids: props.ids,
  156. userTasks: null,
  157. taskName: props.taskName,
  158. taskContent: '',
  159. fixedFlowId: '',
  160. batch: 1,
  161. restrictDay: 1,
  162. trialSelfInspectionRecordId: props.trialSelfInspectionRecordId,
  163. ...props.addition,
  164. })
  165. const formRules = ref({
  166. taskContent: {
  167. required: false,
  168. trigger: 'blur',
  169. message: '请输入任务描述',
  170. },
  171. fixedFlowId: {
  172. required: true,
  173. trigger: 'blur',
  174. message: '请选择任务流程',
  175. },
  176. userTasks: {
  177. required: true,
  178. trigger: 'blur',
  179. message: '请选择任务人',
  180. },
  181. })
  182. //监听
  183. watch(() => [
  184. props.show,
  185. props.projectId,
  186. props.contractId,
  187. props.classifyType,
  188. props.tableOwner,
  189. props.taskName,
  190. props.ids,
  191. props.url,
  192. props.addition,
  193. props.type,
  194. props.typeData,
  195. props.datas,
  196. props.trialSelfInspectionRecordId,
  197. props.nodeId,
  198. props.flowContractId,
  199. ], ([val, pid, cid, cla, tab, name, ids, url, addition, type, typeData, datas, trialSelfInspectionRecordId, nodeid, flowCid]) => {
  200. isShow.value = val
  201. projectId.value = pid
  202. contractId.value = cid
  203. classifyType.value = cla
  204. tableOwner.value = tab
  205. ApiUrl.value = url
  206. nodeId.value = nodeid
  207. //更新到表单数据
  208. formModel.value = {
  209. projectId: pid,
  210. contractId: cid,
  211. ids: ids,
  212. taskName: name,
  213. taskContent: '',
  214. fixedFlowId: '',
  215. batch: 1,
  216. restrictDay: 1,
  217. trialSelfInspectionRecordId: trialSelfInspectionRecordId,
  218. ...addition,
  219. }
  220. isTypes.value = type
  221. typeDatas.value = typeData
  222. reportDatas.value = datas
  223. flowContractId.value = flowCid
  224. if (val) {
  225. getProcessDatasApi()
  226. }
  227. })
  228. //渲染完成
  229. onMounted(() => {
  230. getProcessDatasApi()
  231. })
  232. const processDefaultData = [{ id: 0, fixedFlowName: '自定义流程', disabled: false }]
  233. const getProcessDatasApi = () => {
  234. if (isShow.value) {
  235. const type = isTypes.value
  236. if (type === 'wbs') {
  237. queryFixedFlowApi(type, typeDatas.value)
  238. } else if (type === 'query') {
  239. getProcessData(type, typeDatas.value)
  240. } else if (type === 'log' || type === 'first' ) {
  241. queryFixedFlowApi3(type, typeDatas.value)
  242. }
  243. }
  244. }
  245. //获取资料查询获取流程数据
  246. const infoIds = ref('')
  247. const linkUserJoinString = ref('')
  248. const getProcessData = async (type, datas) => {
  249. linkUserJoinString.value = ''
  250. let flowJson = {}
  251. if (type === 'first') {
  252. flowJson['firstId'] = datas
  253. } else if (type === 'log') {
  254. flowJson['theLogPrimaryKeyId'] = datas
  255. } else if (type === 'wbs' || type === 'query') {
  256. flowJson['privatePKeyId'] = datas
  257. }
  258. infoIds.value = arrToId(reportDatas.value)
  259. const { error, code, data } = await queryFixedFlow1({
  260. projectId: projectId.value,
  261. contractId: flowContractId.value ?? contractId.value,
  262. nodeId:nodeId.value,
  263. classifyType:classifyType.value,
  264. tableOwner:tableOwner.value,
  265. infoIds:infoIds.value,
  266. ...flowJson,
  267. })
  268. if (!error && code === 200) {
  269. const arr = getArrValue(data['records'])
  270. processData.value = [...processDefaultData, ...arr]
  271. } else {
  272. processData.value = processDefaultData
  273. }
  274. }
  275. //获取符合条件的预设流程(三大填报页、日志列表的批量上报、首件列表的批量上报)
  276. const queryFixedFlowApi = async (type, datas) => {
  277. let flowJson = {}
  278. if (type === 'first') {
  279. flowJson['firstId'] = datas
  280. } else if (type === 'log') {
  281. flowJson['theLogPrimaryKeyId'] = datas
  282. } else if (type === 'wbs') {
  283. flowJson['privatePKeyId'] = datas
  284. }
  285. //请求数据
  286. linkUserJoinString.value = ''
  287. const { error, code, data, msg } = await queryFixedFlow({
  288. projectId: projectId.value,
  289. contractId: flowContractId.value ?? contractId.value,
  290. ...flowJson,
  291. nodeId:formModel.value.ids,
  292. classifyType:classifyType.value,
  293. tableOwner:tableOwner.value,
  294. })
  295. if (!error && code === 200) {
  296. const arr = getArrValue(data['records'])
  297. processData.value = [...processDefaultData, ...arr]
  298. } else {
  299. window.$message.error(msg)
  300. processData.value = processDefaultData
  301. }
  302. }
  303. //日志填报获取流程数据
  304. const queryFixedFlowApi3 = async (type, datas) => {
  305. let flowJson = {}
  306. if (type === 'first') {
  307. flowJson['firstId'] = datas
  308. } else if (type === 'log') {
  309. // flowJson['theLogPrimaryKeyId'] = datas
  310. flowJson['theLogPrimaryKeyId'] = formModel.value.ids
  311. } else if (type === 'wbs') {
  312. flowJson['privatePKeyId'] = datas
  313. }
  314. //请求数据
  315. linkUserJoinString.value = ''
  316. const { error, code, data, msg } = await queryFixedFlow3({
  317. projectId: projectId.value,
  318. contractId: flowContractId.value ?? contractId.value,
  319. ...flowJson,
  320. // nodeId:formModel.value.ids,
  321. classifyType:classifyType.value,
  322. tableOwner:tableOwner.value,
  323. })
  324. if (!error && code === 200) {
  325. const arr = getArrValue(data['records'])
  326. processData.value = [...processDefaultData, ...arr]
  327. } else {
  328. window.$message.error(msg)
  329. processData.value = processDefaultData
  330. }
  331. }
  332. //流程数据切换
  333. const diyProcessUser = ref(false)
  334. const handleProcessValue = (val) => {
  335. if (val > 0) {
  336. diyProcessUser.value = false
  337. const list = processData.value
  338. const index = arrIndex(list, 'id', val)
  339. linkUserJoinString.value = list[index]?.linkUserJoinString
  340. } else {
  341. linkUserJoinString.value = ''
  342. diyProcessUser.value = true
  343. }
  344. }
  345. //自定义流程任务人选择完毕
  346. const diyProcessUserChange = (user) => {
  347. formModel.value.userTasks = user
  348. }
  349. //审批内容的标签移除
  350. const taskTagClose = (index) => {
  351. reportDatas.value.splice(index, 1)
  352. emit('tagClose', index)
  353. if (reportDatas.value.length <= 0) {
  354. window.$message?.warning('请重新选择要上报的内容')
  355. cancelReportClick()
  356. }
  357. }
  358. //取消
  359. const cancelReportClick = () => {
  360. linkUserJoinString.value = ''
  361. isShow.value = false
  362. emit('hide', false)
  363. }
  364. //上报
  365. const formReportClick = async () => {
  366. const res = await formValidate(formRef.value)
  367. if (res) await batchApprovalApi()
  368. }
  369. //上报请求
  370. const formReportLoading = ref(false)
  371. const batchApprovalApi = async () => {
  372. formReportLoading.value = true
  373. //发起请求
  374. const { error, code, data } = await ApprovalApi(ApiUrl.value, {
  375. projectId: projectId.value,
  376. contractId: contractId.value,
  377. ...formModel.value,
  378. })
  379. linkUserJoinString.value = ''
  380. formReportLoading.value = false
  381. if (!error && code === 200) {
  382. isShow.value = false
  383. window.$message?.success('上报成功')
  384. emit('hide', false)
  385. emit('finish', data)
  386. } else {
  387. processData.value = []
  388. }
  389. }
  390. </script>
  391. <style lang="scss">
  392. .task-tag-data-box {
  393. position: relative;
  394. border: 1px solid #e0e0e6;
  395. border-radius: 4px;
  396. padding: 5px;
  397. min-height: 40px;
  398. display: flex;
  399. align-items: center;
  400. flex-flow: row wrap;
  401. width: 100%;
  402. .el-tag {
  403. margin: 5px;
  404. }
  405. }
  406. </style>