From 3ab9ac039c0dcb4f35e8d7293a8b159ea8316f9e Mon Sep 17 00:00:00 2001 From: hayu <1604366271@qq.com> Date: Thu, 30 Oct 2025 19:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E7=A8=8B=E7=9B=B4=E8=BD=AC=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/lease/apply.js | 16 + .../business/businessHandling/directApply.vue | 503 ++++++++++++++---- 2 files changed, 415 insertions(+), 104 deletions(-) diff --git a/src/api/lease/apply.js b/src/api/lease/apply.js index fd1f973f..1cb468b1 100644 --- a/src/api/lease/apply.js +++ b/src/api/lease/apply.js @@ -207,3 +207,19 @@ export function getCheckInfo(data) { }) } + +export function getProjectList(data) { + return request({ + url: '/material/material_maMachine/getProjectList', + method: 'get', + params: data, + }) +} + +export function getDepartNameList(data) { + return request({ + url: '/material/material_maMachine/getDepartNameList', + method: 'get', + params: data, + }) +} diff --git a/src/views/business/businessHandling/directApply.vue b/src/views/business/businessHandling/directApply.vue index 348923fd..709245d9 100644 --- a/src/views/business/businessHandling/directApply.vue +++ b/src/views/business/businessHandling/directApply.vue @@ -5,39 +5,86 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + import { getMaTypeOpt } from '@/api/ma/base' -import {getListProject, getListUnite, getAgreement, getUnitProDepList} from '@/api/lease/apply' +import { + getListProject, + getListUnite, + getAgreement, + getUnitProDepList, + getProjectList, + getDepartNameList +} from '@/api/lease/apply' import { downloadFile, downloadFileData } from '@/utils/download' import { getUseringData, receiveSubmitTwo, receiveEdit, receiveDetail, getEquipmentThreeTypes } from '@/api/business/index' import Treeselect from '@riophae/vue-treeselect' import '@riophae/vue-treeselect/dist/vue-treeselect.css' import { getToken } from '@/utils/auth' import Pagination from '@/components/Pagination' +import {getImpUnitListApi} from "@/api/materialsStation"; export default { name: 'DirectApply', @@ -444,6 +538,20 @@ export default { }, // 表单校验 rules: { + impUnitName: [ + { + required: true, + message: '请选择转出分公司', + trigger: 'blur' + } + ], + departName: [ + { + required: true, + message: '请选择转出项目部', + trigger: 'blur' + } + ], backUnitId: [ { required: true, @@ -517,7 +625,12 @@ export default { dialogVisible: false, uploadKey: Date.now(), uploadUrl: process.env.VUE_APP_BASE_API + '/file/upload', // 上传的图片服务器地址 - headers: { Authorization: 'Bearer ' + getToken() } + headers: { Authorization: 'Bearer ' + getToken() }, + impUnitOptions: [], // 分公司下拉选项 + departOptions: [],//项目部下拉 + impProOptions: [],//转出工程下拉 + impUnitOptionsTwo: [], // 分公司下拉选项 + departOptionsTwo: [],//项目部下拉 } }, computed: { @@ -549,11 +662,14 @@ export default { const obj = Object.assign({}, this.$route, { title: '直转申请' }) this.$tab.updatePage(obj) } - this.projectInfoList() // 单位工程下拉选 + if (this.isEdit || this.isDetail) { console.log('isEdit', this.isEdit) this.getTaskInfo() + } else { + this.getImpUnitOptions() } + this.getImpUnitOptionsTwo() console.log(this.$store, 'this.$store.getters') console.log(this.$route.query, 'this.$route.query') }, @@ -573,6 +689,187 @@ export default { } }, methods: { + /** 获取分公司下拉 */ + async getImpUnitOptions() { + try { + const res = await getImpUnitListApi() + this.impUnitOptions = res.data.map(item => ({ + label: item.impUnitName, + value: item.impUnitName + })) + if (this.impUnitOptions.length === 1) { + this.maForm.impUnitName = this.impUnitOptions[0].value + await this.onImpUnitChange(this.maForm.impUnitName) + } + } catch (e) { + console.error('获取分公司下拉失败:', e) + } + }, + + /** 分公司变化 */ + async onImpUnitChange(value) { + this.maForm.departName = '' + this.maForm.backProId = '' + this.maForm.backUnitId = undefined + this.departOptions = [] + this.impProOptions = [] + this.uniteList = [] + + if (!value) return + const res = await getDepartNameList({ companyName: value }) + this.departOptions = res.data.map(item => ({ + label: item.departName, + value: item.departName + })) + if (this.departOptions.length === 1) { + this.maForm.departName = this.departOptions[0].value + await this.onDepartChange(this.maForm.departName) + } + }, + + /** 项目部变化 */ + async onDepartChange(value) { + this.maForm.backProId = '' + this.maForm.backUnitId = undefined + this.impProOptions = [] + this.uniteList = [] + + if (!value) return + const res = await getProjectList({ departName: value }) + this.impProOptions = res.data.map(item => ({ + label: item.proName, + value: item.proId + })) + if (this.impProOptions.length === 1) { + this.maForm.backProId = this.impProOptions[0].value + await this.onProjectChange(this.maForm.backProId) + } + }, + + /** 工程变化 */ + async onProjectChange(value) { + // 每次工程变化都先清空 + this.maForm.backUnitId = undefined + this.uniteList = [] + // 没选工程就直接返回 + if (!value) return + try { + let edit =true; + if (this.isEdit){ + edit=false + } + const res = await getUnitProDepList({ projectId: value, enableFilter: edit }) + this.uniteList = res.data || [] + + // 自动选中唯一叶子节点 + const leafNodes = [] + const findLeaf = nodes => { + nodes.forEach(n => { + if (!n.children || n.children.length === 0) { + leafNodes.push(n) + } else { + findLeaf(n.children) + } + }) + } + findLeaf(this.uniteList) + if (leafNodes.length === 1) { + this.maForm.backUnitId = leafNodes[0].id || leafNodes[0].value + await this.getAgreementId() + } + } catch (e) { + console.error('获取单位列表失败:', e) + } + }, + + /** 获取转入分公司下拉 */ + async getImpUnitOptionsTwo() { + try { + const params = { + enableFilter: false + } + const res = await getImpUnitListApi(params) + this.impUnitOptionsTwo = res.data.map(item => ({ + label: item.impUnitName, + value: item.impUnitName + })) + if (this.impUnitOptionsTwo.length === 1) { + this.maForm.impUnitNameTwo = this.impUnitOptionsTwo[0].value + await this.onImpUnitChangeTwo(this.maForm.impUnitNameTwo) + } + } catch (e) { + console.error('获取分公司下拉失败:', e) + } + }, + /** 分公司变化 */ + async onImpUnitChangeTwo(value) { + this.maForm.departNameTwo = '' + this.maForm.leaseProId = '' + this.maForm.leaseUnitId = undefined + this.departOptionsTwo = [] + this.leaseProjectList = [] + this.lessUniteList = [] + + if (!value) return + const res = await getDepartNameList({ impUnitName: value ,enableFilter: false}) + this.departOptionsTwo = res.data.map(item => ({ + label: item.departName, + value: item.departName + })) + if (this.departOptionsTwo.length === 1) { + this.maForm.departNameTwo = this.departOptionsTwo[0].value + await this.onDepartChangeTwo(this.maForm.departNameTwo) + } + }, + /** 转入项目部变化 */ + async onDepartChangeTwo(value) { + this.maForm.leaseProId = '' + this.maForm.leaseUnitId = undefined + this.leaseProjectList = [] + this.lessUniteList = [] + + if (!value) return + const res = await getProjectList({ departName: value,enableFilter: false }) + this.leaseProjectList = res.data.map(item => ({ + label: item.proName, + value: item.proId + })) + if (this.leaseProjectList.length === 1) { + this.maForm.leaseProId = this.leaseProjectList[0].value + await this.onProjectChangeTwo(this.maForm.leaseProId) + } + }, + /** 转入工程变化 */ + async onProjectChangeTwo(value) { + // 每次工程变化都先清空 + this.maForm.leaseUnitId = undefined + this.lessUniteList = [] + // 没选工程就直接返回 + if (!value) return + try { + const res = await getUnitProDepList({ projectId: value, enableFilter: false }) + this.lessUniteList = res.data || [] + + // 自动选中唯一叶子节点 + const leafNodes = [] + const findLeaf = nodes => { + nodes.forEach(n => { + if (!n.children || n.children.length === 0) { + leafNodes.push(n) + } else { + findLeaf(n.children) + } + }) + } + findLeaf(this.lessUniteList) + if (leafNodes.length === 1) { + this.maForm.leaseUnitId = leafNodes[0].id || leafNodes[0].value + await this.getLeaseAgreementId() + } + } catch (e) { + console.error('获取单位列表失败:', e) + } + }, // 查询 handleQuery() { // 重置分页到第一页 @@ -790,12 +1087,13 @@ export default { this.getTypeModelNameOpt(val) }, uniteChange(val) { - setTimeout(() => { - getListProject({ unitId: this.maForm.backUnitId,enableFilter: true }).then(response => { - this.projectList = response.data - this.maForm.backProId = null - }) - }, 500) + // setTimeout(() => { + // getListProject({ unitId: this.maForm.backUnitId,enableFilter: true }).then(response => { + // this.projectList = response.data + // this.maForm.backProId = null + // }) + // }, 500) + this.getAgreementId() }, projectChange(val) { setTimeout(() => { @@ -814,51 +1112,12 @@ export default { }, 500) }, leaseProjectChange(val) { - setTimeout(() => { - getListUnite({}).then(res => { - this.leaseUniteList = res.data - }) + // setTimeout(() => { + // getListUnite({}).then(res => { + // this.leaseUniteList = res.data + // }) this.getLeaseAgreementId() - }, 500) - }, - /** 租赁单位和工程-下拉选 */ - projectInfoList() { - console.log("kkkkkkkkkkk",this.isEdit) - if (!this.isEdit) { - //转出单位 - getUnitProDepList({ projectId: null,enableFilter: true }).then(response => { - this.uniteList = response.data - }) - //转出工程 - getListProject({ unitId: null,enableFilter: true }).then(response => { - this.projectList = response.data - }) - //转入单位 - getUnitProDepList({ projectId: null }).then(response => { - this.lessUniteList = response.data - }) - //转入工程 - getListProject({ unitId: null }).then(response => { - this.leaseProjectList = response.data - }) - } else { - //转出单位 - getUnitProDepList({ projectId: null,enableFilter: true }).then(response => { - this.uniteList = response.data - }) - //转出工程 - getListProject({ unitId: this.maForm.backUnitId,enableFilter: true }).then(response => { - this.projectList = response.data - }) - //转入单位 - getUnitProDepList({ projectId: null }).then(response => { - this.lessUniteList = response.data - }) - //转入工程 - getListProject({ unitId: this.maForm.leaseUnitId }).then(response => { - this.leaseProjectList = response.data - }) - } + // }, 500) }, //获取任务详情--- 编辑回显数据 async getTaskInfo() { @@ -867,8 +1126,44 @@ export default { const res = await receiveDetail({ id: this.id }) console.log('🚀 ~ getTaskInfo ~ res:', res) this.maForm = res.data + this.maForm.impUnitName=res.data.backImpUnitName + this.maForm.departName=res.data.backDepartName + this.maForm.impUnitNameTwo=res.data.leaseImpUnitName + this.maForm.departNameTwo=res.data.leaseDepartName + this.maForm.leaseUnitId=res.data.leaseUnitId this.multipleSelectionTemp = res.data.directApplyDetails - this.getList() + //查询工程和单位 + if (this.maForm.departName){ + const res = await getProjectList({ departName: this.maForm.departName }) + this.impProOptions = res.data.map(item => ({ + label: item.proName, + value: item.proId + })) + // if (this.impProOptions.length === 1) { + // this.maForm.backProId = this.impProOptions[0].value + await this.onProjectChange(this.maForm.backProId) + // } + } + if (this.maForm.impUnitNameTwo){ + const res = await getDepartNameList({ impUnitName: this.maForm.impUnitNameTwo ,enableFilter: false}) + this.departOptionsTwo = res.data.map(item => ({ + label: item.departName, + value: item.departName + })) + } + if (this.maForm.departNameTwo){ + const res = await getProjectList({ departName: this.maForm.departNameTwo,enableFilter: false }) + this.leaseProjectList = res.data.map(item => ({ + label: item.proName, + value: item.proId + })) + // if (this.leaseProjectList.length === 1) { + // this.maForm.leaseProId = this.leaseProjectList[0].value + await this.onProjectChangeTwo(this.maForm.leaseProId) + // } + } + + await this.getList() console.log('🚀 ~ getTaskInfo ~ this.equipmentList:', this.equipmentList) loading.close() } catch (error) {