enterprise.vue 16 KB

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