ConditionsSet.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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. this.activeIndex = 0
  215. //获取关联关系数据
  216. this.getLinkSetData(this.id, this.jId);
  217. },
  218. //获取样品信息列表
  219. getSampleOptions(id){
  220. getInfoPage({
  221. current:1,
  222. size:100,
  223. type: 1,
  224. standardId: id,
  225. }).then((res) => {
  226. this.ruleLoading = false;
  227. if (res.data.code === 200) {
  228. this.sampleOptions= res.data.data.records.map(item => ({
  229. value: item.id,
  230. label: item.name,
  231. info:item.info
  232. }));
  233. //
  234. } else {
  235. this.sampleOptions = [];
  236. }
  237. });
  238. },
  239. hide() {
  240. this.visible = false
  241. },
  242. handleCancel() {
  243. this.hide()
  244. this.$emit('cancel')
  245. },
  246. handleConfirm() {
  247. saveConditionSet(this.linkListData,this.id).then((res)=>{
  248. if(res.data.code === 200) {
  249. this.$message({
  250. type: 'success',
  251. message: res.data.msg,
  252. })
  253. }else{
  254. this.$message({
  255. type: 'error',
  256. message: res.data.msg,
  257. })
  258. }
  259. })
  260. this.hide()
  261. this.$emit('confirm')
  262. },
  263. handleDeleteLinkItem(item,index){
  264. const {groupId}=item
  265. if(!groupId){
  266. this.linkListData.splice(index, 1);
  267. return
  268. }
  269. this.$confirm('删除后,数据将无法恢复,是否确认删除!', '提示', {
  270. confirmButtonText: '确定',
  271. cancelButtonText: '取消',
  272. type: 'warning'
  273. }).then(() => {
  274. deleteConditionSet({leftId:item.id,groupId:item.groupId}).then((res) => {
  275. if(res.data.code==200){
  276. this.$message.success(res.data.msg);
  277. this.linkListData.splice(index, 1);
  278. this.getLinkSetData(this.id, this.jId);
  279. }else{
  280. this.$message.error(res.data.msg);
  281. }
  282. });
  283. }).catch(() => {
  284. this.$message.info('已取消删除');
  285. })
  286. },
  287. addCondition() {
  288. // 添加条件逻辑
  289. this.addDialogVisible = true
  290. this.addForm = {}
  291. this.basicOptions = []
  292. },
  293. addOperation() {
  294. // 添加操作逻辑
  295. },
  296. async handleSelect(index,item) {
  297. this.paramList[index].standardInfos = []
  298. },
  299. async handleSelect1(index,item) {
  300. this.activeIndex = index
  301. // this.linkListData.forEach(ele=>{
  302. // ele.clicked = false
  303. // })
  304. const hasClicked = this.linkListData.some(item => item.clicked === true);
  305. console.log(hasClicked, 'hasClicked');
  306. if(!hasClicked) {
  307. item.standardInfos=[]
  308. this.addObj.standardInfos=[]
  309. }
  310. },
  311. handleSelectCode(values) {
  312. if (!values || values.length === 0) {
  313. this.addForm.codeValueName = '';
  314. return;
  315. }
  316. // 根据选中的value值找到对应的label
  317. const selectedLabels = values.map(value => {
  318. const option = this.basicOptions.find(opt => opt.value === value);
  319. return option ? option.label : '';
  320. });
  321. this.addForm.codeValueName = selectedLabels.join('/');
  322. this.addForm.codeValue = values
  323. },
  324. handleSelectCodeName(value) {
  325. if (!value) {
  326. this.addForm.codeName = '';
  327. return;
  328. }
  329. this.basicOptions = []
  330. this.sampleOptions.forEach(option => {
  331. if (option.value === value) {
  332. this.addForm.codeName = option.label;
  333. }
  334. });
  335. const selectedOption = this.sampleOptions.find(option => option.value === value);
  336. this.basicOptions = selectedOption ? selectedOption.info.map(item => ({
  337. value: item.id,
  338. label: item.name
  339. })) : [];
  340. },
  341. handleDeleteItem(item, index) {
  342. this.paramList[this.activeIndex].standardInfos.splice(index, 1);
  343. this.addObj={
  344. ... this.paramList[this.activeIndex],
  345. standardInfos:this.paramList[this.activeIndex].standardInfos,
  346. clicked:false
  347. }
  348. this.$forceUpdate();
  349. },
  350. confirmAdd() {
  351. if (!this.addForm.codeName || !this.addForm.codeValue) return this.$message.error('请选择样品信息和基础信息')
  352. this.paramList[this.activeIndex].standardInfos.push(
  353. {name: this.addForm.codeName,
  354. standardInfoGroupNameVO:
  355. {name:this.addForm.codeValueName,ids:this.addForm.codeValue}
  356. },
  357. )
  358. this.addObj={
  359. ... this.paramList[this.activeIndex],
  360. standardInfos: this.paramList[this.activeIndex].standardInfos,
  361. clicked:false
  362. }
  363. this.addDialogVisible = false
  364. this.addForm = {
  365. codeName: '',
  366. codeValue: []
  367. }
  368. },
  369. //保存条件
  370. saveCondition() {
  371. const {standardInfos}=this.addObj
  372. if(!standardInfos||standardInfos.length === 0) {
  373. return this.$message.error('请先添加条件')
  374. }
  375. const hasClicked = this.linkListData.some(item => item.clicked === true);
  376. console.log(hasClicked,'hasClicked');
  377. let obj=JSON.parse(JSON.stringify(this.addObj));
  378. console.log(obj,'obj');
  379. if (!hasClicked) {
  380. // 如果不存在,则将 addObj 添加到数组中
  381. this.linkListData.push(obj);
  382. }else{
  383. const clickedItem = this.linkListData.find(item => item.clicked === true);
  384. if (clickedItem) {
  385. clickedItem.standardInfos =obj.standardInfos;
  386. clickedItem.symbolName=obj.symbolName
  387. clickedItem.id=obj.id
  388. }
  389. }
  390. this.paramList[this.activeIndex].standardInfos = []
  391. this.linkListData .forEach(ele => {
  392. ele.clicked = false;
  393. });
  394. this.addObj.standardInfos = []
  395. },
  396. toggleClick(item, index) {
  397. this.linkListData.forEach(listItem => {
  398. this.$set(listItem, 'clicked', false);
  399. });
  400. this.$set(item, 'clicked', !item.clicked);
  401. let clickedIndex = this.paramList.findIndex(listItem => listItem.id === item.id);
  402. console.log(clickedIndex, 'clickedIndex');
  403. this.activeIndex = clickedIndex;
  404. this.paramList[clickedIndex].standardInfos = JSON.parse(JSON.stringify(item.standardInfos));
  405. this.addObj = { ...item };
  406. console.log(item, 'item');
  407. },
  408. // 获取条件设置
  409. async getConditionSetData(id, groupId, leftId) {
  410. try {
  411. const res = await getConditionSet({ id, groupId,leftId });
  412. if (res.data.code === 200) {
  413. console.log(res.data.data, '获取的条件设置数据');
  414. return res.data.data; // 直接返回数据
  415. } else {
  416. this.$message.error(res.data.msg);
  417. throw new Error(res.data.msg); // 抛出错误,以便在调用处处理
  418. }
  419. } catch (error) {
  420. // 这里可以添加额外的错误处理逻辑,例如记录日志
  421. throw error; // 重新抛出错误,以便在调用处捕获
  422. }
  423. },
  424. //获取关联关系数据
  425. async getLinkSetData(id, groupId) {
  426. try {
  427. const res = await getConditionSet({ id, groupId });
  428. if (res.data.code === 200) {
  429. console.log(res.data.data, '获取的关系数据');
  430. this.linkListData = res.data.data; // 直接返回数据
  431. } else {
  432. this.$message.error(res.data.msg);
  433. throw new Error(res.data.msg); // 抛出错误,以便在调用处处理
  434. }
  435. } catch (error) {
  436. // 这里可以添加额外的错误处理逻辑,例如记录日志
  437. throw error; // 重新抛出错误,以便在调用处捕获
  438. }
  439. }
  440. }
  441. }
  442. </script>
  443. <style lang="scss" scoped>
  444. .conditions-container {
  445. display: flex;
  446. gap: 20px;
  447. font-weight: bold;
  448. // height: 200px;
  449. .green-txt{
  450. color: rgb(46, 123, 115);;
  451. }
  452. .conditions-left,
  453. .conditions-right {
  454. flex: 1;
  455. border: 1px solid #EBEEF5;
  456. border-radius: 4px;
  457. background: #f5f7fa;
  458. }
  459. .condition-list,
  460. .condition-content {
  461. padding: 10px;
  462. }
  463. .condition-item {
  464. span {
  465. display: inline-block;
  466. padding: 8px 8px;
  467. margin: 5px;
  468. background: white;
  469. color: #409EFF;
  470. border-radius: 4px;
  471. cursor: pointer; // 添加指针样式
  472. transition: all 0.3s; // 添加过渡效果
  473. &.active { // 选中状态
  474. background: #67C23A;;
  475. color: white;
  476. }
  477. }
  478. }
  479. .content-item {
  480. margin-bottom: 10px;
  481. padding: 10px;
  482. border: 1px solid #EBEEF5;
  483. border-radius: 4px;
  484. .item-title {
  485. display: flex;
  486. gap: 10px;
  487. align-items: center;
  488. span {
  489. &:first-child {
  490. color: #666;
  491. }
  492. &:nth-child(2) {
  493. color: #409EFF;
  494. }
  495. &:last-child {
  496. color: #666;
  497. }
  498. }
  499. }
  500. }
  501. }
  502. .dialog-title {
  503. display: flex;
  504. flex-direction: column;
  505. color:white ;
  506. padding: 10px;
  507. font-size: 14px;
  508. .marginTop-20{
  509. margin-top: 10px;
  510. }
  511. background: rgb(37, 80, 162);
  512. .el-dialog__header{
  513. padding: 0px;
  514. }
  515. }
  516. .condition-header1 {
  517. display: flex;
  518. justify-content: space-between; // 两端对齐
  519. align-items: center;
  520. padding: 10px;
  521. border-bottom: 1px solid #EBEEF5;
  522. .header-left {
  523. display: flex;
  524. align-items: center;
  525. span {
  526. font-weight: bold;
  527. margin-left: 10px;
  528. }
  529. }
  530. .header-right {
  531. display: flex;
  532. gap: 10px; // 按钮间距
  533. .el-button {
  534. padding: 7px 15px;
  535. &:hover {
  536. opacity: 0.8;
  537. }
  538. }
  539. }
  540. }
  541. .code-list{
  542. display: flex;
  543. font-weight: bold;
  544. .code-item{
  545. margin-right: 5px;
  546. margin-top: 5px;
  547. flex-shrink: 0; // 防止元素在Flex容器中收缩
  548. min-width: 100px;
  549. max-width: 200px;
  550. overflow-x: auto;
  551. white-space: nowrap;
  552. }
  553. }
  554. .condition-item1 {
  555. display: flex;
  556. span {
  557. margin-left: 5px;
  558. display: inline-block;
  559. padding: 8px 8px;
  560. background: rgb(213, 222, 255);;
  561. color: rgba(37,80,162,1);
  562. border-radius: 4px;
  563. cursor: pointer; // 添加指针样式
  564. transition: all 0.3s; // 添加过渡效果
  565. height: 40px;
  566. }
  567. }
  568. .condition-header-content {
  569. display: flex;
  570. justify-content: space-between;
  571. align-items: center;
  572. width: 100%;
  573. .delete-icon {
  574. color: #F56C6C;
  575. cursor: pointer;
  576. font-size: 16px;
  577. &:hover {
  578. opacity: 0.8;
  579. }
  580. }
  581. }
  582. .result-container{
  583. width: 100%;
  584. border: 1px solid #EBEEF5;
  585. border-radius: 4px;
  586. background: #f5f7fa;
  587. margin-top: 10px;
  588. }
  589. .condition-header {
  590. display: flex;
  591. // justify-content: space-between;
  592. align-items: center;
  593. padding: 10px;
  594. border-bottom: 1px solid #EBEEF5;
  595. span {
  596. font-weight: bold;
  597. margin-left: 10px;
  598. }
  599. }
  600. .link-list{
  601. max-height: 350px;
  602. overflow-y: auto;
  603. padding: 10px;
  604. font-weight: bold;
  605. .link-item{
  606. display: flex;
  607. align-items: center;
  608. padding: 10px;
  609. background-color: white;
  610. border-radius: 10px;
  611. cursor: pointer; // 添加指针样式
  612. position: relative; // 添加相对定位
  613. margin-bottom: 10px;
  614. &.clicked {
  615. background-color: #e0e0e0; // 点击时的背景色
  616. }
  617. .el-icon-close {
  618. position: absolute; // 绝对定位
  619. top: 30%; // 垂直居中
  620. right: 10px; // 距离右侧10px
  621. transform: translateY(-50%); // 垂直方向上的偏移量,确保图标垂直居中
  622. color: #F56C6C; // 删除图标的颜色
  623. cursor: pointer; // 添加指针样式
  624. font-size: 16px; // 图标大小
  625. &:hover {
  626. opacity: 0.8; // 悬停效果
  627. }
  628. }
  629. .link-name{
  630. flex-shrink: 0;
  631. background-color: rgb(167, 224, 218);
  632. color: rgba(46, 123, 115, 1);
  633. border-radius: 5px;
  634. text-align: center;
  635. padding:8px;
  636. margin-right: 15px;
  637. }
  638. .code-list{
  639. margin-left: 15px;
  640. display: flex;
  641. overflow-x: auto;
  642. font-weight: bold;
  643. .code-item {
  644. // display: flex;
  645. margin-bottom: 10px;
  646. flex-shrink: 0;
  647. margin-left: 5px;
  648. padding:8px;
  649. background: rgb(213, 222, 255);;
  650. color: #409EFF;
  651. border-radius: 4px;
  652. transition: all 0.3s; // 添加过渡效果
  653. height: 50px;
  654. .code-title{
  655. color: black;
  656. margin-bottom: 10px;
  657. }
  658. .code-detail{
  659. color: rgba(37,80,162,1);
  660. }
  661. }
  662. }
  663. }
  664. }
  665. </style>
  666. <style lang="scss">
  667. .dialog-set {
  668. .el-dialog__header{
  669. padding: 0px;
  670. background: rgb(37, 80, 162);
  671. font-family: 16px;
  672. }
  673. .dialog-footer{
  674. text-align: center;
  675. }
  676. }
  677. </style>