ConditionsSet.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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="handleSelect1(index, item)"
  29. >
  30. {{ item.symbolName }}
  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].standardInfos"
  66. :key="index"
  67. >
  68. <div>
  69. <span>
  70. <div class="condition-header-content">
  71. <div style="color: black;">
  72. {{item.name}}
  73. </div>
  74. <i class="el-icon-close" @click.stop="handleDeleteItem(item,index)"></i>
  75. </div>
  76. <div class="code-list">
  77. <div class="code-item">
  78. {{ item.standardInfoGroupNameVO.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" :class="{ clicked: item.clicked }" @click="toggleClick(item, index)">
  95. <i class="el-icon-close" @click.stop="handleDeleteLinkItem(item,index)"></i>
  96. <div class="link-name">
  97. <span>{{ item.symbolName }}</span>
  98. </div>
  99. <div>
  100. <i class="el-icon-connection" style="color: black; font-size: larger;"></i>
  101. </div>
  102. <div class="code-list">
  103. <div v-for="(codeItem, codeIndex) in item.standardInfos" :key="codeIndex" class="code-item">
  104. <div class="code-title">{{ codeItem.name }}</div>
  105. <div class="code-detail">{{ codeItem.standardInfoGroupNameVO.name }}</div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. <div slot="footer" class="dialog-footer">
  112. <el-button type="primary" @click="handleConfirm" :style="{ background: 'rgb(37, 80, 162)', borderColor: 'rgb(37, 80, 162)' }">保存</el-button>
  113. </div>
  114. <el-dialog
  115. class="dialog-set"
  116. :visible.sync="addDialogVisible"
  117. width="30%"
  118. append-to-body
  119. close-on-click-modal="false"
  120. >
  121. <div slot="title" class="dialog-title">
  122. <div>
  123. <i class="el-icon-plus" ></i>
  124. <span style="margin-left: 10px;">添加条件</span>
  125. </div>
  126. <div class="marginTop-10">同次设置的条件为“或者”关系,不同次设置的条件为“并且”关系</div>
  127. </div>
  128. <el-form ref="addForm" :model="addForm" label-width="80px">
  129. <el-form-item label="样品信息">
  130. <el-select v-model="addForm.codeNameId" placeholder="请选择" style="width: 100%;" @change="handleSelectCodeName">
  131. <el-option
  132. v-for="item in sampleOptions"
  133. :key="item.value"
  134. :label="item.label"
  135. :value="item.value">
  136. </el-option>
  137. </el-select>
  138. </el-form-item>
  139. <el-form-item label="基础信息">
  140. <el-select v-model="addForm.codeValueList" placeholder="请选择" multiple style="width: 100%;" @change="handleSelectCode">
  141. <el-option
  142. v-for="item in basicOptions"
  143. :key="item.value"
  144. :label="item.label"
  145. :value="item.value">
  146. </el-option>
  147. </el-select>
  148. </el-form-item>
  149. </el-form>
  150. <div slot="footer" class="dialog-footer">
  151. <el-button type="primary" @click="confirmAdd" :style="{ background: 'rgb(37, 80, 162)', borderColor: 'rgb(37, 80, 162)' }">确认添加</el-button>
  152. </div>
  153. </el-dialog>
  154. </el-dialog>
  155. </template>
  156. <script>
  157. import {getInfoPage,saveConditionSet,getConditionSet,deleteConditionSet } from "@/api/ruleManage/fileRule.js";
  158. export default {
  159. name: 'ConditionsSet',
  160. data() {
  161. return {
  162. visible: false,
  163. paramList: [
  164. {
  165. symbolName: '',
  166. standardInfos:[
  167. {name: '',
  168. rightStandardInfos: [
  169. {}
  170. ],
  171. standardInfoGroupNameVO:{
  172. name: ''
  173. }
  174. },
  175. {codeName: '', codeValue: []},
  176. ]
  177. }
  178. ] , // 参数列表数据
  179. activeIndex: 0, // 当前选中的参数索引
  180. addDialogVisible: false,
  181. addForm: {
  182. codeName: '',
  183. codeValueList: [],
  184. codeValueName: '',
  185. codeNameId: ''
  186. },
  187. sampleOptions: [
  188. // 添加更多选项...
  189. ],
  190. basicOptions: [],
  191. linkListData: [
  192. ], // 关联关系数据
  193. id:'', // 传入的ID规范文件id
  194. jId:'',//技术指标Id
  195. addObj:{}
  196. }
  197. },
  198. methods: {
  199. show(val,id,Jid) {
  200. console.log(id,'id');
  201. this.jId = Jid
  202. this.id = id
  203. this.getSampleOptions(id)
  204. this.visible = true
  205. if(val.length > 0&&val[0].symbolName) {
  206. this.paramList=val
  207. val.forEach((item,index)=>{
  208. this.handleSelect(index,item)
  209. })
  210. // this.activeIndex = 0
  211. }else{
  212. this.paramList = []
  213. }
  214. //获取关联关系数据
  215. this.getLinkSetData(this.id, this.jId);
  216. },
  217. //获取样品信息列表
  218. getSampleOptions(id){
  219. getInfoPage({
  220. current:1,
  221. size:100,
  222. type: 1,
  223. standardId: id,
  224. }).then((res) => {
  225. this.ruleLoading = false;
  226. if (res.data.code === 200) {
  227. this.sampleOptions= res.data.data.records.map(item => ({
  228. value: item.id,
  229. label: item.name,
  230. info:item.info
  231. }));
  232. //
  233. } else {
  234. this.sampleOptions = [];
  235. }
  236. });
  237. },
  238. hide() {
  239. this.visible = false
  240. },
  241. handleCancel() {
  242. this.hide()
  243. this.$emit('cancel')
  244. },
  245. handleConfirm() {
  246. saveConditionSet(this.linkListData,this.id).then((res)=>{
  247. if(res.data.code === 200) {
  248. this.$message({
  249. type: 'success',
  250. message: res.data.msg,
  251. })
  252. }else{
  253. this.$message({
  254. type: 'error',
  255. message: res.data.msg,
  256. })
  257. }
  258. })
  259. this.hide()
  260. this.$emit('confirm')
  261. },
  262. handleDeleteLinkItem(item,index){
  263. const {groupId}=item
  264. if(!groupId){
  265. this.linkListData.splice(index, 1);
  266. return
  267. }
  268. this.$confirm('删除后,数据将无法恢复,是否确认删除!', '提示', {
  269. confirmButtonText: '确定',
  270. cancelButtonText: '取消',
  271. type: 'warning'
  272. }).then(() => {
  273. deleteConditionSet({leftId:item.id,groupId:item.groupId}).then((res) => {
  274. if(res.data.code==200){
  275. this.$message.success(res.data.msg);
  276. this.linkListData.splice(index, 1);
  277. this.getLinkSetData(this.id, this.jId);
  278. }else{
  279. this.$message.error(res.data.msg);
  280. }
  281. });
  282. }).catch(() => {
  283. this.$message.info('已取消删除');
  284. })
  285. },
  286. addCondition() {
  287. // 添加条件逻辑
  288. this.addDialogVisible = true
  289. this.addForm = {}
  290. this.basicOptions = []
  291. },
  292. addOperation() {
  293. // 添加操作逻辑
  294. },
  295. async handleSelect(index,item) {
  296. this.paramList[index].standardInfos = []
  297. },
  298. async handleSelect1(index,item) {
  299. this.activeIndex = index
  300. this.linkListData.forEach(ele=>{
  301. ele.clicked = false
  302. })
  303. const hasClicked = this.linkListData.some(item => item.clicked === true);
  304. console.log(hasClicked, 'hasClicked');
  305. if(!hasClicked) {
  306. item.standardInfos=[]
  307. }
  308. },
  309. handleSelectCode(values) {
  310. if (!values || values.length === 0) {
  311. this.addForm.codeValueName = '';
  312. return;
  313. }
  314. // 根据选中的value值找到对应的label
  315. const selectedLabels = values.map(value => {
  316. const option = this.basicOptions.find(opt => opt.value === value);
  317. return option ? option.label : '';
  318. });
  319. this.addForm.codeValueName = selectedLabels.join('/');
  320. this.addForm.codeValue = values
  321. },
  322. handleSelectCodeName(value) {
  323. if (!value) {
  324. this.addForm.codeName = '';
  325. return;
  326. }
  327. this.basicOptions = []
  328. this.sampleOptions.forEach(option => {
  329. if (option.value === value) {
  330. this.addForm.codeName = option.label;
  331. }
  332. });
  333. const selectedOption = this.sampleOptions.find(option => option.value === value);
  334. this.basicOptions = selectedOption ? selectedOption.info.map(item => ({
  335. value: item.id,
  336. label: item.name
  337. })) : [];
  338. },
  339. handleDeleteItem(item, index) {
  340. this.paramList[this.activeIndex].standardInfos.splice(index, 1);
  341. this.addObj={
  342. ... this.paramList[this.activeIndex],
  343. standardInfos:this.paramList[this.activeIndex].standardInfos
  344. }
  345. this.$forceUpdate();
  346. },
  347. confirmAdd() {
  348. if (!this.addForm.codeName || !this.addForm.codeValue) return this.$message.error('请选择样品信息和基础信息')
  349. this.paramList[this.activeIndex].standardInfos.push(
  350. {name: this.addForm.codeName,
  351. standardInfoGroupNameVO:
  352. {name:this.addForm.codeValueName,ids:this.addForm.codeValue}
  353. },
  354. )
  355. this.addObj={
  356. ... this.paramList[this.activeIndex],
  357. standardInfos: this.paramList[this.activeIndex].standardInfos
  358. }
  359. this.addDialogVisible = false
  360. this.addForm = {
  361. codeName: '',
  362. codeValue: []
  363. }
  364. },
  365. //保存条件
  366. saveCondition() {
  367. const hasClicked = this.linkListData.some(item => item.clicked === true);
  368. if (!hasClicked) {
  369. // 如果不存在,则将 addObj 添加到数组中
  370. this.linkListData.push(this.addObj);
  371. }else{
  372. const clickedItem = this.linkListData.find(item => item.clicked === true);
  373. if (clickedItem) {
  374. clickedItem.standardInfos = this.addObj.standardInfos;
  375. }
  376. }
  377. this.paramList[this.activeIndex].standardInfos = []
  378. this.linkListData .forEach(ele => {
  379. ele.clicked = false;
  380. });
  381. },
  382. toggleClick(item, index) {
  383. this.linkListData.forEach(listItem => {
  384. this.$set(listItem, 'clicked', false);
  385. });
  386. this.$set(item, 'clicked', !item.clicked);
  387. let clickedIndex = this.paramList.findIndex(listItem => listItem.id === item.id);
  388. console.log(clickedIndex, 'clickedIndex');
  389. this.activeIndex = clickedIndex;
  390. this.paramList[clickedIndex].standardInfos = JSON.parse(JSON.stringify(item.standardInfos));
  391. this.addObj = { ...item };
  392. console.log(item, 'item');
  393. },
  394. // 获取条件设置
  395. async getConditionSetData(id, groupId, leftId) {
  396. try {
  397. const res = await getConditionSet({ id, groupId,leftId });
  398. if (res.data.code === 200) {
  399. console.log(res.data.data, '获取的条件设置数据');
  400. return res.data.data; // 直接返回数据
  401. } else {
  402. this.$message.error(res.data.msg);
  403. throw new Error(res.data.msg); // 抛出错误,以便在调用处处理
  404. }
  405. } catch (error) {
  406. // 这里可以添加额外的错误处理逻辑,例如记录日志
  407. throw error; // 重新抛出错误,以便在调用处捕获
  408. }
  409. },
  410. //获取关联关系数据
  411. async getLinkSetData(id, groupId) {
  412. try {
  413. const res = await getConditionSet({ id, groupId });
  414. if (res.data.code === 200) {
  415. console.log(res.data.data, '获取的关系数据');
  416. this.linkListData = res.data.data; // 直接返回数据
  417. } else {
  418. this.$message.error(res.data.msg);
  419. throw new Error(res.data.msg); // 抛出错误,以便在调用处处理
  420. }
  421. } catch (error) {
  422. // 这里可以添加额外的错误处理逻辑,例如记录日志
  423. throw error; // 重新抛出错误,以便在调用处捕获
  424. }
  425. }
  426. }
  427. }
  428. </script>
  429. <style lang="scss" scoped>
  430. .conditions-container {
  431. display: flex;
  432. gap: 20px;
  433. font-weight: bold;
  434. // height: 200px;
  435. .green-txt{
  436. color: rgb(46, 123, 115);;
  437. }
  438. .conditions-left,
  439. .conditions-right {
  440. flex: 1;
  441. border: 1px solid #EBEEF5;
  442. border-radius: 4px;
  443. background: #f5f7fa;
  444. }
  445. .condition-list,
  446. .condition-content {
  447. padding: 10px;
  448. }
  449. .condition-item {
  450. span {
  451. display: inline-block;
  452. padding: 8px 8px;
  453. margin: 5px;
  454. background: white;
  455. color: #409EFF;
  456. border-radius: 4px;
  457. cursor: pointer; // 添加指针样式
  458. transition: all 0.3s; // 添加过渡效果
  459. &.active { // 选中状态
  460. background: #67C23A;;
  461. color: white;
  462. }
  463. }
  464. }
  465. .content-item {
  466. margin-bottom: 10px;
  467. padding: 10px;
  468. border: 1px solid #EBEEF5;
  469. border-radius: 4px;
  470. .item-title {
  471. display: flex;
  472. gap: 10px;
  473. align-items: center;
  474. span {
  475. &:first-child {
  476. color: #666;
  477. }
  478. &:nth-child(2) {
  479. color: #409EFF;
  480. }
  481. &:last-child {
  482. color: #666;
  483. }
  484. }
  485. }
  486. }
  487. }
  488. .dialog-title {
  489. display: flex;
  490. flex-direction: column;
  491. color:white ;
  492. padding: 10px;
  493. font-size: 14px;
  494. .marginTop-20{
  495. margin-top: 10px;
  496. }
  497. background: rgb(37, 80, 162);
  498. .el-dialog__header{
  499. padding: 0px;
  500. }
  501. }
  502. .condition-header1 {
  503. display: flex;
  504. justify-content: space-between; // 两端对齐
  505. align-items: center;
  506. padding: 10px;
  507. border-bottom: 1px solid #EBEEF5;
  508. .header-left {
  509. display: flex;
  510. align-items: center;
  511. span {
  512. font-weight: bold;
  513. margin-left: 10px;
  514. }
  515. }
  516. .header-right {
  517. display: flex;
  518. gap: 10px; // 按钮间距
  519. .el-button {
  520. padding: 7px 15px;
  521. &:hover {
  522. opacity: 0.8;
  523. }
  524. }
  525. }
  526. }
  527. .code-list{
  528. display: flex;
  529. font-weight: bold;
  530. .code-item{
  531. margin-right: 5px;
  532. margin-top: 5px;
  533. flex-shrink: 0; // 防止元素在Flex容器中收缩
  534. min-width: 100px;
  535. max-width: 200px;
  536. overflow-x: auto;
  537. white-space: nowrap;
  538. }
  539. }
  540. .condition-item1 {
  541. display: flex;
  542. span {
  543. margin-left: 5px;
  544. display: inline-block;
  545. padding: 8px 8px;
  546. background: rgb(213, 222, 255);;
  547. color: rgba(37,80,162,1);
  548. border-radius: 4px;
  549. cursor: pointer; // 添加指针样式
  550. transition: all 0.3s; // 添加过渡效果
  551. height: 40px;
  552. }
  553. }
  554. .condition-header-content {
  555. display: flex;
  556. justify-content: space-between;
  557. align-items: center;
  558. width: 100%;
  559. .delete-icon {
  560. color: #F56C6C;
  561. cursor: pointer;
  562. font-size: 16px;
  563. &:hover {
  564. opacity: 0.8;
  565. }
  566. }
  567. }
  568. .result-container{
  569. width: 100%;
  570. border: 1px solid #EBEEF5;
  571. border-radius: 4px;
  572. background: #f5f7fa;
  573. margin-top: 10px;
  574. }
  575. .condition-header {
  576. display: flex;
  577. // justify-content: space-between;
  578. align-items: center;
  579. padding: 10px;
  580. border-bottom: 1px solid #EBEEF5;
  581. span {
  582. font-weight: bold;
  583. margin-left: 10px;
  584. }
  585. }
  586. .link-list{
  587. max-height: 350px;
  588. overflow-y: auto;
  589. padding: 10px;
  590. font-weight: bold;
  591. .link-item{
  592. display: flex;
  593. align-items: center;
  594. padding: 10px;
  595. background-color: white;
  596. border-radius: 10px;
  597. cursor: pointer; // 添加指针样式
  598. position: relative; // 添加相对定位
  599. margin-bottom: 10px;
  600. &.clicked {
  601. background-color: #e0e0e0; // 点击时的背景色
  602. }
  603. .el-icon-close {
  604. position: absolute; // 绝对定位
  605. top: 30%; // 垂直居中
  606. right: 10px; // 距离右侧10px
  607. transform: translateY(-50%); // 垂直方向上的偏移量,确保图标垂直居中
  608. color: #F56C6C; // 删除图标的颜色
  609. cursor: pointer; // 添加指针样式
  610. font-size: 16px; // 图标大小
  611. &:hover {
  612. opacity: 0.8; // 悬停效果
  613. }
  614. }
  615. .link-name{
  616. flex-shrink: 0;
  617. background-color: rgb(167, 224, 218);
  618. color: rgba(46, 123, 115, 1);
  619. border-radius: 5px;
  620. text-align: center;
  621. padding:8px;
  622. margin-right: 15px;
  623. }
  624. .code-list{
  625. margin-left: 15px;
  626. display: flex;
  627. overflow-x: auto;
  628. font-weight: bold;
  629. .code-item {
  630. // display: flex;
  631. margin-bottom: 10px;
  632. flex-shrink: 0;
  633. margin-left: 5px;
  634. padding:8px;
  635. background: rgb(213, 222, 255);;
  636. color: #409EFF;
  637. border-radius: 4px;
  638. transition: all 0.3s; // 添加过渡效果
  639. height: 50px;
  640. .code-title{
  641. color: black;
  642. margin-bottom: 10px;
  643. }
  644. .code-detail{
  645. color: rgba(37,80,162,1);
  646. }
  647. }
  648. }
  649. }
  650. }
  651. </style>
  652. <style lang="scss">
  653. .dialog-set {
  654. .el-dialog__header{
  655. padding: 0px;
  656. background: rgb(37, 80, 162);
  657. font-family: 16px;
  658. }
  659. .dialog-footer{
  660. text-align: center;
  661. }
  662. }
  663. </style>