enterprise.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <template>
  2. <div class="global-variable" v-loading="loading">
  3. <div class="condition">
  4. <el-form :inline="true" :model="formInline" class="demo-form-inline">
  5. <el-form-item label="单位名称:">
  6. <el-input
  7. v-model="formInline.companyName"
  8. placeholder="请输入单位名称"
  9. size="small"
  10. ></el-input>
  11. </el-form-item>
  12. <el-form-item label="状态:">
  13. <el-select
  14. v-model="formInline.state"
  15. placeholder="选择状态"
  16. size="small "
  17. >
  18. <el-option label="启用" value="1"></el-option>
  19. <el-option label="停用" value="0"></el-option>
  20. </el-select>
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="primary" @click="getTableList" size="small"
  24. >查询</el-button
  25. >
  26. <el-button @click="reset" size="small">重置</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. <div class="list-page">
  31. <div class="newly">
  32. <el-button type="primary" @click="newnuedialog" size="small"
  33. >新增</el-button
  34. >
  35. <el-button type="primary" @click="toggleExpandAll" size="small">{{
  36. defaultExpandAll ? "收起" : "展开"
  37. }}</el-button>
  38. </div>
  39. <el-table
  40. class="center-align-table"
  41. ref="table"
  42. :data="tableData"
  43. border
  44. stripe
  45. row-key="id"
  46. default-expand-all
  47. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  48. >
  49. <!-- Table Columns -->
  50. <el-table-column prop="codeName" align="left" label="单位名称">
  51. </el-table-column>
  52. <el-table-column prop="companyCode" align="center" label="单位ID">
  53. </el-table-column>
  54. <el-table-column
  55. prop="fieldCount"
  56. align="center"
  57. label="风场数量"
  58. min-width="200"
  59. >
  60. <template slot-scope="scope">
  61. <el-button @click="particulars(scope.row)" type="text" size="small">
  62. {{ scope.row.fieldCount ? scope.row.fieldCount : 0 }}
  63. </el-button>
  64. </template>
  65. </el-table-column>
  66. <el-table-column
  67. prop="state"
  68. align="center"
  69. label="状态"
  70. min-width="200"
  71. >
  72. <template slot-scope="{ row }">
  73. {{ row.state == 1 ? "启用" : "停用" }}
  74. </template>
  75. </el-table-column>
  76. <el-table-column prop="createTime" align="center" label="创建时间">
  77. <template slot-scope="{ row }">
  78. {{ $formatDateTWO(row.createTime) }}
  79. </template>
  80. </el-table-column>
  81. <el-table-column
  82. prop="state"
  83. align="center"
  84. fixed="right"
  85. label="操作"
  86. min-width="200"
  87. >
  88. <template slot-scope="scope">
  89. <el-button @click="compile(scope.row)" type="text" size="small"
  90. >编辑</el-button
  91. >
  92. <el-button
  93. @click="newcomer(scope.row, 'addChild')"
  94. type="text"
  95. size="small"
  96. >新增</el-button
  97. >
  98. <el-button
  99. v-if="scope.row.state == 0"
  100. @click="start(scope.row, 1)"
  101. type="text"
  102. size="small"
  103. >启用</el-button
  104. >
  105. <el-button
  106. v-else
  107. style="color: #666"
  108. @click="start(scope.row, 0)"
  109. type="text"
  110. size="small"
  111. >停用</el-button
  112. >
  113. <el-button
  114. style="color: #f00"
  115. @click="deleted(scope.row)"
  116. type="text"
  117. size="small"
  118. >删除</el-button
  119. >
  120. </template>
  121. </el-table-column>
  122. </el-table>
  123. </div>
  124. <!-- 弹出层 -->
  125. <!-- 新增 -->
  126. <el-dialog
  127. :title="title"
  128. :visible.sync="nuedialog"
  129. width="380px"
  130. @close="handleClose"
  131. >
  132. <el-form
  133. ref="newform"
  134. :rules="rules"
  135. :model="newform"
  136. label-width="90px"
  137. class="form-margin"
  138. >
  139. <el-form-item label="单位名称:" prop="companyName">
  140. <el-input v-model="newform.companyName" size="small"></el-input>
  141. </el-form-item>
  142. <el-form-item label="所属省:" prop="province">
  143. <el-select
  144. v-model="newform.province"
  145. placeholder="请选择"
  146. size="small"
  147. value-key="areaId"
  148. @change="fetchCities"
  149. >
  150. <el-option
  151. v-for="item in shengdata"
  152. :key="item.areaId"
  153. :label="item.province"
  154. :value="item"
  155. ></el-option>
  156. </el-select>
  157. </el-form-item>
  158. <el-form-item label="所属市:" prop="city">
  159. <el-select
  160. v-model="newform.city"
  161. placeholder="请选择"
  162. size="small"
  163. value-key="areaId"
  164. @change="$forceUpdate()"
  165. >
  166. <el-option
  167. v-for="item in shidata"
  168. :key="item.areaId"
  169. :label="item.city"
  170. :value="item"
  171. ></el-option>
  172. </el-select>
  173. </el-form-item>
  174. <el-form-item label="备注:">
  175. <el-input
  176. v-model="newform.described"
  177. size="small"
  178. type="textarea"
  179. ></el-input>
  180. </el-form-item>
  181. </el-form>
  182. <span slot="footer" class="dialog-footer">
  183. <el-button @click="nuedialog = false" size="small">取 消</el-button>
  184. <el-button type="primary" @click="newly('newform')" size="small"
  185. >确 定</el-button
  186. >
  187. </span>
  188. </el-dialog>
  189. <!-- 风场数量 -->
  190. <el-dialog title="风场数量" :visible.sync="unusualdialog" width="1000px">
  191. <el-table
  192. class="center-align-table"
  193. :data="FCtableData"
  194. border
  195. :cell-style="rowStyle"
  196. stripe
  197. max-height="500"
  198. >
  199. <!-- Table Columns -->
  200. <el-table-column
  201. fixed
  202. prop="fieldName"
  203. align="center"
  204. label="风场名称"
  205. min-width="150"
  206. >
  207. </el-table-column>
  208. <el-table-column
  209. prop="provinceName"
  210. align="center"
  211. label="所在省"
  212. min-width="100"
  213. >
  214. </el-table-column>
  215. <el-table-column
  216. prop="cityName"
  217. align="center"
  218. label="所在市"
  219. min-width="100"
  220. >
  221. </el-table-column>
  222. <el-table-column
  223. prop="elevationHeight"
  224. align="center"
  225. label="海拔高度/米"
  226. min-width="100"
  227. >
  228. </el-table-column>
  229. <el-table-column
  230. prop="longitude"
  231. align="center"
  232. label="经度"
  233. min-width="100"
  234. >
  235. </el-table-column>
  236. <el-table-column
  237. prop="latitude"
  238. align="center"
  239. label="纬度"
  240. min-width="100"
  241. >
  242. </el-table-column>
  243. <el-table-column
  244. prop="ratedCapacityNumber"
  245. align="center"
  246. label="额定容量/kW"
  247. min-width="100"
  248. >
  249. </el-table-column>
  250. </el-table>
  251. <div class="pagination-container">
  252. <!-- <el-pagination
  253. @current-change="handleCurrentChange"
  254. :current-page.sync="pageNum"
  255. layout="total, prev, pager, next"
  256. :page-size="pageSize"
  257. :total="totalSize"
  258. >
  259. </el-pagination> -->
  260. </div>
  261. </el-dialog>
  262. </div>
  263. </template>
  264. <script>
  265. import Vue from "vue";
  266. import {
  267. getAllWindCompany,
  268. addCompany,
  269. updateCompany,
  270. updateStateCompany,
  271. findAllProvince,
  272. getCitiesByPId,
  273. getWindCompany,
  274. delCompany,
  275. getWindFieldVos,
  276. } from "@/api/ledger.js";
  277. export default {
  278. data() {
  279. return {
  280. loading: false,
  281. // 查询
  282. formInline: {
  283. companyName: "",
  284. state: "",
  285. },
  286. // 新增
  287. newform: {
  288. parentCode: "",
  289. companyName: "",
  290. provinceId: "",
  291. provinceName: "",
  292. cityId: "",
  293. cityName: "",
  294. described: "",
  295. },
  296. shengdata: [],
  297. shidata: [],
  298. defaultExpandAll: true,
  299. rules: {
  300. companyName: [
  301. { required: true, message: "请填写单位名称", trigger: "blur,change" },
  302. ],
  303. province: [{ required: true, message: "请选择省", trigger: "change" }],
  304. city: [{ required: true, message: "请选择市", trigger: "change" }],
  305. },
  306. tableData: [],
  307. FCtableData: [],
  308. detail: {},
  309. nuedialog: false,
  310. unusualdialog: false,
  311. isEdit: false,
  312. title: "新增",
  313. warningShown: false,
  314. addPrarentCompanyCode: null,
  315. pageNum: 1,
  316. pageSize: 10,
  317. totalSize: 0,
  318. };
  319. },
  320. created() {
  321. this.getTableList();
  322. this.postsheng();
  323. },
  324. watch: {
  325. tableData: {
  326. handler(newData) {
  327. this.$nextTick(() => {
  328. this.setExpandAll(this.defaultExpandAll);
  329. });
  330. },
  331. immediate: true,
  332. deep: true,
  333. },
  334. },
  335. methods: {
  336. handleClose() {
  337. Object.assign(this.newform, {
  338. companyName: "",
  339. province: null,
  340. city: null,
  341. described: "",
  342. });
  343. this.$refs.newform.resetFields();
  344. },
  345. rowStyle() {
  346. return "text-align:center";
  347. },
  348. // 查询
  349. getTableList() {
  350. let objectval;
  351. if (this.formInline.companyName === "" && this.formInline.state === "") {
  352. objectval = {};
  353. } else {
  354. objectval = {
  355. companyName: this.formInline.companyName,
  356. state: this.formInline.state,
  357. };
  358. }
  359. this.loading = true;
  360. getAllWindCompany(objectval)
  361. .then((res) => {
  362. this.tableData = res.data;
  363. this.loading = false;
  364. })
  365. .catch((error) => {
  366. console.error(error, "error");
  367. this.loading = false;
  368. });
  369. },
  370. // 重置
  371. reset() {
  372. this.formInline.companyName = "";
  373. this.formInline.state = "";
  374. this.newform.companyName = "";
  375. this.newform.province = "";
  376. this.newform.city = "";
  377. this.newform.described = "";
  378. getAllWindCompany({
  379. companyName: "",
  380. state: "",
  381. }).then((res) => {
  382. this.tableData = res.data;
  383. });
  384. },
  385. // 启用/停用
  386. start(row, type) {
  387. let objectval = {
  388. companyCode: row.companyCode,
  389. state: type === 0 ? 0 : 1,
  390. };
  391. updateStateCompany(objectval).then((res) => {
  392. this.$message({
  393. message: "状态已更新成功",
  394. type: "success",
  395. });
  396. // this.$message(`${type === 1 ? '状态已更新成功' : '状态已更新成功'}`);
  397. row.state = type === 1 ? 0 : 1;
  398. this.getTableList();
  399. });
  400. },
  401. // 省份
  402. postsheng() {
  403. findAllProvince().then((res) => {
  404. this.shengdata = res.data;
  405. });
  406. },
  407. // 市
  408. fetchCities(item, city) {
  409. console.log(item, this.newform.province);
  410. this.newform.province = item;
  411. let data = {
  412. provinceId: item.areaId,
  413. };
  414. getCitiesByPId(data).then((res) => {
  415. this.shidata = res.data;
  416. });
  417. if (city) {
  418. this.newform.city = Object.assign(
  419. {},
  420. { areaId: city.areaId, city: city.city }
  421. );
  422. }
  423. },
  424. // 新增提交
  425. newly(formName) {
  426. this.$refs[formName].validate((valid) => {
  427. if (valid) {
  428. let objectval = {
  429. parentCode: this.addPrarentCompanyCode || 0, // 一级单位默认传0
  430. companyName: this.newform?.companyName, // 企业名称
  431. provinceId: this.newform.province?.areaId, // 省
  432. provinceName: this.newform.province?.province,
  433. cityId: this.newform.city?.areaId, // 市
  434. cityName: this.newform.city?.city,
  435. described: this.newform?.described, // 备注
  436. };
  437. let requestPromise;
  438. if (!this.isEdit) {
  439. requestPromise = addCompany(objectval);
  440. } else {
  441. objectval.companyCode = this.detail.companyCode;
  442. delete objectval.parentCode;
  443. requestPromise = updateCompany(objectval);
  444. }
  445. requestPromise
  446. .then((res) => {
  447. this.addPrarentCompanyCode = null;
  448. if (this.isEdit) {
  449. this.isEdit = false;
  450. }
  451. if (res.code === -1) {
  452. this.$message({
  453. message: "操作失败",
  454. type: "error",
  455. });
  456. } else {
  457. this.$message({
  458. message: "新增成功",
  459. type: "success",
  460. });
  461. }
  462. this.nuedialog = false;
  463. this.getTableList();
  464. })
  465. .catch((error) => {
  466. console.error(error);
  467. });
  468. } else {
  469. console.log("error submit!!");
  470. return false;
  471. }
  472. });
  473. },
  474. // 新增触发 一级新增
  475. newnuedialog() {
  476. this.nuedialog = true;
  477. this.title = "新增";
  478. },
  479. // 新增子级 这是二级入口
  480. newcomer(row, type) {
  481. this.nuedialog = true;
  482. this.addPrarentCompanyCode = row.companyCode;
  483. this.title = "新增子单位";
  484. },
  485. // 删除
  486. deleted(row) {
  487. console.log(row, "row");
  488. if (row.state == "1") {
  489. this.$message({
  490. type: "error",
  491. message: "该项处于启用状态,无法删除!",
  492. });
  493. return;
  494. }
  495. this.$confirm("此操作将永久删除该文件,是否继续?", "提示", {
  496. confirmButtonText: "确定",
  497. cancelButtonText: "取消",
  498. type: "warning",
  499. })
  500. .then(() => {
  501. delCompany({ companyCode: row.companyCode })
  502. .then((res) => {
  503. if (res.code === -1) {
  504. // Adjust based on your API response for a successful delete
  505. this.$message({
  506. type: "error",
  507. message: "删除失败!",
  508. });
  509. } else {
  510. this.$message({
  511. type: "success",
  512. message: "删除成功!",
  513. });
  514. this.getTableList();
  515. }
  516. })
  517. .catch((error) => {
  518. console.error(error);
  519. });
  520. })
  521. .catch(() => {
  522. // 取消删除
  523. this.$message({
  524. type: "info",
  525. message: "已取消删除",
  526. });
  527. });
  528. },
  529. // 展开收起
  530. toggleExpandAll() {
  531. this.defaultExpandAll = !this.defaultExpandAll;
  532. this.$nextTick(() => {
  533. this.setExpandAll(this.defaultExpandAll);
  534. });
  535. },
  536. setExpandAll(expand) {
  537. const table = this.$refs.table;
  538. if (table) {
  539. this.tableData.forEach((row) => {
  540. table.toggleRowExpansion(row, expand);
  541. if (row.children) {
  542. row.children.forEach((child) => {
  543. table.toggleRowExpansion(child, expand);
  544. });
  545. }
  546. });
  547. }
  548. },
  549. //查看风场信息
  550. particulars(row) {
  551. this.unusualdialog = true;
  552. // const arr = {
  553. // companyCode: "arr",
  554. // };
  555. getWindFieldVos({ companyCode: row.companyCode }).then((res) => {
  556. this.FCtableData = res.data;
  557. this.totalSize = res.totalSize;
  558. });
  559. },
  560. // handleCurrentChange(val) {
  561. // this.pageNum = val;
  562. // this.getTableList();
  563. // },
  564. // 编辑回显
  565. compile(row) {
  566. this.title = "编辑";
  567. this.isEdit = true;
  568. getWindCompany({
  569. companyCode: row.companyCode,
  570. }).then((res) => {
  571. const item = JSON.parse(JSON.stringify(res.data));
  572. this.detail = item;
  573. this.newform = Object.assign(
  574. {},
  575. {
  576. companyName: item.companyName,
  577. described: item.described,
  578. }
  579. );
  580. this.newform.province = Object.assign(
  581. {},
  582. { areaId: item.provinceId, provice: item.provinceName }
  583. );
  584. let that = this;
  585. // this.newform.city = Object.assign({}, { areaId: item.cityId, city: item.cityName });
  586. this.fetchCities(this.newform.province, {
  587. areaId: item.cityId,
  588. city: item.cityName,
  589. });
  590. console.log(this.newform, row, item);
  591. this.nuedialog = true;
  592. });
  593. },
  594. },
  595. };
  596. </script>
  597. <style lang="scss" scoped>
  598. .el-select {
  599. width: 250px;
  600. }
  601. .form-margin {
  602. .el-form-item {
  603. margin-bottom: 22px;
  604. }
  605. }
  606. </style>