zhangwencui
2026-06-16 19f0e68b3fe3cf5244a2b936bfef4e0712bdf025
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<template>
  <div class="app-container">
    <div class="search_form">
      <div>
        <span class="search_title">关键词:</span>
        <el-input
          v-model="searchForm.keyword"
          style="width: 240px"
          placeholder="电表名称/表地址/备注"
          clearable
          @keyup.enter="handleQuery"
        />
        <el-button type="primary" @click="handleQuery" style="margin-left: 10px">搜索</el-button>
      </div>
      <div>
        <el-button type="primary" @click="openForm('add')">新增电表</el-button>
        <el-button type="success" :loading="syncing" @click="handleSync">同步电表</el-button>
      </div>
    </div>
    <div class="table_list">
      <PIMTable
        rowKey="id"
        :column="tableColumn"
        :tableData="tableData"
        :page="page"
        :tableLoading="tableLoading"
        @pagination="pagination"
      >
        <template #source="{ row }">
          <el-tag :type="row.source === 'manual' ? 'warning' : 'info'" size="small">
            {{ row.source === "manual" ? "手动" : "同步" }}
          </el-tag>
        </template>
        <template #relayState="{ row }">
          <el-tag :type="row.relayState === '1' ? 'success' : 'danger'" size="small">
            {{ row.relayState === "1" ? "合闸" : row.relayState === "0" ? "拉闸" : "未知" }}
          </el-tag>
        </template>
        <template #operate="{ row }">
          <el-button link type="primary" @click="openForm('edit', row)">编辑</el-button>
          <el-button v-if="row.source === 'manual'" link type="danger" @click="handleDelete(row)">删除</el-button>
        </template>
      </PIMTable>
    </div>
    <form-dia ref="formDiaRef" @close="getList" />
  </div>
</template>
 
<script setup>
import { onMounted, reactive, ref, toRefs } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import FormDia from "./components/formDia.vue";
import { meterListPage, meterSync, meterDelete } from "@/api/energyManagement/tqdianbiao.js";
 
const tableLoading = ref(false);
const syncing = ref(false);
const tableData = ref([]);
const formDiaRef = ref(null);
 
const data = reactive({ searchForm: { keyword: "" } });
const { searchForm } = toRefs(data);
const page = reactive({ current: 1, size: 10, total: 0 });
 
const tableColumn = ref([
  { label: "电表名称", prop: "meterName", minWidth: 120 },
  { label: "电表档案ID", prop: "meterId", width: 120 },
  { label: "表地址", prop: "address", minWidth: 120 },
  { label: "倍率", prop: "rate", width: 70 },
  { label: "来源", prop: "source", dataType: "slot", slot: "source", width: 80 },
  { label: "继电器", prop: "relayState", dataType: "slot", slot: "relayState", width: 90 },
  { label: "备注", prop: "description", minWidth: 100 },
  { label: "同步时间", prop: "syncTime", minWidth: 160 },
  { label: "操作", prop: "operate", dataType: "slot", slot: "operate", width: 120, fixed: "right" },
]);
 
function openForm(type, row) {
  formDiaRef.value.open(type, row);
}
 
function handleQuery() {
  page.current = 1;
  getList();
}
 
function pagination(obj) {
  page.current = obj.page;
  page.size = obj.limit;
  getList();
}
 
async function getList() {
  tableLoading.value = true;
  try {
    const res = await meterListPage({ ...searchForm.value, current: page.current, size: page.size });
    tableData.value = res.data.records;
    page.total = res.data.total;
  } finally {
    tableLoading.value = false;
  }
}
 
async function handleSync() {
  syncing.value = true;
  try {
    const res = await meterSync();
    ElMessage.success(res.msg || "同步成功");
    getList();
  } finally {
    syncing.value = false;
  }
}
 
function handleDelete(row) {
  ElMessageBox.confirm(`确认删除电表「${row.meterName || row.address}」?`, "提示", { type: "warning" })
    .then(async () => {
      await meterDelete([row.id]);
      ElMessage.success("删除成功");
      getList();
    })
    .catch(() => {});
}
 
onMounted(() => getList());
</script>