index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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="任务描述" path="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="任务流程" path="fixedFlowId">
  11. <el-select v-model="formModel.fixedFlowId" block @change="handleProcessValue">
  12. <el-option v-for="item in processData" :label="item.fixedFlowName" :value="item.id"/>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="任务人" path="user" v-if="false">
  16. <HcTasksUser ui="w-full"/>
  17. </el-form-item>
  18. <el-form-item label="任务人">
  19. <div class="form-item-div">{{linkUserJoinString}}</div>
  20. </el-form-item>
  21. <el-form-item label="上报批次" path="batch">
  22. <HcCounter v-model:value="formModel.batch" @update:modelValue="batchUpdateValue"/>
  23. </el-form-item>
  24. <el-form-item label="限定审批时间" path="restrictDay">
  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. typeDatas.value = typeData
  138. if (type !== isTypes.value) {
  139. isTypes.value = type
  140. getProcessDatasApi()
  141. }
  142. })
  143. //渲染完成
  144. onMounted(() => {
  145. getProcessDatasApi()
  146. })
  147. const getProcessDatasApi = () => {
  148. if (isShow.value) {
  149. const type = isTypes.value
  150. if (type === 'first' || type === 'log' || type === 'wbs') {
  151. queryFixedFlowApi(type, typeDatas.value)
  152. } else {
  153. getProcessData()
  154. }
  155. }
  156. }
  157. //获取流程数据
  158. const linkUserJoinString = ref('')
  159. const getProcessData = async () => {
  160. linkUserJoinString.value = ''
  161. const { error, code, data } = await tasksFlowApi.getPageData({
  162. projectId: projectId.value,
  163. contractId: contractId.value,
  164. current: 1, size: 100
  165. })
  166. if (!error && code === 200) {
  167. processData.value = getArrValue(data['records'])
  168. } else {
  169. processData.value = []
  170. }
  171. }
  172. //获取符合条件的预设流程(三大填报页、日志列表的批量上报、首件列表的批量上报)
  173. const queryFixedFlowApi = async (type, datas) => {
  174. let flowJson = {}
  175. if (type === 'first') {
  176. flowJson['firstId'] = datas
  177. } else if (type === 'log') {
  178. flowJson['theLogPrimaryKeyId'] = datas
  179. } else if (type === 'wbs') {
  180. flowJson['privatePKeyId'] = datas
  181. }
  182. //请求数据
  183. linkUserJoinString.value = ''
  184. const { error, code, data } = await queryFixedFlow({
  185. projectId: projectId.value,
  186. contractId: contractId.value,
  187. ...flowJson
  188. })
  189. if (!error && code === 200) {
  190. processData.value = getArrValue(data['records'])
  191. } else {
  192. processData.value = []
  193. }
  194. }
  195. //流程数据切换
  196. const handleProcessValue = (val) => {
  197. const list = processData.value
  198. const index = getIndex(list, 'id', val)
  199. linkUserJoinString.value = list[index]?.linkUserJoinString
  200. }
  201. //上报批次改变
  202. const batchUpdateValue = (val) => {
  203. formModel.value.batch = val
  204. }
  205. //上报批次改变
  206. const restrictDayUpdateValue = (val) => {
  207. formModel.value.restrictDay = val
  208. }
  209. const emit = defineEmits(['hide','finish'])
  210. //取消
  211. const cancelReportClick = () => {
  212. linkUserJoinString.value = ''
  213. isShow.value = false
  214. emit('hide', false)
  215. }
  216. //上报
  217. const formReportClick = async () => {
  218. const res = await formValidate(formRef.value)
  219. if (res) await batchApprovalApi()
  220. }
  221. //上报请求
  222. const formReportLoading = ref(false)
  223. const batchApprovalApi = async () => {
  224. formReportLoading.value = true
  225. const { error, code, data } = await ApprovalApi(ApiUrl.value, {
  226. projectId: projectId.value,
  227. contractId: contractId.value,
  228. ...formModel.value
  229. })
  230. linkUserJoinString.value = ''
  231. formReportLoading.value = false
  232. if (!error && code === 200) {
  233. isShow.value = false
  234. window.$message?.success('上报成功')
  235. emit('hide', false)
  236. emit('finish', data)
  237. } else {
  238. processData.value = []
  239. }
  240. }
  241. </script>