scenePacketList.vue 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  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.parentId != '0' &&
  38. (!scope.row.children ||
  39. scope.row.children.length === 0)
  40. "
  41. @click="addScenario(scope.row)"
  42. class="el-icon-document-add elIcon"
  43. title="添加场景"
  44. ></i>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="指标名称" slot="sublistName" align="left">
  48. <template v-slot="scope">
  49. <span>{{ scope.row.sublistName }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="权重%" slot="weight" align="center">
  53. <template v-slot="scope">
  54. <span v-if="scope.row.weightErr" style="color: red">{{
  55. scope.row.weight
  56. }}</span>
  57. <span v-else>{{ scope.row.weight }}</span>
  58. </template>
  59. </el-table-column>
  60. </tableList>
  61. <div class="btns">
  62. <el-button
  63. type="primary"
  64. v-if="
  65. share === '0' ||
  66. share === '' ||
  67. ((roleCode === '0' || roleCode === '1') && share === '1')
  68. "
  69. @click="save(false)"
  70. >保存</el-button
  71. >
  72. <el-button
  73. type="primary"
  74. v-if="share === '0' || share === '1'"
  75. @click="save(true)"
  76. >另存为</el-button
  77. >
  78. <el-button type="primary" plain @click="cancel">取消</el-button>
  79. </div>
  80. <el-dialog
  81. :title="nameDiaTitle"
  82. :visible.sync="indicatorsVisible"
  83. width="690px"
  84. :close-on-click-modal="false"
  85. :close-on-press-escape="false"
  86. :before-close="indicatorsCancel"
  87. >
  88. <el-form
  89. ref="form"
  90. :model="form"
  91. :rules="rules"
  92. label-width="108px"
  93. >
  94. <el-form-item label="指标名称:" prop="sublistName">
  95. <el-input
  96. placeholder="请输入"
  97. maxlength="20"
  98. v-autoTrim="{ obj: form, key: 'sublistName' }"
  99. v-model="form.sublistName"
  100. >
  101. </el-input>
  102. </el-form-item>
  103. <el-form-item label="权重%:" prop="weight">
  104. <el-input
  105. placeholder="请输入"
  106. maxlength="6"
  107. v-autoTrim="{ obj: form, key: 'weight' }"
  108. v-model="form.weight"
  109. :disabled="editType === 'edit' && isRoot"
  110. >
  111. </el-input>
  112. </el-form-item>
  113. <el-form-item label="备注:" prop="remarks">
  114. <el-input
  115. v-autoTrim="{
  116. obj: form,
  117. key: 'remarks',
  118. }"
  119. v-model="form.remarks"
  120. type="textarea"
  121. placeholder="请输入"
  122. :autosize="{ minRows: 4, maxRows: 4 }"
  123. maxlength="300"
  124. ></el-input>
  125. </el-form-item>
  126. </el-form>
  127. <span slot="footer">
  128. <el-button type="primary" @click="indicatorsConfirm"
  129. >确 定</el-button
  130. >
  131. <el-button @click="indicatorsCancel">取 消</el-button>
  132. </span>
  133. </el-dialog>
  134. <el-dialog
  135. title="场景分类"
  136. :visible.sync="scenarioVisible"
  137. width="690px"
  138. :close-on-click-modal="false"
  139. :close-on-press-escape="false"
  140. :before-close="scenarioCancel"
  141. >
  142. <el-form
  143. ref="formA"
  144. :model="formA"
  145. :rules="rulesA"
  146. label-width="108px"
  147. >
  148. <el-form-item label="场景分类:" prop="sceneType">
  149. <el-select v-model="formA.sceneType">
  150. <el-option
  151. v-for="item in sceneTypeList"
  152. :label="item.caption"
  153. :value="item.code"
  154. :key="item.code"
  155. ></el-option>
  156. </el-select>
  157. </el-form-item>
  158. <el-form-item label="评分规则:" prop="ruleNameArrayS">
  159. <el-cascader
  160. ref="cascader"
  161. v-model="formA.ruleNameArrayS"
  162. :options="ruleList"
  163. :props="props"
  164. @change="ruleSelChange"
  165. ></el-cascader>
  166. <!-- <el-select v-model="formA.rulesId" @change="ruleSelChange">
  167. <el-option
  168. v-for="item in ruleList"
  169. :label="item.ruleName"
  170. :value="item.rulesId"
  171. :key="item.rulesId"
  172. ></el-option>
  173. </el-select> -->
  174. </el-form-item>
  175. </el-form>
  176. <div class="tips">
  177. 解释:基于不同环境要素,在前述主题场景及两条路径的框架下进行场景的精确细分。细分维度包括天气、季节、温度、路况、车况等多种元素,所采纳元素的广度和深度既与需求有关,也与汽车智能化程度(感知能力)相关
  178. </div>
  179. <span slot="footer">
  180. <el-button type="primary" @click="scenarioConfirm"
  181. >下一步</el-button
  182. >
  183. <el-button @click="scenarioCancel">取 消</el-button>
  184. </span>
  185. </el-dialog>
  186. <el-dialog
  187. title="真实场景"
  188. :visible.sync="scenarioListsVisible"
  189. width="90%"
  190. class="scenarioListsDia"
  191. :close-on-click-modal="false"
  192. :close-on-press-escape="false"
  193. :before-close="scenarioListsCancel"
  194. >
  195. <real-scene-list ref="realScene"></real-scene-list>
  196. <span slot="footer">
  197. <el-button type="primary" @click="scenarioListsConfirm"
  198. >确 定</el-button
  199. >
  200. <el-button @click="scenarioListsCancel">取 消</el-button>
  201. </span>
  202. </el-dialog>
  203. <el-dialog
  204. v-if="generalizationVisible"
  205. :visible.sync="generalizationVisible"
  206. :title="generalizationDiaTitle"
  207. width="90%"
  208. class="generalizationDia"
  209. :close-on-click-modal="false"
  210. :close-on-press-escape="false"
  211. :before-close="generalizationCancel"
  212. >
  213. <el-steps :active="stepActive" align-center>
  214. <el-step title="第一步" description="选择场景模板"></el-step>
  215. <el-step title="第二步" description="场景泛化"></el-step>
  216. </el-steps>
  217. <div class="changeBtn">
  218. <el-button
  219. type="primary"
  220. v-if="stepActive === 2"
  221. @click="changeTemplate"
  222. >更换模板</el-button
  223. >
  224. </div>
  225. <div>
  226. <generalization-list
  227. v-if="stepActive === 1"
  228. ref="generalizationList"
  229. ></generalization-list>
  230. <generalization-detail
  231. v-if="stepActive === 2"
  232. ref="generalizationDetail"
  233. :id="generalizationId"
  234. :curId="curNode.id"
  235. :exampleId="curNode.exampleId"
  236. :ruleName="formA.ruleName"
  237. :rulesId="formA.rulesId"
  238. :ruleNameArrayS="formA.ruleNameArrayS"
  239. :genUrlType="genUrlType"
  240. @generalizationBegin="generalizationBegin"
  241. @generalizationDone="generalizationDone"
  242. @getGeneralizationSceneId="getGeneralizationSceneId"
  243. ></generalization-detail>
  244. </div>
  245. <span slot="footer">
  246. <!-- <el-button
  247. v-if="stepActive === 2"
  248. type="primary"
  249. @click="generalizationPrev"
  250. >上一步</el-button
  251. > -->
  252. <el-button
  253. v-if="stepActive === 1"
  254. type="primary"
  255. @click="generalizationNext"
  256. >下一步</el-button
  257. >
  258. <el-button
  259. v-if="stepActive === 2"
  260. type="primary"
  261. @click="generalizationConfirm"
  262. >完成</el-button
  263. >
  264. <!-- <el-button @click="generalizationCancel">取 消</el-button> -->
  265. </span>
  266. </el-dialog>
  267. <el-dialog
  268. title="模板预览"
  269. v-if="templateViewVisible"
  270. :visible.sync="templateViewVisible"
  271. width="90%"
  272. class="templateViewDia"
  273. :close-on-click-modal="false"
  274. :close-on-press-escape="false"
  275. :before-close="templateViewClose"
  276. >
  277. <!-- <view-tree :data="treeData"></view-tree> -->
  278. <template-view
  279. :viewData="treeData"
  280. :errArr="weightErrIds"
  281. ></template-view>
  282. <span slot="footer">
  283. <el-button type="primary" @click="templateViewClose"
  284. >关 闭</el-button
  285. >
  286. </span>
  287. </el-dialog>
  288. </div>
  289. </template>
  290. <script>
  291. import searchLayout from "@/components/grid/searchLayout";
  292. import tableList from "@/components/grid/TableList";
  293. import toolbarTab from "@/components/toolbar/toolbarTab";
  294. import realSceneList from "./components/realSceneList";
  295. import generalizationList from "./components/generalizationList";
  296. import generalizationDetail from "./components/generalizationDetail";
  297. // import viewTree from "./components/elTree";
  298. import templateView from "./components/templateView";
  299. import { mapState } from "vuex";
  300. export default {
  301. name: "scenePacketList", // 场景测试包
  302. components: {
  303. searchLayout,
  304. tableList,
  305. toolbarTab,
  306. realSceneList,
  307. generalizationList,
  308. generalizationDetail,
  309. // viewTree,
  310. templateView,
  311. },
  312. data() {
  313. let validateNum = (rule, value, callback) => {
  314. // 修改一级指标时,权重值为number类型,其余为string
  315. if (typeof value === "number") {
  316. value = value + "";
  317. }
  318. if (value == 0 || value > 100) {
  319. callback(new Error(rule.message));
  320. return;
  321. }
  322. // if (value.startsWith("0")) {
  323. // callback(new Error(rule.message));
  324. // return;
  325. // }
  326. // if (value.includes(".")) {
  327. // callback(new Error(rule.message));
  328. // return;
  329. // }
  330. !/^(0|[1-9][0-9]*)(\.\d{1})?$/.test(value) &&
  331. callback(new Error(rule.message));
  332. callback();
  333. };
  334. let validateSublistName = (rule, value, callback) => {
  335. this.nodeList = [];
  336. this.deepFirstSearch(this.getDataWay.data[0], this.nodeList);
  337. let names = this.nodeList
  338. .filter((i) => i.id != this.form.id)
  339. .map((i) => i.sublistName);
  340. if (names.includes(value)) {
  341. callback(new Error(rule.message));
  342. return;
  343. } else {
  344. callback();
  345. }
  346. };
  347. return {
  348. packageId: "",
  349. share: "",
  350. columns: [
  351. {
  352. label: "操作",
  353. prop: "cgInfos",
  354. template: true,
  355. },
  356. {
  357. label: "指标名称",
  358. prop: "sublistName",
  359. template: true,
  360. },
  361. {
  362. label: "权重%",
  363. prop: "weight",
  364. template: true,
  365. },
  366. {
  367. label: "场景数量",
  368. prop: "sceneNum",
  369. },
  370. {
  371. label: "规则名称",
  372. prop: "ruleName",
  373. },
  374. {
  375. label: "备注",
  376. prop: "remarks",
  377. },
  378. ],
  379. getDataWay: {
  380. //加载表格数据
  381. dataType: "data",
  382. // 给出根节点
  383. data: [
  384. {
  385. children: null,
  386. id: "1",
  387. share: "",
  388. packageAndRules: "",
  389. packageLevel: 1,
  390. parentId: "0", // 判断根路径的标识
  391. remarks: "",
  392. rootId: null,
  393. ruleName: "",
  394. ruleNameArrayS: [],
  395. sceneGeneralizationIds: null,
  396. sceneNaturalIds: "",
  397. sceneReferenceLibIds:null,
  398. sceneNum: 0,
  399. sceneStatueIds: null,
  400. sceneTrafficIds: null,
  401. seq: 0,
  402. sublistName: "一级指标",
  403. weight: 100,
  404. // 配合view-tree即elTree使用
  405. treeNode: "一级指标" + " (" + 100 + "%)",
  406. },
  407. ],
  408. },
  409. idIndex: 1, // 用做新增加点id自加,因为id为空会报错
  410. nameDiaTitle: "", // 编辑该级节点信息的dialog的title
  411. indicatorsVisible: false, // 编辑指标dialog
  412. scenarioVisible: false, // 选择场景dialog
  413. scenarioListsVisible: false, // 真实场景列表dialog
  414. form: {
  415. sublistName: "",
  416. weight: "",
  417. remarks: "",
  418. id: "",
  419. },
  420. rules: {
  421. sublistName: [
  422. { required: true, message: "请输入", trigger: "blur" },
  423. {
  424. validator: validateSublistName,
  425. message: "指标名称重复",
  426. trigger: ["blur"],
  427. },
  428. ],
  429. weight: [
  430. { required: true, message: "请输入", trigger: "blur" },
  431. {
  432. validator: validateNum,
  433. message: "请输入大不于100且最多带有一位小数的正数",
  434. trigger: ["blur"],
  435. },
  436. ],
  437. },
  438. ruleList: [],
  439. formA: {
  440. sceneType: "1",
  441. ruleName: "",
  442. ruleNameArrayS: [],
  443. rulesId: "",
  444. },
  445. rulesA: {
  446. sceneType: [
  447. { required: true, message: "请选择", trigger: "change" },
  448. ],
  449. ruleNameArrayS: [
  450. { required: true, message: "请选择", trigger: "change" },
  451. ],
  452. },
  453. sceneTypeList: [
  454. { caption: "真实场景", code: "1" },
  455. { caption: "泛化场景", code: "2" },
  456. ],
  457. props: {
  458. multiple: false,
  459. label: "name",
  460. value: "code",
  461. },
  462. nodeList: [], // 把当前所有节点遍历到一个扁平数组
  463. curNode: {}, // 当前操作的节点
  464. editType: "", // 点操作编辑的类型 新增or编辑
  465. checkedIdsA: [], // 交通事故列表已选
  466. checkedIdsB: [], // 自然驾驶列表已选
  467. checkedIdsC: [], // 标准法规列表已选
  468. checkedIdsD: [], // 基准化场景列表已选
  469. isRoot: false, // 是否是根节点
  470. templateViewVisible: false, // 模板预览dialog
  471. treeData: [],
  472. weightErrIds: [], // 存储weightErr为false的节点id的数组
  473. generalizationVisible: false, // 泛化dialog
  474. stepActive: 1, // 泛化步骤
  475. generalizationSceneId: "", // 泛化编号
  476. generalizationId: "", // 泛化详情id
  477. genUrlType: 1, // 1为从列表跳入的模板信息,2为泛化后的详情
  478. maxSceneCount: 0, // 可创建的最大场景数量
  479. originRuleList: [], // 原版的res.info
  480. };
  481. },
  482. computed: {
  483. ...mapState(["roleCode"]),
  484. generalizationDiaTitle() {
  485. if(this.stepActive != 2) {
  486. return "泛化场景"
  487. } else {
  488. return "泛化模板-" + (this.generalizationSceneId || "")
  489. }
  490. }
  491. },
  492. methods: {
  493. viewTree() {
  494. this.templateViewVisible = true;
  495. this.nodeList = [];
  496. // 遍历当前树 拿到所有节点的平行展开数组
  497. this.deepFirstSearch(this.getDataWay.data[0], this.nodeList);
  498. let arr = this.nodeList;
  499. this.nodeList = [];
  500. this.weightErrIds = [];
  501. arr.forEach((i) => {
  502. if (i.treeNode) {
  503. i.topic = i.treeNode;
  504. } else {
  505. i.topic = i.sublistName + " (" + i.weight + "%)";
  506. }
  507. i.parentid = i.parentId;
  508. if (i.parentId === "0") {
  509. i.isroot = true;
  510. } else {
  511. i.expanded = true;
  512. }
  513. if (i.weightErr) this.weightErrIds.push(i.id);
  514. });
  515. this.treeData = arr;
  516. },
  517. delRow(row) {
  518. this.$confirm("确认是否删除?", "提示", {
  519. confirmButtonText: "确定",
  520. cancelButtonText: "取消",
  521. type: "warning",
  522. }).then(() => {
  523. this.nodeList = [];
  524. this.deepFirstSearch(
  525. this.getDataWay.data[0],
  526. this.nodeList,
  527. row.parentId
  528. );
  529. let index = this.curNode.children.findIndex(
  530. (i) => i.id === row.id
  531. );
  532. this.curNode.children.splice(index, 1);
  533. let node = null;
  534. if (this.curNode.children && this.curNode.children.length > 0) {
  535. node = this.curNode.children[0];
  536. } else {
  537. // 解决删除该节点前,其父节点只有一个孩子时,场景数量还会存在的问题
  538. this.curNode.sceneNum = 0;
  539. node = this.curNode;
  540. }
  541. if (node.parentId != "0") {
  542. this.sceneNumUpdate(node);
  543. } else {
  544. this.curNode.sceneNum = 0;
  545. }
  546. this.checkWeightValidate();
  547. });
  548. },
  549. // 编辑该级节点信息
  550. editRow(row) {
  551. this.nameDiaTitle = "编辑指标";
  552. this.editType = "edit";
  553. this.indicatorsVisible = true;
  554. if (row.parentId === "0") {
  555. this.isRoot = true;
  556. } else {
  557. this.isRoot = false;
  558. }
  559. this.form.sublistName = row.sublistName;
  560. this.form.weight = row.weight;
  561. this.form.remarks = row.remarks;
  562. this.form.id = row.id;
  563. this.curNode = row;
  564. },
  565. // 增加该级节点的子节点
  566. addIndicators(row) {
  567. this.nameDiaTitle = "添加指标";
  568. this.editType = "add";
  569. this.indicatorsVisible = true;
  570. this.curNode = row;
  571. },
  572. // 添加场景
  573. addScenario(row) {
  574. this.curNode = row;
  575. if (row.sceneGeneralizationIds) {
  576. this.formA.sceneType = "2";
  577. } else {
  578. this.formA.sceneType = "1";
  579. }
  580. if (row.packageAndRules) {
  581. this.formA.rulesId = row.packageAndRules;
  582. this.formA.ruleName = row.ruleName;
  583. this.formA.ruleNameArrayS = row.ruleNameArrayS;
  584. // this.formA.ruleName =
  585. // this.originRuleList.find(
  586. // (i) => i.rulesId === row.packageAndRules
  587. // ).ruleName || "";
  588. }
  589. this.scenarioVisible = true;
  590. },
  591. // 操作节点dialog的确定
  592. indicatorsConfirm() {
  593. this.$refs.form.validate((valid) => {
  594. if (valid) {
  595. if (this.editType == "edit") {
  596. // 编辑节点
  597. this.curNode.sublistName = this.form.sublistName;
  598. this.curNode.weight = this.form.weight;
  599. this.curNode.remarks = this.form.remarks;
  600. // 为了预览展示
  601. this.curNode.treeNode =
  602. this.form.sublistName +
  603. " (" +
  604. this.form.weight +
  605. "%)";
  606. } else {
  607. // 新增节点
  608. ++this.idIndex;
  609. let node = {
  610. children: null,
  611. id: this.idIndex + "",
  612. packageAndRules: "",
  613. packageLevel: 1,
  614. parentId: this.curNode.id || "",
  615. remarks: this.form.remarks || "",
  616. rootId: this.packageId,
  617. ruleName: "",
  618. ruleNameArrayS: [],
  619. sceneGeneralizationIds: null,
  620. sceneNaturalIds: "",
  621. sceneReferenceLibIds:null,
  622. sceneNum: 0,
  623. sceneStatueIds: null,
  624. sceneTrafficIds: null,
  625. seq: 0,
  626. sublistName: this.form.sublistName,
  627. weight: this.form.weight,
  628. treeNode:
  629. this.form.sublistName +
  630. " (" +
  631. this.form.weight +
  632. "%)",
  633. };
  634. if (!this.curNode.children) {
  635. this.curNode.children = [];
  636. }
  637. this.curNode.children.push(node);
  638. }
  639. this.nodeList = [];
  640. // 遍历当前树 拿到所有节点的平行展开数组
  641. this.deepFirstSearch(
  642. this.getDataWay.data[0],
  643. this.nodeList
  644. );
  645. this.checkWeightValidate();
  646. this.indicatorsCancel();
  647. }
  648. });
  649. },
  650. // 操作节点dialog的取消
  651. indicatorsCancel() {
  652. this.$refs.form.resetFields();
  653. this.form.sublistName = "";
  654. this.form.weight = "";
  655. this.form.remarks = "";
  656. this.form.id = "";
  657. this.curNode = {};
  658. this.indicatorsVisible = false;
  659. },
  660. // 场景分类dialog的确定 下一步
  661. scenarioConfirm() {
  662. this.$refs.formA.validate((valid) => {
  663. if (valid) {
  664. this.scenarioVisible = false;
  665. // 真实场景
  666. if (this.formA.sceneType === "1") {
  667. this.scenarioListsVisible = true;
  668. // 切换到第一个tab页并清空所有tab页中查询条件
  669. this.$nextTick(() => {
  670. this.$refs.realScene.activeName = "1";
  671. this.$refs.realScene.doResetA();
  672. this.$refs.realScene.doResetB();
  673. this.$refs.realScene.doResetC();
  674. this.$refs.realScene.doResetD();
  675. // 把选中数据对应的ids组分别传入tabs中,用于后续操作数据进行存储
  676. if (this.curNode.sceneTrafficIds) {
  677. this.$refs.realScene.checkedIdsA =
  678. this.curNode.sceneTrafficIds.split(",");
  679. }
  680. if (this.curNode.sceneNaturalIds) {
  681. this.$refs.realScene.checkedIdsB =
  682. this.curNode.sceneNaturalIds.split(",");
  683. }
  684. if (this.curNode.sceneStatueIds) {
  685. this.$refs.realScene.checkedIdsC =
  686. this.curNode.sceneStatueIds.split(",");
  687. }
  688. if(this.curNode.sceneReferenceLibIds){
  689. this.$refs.realScene.checkedIdsD = this.curNode.sceneReferenceLibIds.split(",")
  690. }
  691. });
  692. } else {
  693. // 泛化场景
  694. if (this.curNode.exampleId) {
  695. // 进详情
  696. this.genUrlType = 2;
  697. this.stepActive = 2;
  698. } else {
  699. // 进列表
  700. this.genUrlType = 1;
  701. this.stepActive = 1;
  702. }
  703. this.generalizationVisible = true;
  704. }
  705. }
  706. });
  707. },
  708. // 场景分类dialog的取消
  709. scenarioCancel() {
  710. this.$refs.formA.resetFields();
  711. this.formA.sceneType = "1";
  712. this.formA.ruleName = "";
  713. this.formA.ruleNameArrayS = [];
  714. this.formA.rulesId = "";
  715. this.scenarioVisible = false;
  716. this.curNode = {};
  717. },
  718. // 选择真实场景dialog的确定
  719. scenarioListsConfirm() {
  720. // 获取选中的数据
  721. this.checkedIdsA = this.$refs.realScene.checkedIdsA;
  722. this.checkedIdsB = this.$refs.realScene.checkedIdsB;
  723. this.checkedIdsC = this.$refs.realScene.checkedIdsC;
  724. this.checkedIdsD = this.$refs.realScene.checkedIdsD;
  725. this.curNode.packageAndRules = this.formA.rulesId;
  726. this.curNode.ruleName = this.formA.ruleName;
  727. this.curNode.ruleNameArrayS = this.formA.ruleNameArrayS;
  728. this.curNode.sceneNum =
  729. this.checkedIdsA.length +
  730. this.checkedIdsB.length +
  731. this.checkedIdsD.length +
  732. this.checkedIdsC.length;
  733. // 选择场景总数为0 则去掉对应的规则名称和id
  734. if (this.curNode.sceneNum === 0) {
  735. this.curNode.packageAndRules = "";
  736. this.curNode.ruleName = "";
  737. this.curNode.ruleNameArrayS = [];
  738. } else {
  739. this.curNode.packageAndRules = this.formA.rulesId;
  740. this.curNode.ruleName = this.formA.ruleName;
  741. this.curNode.ruleNameArrayS = this.formA.ruleNameArrayS;
  742. }
  743. // 选中数据分别传入对应的ids组
  744. this.curNode.sceneTrafficIds = this.checkedIdsA.join(",");
  745. this.curNode.sceneNaturalIds = this.checkedIdsB.join(",");
  746. this.curNode.sceneStatueIds = this.checkedIdsC.join(",");
  747. this.curNode.sceneReferenceLibIds = this.checkedIdsD.join(",");
  748. // 清空泛化场景的数据
  749. this.curNode.exampleId = "";
  750. this.curNode.sceneGeneralizationIds = "";
  751. this.curNode.templateId = "";
  752. this.nodeList = [];
  753. // 遍历当前树 拿到所有节点的平行展开数组
  754. this.deepFirstSearch(this.getDataWay.data[0], this.nodeList);
  755. this.sceneNumUpdate(this.curNode);
  756. this.scenarioListsCancel();
  757. },
  758. // 选择真实场景dialog的取消
  759. scenarioListsCancel() {
  760. this.scenarioCancel();
  761. // 清空选中行数据
  762. this.$refs.realScene.$refs.tableA.$refs.ListTable.clearSelection();
  763. this.$refs.realScene.$refs.tableB.$refs.ListTable.clearSelection();
  764. this.$refs.realScene.$refs.tableC.$refs.ListTable.clearSelection();
  765. this.$refs.realScene.checkedIdsA = [];
  766. this.$refs.realScene.checkedIdsB = [];
  767. this.$refs.realScene.checkedIdsC = [];
  768. this.$refs.realScene.checkedArrA = [];
  769. this.$refs.realScene.checkedArrB = [];
  770. this.$refs.realScene.checkedArrC = [];
  771. this.$refs.realScene.selectedA = false;
  772. this.$refs.realScene.selectedB = false;
  773. this.$refs.realScene.selectedC = false;
  774. this.scenarioListsVisible = false;
  775. },
  776. // 泛化-上一步
  777. generalizationPrev() {
  778. this.stepActive = 1;
  779. },
  780. // 泛化-下一步
  781. generalizationNext() {
  782. let arr = [];
  783. if (
  784. this.$refs.generalizationList &&
  785. this.$refs.generalizationList.checkedArr
  786. ) {
  787. arr = this.$refs.generalizationList.checkedArr;
  788. } else {
  789. return;
  790. }
  791. if (arr.length === 0) {
  792. this.$message.warning("请先选择一条数据");
  793. return;
  794. } else if (arr.length > 1) {
  795. this.$message.warning("只能选择一条数据");
  796. return;
  797. }
  798. this.generalizationId = arr[0].id;
  799. // this.generalizationSceneId = arr[0].sceneId;
  800. this.generalizationSceneId = "";
  801. this.genUrlType = 1;
  802. this.stepActive = 2;
  803. },
  804. // 泛化-完成按钮
  805. generalizationConfirm() {
  806. this.$refs.generalizationDetail.done();
  807. },
  808. // 泛化-取消
  809. generalizationCancel() {
  810. this.$refs.formA.resetFields();
  811. this.formA.ruleName = "";
  812. this.formA.ruleNameArrayS = [];
  813. this.formA.rulesId = "";
  814. this.generalizationVisible = false;
  815. },
  816. getGeneralizationSceneId(sceneId) {
  817. this.generalizationSceneId = sceneId;
  818. },
  819. // 开始泛化
  820. generalizationBegin() {
  821. this.generalizationCancel();
  822. this.curNode.sceneNum = "泛化中";
  823. this.curNode = {};
  824. },
  825. // 泛化完成回调
  826. generalizationDone(info, obj, isSuccess = true) {
  827. this.nodeList = [];
  828. // 遍历当前树 拿到所有节点的平行展开数组
  829. this.deepFirstSearch(this.getDataWay.data[0], this.nodeList);
  830. let node = this.nodeList.find((i) => i.id === obj.curId);
  831. if (node) {
  832. if (isSuccess) {
  833. node.exampleId = info.exampleId;
  834. node.sceneGeneralizationIds = info.sceneGeneralizationIds;
  835. node.sceneNum = info.sceneNum;
  836. node.id = info.sublistId;
  837. node.templateId = info.templateId;
  838. node.packageAndRules = obj.rulesId;
  839. node.ruleName = obj.ruleName;
  840. node.ruleNameArrayS = obj.ruleNameArrayS;
  841. } else {
  842. // 若泛化失败则清空对应字段
  843. node.exampleId = "";
  844. node.sceneGeneralizationIds = "";
  845. node.sceneNum = 0;
  846. node.templateId = "";
  847. node.packageAndRules = "";
  848. node.ruleName = "";
  849. node.ruleNameArrayS = [];
  850. }
  851. // 清空真实场景的数据
  852. node.sceneTrafficIds = "";
  853. node.sceneNaturalIds = "";
  854. node.sceneStatueIds = "";
  855. node.sceneReferenceLibIds = "";
  856. this.sceneNumUpdate(node);
  857. }
  858. },
  859. // 更换模板
  860. changeTemplate() {
  861. this.stepActive = 1;
  862. },
  863. // 校验权重
  864. checkWeightValidate() {
  865. this.allRowWeightErrFalse(this.getDataWay.data[0]);
  866. let ids = [];
  867. for (let index = 0; index < this.nodeList.length; index++) {
  868. const element = this.nodeList[index];
  869. if (element.children && element.children.length > 0) {
  870. let total = 0;
  871. let arr = [];
  872. element.children.forEach((item) => {
  873. total += +this.nodeList.find((i) => i.id === item.id)
  874. .weight;
  875. arr.push(item.id);
  876. });
  877. if (total != 100) {
  878. ids.push(...arr);
  879. }
  880. }
  881. }
  882. this.rowWeightErrTrue(this.getDataWay.data[0], ids);
  883. },
  884. // 通过深度优先找节点
  885. deepFirstSearch(node, nodeList, id) {
  886. if (node) {
  887. // 有id则把对应节点赋给当前操作节点
  888. if (id && node.id === id) {
  889. this.curNode = node;
  890. }
  891. nodeList.push(node);
  892. var children = node.children;
  893. if (children) {
  894. for (var i = 0; i < children.length; i++)
  895. //每次递归的时候将 需要遍历的节点 和 节点所存储的数组传下去
  896. this.deepFirstSearch(children[i], nodeList, id);
  897. }
  898. }
  899. return nodeList;
  900. },
  901. // 使全部节点 weightErr 为 false
  902. allRowWeightErrFalse(node) {
  903. if (node) {
  904. node.weightErr = false;
  905. var children = node.children;
  906. if (children) {
  907. for (var i = 0; i < children.length; i++)
  908. this.allRowWeightErrFalse(children[i]);
  909. }
  910. }
  911. },
  912. // 使部分节点 weightErr 为 true
  913. rowWeightErrTrue(node, arr) {
  914. if (node) {
  915. if (arr.includes(node.id)) {
  916. node.weightErr = true;
  917. }
  918. var children = node.children;
  919. if (children) {
  920. for (var i = 0; i < children.length; i++)
  921. this.rowWeightErrTrue(children[i], arr);
  922. }
  923. }
  924. },
  925. save(isAdd) {
  926. this.nodeList = [];
  927. this.deepFirstSearch(this.getDataWay.data[0], this.nodeList);
  928. for (let index = 0; index < this.nodeList.length; index++) {
  929. const element = this.nodeList[index];
  930. if (element.sceneNum === "泛化中") {
  931. this.$message.error("存在泛化中场景,请稍后进行保存");
  932. return;
  933. }
  934. if (element.sceneNum == 0) {
  935. this.$message.error("场景数量不能为0");
  936. return;
  937. }
  938. if (this.roleCode != "0" && this.roleCode != "1") {
  939. if (element.sceneNum > this.maxSceneCount) {
  940. this.$message.error(
  941. `场景数量不能超过${this.maxSceneCount}`
  942. );
  943. return;
  944. }
  945. }
  946. if (element.children && element.children.length > 0) {
  947. let total = 0;
  948. let arr = [];
  949. element.children.forEach((item) => {
  950. total += +this.nodeList.find((i) => i.id === item.id)
  951. .weight;
  952. arr.push(item.sublistName);
  953. });
  954. if (total != 100) {
  955. this.$message.error(
  956. `${arr.join(",")}等权重相加应为100`
  957. );
  958. return;
  959. }
  960. }
  961. }
  962. if (isAdd || !this.$route.query.packageId) {
  963. // 另存为或新增页面
  964. this.getDataWay.data[0].packageLevel = 1;
  965. } else {
  966. this.getDataWay.data[0].packageLevel = 0;
  967. }
  968. this.getDataWay.data[0].share = this.share;
  969. this.$axios({
  970. method: "post",
  971. url: this.$api.sceneLibrary.saveScenePackage,
  972. data: {
  973. params: this.getDataWay.data,
  974. },
  975. }).then((res) => {
  976. if (res.code == 200) {
  977. this.$message.success("保存成功");
  978. this.cancel();
  979. } else {
  980. this.$message.error(res.message || "保存失败");
  981. }
  982. });
  983. },
  984. cancel() {
  985. this.$router.replace({
  986. path: "/scenarioTestPackageManagementList",
  987. });
  988. },
  989. async getRuleList() {
  990. await this.$axios({
  991. method: "post",
  992. url: this.$api.sceneLibrary.queryCsbNew,
  993. data: {},
  994. }).then((res) => {
  995. if (res.code == 200 && res.info) {
  996. this.originRuleList = res.info;
  997. // let arr = [];
  998. // res.info.forEach((i, index) => {
  999. // arr[index] = Object.assign({}, i);
  1000. // });
  1001. // arr.forEach((i) => {
  1002. // if (i.share === "1") i.ruleName = i.ruleName + "(公有)";
  1003. // });
  1004. // this.ruleList = arr;
  1005. this.ruleList = res.info;
  1006. } else {
  1007. this.$message.error(res.message || "获取评分规则列表失败");
  1008. }
  1009. });
  1010. },
  1011. ruleSelChange(v) {
  1012. let item = this.$refs.cascader.getCheckedNodes(true)[0].data.vo;
  1013. this.formA.ruleName = item.ruleName;
  1014. this.formA.rulesId = item.rulesId;
  1015. // this.formA.ruleName = this.originRuleList.find(
  1016. // (i) => i.rulesId === val
  1017. // ).ruleName;
  1018. },
  1019. // 场景数量更新
  1020. sceneNumUpdate(curNode) {
  1021. let node = this.nodeList.find((i) => i.id === curNode.parentId);
  1022. let sceneNum = 0;
  1023. node.children.forEach((i) => {
  1024. i.sceneNum != "泛化中" ? (sceneNum += i.sceneNum) : null;
  1025. });
  1026. node.sceneNum = sceneNum;
  1027. if (node.parentId === "0") {
  1028. return;
  1029. }
  1030. this.sceneNumUpdate(node);
  1031. },
  1032. templateViewClose() {
  1033. this.templateViewVisible = false;
  1034. this.treeData = [];
  1035. },
  1036. getCount() {
  1037. this.$axios({
  1038. method: "post",
  1039. url: this.$api.sceneLibrary.getSceneParam,
  1040. data: {},
  1041. }).then((res) => {
  1042. if (res.code == 200 && res.info) {
  1043. this.maxSceneCount = res.info.numScenePerPackage || 0;
  1044. } else {
  1045. this.$message.error(res.message || "获取信息失败");
  1046. }
  1047. });
  1048. },
  1049. },
  1050. mounted() {
  1051. if (this.$route.query.packageId) {
  1052. this.packageId = this.$route.query.packageId;
  1053. this.share = this.$route.query.share;
  1054. if (this.packageId) {
  1055. this.$axios({
  1056. method: "post",
  1057. url: this.$api.sceneLibrary.queryScenePackageSublistList,
  1058. data: {
  1059. packageId: this.packageId,
  1060. },
  1061. }).then((res) => {
  1062. if (res.code == 200 && res.info) {
  1063. this.getDataWay.data = res.info;
  1064. } else {
  1065. this.$message.error(res.message || "获取信息失败");
  1066. }
  1067. });
  1068. }
  1069. }
  1070. this.getRuleList();
  1071. if (this.roleCode != "0" && this.roleCode != "1") {
  1072. this.getCount();
  1073. }
  1074. },
  1075. };
  1076. </script>
  1077. <style lang='less' scoped>
  1078. .scenePacketListPanel {
  1079. padding: 30px;
  1080. .viewBox {
  1081. padding: 0 10px 10px;
  1082. }
  1083. .tips {
  1084. padding: 10px 0 10px 18px;
  1085. font-size: 12px;
  1086. color: @gray;
  1087. }
  1088. .scenarioListsDia,
  1089. .generalizationDia {
  1090. /deep/ .el-dialog__body {
  1091. padding: 20px 60px;
  1092. }
  1093. }
  1094. .generalizationDia {
  1095. /deep/ .el-dialog__body {
  1096. position: relative;
  1097. .changeBtn {
  1098. position: absolute;
  1099. top: 20px;
  1100. right: 60px;
  1101. }
  1102. }
  1103. }
  1104. .el-form {
  1105. .el-input,
  1106. .el-select,
  1107. .el-cascader {
  1108. width: 100%;
  1109. }
  1110. .el-cascader {
  1111. height: 32px;
  1112. line-height: 32px;
  1113. }
  1114. .el-select /deep/ .el-input, .el-cascader /deep/ .el-input {
  1115. width: 100%;
  1116. }
  1117. }
  1118. .btns {
  1119. padding: 30px 0;
  1120. text-align: center;
  1121. }
  1122. .templateViewDia {
  1123. /deep/ .el-dialog {
  1124. // max-height: 80%;
  1125. height: calc(100% - 12vh - 15px);
  1126. margin-top: 6vh !important;
  1127. // height: 600px;
  1128. // overflow: auto;
  1129. // overflow: hidden;
  1130. .el-dialog__body {
  1131. // height: 100%;
  1132. height: calc(100% - 130px);
  1133. overflow: auto;
  1134. &.toCenter {
  1135. display: flex;
  1136. justify-content: center;
  1137. align-items: center;
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. </style>