index.vue 9.2 KB

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