scenePacketList.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. <template>
  2. <div class="scenePacketListPanel">
  3. <div class="viewBox">
  4. <el-button icon="el-icon-view" @click="viewTree" type="primary"
  5. >模板预览</el-button
  6. >
  7. </div>
  8. <tableList ref="table" :columns="columns" :getDataWay="getDataWay">
  9. <el-table-column label="操作" slot="cgInfos" align="center" type="">
  10. <template v-slot="scope">
  11. <i
  12. v-if="
  13. (scope.row.children &&
  14. scope.row.children.length > 0) ||
  15. (!scope.row.children && scope.row.sceneNum === 0) ||
  16. (scope.row.children &&
  17. scope.row.children.length === 0 &&
  18. scope.row.sceneNum === 0)
  19. "
  20. @click="addIndicators(scope.row)"
  21. class="el-icon-plus elIcon"
  22. title="添加"
  23. ></i>
  24. <i
  25. @click="editRow(scope.row)"
  26. class="el-icon-edit-outline elIcon"
  27. title="编辑"
  28. ></i>
  29. <i
  30. v-if="scope.row.parentId != '0'"
  31. @click="delRow(scope.row)"
  32. class="el-icon-delete elIcon"
  33. title="删除"
  34. ></i>
  35. <i
  36. v-if="
  37. !scope.row.children ||
  38. scope.row.children.length === 0
  39. "
  40. @click="addScenario(scope.row)"
  41. class="el-icon-document-add elIcon"
  42. title="添加场景"
  43. ></i>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="指标名称" slot="sublistName" align="left">
  47. <template v-slot="scope">
  48. <span>{{ scope.row.sublistName }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="权重%" slot="weight" align="center">
  52. <template v-slot="scope">
  53. <span v-if="scope.row.weightErr" style="color: red">{{
  54. scope.row.weight
  55. }}</span>
  56. <span v-else>{{ scope.row.weight }}</span>
  57. </template>
  58. </el-table-column>
  59. </tableList>
  60. <div class="btns">
  61. <el-button
  62. type="primary"
  63. v-if="share === '0' || share === ''"
  64. @click="save(false)"
  65. >保存</el-button
  66. >
  67. <el-button
  68. type="primary"
  69. v-if="share === '0' || share === '1'"
  70. @click="save(true)"
  71. >另存为</el-button
  72. >
  73. <el-button type="primary" plain @click="cancel">取消</el-button>
  74. </div>
  75. <el-dialog
  76. :title="nameDiaTitle"
  77. :visible.sync="indicatorsVisible"
  78. width="690px"
  79. :close-on-click-modal="false"
  80. :close-on-press-escape="false"
  81. :before-close="indicatorsCancel"
  82. >
  83. <el-form
  84. ref="form"
  85. :model="form"
  86. :rules="rules"
  87. label-width="108px"
  88. >
  89. <el-form-item label="指标名称:" prop="sublistName">
  90. <el-input
  91. placeholder="请输入"
  92. maxlength="20"
  93. v-autoTrim="{ obj: form, key: 'sublistName' }"
  94. v-model="form.sublistName"
  95. >
  96. </el-input>
  97. </el-form-item>
  98. <el-form-item label="权重:" prop="weight">
  99. <el-input
  100. placeholder="请输入"
  101. maxlength="6"
  102. v-autoTrim="{ obj: form, key: 'weight' }"
  103. v-model="form.weight"
  104. :disabled="editType === 'edit' && isRoot"
  105. >
  106. </el-input>
  107. </el-form-item>
  108. <el-form-item label="备注:" prop="remarks">
  109. <el-input
  110. v-autoTrim="{
  111. obj: form,
  112. key: 'remarks',
  113. }"
  114. v-model="form.remarks"
  115. type="textarea"
  116. placeholder="请输入"
  117. :autosize="{ minRows: 4, maxRows: 4 }"
  118. maxlength="300"
  119. ></el-input>
  120. </el-form-item>
  121. </el-form>
  122. <span slot="footer">
  123. <el-button type="primary" @click="indicatorsConfirm"
  124. >确 定</el-button
  125. >
  126. <el-button @click="indicatorsCancel">取 消</el-button>
  127. </span>
  128. </el-dialog>
  129. <el-dialog
  130. title="场景分类"
  131. :visible.sync="scenarioVisible"
  132. width="690px"
  133. :close-on-click-modal="false"
  134. :close-on-press-escape="false"
  135. :before-close="scenarioCancel"
  136. >
  137. <el-form
  138. ref="formA"
  139. :model="formA"
  140. :rules="rulesA"
  141. label-width="108px"
  142. >
  143. <el-form-item label="场景分类:" prop="sceneType">
  144. <el-select v-model="formA.sceneType">
  145. <el-option
  146. v-for="item in sceneTypeList"
  147. :label="item.caption"
  148. :value="item.code"
  149. :key="item.code"
  150. ></el-option>
  151. </el-select>
  152. </el-form-item>
  153. <el-form-item label="评分规则:" prop="rulesId">
  154. <el-select v-model="formA.rulesId" @change="ruleSelChange">
  155. <el-option
  156. v-for="item in ruleList"
  157. :label="item.ruleName"
  158. :value="item.rulesId"
  159. :key="item.rulesId"
  160. ></el-option>
  161. </el-select>
  162. </el-form-item>
  163. </el-form>
  164. <div class="tips">
  165. 解释:基于不同环境要素,在前述主题场景及两条路径的框架下进行场景的精确细分。细分维度包括天气、季节、温度、路况、车况等多种元素,所采纳元素的广度和深度既与需求有关,也与汽车智能化程度(感知能力)相关
  166. </div>
  167. <span slot="footer">
  168. <el-button type="primary" @click="scenarioConfirm"
  169. >下一步</el-button
  170. >
  171. <el-button @click="scenarioCancel">取 消</el-button>
  172. </span>
  173. </el-dialog>
  174. <el-dialog
  175. title="真实场景"
  176. :visible.sync="scenarioListsVisible"
  177. width="90%"
  178. class="scenarioListsDia"
  179. :close-on-click-modal="false"
  180. :close-on-press-escape="false"
  181. :before-close="scenarioListsCancel"
  182. >
  183. <real-scene-list ref="realScene"></real-scene-list>
  184. <span slot="footer">
  185. <el-button type="primary" @click="scenarioListsConfirm"
  186. >确 定</el-button
  187. >
  188. <el-button @click="scenarioListsCancel">取 消</el-button>
  189. </span>
  190. </el-dialog>
  191. <el-dialog
  192. title="模板预览"
  193. :visible.sync="templateViewVisible"
  194. width="90%"
  195. class="templateViewDia"
  196. :close-on-click-modal="false"
  197. :close-on-press-escape="false"
  198. :before-close="templateViewClose"
  199. >
  200. <view-tree :data="treeData"></view-tree>
  201. <span slot="footer">
  202. <el-button type="primary" @click="templateViewClose"
  203. >关 闭</el-button
  204. >
  205. </span>
  206. </el-dialog>
  207. </div>
  208. </template>
  209. <script>
  210. import searchLayout from "@/components/grid/searchLayout";
  211. import tableList from "@/components/grid/TableList";
  212. import toolbarTab from "@/components/toolbar/toolbarTab";
  213. import realSceneList from "./components/realSceneList";
  214. import viewTree from "./components/elTree";
  215. export default {
  216. name: "scenePacketList", // 场景数据包
  217. components: {
  218. searchLayout,
  219. tableList,
  220. toolbarTab,
  221. realSceneList,
  222. viewTree,
  223. },
  224. data() {
  225. let validateNum = (rule, value, callback) => {
  226. // 修改一级指标时,权重值为number类型,其余为string
  227. if (typeof value === "number") {
  228. value = value + "";
  229. }
  230. if (value == 0 || value > 100) {
  231. callback(new Error(rule.message));
  232. return;
  233. }
  234. if (value.startsWith("0")) {
  235. callback(new Error(rule.message));
  236. return;
  237. }
  238. if (value.includes(".")) {
  239. callback(new Error(rule.message));
  240. return;
  241. }
  242. // !/^(0|[1-9]+[0]*)[(\.\d{1,2})]?$/.test(value) &&
  243. !/^[1-9]+[0]*$/.test(value) && callback(new Error(rule.message));
  244. callback();
  245. };
  246. let validateSublistName = (rule, value, callback) => {
  247. this.nodeList = [];
  248. this.deepFirstSearch(this.getDataWay.data[0], this.nodeList);
  249. let names = this.nodeList
  250. .filter((i) => i.id != this.form.id)
  251. .map((i) => i.sublistName);
  252. if (names.includes(value)) {
  253. callback(new Error(rule.message));
  254. return;
  255. } else {
  256. callback();
  257. }
  258. };
  259. return {
  260. packageId: "",
  261. share: "",
  262. columns: [
  263. {
  264. label: "操作",
  265. prop: "cgInfos",
  266. template: true,
  267. },
  268. {
  269. label: "指标名称",
  270. prop: "sublistName",
  271. template: true,
  272. },
  273. {
  274. label: "权重%",
  275. prop: "weight",
  276. template: true,
  277. },
  278. {
  279. label: "场景数量",
  280. prop: "sceneNum",
  281. },
  282. {
  283. label: "规则名称",
  284. prop: "ruleName",
  285. },
  286. {
  287. label: "备注",
  288. prop: "remarks",
  289. },
  290. ],
  291. getDataWay: {
  292. //加载表格数据
  293. dataType: "data",
  294. // 给出根节点
  295. data: [
  296. {
  297. children: null,
  298. id: "1",
  299. packageAndRules: "",
  300. packageLevel: 1,
  301. parentId: "0",
  302. remarks: "",
  303. rootId: null,
  304. ruleName: "",
  305. sceneGeneralizationIds: null,
  306. sceneNaturalIds: "",
  307. sceneNum: 0,
  308. sceneStatueIds: null,
  309. sceneTrafficIds: null,
  310. seq: 0,
  311. sublistName: "一级指标",
  312. weight: 100,
  313. treeNode: "一级指标" + " (" + 100 + "%)",
  314. },
  315. ],
  316. },
  317. idIndex: 1, // 用做新增加点id自加,因为id为空会报错
  318. nameDiaTitle: "", // 编辑该级节点信息的dialog的title
  319. indicatorsVisible: false, // 编辑指标
  320. scenarioVisible: false, // 选择场景
  321. scenarioListsVisible: false, // 真实场景列表
  322. form: {
  323. sublistName: "",
  324. weight: "",
  325. remarks: "",
  326. id: "",
  327. },
  328. rules: {
  329. sublistName: [
  330. { required: true, message: "请输入", trigger: "blur" },
  331. {
  332. validator: validateSublistName,
  333. message: "指标名称重复",
  334. trigger: ["blur"],
  335. },
  336. ],
  337. weight: [
  338. { required: true, message: "请输入", trigger: "blur" },
  339. {
  340. validator: validateNum,
  341. message: "请输入大不于100的正整数",
  342. trigger: ["blur"],
  343. },
  344. ],
  345. },
  346. ruleList: [],
  347. formA: {
  348. sceneType: "1",
  349. ruleName: "",
  350. rulesId: "",
  351. },
  352. rulesA: {
  353. sceneType: [
  354. { required: true, message: "请选择", trigger: "change" },
  355. ],
  356. rulesId: [
  357. { required: true, message: "请选择", trigger: "change" },
  358. ],
  359. },
  360. sceneTypeList: [{ caption: "真实场景", code: "1" }],
  361. nodeList: [], // 把当前所有节点遍历到一个扁平数组
  362. curNode: {}, // 当前操作的节点
  363. editType: "", // 点操作编辑的类型 新增or编辑
  364. checkedIdsA: [], // 交通事故列表已选
  365. checkedIdsB: [], // 自然驾驶列表已选
  366. checkedIdsC: [], // 标准法规列表已选
  367. isRoot: false, // 是否是根节点
  368. templateViewVisible: false,
  369. treeData: [],
  370. };
  371. },
  372. computed: {},
  373. methods: {
  374. viewTree() {
  375. this.templateViewVisible = true;
  376. this.treeData = this.getDataWay.data;
  377. },
  378. delRow(row) {
  379. this.$confirm("确认是否删除?", "提示", {
  380. confirmButtonText: "确定",
  381. cancelButtonText: "取消",
  382. type: "warning",
  383. }).then(() => {
  384. this.nodeList = [];
  385. this.deepFirstSearch(
  386. this.getDataWay.data[0],
  387. this.nodeList,
  388. row.parentId
  389. );
  390. let index = this.curNode.children.findIndex(
  391. (i) => i.id === row.id
  392. );
  393. this.curNode.children.splice(index, 1);
  394. this.checkWeightValidate();
  395. });
  396. },
  397. // 编辑该级节点信息
  398. editRow(row) {
  399. this.nameDiaTitle = "编辑指标";
  400. this.editType = "edit";
  401. this.indicatorsVisible = true;
  402. if (row.parentId === "0") {
  403. this.isRoot = true;
  404. } else {
  405. this.isRoot = false;
  406. }
  407. this.form.sublistName = row.sublistName;
  408. this.form.weight = row.weight;
  409. this.form.remarks = row.remarks;
  410. this.form.id = row.id;
  411. this.curNode = row;
  412. },
  413. // 增加该级节点的子节点
  414. addIndicators(row) {
  415. this.nameDiaTitle = "添加指标";
  416. this.editType = "add";
  417. this.indicatorsVisible = true;
  418. this.curNode = row;
  419. },
  420. // 添加场景
  421. addScenario(row) {
  422. this.curNode = row;
  423. if (row.packageAndRules) {
  424. this.formA.rulesId = row.packageAndRules;
  425. this.formA.ruleName = this.ruleList.find(
  426. (i) => i.rulesId === row.packageAndRules
  427. ).ruleName;
  428. }
  429. this.scenarioVisible = true;
  430. },
  431. // 操作节点dialog的确定
  432. indicatorsConfirm() {
  433. this.$refs.form.validate((valid) => {
  434. if (valid) {
  435. if (this.editType == "edit") {
  436. // 编辑节点
  437. this.curNode.sublistName = this.form.sublistName;
  438. this.curNode.weight = this.form.weight;
  439. this.curNode.remarks = this.form.remarks;
  440. // 为了预览展示
  441. this.curNode.treeNode =
  442. this.form.sublistName +
  443. " (" +
  444. this.form.weight +
  445. "%)";
  446. } else {
  447. // 新增节点
  448. ++this.idIndex;
  449. let node = {
  450. children: null,
  451. id: this.idIndex + "",
  452. packageAndRules: "",
  453. packageLevel: 1,
  454. parentId: this.curNode.id || "",
  455. remarks: this.form.remarks || "",
  456. rootId: this.packageId,
  457. ruleName: "",
  458. sceneGeneralizationIds: null,
  459. sceneNaturalIds: "",
  460. sceneNum: 0,
  461. sceneStatueIds: null,
  462. sceneTrafficIds: null,
  463. seq: 0,
  464. sublistName: this.form.sublistName,
  465. weight: this.form.weight,
  466. treeNode:
  467. this.form.sublistName +
  468. " (" +
  469. this.form.weight +
  470. "%)",
  471. };
  472. if (!this.curNode.children) {
  473. this.curNode.children = [];
  474. }
  475. this.curNode.children.push(node);
  476. }
  477. this.nodeList = [];
  478. // 遍历当前树 拿到所有节点的平行展开数组
  479. this.deepFirstSearch(
  480. this.getDataWay.data[0],
  481. this.nodeList
  482. );
  483. // console.log(this.getDataWay.data[0]);
  484. this.checkWeightValidate();
  485. this.indicatorsCancel();
  486. }
  487. });
  488. },
  489. // 操作节点dialog的取消
  490. indicatorsCancel() {
  491. this.$refs.form.resetFields();
  492. this.form.sublistName = "";
  493. this.form.weight = "";
  494. this.form.remarks = "";
  495. this.form.id = "";
  496. this.curNode = {};
  497. this.indicatorsVisible = false;
  498. },
  499. // 场景分类dialog的确定 下一步
  500. scenarioConfirm() {
  501. this.$refs.formA.validate((valid) => {
  502. if (valid) {
  503. this.scenarioVisible = false;
  504. this.scenarioListsVisible = true;
  505. // 切换到第一个tab页并清空所有tab页中查询条件
  506. this.$nextTick(() => {
  507. this.$refs.realScene.activeName = "1";
  508. this.$refs.realScene.doResetA();
  509. this.$refs.realScene.doResetB();
  510. this.$refs.realScene.doResetC();
  511. // 把选中数据对应的ids组分别传入tabs中,用于后续操作数据进行存储
  512. if (this.curNode.sceneTrafficIds) {
  513. this.$refs.realScene.checkedIdsA =
  514. this.curNode.sceneTrafficIds.split(",");
  515. }
  516. if (this.curNode.sceneNaturalIds) {
  517. this.$refs.realScene.checkedIdsB =
  518. this.curNode.sceneNaturalIds.split(",");
  519. }
  520. if (this.curNode.sceneStatueIds) {
  521. this.$refs.realScene.checkedIdsC =
  522. this.curNode.sceneStatueIds.split(",");
  523. }
  524. });
  525. }
  526. });
  527. },
  528. // 场景分类dialog的取消
  529. scenarioCancel() {
  530. this.$refs.formA.resetFields();
  531. this.formA.sceneType = "1";
  532. this.formA.ruleName = "";
  533. this.formA.rulesId = "";
  534. this.scenarioVisible = false;
  535. this.curNode = {};
  536. },
  537. // 选择真实场景dialog的确定
  538. scenarioListsConfirm() {
  539. // 获取选中的数据
  540. this.checkedIdsA = this.$refs.realScene.checkedIdsA;
  541. this.checkedIdsB = this.$refs.realScene.checkedIdsB;
  542. this.checkedIdsC = this.$refs.realScene.checkedIdsC;
  543. this.curNode.packageAndRules = this.formA.rulesId;
  544. this.curNode.ruleName = this.formA.ruleName;
  545. this.curNode.sceneNum =
  546. this.checkedIdsA.length +
  547. this.checkedIdsB.length +
  548. this.checkedIdsC.length;
  549. // 选择场景总数为0 则去掉对应的规则名称和id
  550. if (this.curNode.sceneNum === 0) {
  551. this.curNode.packageAndRules = "";
  552. this.curNode.ruleName = "";
  553. } else {
  554. this.curNode.packageAndRules = this.formA.rulesId;
  555. this.curNode.ruleName = this.formA.ruleName;
  556. }
  557. // 选中数据分别传入对应的ids组
  558. this.curNode.sceneTrafficIds = this.checkedIdsA.join(",");
  559. this.curNode.sceneNaturalIds = this.checkedIdsB.join(",");
  560. this.curNode.sceneStatueIds = this.checkedIdsC.join(",");
  561. this.nodeList = [];
  562. // 遍历当前树 拿到所有节点的平行展开数组
  563. this.deepFirstSearch(this.getDataWay.data[0], this.nodeList);
  564. if (this.curNode.parentId != "0") {
  565. this.sceneNumUpdate(this.curNode);
  566. }
  567. this.scenarioListsCancel();
  568. },
  569. // 选择真实场景dialog的取消
  570. scenarioListsCancel() {
  571. this.scenarioCancel();
  572. // 清空选中行数据
  573. this.$refs.realScene.$refs.tableA.$refs.ListTable.clearSelection();
  574. this.$refs.realScene.$refs.tableB.$refs.ListTable.clearSelection();
  575. this.$refs.realScene.$refs.tableC.$refs.ListTable.clearSelection();
  576. this.$refs.realScene.checkedIdsA = [];
  577. this.$refs.realScene.checkedIdsB = [];
  578. this.$refs.realScene.checkedIdsC = [];
  579. this.$refs.realScene.checkedArrA = [];
  580. this.$refs.realScene.checkedArrB = [];
  581. this.$refs.realScene.checkedArrC = [];
  582. this.$refs.realScene.selectedA = false;
  583. this.$refs.realScene.selectedB = false;
  584. this.$refs.realScene.selectedC = false;
  585. this.scenarioListsVisible = false;
  586. },
  587. // 校验权重
  588. checkWeightValidate() {
  589. this.allRowWeightErrFalse(this.getDataWay.data[0]);
  590. let ids = [];
  591. for (let index = 0; index < this.nodeList.length; index++) {
  592. const element = this.nodeList[index];
  593. if (element.children && element.children.length > 0) {
  594. let total = 0;
  595. let arr = [];
  596. element.children.forEach((item) => {
  597. // console.log(this.nodeList);
  598. total += +this.nodeList.find((i) => i.id === item.id)
  599. .weight;
  600. arr.push(item.id);
  601. });
  602. if (total != 100) {
  603. ids.push(...arr);
  604. }
  605. }
  606. }
  607. this.rowWeightErrTrue(this.getDataWay.data[0], ids);
  608. // console.log(this.getDataWay.data[0]);
  609. },
  610. // 深度优先遍历
  611. /* deepFirstSearch(node, nodeList) {
  612. if (node) {
  613. nodeList.push(node);
  614. var children = node.children;
  615. if (children) {
  616. for (var i = 0; i < children.length; i++)
  617. //每次递归的时候将 需要遍历的节点 和 节点所存储的数组传下去
  618. this.deepFirstSearch(children[i], nodeList);
  619. }
  620. }
  621. return nodeList;
  622. }, */
  623. // 通过深度优先找节点
  624. deepFirstSearch(node, nodeList, id) {
  625. if (node) {
  626. // 有id则把对应节点赋给当前操作节点
  627. if (id && node.id === id) {
  628. this.curNode = node;
  629. }
  630. nodeList.push(node);
  631. var children = node.children;
  632. if (children) {
  633. for (var i = 0; i < children.length; i++)
  634. //每次递归的时候将 需要遍历的节点 和 节点所存储的数组传下去
  635. this.deepFirstSearch(children[i], nodeList, id);
  636. }
  637. }
  638. return nodeList;
  639. },
  640. // 使全部节点 weightErr 为 false
  641. allRowWeightErrFalse(node) {
  642. if (node) {
  643. node.weightErr = false;
  644. var children = node.children;
  645. if (children) {
  646. for (var i = 0; i < children.length; i++)
  647. this.allRowWeightErrFalse(children[i]);
  648. }
  649. }
  650. },
  651. // 使部分节点 weightErr 为 true
  652. rowWeightErrTrue(node, arr) {
  653. if (node) {
  654. if (arr.includes(node.id)) {
  655. node.weightErr = true;
  656. }
  657. var children = node.children;
  658. if (children) {
  659. for (var i = 0; i < children.length; i++)
  660. this.rowWeightErrTrue(children[i], arr);
  661. }
  662. }
  663. },
  664. save(isAdd) {
  665. this.nodeList = [];
  666. this.deepFirstSearch(this.getDataWay.data[0], this.nodeList);
  667. for (let index = 0; index < this.nodeList.length; index++) {
  668. const element = this.nodeList[index];
  669. if (element.children && element.children.length > 0) {
  670. let total = 0;
  671. let arr = [];
  672. element.children.forEach((item) => {
  673. total += +this.nodeList.find((i) => i.id === item.id)
  674. .weight;
  675. arr.push(item.sublistName);
  676. });
  677. if (total != 100) {
  678. this.$message.error(
  679. `${arr.join(",")}等权重相加应为100`
  680. );
  681. return;
  682. }
  683. }
  684. }
  685. if (isAdd || !this.$route.query.packageId) {
  686. // 另存为或新增页面
  687. this.getDataWay.data[0].packageLevel = 1;
  688. } else {
  689. this.getDataWay.data[0].packageLevel = 0;
  690. }
  691. this.$axios({
  692. method: "post",
  693. url: this.$api.sceneLibrary.saveScenePackage,
  694. data: {
  695. params: this.getDataWay.data,
  696. },
  697. }).then((res) => {
  698. if (res.code == 200) {
  699. this.$message.success("保存成功");
  700. this.cancel();
  701. } else {
  702. this.$message.error(res.message || "保存失败");
  703. }
  704. });
  705. },
  706. cancel() {
  707. this.$router.replace({
  708. path: "/scenarioTestPackageManagementList",
  709. });
  710. },
  711. async getRuleList() {
  712. await this.$axios({
  713. method: "post",
  714. url: this.$api.sceneLibrary.queryCsb,
  715. data: {},
  716. }).then((res) => {
  717. if (res.code == 200 && res.info) {
  718. this.ruleList = res.info;
  719. } else {
  720. this.$message.error(res.message || "获取评分规则列表失败");
  721. }
  722. });
  723. },
  724. ruleSelChange(val) {
  725. this.formA.ruleName = this.ruleList.find(
  726. (i) => i.rulesId === val
  727. ).ruleName;
  728. },
  729. // 场景数量更新
  730. sceneNumUpdate(curNode) {
  731. let node = this.nodeList.find((i) => i.id === curNode.parentId);
  732. let sceneNum = 0;
  733. node.children.forEach((i) => {
  734. sceneNum += i.sceneNum;
  735. });
  736. node.sceneNum = sceneNum;
  737. if (node.parentId === "0") {
  738. return;
  739. }
  740. this.sceneNumUpdate(node);
  741. },
  742. templateViewClose() {
  743. this.templateViewVisible = false;
  744. this.treeData = [];
  745. },
  746. },
  747. mounted() {
  748. if (this.$route.query.packageId) {
  749. this.packageId = this.$route.query.packageId;
  750. this.share = this.$route.query.share;
  751. if (this.packageId) {
  752. this.$axios({
  753. method: "post",
  754. url: this.$api.sceneLibrary.queryScenePackageSublistList,
  755. data: {
  756. packageId: this.packageId,
  757. },
  758. }).then((res) => {
  759. if (res.code == 200 && res.info) {
  760. this.getDataWay.data = res.info;
  761. } else {
  762. this.$message.error(res.message || "获取信息失败");
  763. }
  764. });
  765. }
  766. }
  767. this.getRuleList();
  768. },
  769. };
  770. </script>
  771. <style lang='less' scoped>
  772. .scenePacketListPanel {
  773. padding: 30px;
  774. .viewBox {
  775. padding: 0 10px 10px;
  776. }
  777. .tips {
  778. padding: 10px 0 10px 18px;
  779. font-size: 12px;
  780. color: @gray;
  781. }
  782. .scenarioListsDia {
  783. /deep/ .el-dialog__body {
  784. padding: 20px 60px;
  785. }
  786. }
  787. .btns {
  788. padding: 30px 0;
  789. text-align: center;
  790. }
  791. .templateViewDia {
  792. /deep/ .el-dialog {
  793. max-height: 80%;
  794. overflow: auto;
  795. .el-dialog__body {
  796. max-height: calc(100%-130px);
  797. overflow: auto;
  798. }
  799. }
  800. }
  801. }
  802. </style>