<template>
<dialog-edit
:visible.sync="open"
:title="activeTitle"
@close="handleDialogClose"
@changeTab="handleTabChange"
:menuTab="pageMenuTab"
:reserve="true"
>
<!-- 设备台账详情页 -->
<template slot="equipmentDetail">
<div class="dialog-content-wrap">
<formlist
v-if="dictLoaded"
:form="form"
:form2="formData"
:dictData="dictData"
ref="formList"
:readonly="true"
:width="'120px'"
/>
</div>
</template>
<!-- 气量检测页 -->
<template slot="GasMeasurement">
<div class="dialog-content-wrap" v-if="GasMeasurementReady">
<gas-detection
ref="GasMeasurementRef"
:equipment-id="currentEquipmentId"
@on-new="handleNewDetection"
@on-delete="handleDeleteDetection"
/>
</div>
</template>
<template v-slot:footer>
<div class="dialog_footer">
<el-button @click="handleCancel">关闭</el-button>
</div>
</template>
</dialog-edit>
</template>
<script>
import { getDictionaries } from "@/utils";
import DialogEdit from '@/components/dialogEdit'
import GasMeasurement from "../cmmsGasMeasurement/cmmsGasMeasurement.vue";
// 需要导入API函数
import { getCmmsEquipmentInfo } from "@/api/cmmsEquipmentInfo/cmmsEquipmentInfo.js";
export default {
name: "EquipmentDetailDialog",
components: {
GasMeasurement,
DialogEdit,
},
data() {
return {
dictLoaded: false,
form: [
{
arr: [
{
code: "equipmentCode",
title: "设备编码",
type: 0,
readonly: true,
verification: true,
rule: "0",
customTips: "",
regular: "",
dictionary: "",
},
{
code: "equipmentCategory",
title: "设备大类",
type: 1,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择设备大类",
dictionary: "equipment_category",
},
{
code: "equipmentSubcategory",
title: "设备小类",
type: 1,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择设备小类",
dictionary: "equipment_subcategory",
},
{
code: "modelDescription",
title: "燃气表型号描述",
type: 0,
readonly: true,
verification: true,
rule: "0",
customTips: "燃气表的具体型号描述",
regular: "",
},
{
code: "specificationModel",
title: "规格型号",
type: 0,
readonly: true,
verification: true,
rule: "0",
customTips: "设备的规格型号",
regular: "",
},
{
code: "accuracyLevel",
title: "器具准确度等级",
type: 1,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择准确度等级",
dictionary: "accuracy_level",
},
{
code: "manufacturer",
title: "器具生产单位",
type: 0,
readonly: true,
verification: true,
rule: "0",
customTips: "设备的生产厂家",
regular: "",
},
{
code: "ownershipType",
title: "归属类型",
type: 1,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择设备归属类型",
dictionary: "ownership_type",
},
{
code: "equipmentOwner",
title: "设备归属方",
type: 0,
readonly: true,
verification: true,
rule: "0",
customTips: "设备的所有者",
regular: "",
},
{
code: "purchaseDate",
title: "采购日期",
type: 6,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择采购日期",
dateType: "date",
dateFormat: "yyyy-MM-dd",
},
{
code: "storageLocation",
title: "存放位置",
type: 0,
readonly: true,
verification: true,
rule: "0",
customTips: "设备当前的存放位置",
regular: "",
},
{
code: "overdueYears",
title: "超期年限(年)",
type: 3,
readonly: true,
verification: true,
rule: "0",
customTips: "超出检定有效期的年限",
regular: "^[0-9]{1,2}$",
min: 0,
max: 20,
},
{
code: "lastVerificationDate",
title: "最后检定日期",
type: 6,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择最后检定日期",
dateType: "date",
dateFormat: "yyyy-MM-dd",
},
{
code: "equipmentStatus",
title: "设备状态",
type: 1,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择设备当前状态",
dictionary: "equipment_status",
},
{
code: "storageStatus",
title: "仓储状态",
type: 1,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择仓储状态",
dictionary: "storage_status",
},
{
code: "inspectionStatus",
title: "检测状态",
type: 1,
readonly: true,
verification: true,
rule: "0",
customTips: "请选择检测状态",
dictionary: "inspection_status",
},
{
code: "equipmentPhoto",
title: "设备照片",
type: 30,
readonly: true,
verification: true,
rule: "0",
customTips: "请上传设备照片",
multiple: false,
fileNum: 1,
accept: "image/jpeg,image/png",
maxSize: 5,
},
{
code: "remarks",
title: "备注",
type: 2,
readonly: true,
verification: true,
rule: "0",
customTips: "请填写备注信息",
rows: 4,
},
],
},
],
formData: {},
open: false,
dictData: {},
active: "equipmentDetail",
activeTitle: "设备详情",
currentEquipmentId: null,
GasMeasurementReady: false,
pageMenuTab: [
{
title: "基础信息",
sxTitle: "equipmentDetail",
hide: false,
icon: "el-icon-document",
},
{
title: "气量监测",
sxTitle: "GasMeasurement",
hide: false,
icon: "el-icon-data-line",
},
],
};
},
methods: {
async init(row) {
this.open = true;
this.active = "equipmentDetail";
this.activeTitle = "基础详情";
this.currentEquipmentId = row.id;
try {
// 并行加载字典和设备详情
const [dictData, detailData] = await Promise.all([
this.loadDictData().catch((e) => {
console.error("字典加载失败:", e);
return {};
}),
this.loadEquipmentDetail(row.id).catch((e) => {
console.error("设备详情加载失败:", e);
return this.useRowDataAsFallback(row);
}),
]);
this.dictData = dictData;
this.formData = detailData;
this.dictLoaded = true;
// 确保表单组件已渲染
this.$nextTick(() => {
if (this.$refs.formList) {
this.$refs.formList.refreshForm();
}
});
} catch (error) {
console.error("初始化异常:", error);
this.dictLoaded = true;
}
},
async loadEquipmentDetail(equipmentId) {
try {
const response = await getCmmsEquipmentInfo(equipmentId);
// 增加响应为 undefined 的检查
if (!response) {
throw new Error("API返回空响应");
}
// 检查响应结构,避免访问 undefined.data
if (response.data.code === 0 && response.data.data) {
const detailData = response.data.data;
return {
...detailData,
purchaseDate: detailData.purchaseDate
? this.formatDate(detailData.purchaseDate)
: null,
lastVerificationDate: detailData.lastVerificationDate
? this.formatDate(detailData.lastVerificationDate)
: null,
};
} else {
throw new Error(response.data.msg || "设备详情数据格式错误");
}
} catch (error) {
throw new Error(`加载设备详情失败: ${error.message}`);
}
},
async loadDictData() {
const dictKeys = [
"equipment_category",
"equipment_subcategory",
"accuracy_level",
"ownership_type",
"equipment_status",
"storage_status",
"inspection_status",
];
try {
const data = await getDictionaries(dictKeys);
this.dictData = Object.fromEntries(
dictKeys.map((key) => [key, data[key] || []])
);
} catch (error) {
console.error("加载字典数据失败:", error);
this.dictData = Object.fromEntries(dictKeys.map((key) => [key, []]));
}
},
formatDate(dateString) {
return dateString
? new Date(dateString).toISOString().split("T")[0]
: null;
},
// 添加这个方法
handleDialogClose() {
this.handleCancel();
this.$emit("close"); // 确保触发close事件
},
useRowDataAsFallback(row) {
return {
...row,
purchaseDate: row.purchaseDate
? this.formatDate(row.purchaseDate)
: null,
lastVerificationDate: row.lastVerificationDate
? this.formatDate(row.lastVerificationDate)
: null,
};
},
handleCancel() {
this.open = false;
this.GasMeasurementReady = false;
this.$emit("closed");
},
handleTabChange(activeTab) {
this.active = activeTab;
const activeItem = this.pageMenuTab.find(
(item) => item.sxTitle === activeTab
);
if (activeItem) {
this.activeTitle = activeItem.title;
}
if (activeTab === "GasMeasurement") {
// 确保设备ID已设置后再渲染组件
this.GasMeasurementReady = !!this.currentEquipmentId;
this.$nextTick(() => {
if (this.$refs.GasMeasurementRef) {
this.$refs.GasMeasurementRef.refreshData();
}
});
}
},
},
mounted() {
// 确保组件正常挂载
this.$nextTick(() => {
console.log("formList组件实例:", this.$refs.formList);
});
},
};
</script>
<style scoped>
.dialog-content-wrap {
padding: 15px;
height: 100%;
overflow: auto;
}
</style>
气量监测的地方是个分页查询,怎么修改这个文件
这个是分页的vue
/**
* 气量监测页面
*
* @author gucw
* @date 2025-06-10
*/
<template>
<div class="mod-config padding">
<el-form
:inline="true"
:model="dataForm"
ref="form"
@keyup.enter.native="getDataList()"
>
<el-form-item label="读数录入时间">
<el-date-picker
v-model="readingTimeList"
type="daterange"
range-separator="-"
value-format="yyyy-MM-dd"
start-placeholder="开始日期"
end-placeholder=" 结束日期"
></el-date-picker>
</el-form-item>
<el-form-item label="类型(空跑/检测/计费)" prop="measurementType">
<el-select
v-model="dataForm.measurementType"
:placeholder="'请选择类型(空跑/检测/计费)'"
>
<el-option
v-for="(item, index) in measurement_type"
:key="item.cId"
:label="item.entryname"
:value="item.entrycode"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button
v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:list')"
@click="getDataList()"
type="primary"
>查询</el-button
>
<el-button
v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:list')"
@click="resetForm('form')"
>重置</el-button
>
<el-button
v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:add')"
type="primary"
@click="addOrUpdateHandle()"
>新增</el-button
>
<el-button
v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:remove')"
type="danger"
@click="deleteHandle()"
>批量删除</el-button
>
</el-form-item>
</el-form>
<EproTable
class="m-t-10"
:tableData="dataList"
:titleData="titleForm"
:optionData="optionData"
:disselected="false"
@tableSelect="getTableSelect"
v-loading="tableLoading"
>
<el-table-column
slot="action"
fixed="right"
label="操作"
align="center"
width="110"
>
<template slot-scope="scope">
<el-tooltip
content="编辑"
placement="top"
v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:edit')"
>
<div
class="iconfont icon-edit click iconStyle pifu"
@click.stop="addOrUpdateHandle(scope.row)"
></div>
</el-tooltip>
<el-tooltip
content="删除"
placement="top"
v-if="isAuth('cmmsGasMeasurement:cmmsGasMeasurement:remove')"
>
<div
class="iconfont icon-delete click iconStyle pifu"
@click.stop="deleteHandle(scope.row.id)"
></div>
</el-tooltip>
</template>
</el-table-column>
</EproTable>
<el-pagination
background
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
:total="totalCount"
layout="total, sizes, prev, pager, next, jumper"
>
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update
v-if="addOrUpdateVisible"
ref="addOrUpdate"
@refreshDataList="getDataList"
></add-or-update>
</div>
</template>
<script>
import AddOrUpdate from "./cmmsGasMeasurementAddAndUpdate";
import {
listCmmsGasMeasurement,
delCmmsGasMeasurement,
} from "@/api/cmmsGasMeasurement/cmmsGasMeasurement.js";
import EproTable from "@/components/epro-table/epro-table";
import { getDictionaries } from "@/utils";
export default {
data() {
return {
dataList: [],
pageIndex: 1,
pageSize: 10,
totalCount: 0,
tableLoading: false,
dataListSelections: [],
addOrUpdateVisible: false,
readingTimeList: [],
measurement_stage: [],
measurement_type: [],
optionData: {
readingValue: { width: "150px" },
readingTime: { width: "150px" },
stageDict: { width: "150px" },
measurementTypeDict: { width: "150px" },
gasVolume: { width: "150px" },
},
titleForm: {
readingValue: "读数",
readingTime: "读数录入时间",
stageDict: "阶段(出库/检测后/检测前/入库/拆表后)",
measurementTypeDict: "类型(空跑/检测/计费)",
gasVolume: "气量",
},
dataForm: {
readingTime: null,
measurementType: null,
},
};
},
components: {
AddOrUpdate,
EproTable,
},
activated() {
this.getDataList();
this.getDictionaries();
},
methods: {
// 获取table数据
getTableSelect(val) {
this.dataListSelections = val;
},
// 获取数据列表
getDataList() {
this.$set(this.dataForm, "page", this.pageIndex);
this.$set(this.dataForm, "limit", this.pageSize);
this.$set(this.dataForm, "beginreadingTime", this.readingTimeList[0]);
this.$set(this.dataForm, "endreadingTime", this.readingTimeList[1]);
this.tableLoading = true;
listCmmsGasMeasurement(this.dataForm).then(({ data }) => {
this.dataList = data.page.list;
this.totalCount = data.page.totalCount;
this.tableLoading = false;
});
},
// 获取字典
getDictionaries() {
return new Promise((resolve) => {
let arr = ["measurement_stage", "measurement_type"];
getDictionaries(arr).then((data) => {
this.measurement_stage = data["measurement_stage"];
this.measurement_type = data["measurement_type"];
resolve();
});
});
},
// 每页数
sizeChangeHandle(val) {
this.pageSize = val;
this.pageIndex = 1;
this.getDataList();
},
// 当前页
currentChangeHandle(val) {
this.pageIndex = val;
this.getDataList();
},
//重置表格
resetForm(formName) {
this.$refs[formName].resetFields();
this.readingTimeList = [];
this.getDataList();
},
// 新增 / 修改
addOrUpdateHandle(data) {
this.addOrUpdateVisible = true;
this.$nextTick(() => {
this.$refs.addOrUpdate.init(data);
});
},
// 删除
deleteHandle(id) {
if (this.dataListSelections.length === 0 && !id) {
this.$message({
message: "请选择数据",
type: "warning",
});
return;
}
var ids = id
? [id]
: this.dataListSelections.map((item) => {
return item.id;
});
this.$confirm(
`确定对[id=${ids.join(",")}]进行[${
ids.length == 1 ? "删除" : "批量删除"
}]操作?`,
"提示",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}
).then(() => {
delCmmsGasMeasurement(ids).then(({ data }) => {
if (data.code === 0) {
this.getDataList();
this.$message.success("删除成功");
} else {
this.$message.error(data.msg);
}
});
});
},
},
};
</script>
最新发布