EditAnalysis.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <!--
  2. * @Author: your name
  3. * @Date: 2024-05-29 09:14:23
  4. * @LastEditTime: 2024-06-25 17:03:54
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/performance/components/EditAnalysis.vue
  8. -->
  9. <template>
  10. <div v-loading="loading">
  11. <el-form ref="form" :model="form" label-width="120px">
  12. <el-collapse v-model="activeNames">
  13. <el-collapse-item title="基础筛选:" name="1">
  14. <el-row class="flex-wrap-row" :gutter="5">
  15. <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="5">
  16. <el-form-item label="分析类型" prop="configAnalysis">
  17. <el-select
  18. v-model="form.configAnalysis"
  19. placeholder="请选择分析类型"
  20. size="small"
  21. clearable
  22. >
  23. <el-option
  24. v-for="item in analysisTypeList"
  25. :key="item.typeCode"
  26. :label="item.typeName"
  27. :value="item.typeCode"
  28. ></el-option>
  29. </el-select> </el-form-item
  30. ></el-col>
  31. <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="5" prop="turbines">
  32. <el-form-item label="机组编号">
  33. <el-select
  34. clearable
  35. v-model="form.turbines"
  36. placeholder="请选择机组编号"
  37. size="small"
  38. >
  39. <el-option
  40. v-for="item in windEngineGroupList"
  41. :key="item"
  42. :label="item"
  43. :value="item"
  44. ></el-option>
  45. </el-select> </el-form-item
  46. ></el-col>
  47. <el-col :span="5">
  48. <el-form-item class="searchFrom">
  49. <el-button type="primary" @click="onSubmit" size="small"
  50. >查询</el-button
  51. >
  52. </el-form-item>
  53. </el-col>
  54. </el-row>
  55. </el-collapse-item>
  56. </el-collapse>
  57. </el-form>
  58. <el-card shadow="always" class="box-card">
  59. <el-row>
  60. <el-col :span="12"
  61. ><div class="left">
  62. <div>
  63. <span>机组编号:</span>
  64. <el-select
  65. v-model="engineCode"
  66. placeholder="请选择机组编号"
  67. size="small"
  68. clearable
  69. @change="handleEngineCode"
  70. >
  71. <el-option
  72. v-for="item in windEngineGroupList"
  73. :key="item"
  74. :label="item"
  75. :value="item"
  76. ></el-option>
  77. </el-select>
  78. </div>
  79. <div>
  80. 1.额定容量:{{
  81. windDetail.ratedCapacity ? windDetail.ratedCapacity : 0
  82. }}
  83. <span> (kW)</span>
  84. </div>
  85. <!-- <div>2.发电机类型(Generator Type):{{}}</div> -->
  86. <div>2.风机编号:{{ windDetail.engineCode }}</div>
  87. <div>3.经度(Longitude):{{ windDetail.longitude }}</div>
  88. <div>4.维度(Dimensionality):{{ windDetail.latitude }}</div>
  89. <div>
  90. 5.海拔高度(Altitude):{{
  91. windDetail.elevationHeight ? windDetail.elevationHeight : 0
  92. }}
  93. <span>(米)</span>
  94. </div>
  95. <div>6.风机名称:{{ windDetail.engineName }}</div>
  96. <div>
  97. 7.是否标杆(Benchmarking or not):{{
  98. windDetail.sightcing == 1 ? "是" : "否"
  99. }}
  100. </div>
  101. <div>8.风场编号:{{ windDetail.fieldCode }}</div>
  102. <div>
  103. 9.轮毂高度:{{ windDetail.hubHeight ? windDetail.hubHeight : 0 }}
  104. <span>(米)</span>
  105. </div>
  106. <div>10.机型编号:{{ windDetail.millTypeCode }}</div>
  107. <div>
  108. 11.切入风速:{{
  109. windDetail.ratedCutInWindspeed
  110. ? windDetail.ratedCutInWindspeed
  111. : 0
  112. }}<span>(m/s)</span>
  113. </div>
  114. <div>
  115. 12.切出风速:{{
  116. windDetail.ratedCutOutWindspeed
  117. ? windDetail.ratedCutOutWindspeed
  118. : 0
  119. }}<span>(m/s)</span>
  120. </div>
  121. </div>
  122. </el-col>
  123. <el-col :span="12" v-loading="htmlLoading">
  124. <div class="right">
  125. <iframe
  126. v-if="htmlLoading"
  127. :src="windDetail.elevationHeight"
  128. frameborder="0"
  129. @load="iframeLoad"
  130. width="100%"
  131. height="100%"
  132. ></iframe>
  133. <img
  134. v-else
  135. style="width: 100%"
  136. src="../../../assets/img/loadingError.webp"
  137. alt=""
  138. />
  139. </div>
  140. </el-col>
  141. </el-row>
  142. </el-card>
  143. <el-empty :image-size="200" v-if="flage"></el-empty>
  144. <div class="abalysisType" v-else>
  145. <el-tabs
  146. v-model="editableTabsValue"
  147. type="card"
  148. editable
  149. @edit="handleTabsEdit"
  150. >
  151. <el-tab-pane
  152. :key="item.commentTypeCode"
  153. v-for="(item, index) in editableTabs"
  154. :label="item.commentTypeName"
  155. :name="item.commentTypeCode"
  156. >
  157. <tinymce-editor
  158. ref="editor"
  159. v-model="item.comment"
  160. :disabled="disabled"
  161. @input="handleEditorInput(index, $event)"
  162. @onClick="onClick"
  163. >
  164. </tinymce-editor>
  165. </el-tab-pane>
  166. </el-tabs>
  167. <div style="margin-top: 20px; display: flex; justify-content: end">
  168. <el-button type="primary" @click="handleComment"
  169. >提交分析编辑描述</el-button
  170. >
  171. </div>
  172. </div>
  173. <el-dialog
  174. title="新增"
  175. :visible.sync="dialogVisible"
  176. width="30%"
  177. :before-close="handleClose"
  178. >
  179. <el-form
  180. :inline="true"
  181. ref="formInline"
  182. :model="formInline"
  183. :rules="rules"
  184. class="demo-form-inline"
  185. >
  186. <el-form-item label="类型名称" prop="commentTypeName">
  187. <el-input
  188. v-model="formInline.commentTypeName"
  189. placeholder="请输入类型名称"
  190. ></el-input>
  191. </el-form-item>
  192. </el-form>
  193. <span slot="footer" class="dialog-footer">
  194. <el-button @click="dialogVisible = false">取 消</el-button>
  195. <el-button type="primary" @click="addAnalysisNameFn('formInline')"
  196. >确 定</el-button
  197. >
  198. </span>
  199. </el-dialog>
  200. </div>
  201. </template>
  202. <script>
  203. import {
  204. analysisDetail,
  205. analysisEditQuery,
  206. delAnalysisCommentType,
  207. addAnalysisCommentType,
  208. analysisCommentEdit,
  209. } from "@/api/performance";
  210. import { getWindEngineGroup } from "@/api/ledger";
  211. import TinymceEditor from "@/components/Tinymce.vue";
  212. export default {
  213. components: {
  214. TinymceEditor,
  215. },
  216. data() {
  217. return {
  218. htmlLoading: true,
  219. loading: false,
  220. engineCode: null, //台账机组编号
  221. windDetail: {},
  222. flage: false,
  223. rules: {
  224. commentTypeName: {
  225. required: true,
  226. message: "请输入类型名称",
  227. trigger: "blur",
  228. },
  229. },
  230. value4: "",
  231. value1: "",
  232. form: {
  233. configAnalysis: "",
  234. turbines: "",
  235. },
  236. activeNames: ["1"],
  237. msg: "",
  238. disabled: false,
  239. value: "",
  240. options: [],
  241. editableTabsValue: "",
  242. formInline: {
  243. commentTypeName: "",
  244. },
  245. dialogVisible: false,
  246. editableTabs: [],
  247. analysisTypeList: [],
  248. windEngineGroupList: [],
  249. formData: { content: "<p>Hello, Tinymce!</p>" },
  250. tabIndex: 2,
  251. };
  252. },
  253. created() {
  254. //获取分析 分析类型、机组编号 列表
  255. this.getWindCodeList();
  256. },
  257. methods: {
  258. iframeLoad() {
  259. this.htmlLoading = false;
  260. },
  261. async handleComment() {
  262. this.loading = true;
  263. try {
  264. await analysisCommentEdit({
  265. batchCode: this.$route.query.batchCode,
  266. analysisTypeCode: this.form.configAnalysis,
  267. commentList: this.editableTabs.map((item) => {
  268. return {
  269. commentTypeCode: item.commentTypeCode,
  270. comment: item.comment,
  271. };
  272. }),
  273. });
  274. this.$message({
  275. type: "success",
  276. message: "保存成功",
  277. });
  278. this.loading = false;
  279. this.getDetailInfo();
  280. } catch (e) {
  281. console.error(e);
  282. this.loading = false;
  283. }
  284. },
  285. handleEditorInput(index, newVal) {
  286. // 更新对应的 comment 值
  287. this.$set(this.editableTabs, index, {
  288. ...this.editableTabs[index],
  289. comment: newVal,
  290. });
  291. },
  292. handleEngineCode(e) {
  293. console.log(e);
  294. this.engineCode = e;
  295. this.getWindEngList();
  296. },
  297. async getWindEngList() {
  298. try {
  299. const res = await getWindEngineGroup({
  300. engineCode: this.engineCode,
  301. });
  302. this.windDetail = res.data;
  303. } catch (error) {
  304. console.error(error);
  305. }
  306. },
  307. async getDetailInfo() {
  308. const formData = new FormData();
  309. formData.append("batchCode", this.$route.query.batchCode);
  310. formData.append("analysisTypeCode", this.form.configAnalysis);
  311. formData.append("fieldEngineCode", this.form.turbines);
  312. //获取详情信息
  313. this.loading = true;
  314. try {
  315. const response = await analysisDetail(formData);
  316. if (response.data.length === 0 || response.data === null) {
  317. this.flage = true;
  318. } else {
  319. this.flage = false;
  320. }
  321. if (
  322. response.data.length > 0 &&
  323. response.data[0].commentDescriptionVos &&
  324. response.data[0].commentDescriptionVos.length > 0
  325. ) {
  326. this.editableTabs = this.mergeData(
  327. response.data[0].commentDescriptionVos,
  328. response.data[0].commentTypeRelations
  329. );
  330. this.editableTabsValue =
  331. this.editableTabs.length > 0
  332. ? this.editableTabs[0].commentTypeCode
  333. : "";
  334. }
  335. this.loading = false;
  336. } catch (error) {
  337. console.error(error);
  338. this.loading = false;
  339. }
  340. },
  341. mergeData(arr, brr) {
  342. // 创建一个新的结果数组
  343. const result = [];
  344. // 遍历 brr 数组
  345. brr.forEach((brrItem) => {
  346. // 在 arr 中寻找具有相同 commentTypeCode 的项
  347. const foundItem = arr.find(
  348. (arrItem) => arrItem.commentTypeCode === brrItem.commentTypeCode
  349. );
  350. if (foundItem) {
  351. // 如果找到了相同的项,就合并它们
  352. result.push({
  353. ...foundItem,
  354. ...brrItem,
  355. });
  356. } else {
  357. // 如果没有找到相同的项,就将 brrItem 添加到结果数组中
  358. result.push(brrItem);
  359. }
  360. });
  361. // 返回结果数组
  362. return result;
  363. },
  364. handleClose(done) {
  365. this.$confirm("确认关闭?")
  366. .then((_) => {
  367. done();
  368. })
  369. .catch((_) => {});
  370. },
  371. async getWindCodeList() {
  372. this.loading = true;
  373. try {
  374. const response = await analysisEditQuery({
  375. batchCode: this.$route.query.batchCode,
  376. });
  377. this.analysisTypeList = response.data.analysisTypeList;
  378. this.windEngineGroupList = response.data.windEngineGroupList;
  379. this.form.configAnalysis = response.data.analysisTypeList[0].typeCode;
  380. this.form.turbines = response.data.windEngineGroupList[0];
  381. this.engineCode = response.data.windEngineGroupList[0];
  382. this.getDetailInfo();
  383. this.getWindEngList();
  384. this.loading = false;
  385. } catch (error) {
  386. console.error(error);
  387. this.loading = false;
  388. }
  389. },
  390. // 鼠标单击的事件
  391. onClick(e, editor) {
  392. console.log("Element clicked");
  393. console.log(e);
  394. console.log(editor);
  395. },
  396. onSubmit() {
  397. this.getDetailInfo();
  398. },
  399. //新增分析结果类型
  400. addAnalysisNameFn(formName) {
  401. this.$refs[formName].validate(async (valid) => {
  402. if (valid) {
  403. this.loading = true;
  404. try {
  405. await addAnalysisCommentType({
  406. batchCode: this.$route.query.batchCode,
  407. analysisTypeCode: this.form.configAnalysis,
  408. commentTypeName: this.formInline.commentTypeName,
  409. });
  410. this.$refs[formName].resetFields();
  411. this.dialogVisible = false;
  412. this.loading = false;
  413. this.$message({
  414. type: "success",
  415. message: "添加成功",
  416. });
  417. this.getWindCodeList();
  418. } catch (e) {
  419. console.error(e);
  420. this.loading = false;
  421. }
  422. } else {
  423. console.log("error submit!!");
  424. return false;
  425. }
  426. });
  427. },
  428. handleTabsEdit(targetName, action) {
  429. if (action === "add") {
  430. this.dialogVisible = true;
  431. this.formInline.commentTypeName = "";
  432. }
  433. if (action === "remove") {
  434. const obj = this.editableTabs.filter(
  435. (item) => item.commentTypeCode === targetName
  436. )[0];
  437. if (
  438. obj.commentTypeName === "分析内容与可视化分析" ||
  439. obj.commentTypeName === "现象描述" ||
  440. obj.commentTypeName === "原因描述" ||
  441. obj.commentTypeName === "排查建议"
  442. ) {
  443. this.$message({
  444. type: "error",
  445. message:
  446. "分析内容与可视化分析、现象描述、原因描述、排查建议 分析类型不可删除!",
  447. });
  448. return;
  449. }
  450. this.$confirm("此操作将永久删除该评价类型, 是否继续?", "提示", {
  451. confirmButtonText: "确定",
  452. cancelButtonText: "取消",
  453. type: "warning",
  454. })
  455. .then(async () => {
  456. this.loading = true;
  457. try {
  458. const formData = new FormData();
  459. formData.append("commentTypeCode", targetName);
  460. await delAnalysisCommentType(formData);
  461. this.$message({
  462. type: "success",
  463. message: "删除成功!",
  464. });
  465. this.editableTabsValue =
  466. this.editableTabs.length > 0
  467. ? this.editableTabs[0].commentTypeCode
  468. : "";
  469. this.getWindCodeList();
  470. this.loading = false;
  471. } catch (error) {
  472. console.error(error);
  473. this.loading = false;
  474. }
  475. })
  476. .catch(() => {
  477. this.$message({
  478. type: "info",
  479. message: "已取消删除",
  480. });
  481. });
  482. }
  483. },
  484. },
  485. };
  486. </script>
  487. <style scoped lang="scss">
  488. .box-card {
  489. margin: 10px 0;
  490. // box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
  491. width: 100%;
  492. font-size: 14px;
  493. .el-card__body {
  494. width: 100%;
  495. .left {
  496. > div {
  497. line-height: 3;
  498. }
  499. }
  500. }
  501. }
  502. ::v-deep .searchFrom {
  503. .el-form-item__content {
  504. display: flex !important;
  505. justify-content: end !important;
  506. align-items: center !important;
  507. i {
  508. margin-left: 10px;
  509. font-size: 20px;
  510. }
  511. }
  512. }
  513. ::v-deep.el-input--small .el-input__inner {
  514. width: 200px !important;
  515. }
  516. .demo-input-suffix {
  517. display: flex !important;
  518. }
  519. ::v-deep.demo-input-suffix .el-input--small {
  520. width: 100px !important;
  521. }
  522. ::v-deep.demo-input-suffix .el-input--small .el-input__inner {
  523. width: 90px !important;
  524. }
  525. .abalysisType {
  526. margin-top: 30px;
  527. }
  528. </style>