yxpoint.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <div class="devicemenu">
  3. <el-space wrap :size="10">
  4. <el-input
  5. v-model="state.SearchVal"
  6. placeholder="筛选"
  7. style="width: 180px"
  8. size="mini"
  9. />
  10. <el-button class="buttons" size="mini" round @click="search"
  11. >查询</el-button
  12. >
  13. <el-button
  14. class="buttons"
  15. size="mini"
  16. round
  17. @click="handleEdit(state.addFormData)"
  18. :disabled="desc.code == ''"
  19. >新增</el-button
  20. >
  21. <el-upload
  22. class="upload-demo"
  23. :disabled="desc.code == ''"
  24. action="/sharding/device/input"
  25. :show-file-list="false"
  26. :on-success="handleSuccess"
  27. :on-progress="handleProgress"
  28. :on-error="handleError"
  29. >
  30. <el-button :disabled="desc.code == ''" class="buttons" size="mini" round
  31. >导入</el-button
  32. >
  33. </el-upload>
  34. <el-button
  35. class="buttons"
  36. size="mini"
  37. round
  38. @click="export2Excel"
  39. :disabled="desc.code == ''"
  40. >导出</el-button
  41. >
  42. </el-space>
  43. </div>
  44. <div class="yxpoint-table">
  45. <el-table
  46. :data="state.pointTableData"
  47. stripe
  48. style="width: 100%"
  49. height="calc(100% - 45px)"
  50. >
  51. <el-table-column type="index" width="50" />
  52. <el-table-column prop="metricCode" label="测点编码"></el-table-column>
  53. <el-table-column label="名称">
  54. <template #default="scope">
  55. <el-popover
  56. placement="right"
  57. popper-class="point-popover"
  58. :width="260"
  59. trigger="click"
  60. >
  61. <template #reference>
  62. <el-button
  63. type="text"
  64. style="color: #05bb4c"
  65. size="small"
  66. @click="handleClick(scope)"
  67. >{{ scope.row.name }}</el-button
  68. >
  69. </template>
  70. <el-table
  71. size="mini"
  72. :data="scope.row.deviceModelMetrics"
  73. max-height="400px"
  74. >
  75. <el-table-column
  76. property="devicemodel"
  77. label="机型"
  78. align="center"
  79. ></el-table-column>
  80. <el-table-column
  81. property="uniformcode"
  82. label="统一编码"
  83. align="center"
  84. ></el-table-column>
  85. <el-table-column
  86. property="multiplier"
  87. label="倍率"
  88. align="center"
  89. ></el-table-column>
  90. </el-table>
  91. </el-popover>
  92. </template>
  93. </el-table-column>
  94. <el-table-column
  95. v-for="(item, index) in state.tableHeader"
  96. :key="index"
  97. :prop="item.code"
  98. :label="item.text"
  99. >
  100. <template #default="{ row }">
  101. {{ row[item.code] ? row[item.code] : "--" }}
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="操作" width="180" align="center">
  105. <template #default="scope">
  106. <el-button
  107. type="text"
  108. style="color: #05bb4c"
  109. @click="handleEdit(scope.row)"
  110. >编辑</el-button
  111. >
  112. <el-button
  113. type="text"
  114. style="color: red"
  115. @click="handleDelete(scope.row)"
  116. >删除</el-button
  117. >
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <div class="pagination">
  122. <el-pagination
  123. layout="total, sizes, prev, pager, next"
  124. :page-sizes="[19, 50, 100, 200, 500]"
  125. @size-change="
  126. (value) => {
  127. query.limit = value;
  128. query.page = 1;
  129. getPoint(desc);
  130. }
  131. "
  132. :current-page="query.page"
  133. :page-size="query.limit"
  134. :total="pageTotal"
  135. @current-change="handlePageChange"
  136. ></el-pagination>
  137. </div>
  138. </div>
  139. <!-- 传感点编辑弹出框 -->
  140. <el-dialog v-model="editVisible" width="40%">
  141. <el-form :model="editFormData" label-width="80px">
  142. <el-form-item label="编码">
  143. <el-input v-model="editFormData.metriccode"></el-input>
  144. </el-form-item>
  145. <el-row :gutter="24">
  146. <el-col :span="12">
  147. <el-form-item label="名称">
  148. <el-input v-model="editFormData.name"></el-input>
  149. </el-form-item>
  150. </el-col>
  151. <el-col :span="12">
  152. <el-form-item label="英文名称">
  153. <el-input v-model="editFormData.enname"></el-input>
  154. </el-form-item>
  155. </el-col>
  156. </el-row>
  157. <el-row :gutter="24">
  158. <el-col :span="12">
  159. <el-form-item label="标准单位">
  160. <el-input v-model="editFormData.unitname"></el-input>
  161. </el-form-item>
  162. </el-col>
  163. <el-col :span="12">
  164. <el-form-item label="单位名称">
  165. <el-input v-model="editFormData.unitnamecn"></el-input>
  166. </el-form-item>
  167. </el-col>
  168. </el-row>
  169. <el-form-item label="描述">
  170. <el-input
  171. v-model="editFormData.description"
  172. :rows="3"
  173. type="textarea"
  174. clearable
  175. ></el-input>
  176. </el-form-item>
  177. <el-row :gutter="24">
  178. <el-col :span="12">
  179. <el-form-item label="数据类型">
  180. <el-select v-model="editFormData.categorydata" placeholder="Select">
  181. <el-option
  182. v-for="item in state.categorydataoptions"
  183. :key="item"
  184. :label="item"
  185. :value="item"
  186. >
  187. </el-option>
  188. </el-select>
  189. </el-form-item>
  190. </el-col>
  191. <el-col :span="12">
  192. <el-form-item label="结构">
  193. <el-cascader
  194. v-model="editFormData.structurecode"
  195. :options="cascaderdata"
  196. :props="{ checkStrictly: true, emitPath: false }"
  197. clearable
  198. />
  199. </el-form-item>
  200. </el-col>
  201. </el-row>
  202. <el-row :gutter="24">
  203. <el-col :span="12">
  204. <el-form-item label="物理类型">
  205. <el-input v-model="editFormData.categorysci"></el-input>
  206. </el-form-item>
  207. </el-col>
  208. <el-col :span="12">
  209. <el-form-item label="系统分类">
  210. <el-input v-model="editFormData.categorysys"></el-input>
  211. </el-form-item>
  212. </el-col>
  213. </el-row>
  214. <el-form-item label="适配机型" class="deviceModelClass">
  215. <el-select
  216. v-model="state.deviceModelSel"
  217. style="margin-right: 20px"
  218. placeholder="新增机型"
  219. size="mini"
  220. >
  221. <el-option
  222. v-for="item in state.deviceModel"
  223. :key="item.code"
  224. :label="item.code"
  225. :value="item.code"
  226. >
  227. </el-option>
  228. </el-select>
  229. <el-button
  230. v-show="state.deviceModelSel != ''"
  231. size="mini"
  232. class="buttons"
  233. round
  234. @click="deviceModelAdd()"
  235. >新增机型
  236. </el-button>
  237. <el-table
  238. :data="editFormData.deviceModelMetrics"
  239. style="width: 100%; margin-top: 10px"
  240. max-height="200px"
  241. >
  242. <el-table-column prop="devicemodel" label="机型" />
  243. <el-table-column label="倍率">
  244. <template #default="scope">
  245. <el-input v-model="scope.row.multiplier" size="mini" />
  246. </template>
  247. </el-table-column>
  248. <el-table-column label="统一编码">
  249. <template #default="scope">
  250. <el-input v-model="scope.row.uniformcode" size="mini" />
  251. </template>
  252. </el-table-column>
  253. </el-table>
  254. </el-form-item>
  255. </el-form>
  256. <template #footer>
  257. <span class="footerButton">
  258. <el-button size="mini" round @click="editVisible = false"
  259. >取 消</el-button
  260. >
  261. <el-button size="mini" round @click="saveEdit">确 定</el-button>
  262. </span>
  263. </template>
  264. </el-dialog>
  265. </template>
  266. <script setup>
  267. import { ref, onMounted, inject, reactive, watch } from "vue";
  268. import { ElMessageBox, ElMessage } from "element-plus";
  269. import {
  270. point,
  271. metrics,
  272. delmetrics,
  273. device_list,
  274. getWtModel,
  275. } from "@/api/zhbj/index.js";
  276. import { outExportExcel } from "@/tools/excel/exportExcel.js"; //引入文件
  277. onMounted(() => {
  278. getPoint(desc.value);
  279. getDeviceModel();
  280. getequipmentmodel_list();
  281. });
  282. let editFormData = ref({});
  283. let editVisible = ref(false); //传感点
  284. let desc = inject("desc");
  285. let treeId = inject("treeId");
  286. let cascaderdata = inject("cascaderdata");
  287. watch(
  288. () => treeId,
  289. (newV, old) => {
  290. state.addFormData.structurecode = desc.value.code;
  291. getPoint(desc.value);
  292. },
  293. {
  294. deep: true,
  295. }
  296. );
  297. let state = reactive({
  298. tableHeader: [
  299. { text: "单位", code: "unitName" },
  300. { text: "测点类型", code: "categoryData" },
  301. { text: "物理类型", code: "categorysci" },
  302. { text: "数据类型", code: "categorysci" },
  303. { text: "描述", code: "description" },
  304. ],
  305. pointTableData: "",
  306. SearchVal: "",
  307. selectPoint: "",
  308. selectModel: "",
  309. modelList: [],
  310. categorydataoptions: ["AI", "DI", "CI"],
  311. addFormData: {
  312. categorydata: "AI",
  313. categoryres1: null,
  314. categoryres2: null,
  315. categoryres3: null,
  316. categoryres4: null,
  317. categoryres5: null,
  318. categorysci: null,
  319. categorysys: null,
  320. description: null,
  321. deviceid: "windturbine",
  322. enname: null,
  323. id: null,
  324. metriccode: "",
  325. name: "",
  326. structurecode: "",
  327. unitname: null,
  328. unitnamecn: null,
  329. deviceModelMetrics: [],
  330. },
  331. });
  332. const query = reactive({
  333. page: 1,
  334. limit: 19,
  335. });
  336. let pageTotal = ref(0);
  337. const search = async () => {
  338. getPoint(desc.value);
  339. };
  340. // getPoint
  341. const getPoint = async (node) => {
  342. const res = await point(
  343. node.code,
  344. query.page,
  345. query.limit,
  346. state.selectPoint,
  347. state.SearchVal,
  348. "windturbine",
  349. state.selectModel
  350. );
  351. pageTotal.value = res.total;
  352. state.pointTableData = res.records
  353. ?.sort((a, b) => {
  354. return a.id - b.id;
  355. })
  356. .map((item, index) => {
  357. return { ...item, index: index + 1 };
  358. });
  359. };
  360. // 机型
  361. const getequipmentmodel_list = async () => {
  362. const { data } = await getWtModel();
  363. state.modelList = data;
  364. };
  365. // 测点 编辑
  366. const handleEdit = (row) => {
  367. if (!row.deviceModelMetrics) {
  368. row.deviceModelMetrics = [];
  369. }
  370. editFormData.value = row;
  371. editVisible.value = true;
  372. };
  373. //测点 add
  374. const postmetrics = async () => {
  375. const res = await metrics(editFormData.value);
  376. if (res.code == 200) {
  377. ElMessage.success(`操作成功!`);
  378. editVisible.value = false;
  379. } else {
  380. ElMessage.success(res.msg);
  381. }
  382. getPoint(desc.value);
  383. };
  384. // 保存编辑
  385. const saveEdit = async () => {
  386. postmetrics();
  387. };
  388. // 测点 删除
  389. const handleDelete = (row) => {
  390. // 二次确认删除
  391. ElMessageBox.confirm("确定要删除吗?", "提示", {
  392. type: "warning",
  393. })
  394. .then(async () => {
  395. const res = await delmetrics(row.id);
  396. if (res == 1) {
  397. ElMessage.success(`删除成功!`);
  398. } else {
  399. ElMessage.success("删除失败");
  400. }
  401. getPoint(desc.value);
  402. })
  403. .catch(() => {});
  404. };
  405. //deviceModelAdd 新增机型
  406. const deviceModelAdd = async () => {
  407. if (state.deviceModelSel == "") return;
  408. let obj = {
  409. deviceid: editFormData.value.deviceid,
  410. devicemodel: state.deviceModelSel,
  411. id: null,
  412. metriccode: editFormData.value.metriccode,
  413. multiplier: 0,
  414. uniformcode: "",
  415. };
  416. editFormData.value.deviceModelMetrics.push(obj);
  417. };
  418. //getDeviceModel
  419. const getDeviceModel = async () => {
  420. const res = await device_list();
  421. state.deviceModel = res;
  422. };
  423. // 分页导航
  424. const handlePageChange = (val) => {
  425. query.page = val;
  426. getPoint(desc.value);
  427. };
  428. // 批量导入
  429. const handleSuccess = (response, file, fileList) => {
  430. ElMessage.success("导入成功!");
  431. getPoint(desc.value);
  432. };
  433. const handleProgress = (response, file, fileList) => {};
  434. const handleError = (response, file, fileList) => {
  435. ElMessage.success("导入失败!");
  436. };
  437. // 批量导出
  438. const export2Excel = async () => {
  439. const tableData = await point(
  440. desc.value.code,
  441. 1,
  442. 99999999,
  443. state.selectPoint,
  444. state.SearchVal,
  445. "windturbine",
  446. state.selectModel
  447. );
  448. ElMessage.success(`导出成功!`);
  449. const tableHeader = [
  450. "上级结构编码",
  451. "测点编码",
  452. "名称",
  453. "英文名称",
  454. "单位",
  455. "测点类型",
  456. "物理类型",
  457. "描述",
  458. ];
  459. const tableKey = [
  460. "structurecode",
  461. "metriccode",
  462. "name",
  463. "enname",
  464. "unitname",
  465. "categorydata",
  466. "categorysci",
  467. "description",
  468. ];
  469. outExportExcel(tableHeader, tableKey, tableData.records, "测点导出excel");
  470. };
  471. const handleClick = ({ row }) => {
  472. console.log(row.index);
  473. };
  474. </script>
  475. <style lang="less" scoped>
  476. .buttons {
  477. background-color: rgba(5, 187, 76, 0.2);
  478. border: 1px solid #3b6c53;
  479. color: #b3b3b3;
  480. font-size: 14px;
  481. &:hover {
  482. background-color: rgba(5, 187, 76, 0.5);
  483. color: #ffffff;
  484. }
  485. }
  486. .devicemenu {
  487. margin-bottom: 10px;
  488. }
  489. .yxpoint-table {
  490. height: calc(100% - 39px);
  491. }
  492. .devicemenu {
  493. margin-bottom: 10px;
  494. }
  495. </style>
  496. <style lang="less">
  497. .point-popover {
  498. &.is-light {
  499. background: #081410;
  500. }
  501. .el-table {
  502. background: transparent;
  503. & th.el-table__cell {
  504. background: transparent;
  505. }
  506. & tr {
  507. background-color: transparent;
  508. }
  509. &::before {
  510. background-color: transparent;
  511. }
  512. }
  513. .el-popper__arrow::before {
  514. background: #081410 !important;
  515. border: 1px solid #081410 !important;
  516. }
  517. }
  518. </style>