代码提交
This commit is contained in:
parent
82b511b50b
commit
8b6c4caa1d
|
|
@ -92,11 +92,12 @@
|
|||
</el-form>
|
||||
|
||||
<el-card class="content-box">
|
||||
<el-row>
|
||||
<!-- <el-row>
|
||||
<el-col :span="24" style="text-align: right;">
|
||||
<el-button type="primary" icon="el-icon-refresh" size="mini" @click="onHandleBatchRetire">批量退役</el-button>
|
||||
<el-button type="primary" icon="el-icon-refresh" size="mini" @click="onHandleBatchRetire">批量退役
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-row>-->
|
||||
<div class="table-container">
|
||||
<el-table :data="tableData" style="width: 100%" border stripe height="100%">
|
||||
<el-table-column align="center" show-overflow-tooltip type="index" label="序号" width="50"/>
|
||||
|
|
@ -134,14 +135,14 @@
|
|||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" show-overflow-tooltip prop="address" label="操作">
|
||||
<!-- <el-table-column align="center" show-overflow-tooltip prop="address" label="操作">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="primary" size="mini" @click="onHandleRetire(scope.row)">退役</el-button>
|
||||
<!-- <el-button type="primary" size="mini" @click="onHandleRetireEquipment(scope.row)">
|
||||
<!– <el-button type="primary" size="mini" @click="onHandleRetireEquipment(scope.row)">
|
||||
退役装备
|
||||
</el-button> -->
|
||||
</el-button> –>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table-column>-->
|
||||
</el-table>
|
||||
</div>
|
||||
<div class="pagination-wrapper">
|
||||
|
|
@ -370,6 +371,7 @@ export default {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dialog-table {
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@
|
|||
</el-form-item>
|
||||
|
||||
|
||||
|
||||
</el-form>
|
||||
|
||||
</el-card>
|
||||
|
|
@ -318,6 +317,7 @@ export default {
|
|||
proLocation: '', // 详细地址
|
||||
useUnit: '', // 需求单位
|
||||
useTime: null,
|
||||
leaseType: '0',
|
||||
pageNum: 1, // 页码
|
||||
pageSize: 10 // 每页条数
|
||||
},
|
||||
|
|
@ -337,7 +337,7 @@ export default {
|
|||
proCounty: [{ required: true, message: '请选择项目所在区/县', trigger: 'change' }],
|
||||
proLocation: [{ required: true, message: '请输入详细地址', trigger: 'blur' }],
|
||||
useUnit: [{ required: true, message: '请输入需求单位', trigger: 'blur' }],
|
||||
useTimeRange: [{ required: true, message: '请选择使用到期日期', trigger: 'change' }],
|
||||
useTimeRange: [{ required: true, message: '请选择使用到期日期', trigger: 'change' }]
|
||||
|
||||
},
|
||||
|
||||
|
|
@ -403,8 +403,8 @@ export default {
|
|||
'queryParams.useTimeRange'(newVal) {
|
||||
if (newVal && newVal.length === 2 && this.tableList.length > 0) {
|
||||
this.tableList.forEach(item => {
|
||||
item.useTimeRange = [...newVal]; // 同步主表单的日期范围
|
||||
});
|
||||
item.useTimeRange = [...newVal] // 同步主表单的日期范围
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -415,12 +415,12 @@ export default {
|
|||
const [resProject, resVoltage] = await Promise.all([
|
||||
getUseProjectListAPI(),
|
||||
getVoltageListAPI()
|
||||
]);
|
||||
])
|
||||
this.useProjectList = resProject.data || []
|
||||
this.voltageList = resVoltage.data || []
|
||||
} catch (error) {
|
||||
this.$message.error('获取项目或电压等级列表失败');
|
||||
console.error(error);
|
||||
this.$message.error('获取项目或电压等级列表失败')
|
||||
console.error(error)
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -461,14 +461,14 @@ export default {
|
|||
async getList(emit = {}) {
|
||||
// 如果从emit传入id,更新查询参数
|
||||
if (emit.id) {
|
||||
this.queryParams.id = emit.id;
|
||||
this.$route.query.id = this.queryParams.id;
|
||||
this.queryParams.id = emit.id
|
||||
this.$route.query.id = this.queryParams.id
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
this.isLoading = true
|
||||
try {
|
||||
const params = { ...this.queryParams };
|
||||
const res = await getApplyDetailsApi(params); // 调用接口获取详情
|
||||
const params = { ...this.queryParams }
|
||||
const res = await getApplyDetailsApi(params) // 调用接口获取详情
|
||||
|
||||
// 初始化表格数据(重点处理日期)
|
||||
this.tableList = (res.data.devDetailsList || []).map(item => ({
|
||||
|
|
@ -477,29 +477,29 @@ export default {
|
|||
useTimeRange: item.useStartTime && item.useEndTime
|
||||
? [new Date(item.useStartTime), new Date(item.useEndTime)]
|
||||
: [] // 无日期时设为空数组
|
||||
}));
|
||||
}))
|
||||
|
||||
// 如果是编辑/查看模式,初始化主表单数据
|
||||
if (this.queryParams.id && res.data.devInfo) {
|
||||
Object.assign(this.queryParams, res.data.devInfo);
|
||||
Object.assign(this.queryParams, res.data.devInfo)
|
||||
|
||||
// 初始化主表单的全局日期范围(如果后端返回了全局日期)
|
||||
if (res.data.devInfo.useStartTime && res.data.devInfo.useEndTime) {
|
||||
this.queryParams.useTimeRange = [
|
||||
new Date(res.data.devInfo.useStartTime),
|
||||
new Date(res.data.devInfo.useEndTime)
|
||||
];
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
this.total = res.data.total || 0;
|
||||
this.total = res.data.total || 0
|
||||
} catch (error) {
|
||||
this.tableList = [];
|
||||
this.total = 0;
|
||||
this.$message.error('获取申请详情失败');
|
||||
console.error('getList error:', error);
|
||||
this.tableList = []
|
||||
this.total = 0
|
||||
this.$message.error('获取申请详情失败')
|
||||
console.error('getList error:', error)
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
this.isLoading = false
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -517,20 +517,20 @@ export default {
|
|||
})
|
||||
}).catch(() => {
|
||||
// 用户点击取消,不做操作
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
// 打开添加申请弹窗
|
||||
handleDialog() {
|
||||
this.addQuery.pageNum = 1;
|
||||
this.resetAddQuery(); // 打开时重置查询条件和分页
|
||||
this.addQuery.pageNum = 1
|
||||
this.resetAddQuery() // 打开时重置查询条件和分页
|
||||
this.openAdd = true
|
||||
// 确保弹窗打开后表格能正确渲染
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.addTable) {
|
||||
this.$refs.addTable.clearSelection();
|
||||
this.$refs.addTable.clearSelection()
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -539,70 +539,70 @@ export default {
|
|||
*/
|
||||
getApplyList(pagination = {}) {
|
||||
// 合并分页参数,优先使用分页组件传递的参数
|
||||
const pageNum = pagination.pageNum || this.addQuery.pageNum;
|
||||
const pageSize = pagination.pageSize || this.addQuery.pageSize;
|
||||
const pageNum = pagination.pageNum || this.addQuery.pageNum
|
||||
const pageSize = pagination.pageSize || this.addQuery.pageSize
|
||||
|
||||
// 更新组件内的分页状态
|
||||
this.addQuery.pageNum = pageNum;
|
||||
this.addQuery.pageSize = pageSize;
|
||||
this.addQuery.pageNum = pageNum
|
||||
this.addQuery.pageSize = pageSize
|
||||
|
||||
// 构造完整的查询参数(包含devType)
|
||||
const queryParams = {
|
||||
...this.filterParams,
|
||||
pageNum,
|
||||
pageSize
|
||||
};
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
this.isLoading = true
|
||||
|
||||
getApplyListApi(queryParams)
|
||||
.then(response => {
|
||||
if (response && response.data) {
|
||||
this.addList = response.data.rows || [];
|
||||
this.addTotal = response.data.total || 0;
|
||||
this.addList = response.data.rows || []
|
||||
this.addTotal = response.data.total || 0
|
||||
|
||||
// 初始化申请数量
|
||||
this.addList.forEach(item => {
|
||||
item.num = item.manageType === 0 ? 1 : 0;
|
||||
});
|
||||
item.num = item.manageType == '0' ? 1 : 0
|
||||
})
|
||||
} else {
|
||||
this.addList = [];
|
||||
this.addTotal = 0;
|
||||
this.$message.warning('获取数据格式异常');
|
||||
this.addList = []
|
||||
this.addTotal = 0
|
||||
this.$message.warning('获取数据格式异常')
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
this.addList = [];
|
||||
this.addTotal = 0;
|
||||
this.$message.error(`获取设备列表失败:${error.message || '未知错误'}`);
|
||||
console.error('分页查询失败:', error);
|
||||
this.addList = []
|
||||
this.addTotal = 0
|
||||
this.$message.error(`获取设备列表失败:${error.message || '未知错误'}`)
|
||||
console.error('分页查询失败:', error)
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoading = false;
|
||||
});
|
||||
this.isLoading = false
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 添加申请查询(核心:处理devType筛选逻辑)
|
||||
*/
|
||||
handleAddQuery() {
|
||||
this.addQuery.pageNum = 1; // 查询时重置页码为1
|
||||
this.addQuery.pageNum = 1 // 查询时重置页码为1
|
||||
|
||||
const queryParams = { ...this.addQuery };
|
||||
const queryParams = { ...this.addQuery }
|
||||
|
||||
// 1. 处理devType(直接使用选择的分类值:1=装备,2=工具)
|
||||
const devType = queryParams.devType || '';
|
||||
const devType = queryParams.devType || ''
|
||||
|
||||
// 2. 处理装备分类(仅当选择装备时生效)
|
||||
let categoryEquipment = '';
|
||||
let categoryEquipment = ''
|
||||
if (devType === '1' && queryParams.categoryPath && Array.isArray(queryParams.categoryPath) && queryParams.categoryPath.length > 0) {
|
||||
categoryEquipment = String(queryParams.categoryPath[queryParams.categoryPath.length - 1]);
|
||||
categoryEquipment = String(queryParams.categoryPath[queryParams.categoryPath.length - 1])
|
||||
}
|
||||
|
||||
// 3. 处理工具分类(仅当选择工具时生效)
|
||||
let toolTypeId = '';
|
||||
let toolTypeId = ''
|
||||
if (devType === '2' && queryParams.toolCategoryPath && Array.isArray(queryParams.toolCategoryPath) && queryParams.toolCategoryPath.length > 0) {
|
||||
toolTypeId = String(queryParams.toolCategoryPath[queryParams.toolCategoryPath.length - 1]);
|
||||
toolTypeId = String(queryParams.toolCategoryPath[queryParams.toolCategoryPath.length - 1])
|
||||
}
|
||||
|
||||
// 保存筛选条件(包含devType)
|
||||
|
|
@ -614,13 +614,13 @@ export default {
|
|||
toolTypeId,
|
||||
devType, // 关键:将devType传递给后端筛选
|
||||
manageType: queryParams.manageType // 关键:将manageType传递给后端筛选
|
||||
};
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
this.getApplyList({
|
||||
pageNum: this.addQuery.pageNum,
|
||||
pageSize: this.addQuery.pageSize
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -636,7 +636,7 @@ export default {
|
|||
toolCategoryPath: '',
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
};
|
||||
}
|
||||
|
||||
// 同步重置筛选参数
|
||||
this.filterParams = {
|
||||
|
|
@ -646,10 +646,10 @@ export default {
|
|||
categoryEquipment: '',
|
||||
toolTypeId: '',
|
||||
devType: '' // 重置devType筛选
|
||||
};
|
||||
}
|
||||
|
||||
// 重置后触发一次查询
|
||||
this.getApplyList({ pageNum: 1, pageSize: this.addQuery.pageSize });
|
||||
this.getApplyList({ pageNum: 1, pageSize: this.addQuery.pageSize })
|
||||
},
|
||||
|
||||
// 返回上一页
|
||||
|
|
@ -666,6 +666,7 @@ export default {
|
|||
|
||||
// 选择项变化(表格勾选时触发,保留devType)
|
||||
handleSelectionChange(selection) {
|
||||
console.log(selection)
|
||||
this.addTempList = []
|
||||
this.ids = selection.map(item => item.id)
|
||||
selection.forEach(item => {
|
||||
|
|
@ -679,7 +680,7 @@ export default {
|
|||
manageType: item.manageType,
|
||||
devCode: item.devCode,
|
||||
storageNum: item.storageNum,
|
||||
num: item.manageType == 0 ? 1 : item.storageNum, // 编码设备默认1,数量设备取输入值
|
||||
num: item.manageType === '0' ? '1' : item.storageNum, // 编码设备默认1,数量设备取输入值
|
||||
useTime: this.queryParams.useTime ? new Date(this.queryParams.useTime) : null // 默认为主表单的使用日期
|
||||
})
|
||||
})
|
||||
|
|
@ -711,7 +712,7 @@ export default {
|
|||
})
|
||||
row.num = row.storageNum // 超过库存时,自动设为最大库存
|
||||
} else if (row.num < 0) {
|
||||
row.num = 0; // 防止输入负数
|
||||
row.num = 0 // 防止输入负数
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -723,7 +724,7 @@ export default {
|
|||
}
|
||||
|
||||
const itemsToAdd = this.addList.filter(item => this.ids.includes(item.id))
|
||||
const invalidItem = itemsToAdd.find(item => item.manageType === 1 && (item.num === 0 || !item.num))
|
||||
const invalidItem = itemsToAdd.find(item => item.manageType === '1' && (item.num == 0 || !item.num))
|
||||
if (invalidItem) {
|
||||
this.$message.error('请为数量管理的设备填写申请数量。')
|
||||
return
|
||||
|
|
@ -752,54 +753,54 @@ export default {
|
|||
// 提交
|
||||
async submit() {
|
||||
this.$refs.queryForm.validate(async(valid) => {
|
||||
if (!valid) return;
|
||||
if (!valid) return
|
||||
|
||||
this.$confirm('是否确定提交申请?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async() => {
|
||||
this.isLoading = true;
|
||||
this.isLoading = true
|
||||
try {
|
||||
// --- 修改开始:健壮的日期格式化函数 ---
|
||||
const safeFormatDate = (dateInput) => {
|
||||
// 1. 检查输入是否为 null 或 undefined
|
||||
if (!dateInput) {
|
||||
console.warn('尝试格式化一个空的日期值');
|
||||
return ''; // 或根据业务返回 '1970-01-01' 等默认值
|
||||
console.warn('尝试格式化一个空的日期值')
|
||||
return '' // 或根据业务返回 '1970-01-01' 等默认值
|
||||
}
|
||||
|
||||
// 2. 确保输入是一个 Date 对象
|
||||
let date;
|
||||
let date
|
||||
if (dateInput instanceof Date) {
|
||||
date = dateInput;
|
||||
date = dateInput
|
||||
} else {
|
||||
// 如果是字符串,尝试将其转换为 Date 对象
|
||||
date = new Date(dateInput);
|
||||
date = new Date(dateInput)
|
||||
}
|
||||
|
||||
// 3. 检查 Date 对象是否有效
|
||||
if (isNaN(date.getTime())) {
|
||||
console.error('无效的日期值:', dateInput);
|
||||
return ''; // 或抛出错误
|
||||
console.error('无效的日期值:', dateInput)
|
||||
return '' // 或抛出错误
|
||||
}
|
||||
|
||||
// 4. 执行格式化
|
||||
const year = date.getFullYear();
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = date.getDate().toString().padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
};
|
||||
const year = date.getFullYear()
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0')
|
||||
const day = date.getDate().toString().padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
// --- 修改结束 ---
|
||||
|
||||
// 1. 处理主表单的日期范围
|
||||
const devInfo = { ...this.queryParams };
|
||||
const devInfo = { ...this.queryParams }
|
||||
if (devInfo.useTimeRange && devInfo.useTimeRange.length === 2) {
|
||||
// 使用健壮的格式化函数
|
||||
devInfo.useStartTime = safeFormatDate(devInfo.useTimeRange[0]);
|
||||
devInfo.useEndTime = safeFormatDate(devInfo.useTimeRange[1]);
|
||||
devInfo.useStartTime = safeFormatDate(devInfo.useTimeRange[0])
|
||||
devInfo.useEndTime = safeFormatDate(devInfo.useTimeRange[1])
|
||||
}
|
||||
delete devInfo.useTimeRange;
|
||||
delete devInfo.useTimeRange
|
||||
|
||||
// 2. 处理表格数据的日期
|
||||
const tempTableList = this.tableList.map(item => ({
|
||||
|
|
@ -810,35 +811,35 @@ export default {
|
|||
useEndTime: safeFormatDate(item.useTimeRange[1]),
|
||||
useTimeRange: undefined,
|
||||
useTime: undefined
|
||||
}));
|
||||
}))
|
||||
|
||||
const params = {
|
||||
devInfo,
|
||||
devDetailsList: tempTableList
|
||||
};
|
||||
}
|
||||
|
||||
// ... 后续提交逻辑 ...
|
||||
let res;
|
||||
let res
|
||||
if (!this.routerParams.id) {
|
||||
res = await addApplyApi(params);
|
||||
res = await addApplyApi(params)
|
||||
} else {
|
||||
res = await editApplyApi(params);
|
||||
res = await editApplyApi(params)
|
||||
}
|
||||
|
||||
if (res.code === 200) {
|
||||
this.$message.success(res.message || '操作成功!');
|
||||
this.$router.go(-1);
|
||||
this.$message.success(res.message || '操作成功!')
|
||||
this.$router.go(-1)
|
||||
} else {
|
||||
this.$message.error(res.message || '操作失败!');
|
||||
this.$message.error(res.message || '操作失败!')
|
||||
}
|
||||
} catch (error) {
|
||||
this.$message.error('提交申请异常,请稍后重试');
|
||||
console.error('submit error:', error);
|
||||
this.$message.error('提交申请异常,请稍后重试')
|
||||
console.error('submit error:', error)
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
this.isLoading = false
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// 处理分类树数据(适配六级分类)
|
||||
|
|
|
|||
Loading…
Reference in New Issue