index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 } 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. classifyType: {
  88. type: [String, Number],
  89. default: '',
  90. },
  91. tableOwner: {
  92. type: [String, Number],
  93. default: '',
  94. },
  95. url: {
  96. type: [String, Number],
  97. default: '',
  98. },
  99. datas: {
  100. type: Array,
  101. default: () => ([]),
  102. },
  103. isDatas: {
  104. type: Boolean,
  105. default: false,
  106. },
  107. addition: {
  108. type: Object,
  109. default: () => ({}),
  110. },
  111. type: { //first,log,wbs
  112. type: [String, Number],
  113. default: '',
  114. },
  115. typeData: {
  116. type: [String, Number, Array, Object],
  117. default: '',
  118. },
  119. trialSelfInspectionRecordId: {
  120. type: [String, Number],
  121. default: '',
  122. },
  123. nodeId:{
  124. type: [String, Number],
  125. default: '',
  126. },
  127. reportArr: {
  128. type: Array,
  129. default: () => ([]),
  130. },
  131. })
  132. const emit = defineEmits(['hide', 'finish', 'tagClose'])
  133. //变量
  134. const isShow = ref(props.show)
  135. const projectId = ref(props.projectId)
  136. const contractId = ref(props.contractId)
  137. const classifyType = ref(props.classifyType)
  138. const tableOwner = ref(props.tableOwner)
  139. const ApiUrl = ref(props.url)
  140. const isTypes = ref(props.type)
  141. const typeDatas = ref(props.typeData)
  142. const reportDatas = ref(props.datas)
  143. const nodeId = ref(props.nodeId)
  144. //表单
  145. const formRef = ref(null)
  146. const processData = ref([])
  147. const formModel = ref({
  148. projectId: projectId.value,
  149. contractId: contractId.value,
  150. ids: props.ids,
  151. userTasks: null,
  152. taskName: props.taskName,
  153. taskContent: '',
  154. fixedFlowId: '',
  155. batch: 1,
  156. restrictDay: 1,
  157. trialSelfInspectionRecordId: props.trialSelfInspectionRecordId,
  158. ...props.addition,
  159. })
  160. const formRules = ref({
  161. taskContent: {
  162. required: false,
  163. trigger: 'blur',
  164. message: '请输入任务描述',
  165. },
  166. fixedFlowId: {
  167. required: true,
  168. trigger: 'blur',
  169. message: '请选择任务流程',
  170. },
  171. userTasks: {
  172. required: true,
  173. trigger: 'blur',
  174. message: '请选择任务人',
  175. },
  176. })
  177. //监听
  178. watch(() => [
  179. props.show,
  180. props.projectId,
  181. props.contractId,
  182. props.classifyType,
  183. props.tableOwner,
  184. props.taskName,
  185. props.ids,
  186. props.url,
  187. props.addition,
  188. props.type,
  189. props.typeData,
  190. props.datas,
  191. props.trialSelfInspectionRecordId,
  192. props.nodeId,
  193. ], ([val, pid, cid, cla, tab, name, ids, url, addition, type, typeData, datas, trialSelfInspectionRecordId, nodeid]) => {
  194. isShow.value = val
  195. projectId.value = pid
  196. contractId.value = cid
  197. classifyType.value = cla
  198. tableOwner.value = tab
  199. ApiUrl.value = url
  200. nodeId.value = nodeid
  201. //更新到表单数据
  202. formModel.value = {
  203. projectId: pid,
  204. contractId: cid,
  205. ids: ids,
  206. taskName: name,
  207. taskContent: '',
  208. fixedFlowId: '',
  209. batch: 1,
  210. restrictDay: 1,
  211. trialSelfInspectionRecordId: trialSelfInspectionRecordId,
  212. ...addition,
  213. }
  214. isTypes.value = type
  215. typeDatas.value = typeData
  216. reportDatas.value = datas
  217. if (val) {
  218. getProcessDatasApi()
  219. }
  220. })
  221. //渲染完成
  222. onMounted(() => {
  223. getProcessDatasApi()
  224. })
  225. const processDefaultData = [{ id: 0, fixedFlowName: '自定义流程', disabled: false }]
  226. const getProcessDatasApi = () => {
  227. if (isShow.value) {
  228. const type = isTypes.value
  229. // if (type === 'first' || type === 'log' || type === 'wbs') {
  230. // queryFixedFlowApi(type, typeDatas.value)
  231. // }
  232. //日志填报先不调这个接口
  233. if (type === 'first' || type === 'wbs') {
  234. queryFixedFlowApi(type, typeDatas.value)
  235. } else if (type === 'query') {
  236. getProcessData(type, typeDatas.value)
  237. }
  238. }
  239. }
  240. //获取流程数据
  241. const infoIds = ref('')
  242. const linkUserJoinString = ref('')
  243. const getProcessData = async (type, datas) => {
  244. linkUserJoinString.value = ''
  245. let flowJson = {}
  246. if (type === 'first') {
  247. flowJson['firstId'] = datas
  248. } else if (type === 'log') {
  249. flowJson['theLogPrimaryKeyId'] = datas
  250. } else if (type === 'wbs' || type === 'query') {
  251. flowJson['privatePKeyId'] = datas
  252. }
  253. infoIds.value = arrToId(reportDatas.value)
  254. const { error, code, data } = await queryFixedFlow1({
  255. projectId: projectId.value,
  256. contractId: contractId.value,
  257. nodeId:nodeId.value,
  258. classifyType:classifyType.value,
  259. tableOwner:tableOwner.value,
  260. infoIds:infoIds.value,
  261. ...flowJson,
  262. })
  263. if (!error && code === 200) {
  264. const arr = getArrValue(data['records'])
  265. processData.value = [...processDefaultData, ...arr]
  266. } else {
  267. processData.value = processDefaultData
  268. }
  269. }
  270. //获取符合条件的预设流程(三大填报页、日志列表的批量上报、首件列表的批量上报)
  271. const queryFixedFlowApi = async (type, datas) => {
  272. let flowJson = {}
  273. if (type === 'first') {
  274. flowJson['firstId'] = datas
  275. } else if (type === 'log') {
  276. flowJson['theLogPrimaryKeyId'] = datas
  277. } else if (type === 'wbs') {
  278. flowJson['privatePKeyId'] = datas
  279. }
  280. //请求数据
  281. linkUserJoinString.value = ''
  282. const { error, code, data } = await queryFixedFlow({
  283. projectId: projectId.value,
  284. contractId: contractId.value,
  285. ...flowJson,
  286. nodeId:formModel.value.ids,
  287. classifyType:classifyType.value,
  288. tableOwner:tableOwner.value,
  289. })
  290. if (!error && code === 200) {
  291. const arr = getArrValue(data['records'])
  292. processData.value = [...processDefaultData, ...arr]
  293. } else {
  294. processData.value = processDefaultData
  295. }
  296. }
  297. //流程数据切换
  298. const diyProcessUser = ref(false)
  299. const handleProcessValue = (val) => {
  300. if (val > 0) {
  301. diyProcessUser.value = false
  302. const list = processData.value
  303. const index = arrIndex(list, 'id', val)
  304. linkUserJoinString.value = list[index]?.linkUserJoinString
  305. } else {
  306. linkUserJoinString.value = ''
  307. diyProcessUser.value = true
  308. }
  309. }
  310. //自定义流程任务人选择完毕
  311. const diyProcessUserChange = (user) => {
  312. formModel.value.userTasks = user
  313. }
  314. //审批内容的标签移除
  315. const taskTagClose = (index) => {
  316. reportDatas.value.splice(index, 1)
  317. emit('tagClose', index)
  318. if (reportDatas.value.length <= 0) {
  319. window.$message?.warning('请重新选择要上报的内容')
  320. cancelReportClick()
  321. }
  322. }
  323. //取消
  324. const cancelReportClick = () => {
  325. linkUserJoinString.value = ''
  326. isShow.value = false
  327. emit('hide', false)
  328. }
  329. //上报
  330. const formReportClick = async () => {
  331. const res = await formValidate(formRef.value)
  332. if (res) await batchApprovalApi()
  333. }
  334. //上报请求
  335. const formReportLoading = ref(false)
  336. const batchApprovalApi = async () => {
  337. formReportLoading.value = true
  338. //发起请求
  339. const { error, code, data } = await ApprovalApi(ApiUrl.value, {
  340. projectId: projectId.value,
  341. contractId: contractId.value,
  342. ...formModel.value,
  343. })
  344. linkUserJoinString.value = ''
  345. formReportLoading.value = false
  346. if (!error && code === 200) {
  347. isShow.value = false
  348. window.$message?.success('上报成功')
  349. emit('hide', false)
  350. emit('finish', data)
  351. } else {
  352. processData.value = []
  353. }
  354. }
  355. </script>
  356. <style lang="scss">
  357. .task-tag-data-box {
  358. position: relative;
  359. border: 1px solid #e0e0e6;
  360. border-radius: 4px;
  361. padding: 5px;
  362. min-height: 40px;
  363. display: flex;
  364. align-items: center;
  365. flex-flow: row wrap;
  366. width: 100%;
  367. .el-tag {
  368. margin: 5px;
  369. }
  370. }
  371. </style>