ConditionsSet.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <template>
  2. <el-dialog
  3. class="dialog-set"
  4. :visible.sync="visible"
  5. width="70%"
  6. append-to-body
  7. >
  8. <div slot="title" class="dialog-title">
  9. <div>
  10. <i class="el-icon-s-tools" ></i>
  11. <span style="margin-left: 10px;">条件设置</span>
  12. </div>
  13. <div class="marginTop-10">设置样品信息和技术指标的关联关系,满足条件时回显对应参数</div>
  14. </div>
  15. <div class="conditions-container">
  16. <!-- 左侧条件列表 -->
  17. <div class="conditions-left">
  18. <div class="condition-header">
  19. <i class="el-icon-s-operation" style="color: rgb(46, 123, 115);"></i>
  20. <span>参数列表</span>
  21. </div>
  22. <div class="condition-list">
  23. <div class="condition-item">
  24. <span
  25. v-for="(item, index) in paramList"
  26. :key="index"
  27. :class="{ active: activeIndex === index }"
  28. @click="handleSelect(index, item)"
  29. >
  30. {{ item.paramName }}
  31. </span>
  32. </div>
  33. </div>
  34. </div>
  35. <!-- 右侧操作列表 -->
  36. <div class="conditions-right">
  37. <div class="condition-header1">
  38. <div class="header-left">
  39. <i class="el-icon-s-operation" style="color: rgb(46, 123, 115);"></i>
  40. <span>条件列表</span>
  41. </div>
  42. <div class="header-right">
  43. <el-button
  44. type="primary"
  45. size="small"
  46. :style="{ background: 'rgb(37, 80, 162)', borderColor: 'rgb(37, 80, 162)' }"
  47. @click="addCondition"
  48. >
  49. <i class="el-icon-plus"></i>
  50. 添加条件
  51. </el-button>
  52. <el-button
  53. type="success"
  54. size="small"
  55. @click="saveCondition"
  56. >
  57. <i class="el-icon-check"></i>
  58. 保存条件
  59. </el-button>
  60. </div>
  61. </div>
  62. <div class="condition-list">
  63. <div class="condition-item1">
  64. <div
  65. v-for="(item, index) in paramList[activeIndex].codeList"
  66. :key="index"
  67. >
  68. <div>
  69. <span>
  70. <div class="condition-header-content">
  71. <div style="color: black;">
  72. {{item.codeName}}
  73. </div>
  74. <i class="el-icon-close" @click.stop="handleDeleteItem(item,index)"></i>
  75. </div>
  76. <div class="code-list">
  77. <div v-for="(item1,index) in item.codeValue" :key="index" class="code-item">
  78. {{ item1.name }}
  79. </div>
  80. </div>
  81. </span>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <div class="result-container">
  89. <div class="condition-header">
  90. <i class="el-icon-connection" style="color: rgb(46, 123, 115);"></i>
  91. <span>关联关系</span>
  92. </div>
  93. <div class="link-list">
  94. <div v-for="(item, index) in linkListData" :key="index" class="link-item">
  95. <div class="link-name">
  96. <span>{{ item.paramName }}</span>
  97. </div>
  98. <div>
  99. <i class="el-icon-connection" style="color: black; font-size: larger;"></i>
  100. </div>
  101. <div class="code-list">
  102. <div v-for="(codeItem, codeIndex) in item.codeList" :key="codeIndex" class="code-item">
  103. <div class="code-title">{{ codeItem.codeName }}</div>
  104. <div class="code-detail">{{ codeItem.codeValueName }}</div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. <div slot="footer" class="dialog-footer">
  111. <el-button type="primary" @click="handleConfirm" :style="{ background: 'rgb(37, 80, 162)', borderColor: 'rgb(37, 80, 162)' }">保存</el-button>
  112. </div>
  113. <el-dialog
  114. class="dialog-set"
  115. :visible.sync="addDialogVisible"
  116. width="30%"
  117. append-to-body
  118. close-on-click-modal="false"
  119. >
  120. <div slot="title" class="dialog-title">
  121. <div>
  122. <i class="el-icon-plus" ></i>
  123. <span style="margin-left: 10px;">添加条件</span>
  124. </div>
  125. <div class="marginTop-10">同次设置的条件为“或者”关系,不同次设置的条件为“并且”关系</div>
  126. </div>
  127. <el-form ref="addForm" :model="addForm" label-width="80px">
  128. <el-form-item label="样品信息">
  129. <el-select v-model="addForm.codeNameId" placeholder="请选择" style="width: 100%;" @change="handleSelectCodeName">
  130. <el-option
  131. v-for="item in sampleOptions"
  132. :key="item.value"
  133. :label="item.label"
  134. :value="item.value">
  135. </el-option>
  136. </el-select>
  137. </el-form-item>
  138. <el-form-item label="基础信息">
  139. <el-select v-model="addForm.codeValueList" placeholder="请选择" multiple style="width: 100%;" @change="handleSelectCode">
  140. <el-option
  141. v-for="item in basicOptions"
  142. :key="item.value"
  143. :label="item.label"
  144. :value="item.value">
  145. </el-option>
  146. </el-select>
  147. </el-form-item>
  148. </el-form>
  149. <div slot="footer" class="dialog-footer">
  150. <el-button type="primary" @click="confirmAdd" :style="{ background: 'rgb(37, 80, 162)', borderColor: 'rgb(37, 80, 162)' }">确认添加</el-button>
  151. </div>
  152. </el-dialog>
  153. </el-dialog>
  154. </template>
  155. <script>
  156. import {getInfoPage,saveConditionSet,getConditionSet } from "@/api/ruleManage/fileRule.js";
  157. export default {
  158. name: 'ConditionsSet',
  159. data() {
  160. return {
  161. visible: false,
  162. paramList: [
  163. {
  164. paramName: '<0.75',
  165. codeList:[
  166. {codeName: 'C3A', codeValue: [
  167. {name:'矿渣硅酸盐水泥',value:'1'}
  168. ]},
  169. {codeName: 'C3S', codeValue: []},
  170. ]
  171. }
  172. ] , // 参数列表数据
  173. activeIndex: 0, // 当前选中的参数索引
  174. addDialogVisible: false,
  175. addForm: {
  176. codeName: '',
  177. codeValueList: [],
  178. codeValueName: '',
  179. codeNameId: ''
  180. },
  181. sampleOptions: [
  182. // 添加更多选项...
  183. ],
  184. basicOptions: [],
  185. linkListData: [
  186. {paramName:'<0.75',codeList:[
  187. {codeName: 'C3A', codeValue: [
  188. {name:'矿渣硅酸盐水泥',value:'1'},
  189. {name:'矿渣硅酸盐水泥2',value:'1'}
  190. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥2'},
  191. {codeName: 'C3A33', codeValue: [
  192. {name:'矿渣硅酸盐水泥77',value:'1'},
  193. {name:'矿渣硅酸盐水泥2',value:'1'}
  194. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥2'},
  195. {codeName: 'C3A33', codeValue: [
  196. {name:'矿渣硅酸盐水泥77',value:'1'},
  197. {name:'矿渣硅酸盐水泥2',value:'1'}
  198. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥2'},
  199. {codeName: 'C3A33', codeValue: [
  200. {name:'矿渣硅酸盐水泥77',value:'1'},
  201. {name:'矿渣硅酸盐水泥2',value:'1'}
  202. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥2'},
  203. {codeName: 'C3A33', codeValue: [
  204. {name:'矿渣硅酸盐水泥77',value:'1'},
  205. {name:'矿渣硅酸盐水泥2',value:'1'}
  206. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥2'},
  207. {codeName: 'C3A33', codeValue: [
  208. {name:'矿渣硅酸盐水泥77',value:'1'},
  209. {name:'矿渣硅酸盐水泥2',value:'1'}
  210. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥2'},
  211. {codeName: 'C3A33', codeValue: [
  212. {name:'矿渣硅酸盐水泥77',value:'1'},
  213. {name:'矿渣硅酸盐水泥2',value:'1'}
  214. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥2888'},
  215. {codeName: 'C3A33', codeValue: [
  216. {name:'矿渣硅酸盐水泥77',value:'1'},
  217. {name:'矿渣硅酸盐水泥2',value:'1'}
  218. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥2888'},
  219. {codeName: 'C3A33', codeValue: [
  220. {name:'矿渣硅酸盐水泥77',value:'1'},
  221. {name:'矿渣硅酸盐水泥2',value:'1'}
  222. ],codeValueName: '矿渣硅酸盐水泥/矿渣硅酸盐水泥288899'},
  223. ]},
  224. ], // 关联关系数据
  225. id:'', // 传入的ID规范文件id
  226. }
  227. },
  228. methods: {
  229. show(val,id) {
  230. this.id = id
  231. this.getSampleOptions(id)
  232. this.visible = true
  233. if(val.length > 0&&val[0].name) {
  234. this.paramList = val.map(item => {
  235. return {
  236. paramName: item.symbolName,
  237. codeList: [],
  238. id: item.id
  239. }
  240. })
  241. }else{
  242. this.paramList = []
  243. }
  244. this.getConditionSetData(this.id);
  245. },
  246. //获取样品信息列表
  247. getSampleOptions(id){
  248. getInfoPage({
  249. current:1,
  250. size:100,
  251. type: 1,
  252. standardId: id,
  253. }).then((res) => {
  254. this.ruleLoading = false;
  255. if (res.data.code === 200) {
  256. this.sampleOptions= res.data.data.records.map(item => ({
  257. value: item.id,
  258. label: item.name,
  259. info:item.info
  260. }));
  261. //
  262. } else {
  263. this.sampleOptions = [];
  264. }
  265. });
  266. },
  267. hide() {
  268. this.visible = false
  269. },
  270. handleCancel() {
  271. this.hide()
  272. this.$emit('cancel')
  273. },
  274. handleConfirm() {
  275. this.hide()
  276. this.$emit('confirm')
  277. },
  278. addCondition() {
  279. // 添加条件逻辑
  280. this.addDialogVisible = true
  281. this.addForm = {}
  282. },
  283. addOperation() {
  284. // 添加操作逻辑
  285. },
  286. handleSelect(index) {
  287. this.activeIndex = index
  288. },
  289. handleSelectCode(values) {
  290. if (!values || values.length === 0) {
  291. this.addForm.codeValueName = '';
  292. return;
  293. }
  294. // 根据选中的value值找到对应的label
  295. const selectedLabels = values.map(value => {
  296. const option = this.basicOptions.find(opt => opt.value === value);
  297. return option ? option.label : '';
  298. });
  299. this.addForm.codeValueName = selectedLabels.join('/');
  300. this.addForm.codeValue = values
  301. },
  302. handleSelectCodeName(value) {
  303. if (!value) {
  304. this.addForm.codeName = '';
  305. return;
  306. }
  307. this.sampleOptions.forEach(option => {
  308. if (option.value === value) {
  309. this.addForm.codeName = option.label;
  310. }
  311. });
  312. const selectedOption = this.sampleOptions.find(option => option.value === value);
  313. console.log(selectedOption,'selectedOption');
  314. this.basicOptions = selectedOption ? selectedOption.info.map(item => ({
  315. value: item.id,
  316. label: item.name
  317. })) : [];
  318. },
  319. handleDeleteItem(item, index) {
  320. this.paramList[this.activeIndex].codeList.splice(index, 1)
  321. this.$message.success('删除成功')
  322. },
  323. confirmAdd() {
  324. if (!this.addForm.codeName || !this.addForm.codeValue) return this.$message.error('请选择样品信息和基础信息')
  325. this.paramList[this.activeIndex].codeList.push(
  326. {codeName: this.addForm.codeName,
  327. codeValue: [
  328. {name:this.addForm.codeValueName,value:this.addForm.codeValue}
  329. ]},
  330. )
  331. this.addDialogVisible = false
  332. this.addForm = {
  333. codeName: '',
  334. codeValue: []
  335. }
  336. this.$message.success('添加成功')
  337. },
  338. //保存条件
  339. saveCondition() {
  340. let resArr = this.paramList.map(item => {
  341. // 收集所有 codeValue 的 value,不需要额外的数组包装
  342. const rightIds = item.codeList.reduce((acc, codeItem) => {
  343. // codeItem.codeValue[0].value 是一个数组,直接展开到 acc 中
  344. return [...acc, ...codeItem.codeValue[0].value];
  345. }, []);
  346. return {
  347. leftId: item.id, // leftId 保持数组形式
  348. rightIds // rightIds 是展开后的一维数组
  349. };
  350. });
  351. // 调用保存接口
  352. if (resArr.length === 0) {
  353. this.$message.warning('请先设置关联关系');
  354. return;
  355. }
  356. console.log(resArr,'resArr');
  357. saveConditionSet(resArr).then((res) => {
  358. if(res.data.code == 200) {
  359. this.$message.success(res.data.msg);
  360. this.getConditionSetData(this.id);
  361. } else {
  362. this.$message.error(res.data.msg);
  363. }
  364. }).finally(() => {
  365. this.saveYpLoad = false;
  366. });
  367. },
  368. // 获取条件设置
  369. getConditionSetData(id) {
  370. getConditionSet({id}).then((res) => {
  371. if (res.data.code === 200) {
  372. console.log(res.data.data, '获取的条件设置数据');
  373. // this.paramList = res.data.data.map(item => ({
  374. // paramName: item.symbolName,
  375. // codeList: item.codeList.map(codeItem => ({
  376. // codeName: codeItem.codeName,
  377. // codeValue: codeItem.codeValue.map(val => ({ name: val.name, value: val.value }))
  378. // })),
  379. // id: item.id
  380. // }));
  381. } else {
  382. // this.$message.error(res.data.msg);
  383. }
  384. });
  385. }
  386. }
  387. }
  388. </script>
  389. <style lang="scss" scoped>
  390. .conditions-container {
  391. display: flex;
  392. gap: 20px;
  393. font-weight: bold;
  394. // height: 200px;
  395. .green-txt{
  396. color: rgb(46, 123, 115);;
  397. }
  398. .conditions-left,
  399. .conditions-right {
  400. flex: 1;
  401. border: 1px solid #EBEEF5;
  402. border-radius: 4px;
  403. background: #f5f7fa;
  404. }
  405. .condition-list,
  406. .condition-content {
  407. padding: 10px;
  408. }
  409. .condition-item {
  410. span {
  411. display: inline-block;
  412. padding: 8px 8px;
  413. margin: 5px;
  414. background: white;
  415. color: #409EFF;
  416. border-radius: 4px;
  417. cursor: pointer; // 添加指针样式
  418. transition: all 0.3s; // 添加过渡效果
  419. &.active { // 选中状态
  420. background: #67C23A;;
  421. color: white;
  422. }
  423. }
  424. }
  425. .content-item {
  426. margin-bottom: 10px;
  427. padding: 10px;
  428. border: 1px solid #EBEEF5;
  429. border-radius: 4px;
  430. .item-title {
  431. display: flex;
  432. gap: 10px;
  433. align-items: center;
  434. span {
  435. &:first-child {
  436. color: #666;
  437. }
  438. &:nth-child(2) {
  439. color: #409EFF;
  440. }
  441. &:last-child {
  442. color: #666;
  443. }
  444. }
  445. }
  446. }
  447. }
  448. .dialog-title {
  449. display: flex;
  450. flex-direction: column;
  451. color:white ;
  452. padding: 10px;
  453. font-size: 14px;
  454. .marginTop-20{
  455. margin-top: 10px;
  456. }
  457. background: rgb(37, 80, 162);
  458. .el-dialog__header{
  459. padding: 0px;
  460. }
  461. }
  462. .condition-header1 {
  463. display: flex;
  464. justify-content: space-between; // 两端对齐
  465. align-items: center;
  466. padding: 10px;
  467. border-bottom: 1px solid #EBEEF5;
  468. .header-left {
  469. display: flex;
  470. align-items: center;
  471. span {
  472. font-weight: bold;
  473. margin-left: 10px;
  474. }
  475. }
  476. .header-right {
  477. display: flex;
  478. gap: 10px; // 按钮间距
  479. .el-button {
  480. padding: 7px 15px;
  481. &:hover {
  482. opacity: 0.8;
  483. }
  484. }
  485. }
  486. }
  487. .code-list{
  488. display: flex;
  489. font-weight: bold;
  490. .code-item{
  491. margin-right: 5px;
  492. margin-top: 5px;
  493. }
  494. }
  495. .condition-item1 {
  496. display: flex;
  497. span {
  498. margin-left: 5px;
  499. display: inline-block;
  500. padding: 8px 8px;
  501. background: rgb(213, 222, 255);;
  502. color: rgba(37,80,162,1);
  503. border-radius: 4px;
  504. cursor: pointer; // 添加指针样式
  505. transition: all 0.3s; // 添加过渡效果
  506. height: 40px;
  507. }
  508. }
  509. .condition-header-content {
  510. display: flex;
  511. justify-content: space-between;
  512. align-items: center;
  513. width: 100%;
  514. .delete-icon {
  515. color: #F56C6C;
  516. cursor: pointer;
  517. font-size: 16px;
  518. &:hover {
  519. opacity: 0.8;
  520. }
  521. }
  522. }
  523. .result-container{
  524. width: 100%;
  525. border: 1px solid #EBEEF5;
  526. border-radius: 4px;
  527. background: #f5f7fa;
  528. margin-top: 10px;
  529. }
  530. .condition-header {
  531. display: flex;
  532. // justify-content: space-between;
  533. align-items: center;
  534. padding: 10px;
  535. border-bottom: 1px solid #EBEEF5;
  536. span {
  537. font-weight: bold;
  538. margin-left: 10px;
  539. }
  540. }
  541. .link-list{
  542. max-height: 350px;
  543. overflow-y: auto;
  544. padding: 10px;
  545. font-weight: bold;
  546. .link-item{
  547. display: flex;
  548. align-items: center;
  549. padding: 10px;
  550. background-color: white;
  551. border-radius: 10px;
  552. padding: 10px;
  553. .link-name{
  554. flex-shrink: 0;
  555. background-color: rgb(167, 224, 218);
  556. color: rgba(46, 123, 115, 1);
  557. border-radius: 5px;
  558. text-align: center;
  559. padding:8px;
  560. margin-right: 15px;
  561. }
  562. .code-list{
  563. margin-left: 15px;
  564. display: flex;
  565. overflow-x: auto;
  566. font-weight: bold;
  567. .code-item {
  568. // display: flex;
  569. margin-bottom: 10px;
  570. flex-shrink: 0;
  571. margin-left: 5px;
  572. padding:8px;
  573. background: rgb(213, 222, 255);;
  574. color: #409EFF;
  575. border-radius: 4px;
  576. cursor: pointer; // 添加指针样式
  577. transition: all 0.3s; // 添加过渡效果
  578. height: 50px;
  579. .code-title{
  580. color: black;
  581. margin-bottom: 10px;
  582. }
  583. .code-detail{
  584. color: rgba(37,80,162,1);
  585. }
  586. }
  587. }
  588. }
  589. }
  590. </style>
  591. <style lang="scss">
  592. .dialog-set {
  593. .el-dialog__header{
  594. padding: 0px;
  595. background: rgb(37, 80, 162);
  596. font-family: 16px;
  597. }
  598. .dialog-footer{
  599. text-align: center;
  600. }
  601. }
  602. </style>