index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <el-dialog v-model="isShow" :title="title" width="47rem" class="hc-modal-border" draggable destroy-on-close @closed="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 label="任务描述" prop="taskContent">
  8. <el-input type="textarea" v-model="formModel.taskContent" placeholder="请输入任务描述" :autosize="{ minRows: 3, maxRows: 5 }"/>
  9. </el-form-item>
  10. <el-form-item label="任务流程" prop="fixedFlowId">
  11. <el-select v-model="formModel.fixedFlowId" block @change="handleProcessValue">
  12. <el-option v-for="item in processData" :label="item.fixedFlowName" :disabled="item.disabled" :value="item.id"/>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="任务人" prop="user" v-if="diyProcessUser">
  16. <HcTasksUser ui="w-full" :projectId="projectId" :contractId="contractId" :type="type" :typeData="typeData" @change="diyProcessUserChange"/>
  17. </el-form-item>
  18. <el-form-item label="任务人" v-else>
  19. <div class="form-item-div">{{linkUserJoinString}}</div>
  20. </el-form-item>
  21. <el-form-item label="上报批次">
  22. <HcCounter v-model:value="formModel.batch" @update:modelValue="batchUpdateValue"/>
  23. </el-form-item>
  24. <el-form-item label="限定审批时间">
  25. <HcCounter v-model:value="formModel.restrictDay" text="(天)" @update:modelValue="restrictDayUpdateValue"/>
  26. </el-form-item>
  27. </el-form>
  28. <template #footer>
  29. <div class="dialog-footer">
  30. <el-button size="large" @click="cancelReportClick">取消</el-button>
  31. <el-button type="primary" hc-btn :loading="formReportLoading" @click="formReportClick">提交</el-button>
  32. </div>
  33. </template>
  34. </el-dialog>
  35. </template>
  36. <script setup>
  37. import {ref,watch,onMounted} from "vue";
  38. import tasksFlowApi from '~api/tasks/flow';
  39. import {ApprovalApi,queryFixedFlow} from '~api/other';
  40. import {getArrValue,getIndex,formValidate} from "vue-utils-plus"
  41. const props = defineProps({
  42. show: {
  43. type: Boolean,
  44. default: false
  45. },
  46. title: {
  47. type: String,
  48. default: '上报审批'
  49. },
  50. taskName: {
  51. type: String,
  52. default: ''
  53. },
  54. ids: {
  55. type: String,
  56. default: null
  57. },
  58. projectId: {
  59. type: [String,Number],
  60. default: ''
  61. },
  62. contractId: {
  63. type: [String,Number],
  64. default: ''
  65. },
  66. url: {
  67. type: [String,Number],
  68. default: ''
  69. },
  70. addition: {
  71. type: Object,
  72. default: () => ({})
  73. },
  74. type: { //first,log,wbs
  75. type: [String,Number],
  76. default: ''
  77. },
  78. typeData: {
  79. type: [String, Number, Array, Object],
  80. default: ''
  81. },
  82. })
  83. //变量
  84. const isShow = ref(props.show)
  85. const projectId = ref(props.projectId)
  86. const contractId = ref(props.contractId)
  87. const ApiUrl = ref(props.url)
  88. const isTypes = ref(props.type)
  89. const typeDatas = ref(props.typeData)
  90. //表单
  91. const formRef = ref(null)
  92. const processData = ref([])
  93. const formModel = ref({
  94. projectId: projectId.value, contractId: contractId.value, ids: props.ids,
  95. taskName: props.taskName, taskContent: '', fixedFlowId: '', batch: 1, restrictDay: 1,
  96. ...props.addition
  97. })
  98. const formRules = ref({
  99. taskContent: {
  100. required: true,
  101. trigger: "blur",
  102. message: "请输入任务描述"
  103. },
  104. fixedFlowId: {
  105. required: true,
  106. trigger: "blur",
  107. message: "请选择任务流程"
  108. },
  109. user: {
  110. required: true,
  111. trigger: "blur",
  112. message: "请选择任务人"
  113. }
  114. })
  115. //监听
  116. watch(() => [
  117. props.show,
  118. props.projectId,
  119. props.contractId,
  120. props.taskName,
  121. props.ids,
  122. props.url,
  123. props.addition,
  124. props.type,
  125. props.typeData
  126. ], ([val,pid,cid,name,ids,url,addition, type, typeData]) => {
  127. isShow.value = val
  128. projectId.value = pid
  129. contractId.value = cid
  130. ApiUrl.value = url
  131. //更新到表单数据
  132. formModel.value = {
  133. projectId: pid, contractId: cid, ids: ids, taskName: name,
  134. taskContent: '', fixedFlowId: '', batch: 1, restrictDay: 1,
  135. ...addition
  136. }
  137. isTypes.value = type
  138. typeDatas.value = typeData
  139. if (val) {
  140. getProcessDatasApi()
  141. }
  142. })
  143. //渲染完成
  144. onMounted(() => {
  145. getProcessDatasApi()
  146. })
  147. const processDefaultData = [{ id: 0, fixedFlowName: '自定义流程', disabled: false}]
  148. const getProcessDatasApi = () => {
  149. if (isShow.value) {
  150. const type = isTypes.value
  151. if (type === 'first' || type === 'log' || type === 'wbs') {
  152. queryFixedFlowApi(type, typeDatas.value)
  153. } else {
  154. getProcessData()
  155. }
  156. }
  157. }
  158. //获取流程数据
  159. const linkUserJoinString = ref('')
  160. const getProcessData = async () => {
  161. linkUserJoinString.value = ''
  162. const { error, code, data } = await tasksFlowApi.getPageData({
  163. projectId: projectId.value,
  164. contractId: contractId.value,
  165. current: 1, size: 100
  166. })
  167. if (!error && code === 200) {
  168. const arr = getArrValue(data['records'])
  169. processData.value = [...processDefaultData, ...arr]
  170. } else {
  171. processData.value = processDefaultData
  172. }
  173. }
  174. //获取符合条件的预设流程(三大填报页、日志列表的批量上报、首件列表的批量上报)
  175. const queryFixedFlowApi = async (type, datas) => {
  176. let flowJson = {}
  177. if (type === 'first') {
  178. flowJson['firstId'] = datas
  179. } else if (type === 'log') {
  180. flowJson['theLogPrimaryKeyId'] = datas
  181. } else if (type === 'wbs') {
  182. flowJson['privatePKeyId'] = datas
  183. }
  184. //请求数据
  185. linkUserJoinString.value = ''
  186. const { error, code, data } = await queryFixedFlow({
  187. projectId: projectId.value,
  188. contractId: contractId.value,
  189. ...flowJson
  190. })
  191. if (!error && code === 200) {
  192. const arr = getArrValue(data['records'])
  193. processData.value = [...processDefaultData, ...arr]
  194. } else {
  195. processData.value = processDefaultData
  196. }
  197. }
  198. //流程数据切换
  199. const diyProcessUser = ref(false)
  200. const handleProcessValue = (val) => {
  201. if (val > 0) {
  202. diyProcessUser.value = false
  203. const list = processData.value
  204. const index = getIndex(list, 'id', val)
  205. linkUserJoinString.value = list[index]?.linkUserJoinString
  206. } else {
  207. linkUserJoinString.value = ''
  208. diyProcessUser.value = true
  209. }
  210. }
  211. //自定义流程任务人选择完毕
  212. const userTasks = ref([])
  213. const diyProcessUserChange = (user, userId, users) => {
  214. userTasks.value = user
  215. }
  216. //上报批次改变
  217. const batchUpdateValue = (val) => {
  218. formModel.value.batch = val
  219. }
  220. //上报批次改变
  221. const restrictDayUpdateValue = (val) => {
  222. formModel.value.restrictDay = val
  223. }
  224. const emit = defineEmits(['hide','finish'])
  225. //取消
  226. const cancelReportClick = () => {
  227. linkUserJoinString.value = ''
  228. isShow.value = false
  229. emit('hide', false)
  230. }
  231. //上报
  232. const formReportClick = async () => {
  233. const res = await formValidate(formRef.value)
  234. if (res) await batchApprovalApi()
  235. }
  236. //上报请求
  237. const formReportLoading = ref(false)
  238. const batchApprovalApi = async () => {
  239. const type = isTypes.value
  240. formReportLoading.value = true
  241. //处理数据
  242. let flowJson = {}
  243. if (type === 'first' || type === 'log' || type === 'wbs') {
  244. flowJson['userTasks'] = userTasks.value
  245. }
  246. //发起请求
  247. const { error, code, data } = await ApprovalApi(ApiUrl.value, {
  248. projectId: projectId.value,
  249. contractId: contractId.value,
  250. ...formModel.value,
  251. ...flowJson
  252. })
  253. linkUserJoinString.value = ''
  254. formReportLoading.value = false
  255. if (!error && code === 200) {
  256. isShow.value = false
  257. window.$message?.success('上报成功')
  258. emit('hide', false)
  259. emit('finish', data)
  260. } else {
  261. processData.value = []
  262. }
  263. }
  264. </script>