KnowledgeAll.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <div class="addMedicalMultRelationWrapper">
  3. <crumbs :title="minTitle" fix="fixed" linkTo=""></crumbs>
  4. <TreeTab @getTreeList="getTreeList" />
  5. <div class="updataData" @click="updataTree" v-if="id == 1||id == 2||id == 3||id == 4"><span>更新数据</span></div>
  6. <div class="contents">
  7. <div class="content">
  8. <div class="addBtn" v-if="list.length == 0">
  9. <!-- <el-button
  10. @click="addConcept"
  11. >+ 新 增</el-button> -->
  12. </div>
  13. <div class="tree">
  14. <el-tree
  15. :data="list"
  16. :props="defaultProps"
  17. node-key="conceptId"
  18. draggable
  19. :allow-drag="allowDrag"
  20. :allow-drop="allowDrop"
  21. :expand-on-click-node="true"
  22. :render-after-expand="true"
  23. :highlight-current="true"
  24. :default-expanded-keys="defaultExpandedArr"
  25. @node-click = "handleNodeClick"
  26. >
  27. <span class="custom-tree-node" slot-scope="{ node, data }" >
  28. <span class="custom-tree-node-name ellipsis" :class="{colorGray: data.isDeletedConcept == 'Y'}" :title="node.label">{{ node.label }}</span>
  29. <span class="btn-box">
  30. <el-button
  31. class="btn-add fl"
  32. v-show="data.level < 2"
  33. type="text"
  34. size="mini"
  35. @click="(e) => append(data, e)">
  36. + 增加
  37. </el-button>
  38. <el-button
  39. class="btn-del fr"
  40. v-show="data.level != 0"
  41. type="text"
  42. size="mini"
  43. @click="() => remove(node, data)">
  44. 删除
  45. </el-button>
  46. </span>
  47. </span>
  48. </el-tree>
  49. </div>
  50. <div class="btn">
  51. <el-button
  52. type="primary"
  53. :disabled = 'saveDisable'
  54. @click="confirm"
  55. >确 定</el-button>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="btmFix"></div>
  60. <SearchList
  61. v-if="showSearch"
  62. :conceptList="conceptList"
  63. :addLevel="addLevel"
  64. @closeSearch="closeSearch"
  65. @selectConcept="selectConcept"
  66. @searchConcept="searchConcept" />
  67. </div>
  68. </template>
  69. <script type="text/javascript">
  70. import api from '@api/knowledgeTree.js';
  71. import SearchList from '../basicKnow/SearchList.vue';
  72. import TreeTab from '../basicKnow/TreeTab.vue';
  73. export default {
  74. name:'KnowledgeAll',
  75. components:{
  76. SearchList,TreeTab
  77. },
  78. data(){
  79. return{
  80. minTitle:'树形结构维护',
  81. id:1,
  82. list: [],
  83. defaultProps: {
  84. children: 'nodeList',
  85. label: 'conceptName'
  86. },
  87. conceptList: [], //概念列表
  88. showSearch: false,
  89. addLevel: 0, //添加级别
  90. excludedConceptIds:[],
  91. operaList: [],
  92. relationConceptId: '', //关联父类ID
  93. level: 0, //层级(修改时只能显示三级)
  94. saveDisable: false, //保存按钮禁止点击
  95. defaultExpandedArr: [],
  96. relationTypes:[]
  97. }
  98. },
  99. created(){
  100. this.getTreeList(1)
  101. },
  102. methods:{
  103. updataTree(){
  104. const {id} = this
  105. api.clearDrug({}).then((res)=>{
  106. const loading = this.$loading({
  107. lock: true,
  108. text: 'Loading',
  109. spinner: 'el-icon-loading',
  110. background: 'rgba(0, 0, 0, 0.7)'
  111. });
  112. this.getTreeList(id)
  113. })
  114. },
  115. getTreeList(id){
  116. if(id != this.id){
  117. this.id = id
  118. this.showSearch = false
  119. }
  120. const loading = this.$loading({
  121. lock: true,
  122. text: 'Loading',
  123. spinner: 'el-icon-loading',
  124. background: 'rgba(0, 0, 0, 0.7)'
  125. });
  126. const params = {
  127. "type": id,
  128. }
  129. api.getlistTree(params).then((res) => {
  130. loading.close();
  131. const { data } = res
  132. if(data.code == '0') {
  133. let result = data.data.treeDTO||{}
  134. this.relationTypes = data.data.types||[]
  135. const itemStr = JSON.stringify(result)
  136. let tmp = itemStr.replace(/nextTree/g,'nodeList').replace(/id/g,'conceptId').replace(/name/g,'conceptName')
  137. let item = JSON.parse(tmp)
  138. item.level = 0
  139. item.isExpanded = false
  140. item.nodeList = this.IteraNodeList(item.nodeList, [], 1)
  141. let arr = []
  142. arr[0] = item
  143. this.list = [...arr]
  144. } else {
  145. this.message(data.msg);
  146. }
  147. this.saveDisable = false;
  148. })
  149. },
  150. allowDrop(draggingNode, dropNode, type) {
  151. if(draggingNode.parent.data.conceptName !== dropNode.parent.data.conceptName){
  152. return false
  153. }else{
  154. return type !== 'inner'
  155. }
  156. },
  157. allowDrag(draggingNode) {
  158. return draggingNode.data.level != 0;//一级不可拖动
  159. },
  160. handleNodeClick(data) {
  161. if(data.nodeList.length > 0) {
  162. if(!data.isExpanded) {
  163. this.defaultExpandedArr.push(data.conceptId)
  164. } else {
  165. this.defaultExpandedArr = this.defaultExpandedArr.filter(item => item !== data.conceptId)
  166. }
  167. this.$set(data, 'isExpanded', !data.isExpanded);
  168. }
  169. },
  170. // addConcept(e) {
  171. // console.log(e)
  172. // this.addLevel = 0;
  173. // this.openSearch(e);
  174. // },
  175. confirm() {
  176. if(!this.list[0] || this.list[0].nodeList.length == 0) {
  177. this.message('请输入数据信息');
  178. return
  179. }
  180. const param = {
  181. conceptId: this.list[0].conceptId,
  182. sonRelationId: 17,
  183. isOrderBy: 1
  184. }
  185. const nodeListResult = []
  186. this.IteraNodeList(this.list[0].nodeList, nodeListResult, 0)
  187. param.nodeList = nodeListResult
  188. this.saveDisable = true //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  189. api.addTreeRelation(this.reparams(param)).then((res) => {
  190. const { data } = res
  191. if(data.code == '0') {
  192. this.message(res.data.msg||'保存成功','success');
  193. } else {
  194. this.message(data.msg);
  195. }
  196. this.saveDisable = false;
  197. })
  198. },
  199. IteraNodeList(nodeList, nodeListResult, type, level = 1) {
  200. this.level= level + 1
  201. for(let i = 0; i <nodeList.length; i++) {
  202. let newChild;
  203. if(type == '0') { //添加的时候保存所有的id列表
  204. newChild = {conceptId: nodeList[i].conceptId, relationId: 17,nodeList:[],sonRelationId: 17, isExpanded:false}
  205. } else if(type == '1') { //修改的时候添加层级
  206. const item = JSON.parse(JSON.stringify(nodeList[i]))
  207. newChild = Object.assign(item, {level: level, nodeList: [],sonRelationId: 17, isExpanded:false})
  208. } else if(type == '2') { //移除节点的时候同时移除节点(搜索时排除的id列表)
  209. newChild = nodeList[i].conceptId
  210. }
  211. if(nodeList[i].nodeList &&nodeList[i].nodeList.length > 0&&level < 3) {
  212. if(type == '0' || type =='1') {
  213. this.IteraNodeList(nodeList[i].nodeList, newChild.nodeList, type, level+1)
  214. } else if(type == '2') {
  215. this.IteraNodeList(nodeList[i].nodeList, nodeListResult, type, level+1)
  216. }
  217. }
  218. nodeListResult.push(newChild)
  219. }
  220. return nodeListResult
  221. },
  222. searchConcept(txt) {
  223. let excludedConceptIds = [];
  224. if(!txt){
  225. this.conceptList = []
  226. return
  227. }
  228. if(this.list[0]) {
  229. excludedConceptIds.push(this.list[0].conceptId)
  230. this.excludedConceptIds = this.IteraNodeList(this.list[0].nodeList,excludedConceptIds, 2)
  231. }
  232. const params = {
  233. "typeId": this.addLevel === 1 ? this.relationTypes[2] : this.addLevel === 2 ? this.relationTypes[4] : 1,
  234. "name": txt,
  235. "excludedConceptIds": this.excludedConceptIds,
  236. "relationId": this.addLevel === 1 ? this.relationTypes[1] : this.addLevel === 2 ? this.relationTypes[3] : 1,
  237. "relationConceptId": this.relationConceptId,
  238. }
  239. api.getTreeSearchList(params).then((res) => {
  240. const { data } = res
  241. if(data.code == '0') {
  242. this.conceptList = data.data
  243. }
  244. })
  245. },
  246. selectConcept(data) {
  247. const {item,txt} = data
  248. if(this.addLevel == 0) {
  249. this.list.push(Object.assign({}, item, {nodeList: [], level: 0, conceptId: item.conceptId, sonRelationId: 17}))
  250. this.list = JSON.parse(JSON.stringify(this.list))
  251. }else {
  252. const data = this.operaList
  253. const newChild = Object.assign({}, item, {nodeList: [], level: data.level+1, conceptId: item.conceptId, relationId: 17,sonRelationId: 17});
  254. // const newChild = { id: id++, label: 'nodeList', level: data.level+1, children: [] };
  255. if (!data.nodeList) {
  256. this.$set(data, 'nodeList', []);
  257. }
  258. data.nodeList.push(newChild);
  259. }
  260. this.conceptList = [];
  261. this.searchConcept(txt)
  262. // this.closeSearch();
  263. },
  264. openSearch(e) {
  265. this.showSearch = true
  266. },
  267. closeSearch() {
  268. this.conceptText = ''
  269. this.conceptList = []
  270. this.showSearch = false
  271. },
  272. append(data, e) {
  273. this.addLevel = data.level+1;
  274. this.relationConceptId = data.conceptId
  275. this.operaList = data;
  276. this.openSearch(data);
  277. // const newChild = { id: id++, label: 'testtest', level: data.level+1, nodeList: [] };
  278. // if (!data.nodeList) {
  279. // this.$set(data, 'nodeList', []);
  280. // }
  281. // data.nodeList.push(newChild);
  282. },
  283. remove(node, data) {
  284. const parent = node.parent;
  285. const nodeList = parent.data.nodeList || parent.data;
  286. const index = nodeList.findIndex(d => d.conceptId === data.conceptId);
  287. nodeList.splice(index, 1);
  288. },
  289. reparams(param){
  290. let params = []
  291. const tmplis = param.nodeList||[];
  292. for(let i = 0;i < tmplis.length;i++){
  293. let item = tmplis[i],sonIds=[]
  294. if(item.nodeList&&item.nodeList.length>0){
  295. for(let j = 0;j < item.nodeList.length;j++){
  296. sonIds.push(item.nodeList[j].conceptId)
  297. }
  298. }
  299. let obj = {
  300. "eid": item.conceptId,
  301. "eids": sonIds,
  302. "rid": this.relationTypes[1],
  303. "sid": param.conceptId,
  304. "srid": this.relationTypes[3]
  305. }
  306. params.push(obj)
  307. }
  308. return params
  309. },
  310. message(msg,type){
  311. this.$message({
  312. showClose: true,
  313. message:msg,
  314. type:type||'warning'
  315. })
  316. },
  317. }
  318. }
  319. </script>
  320. <style lang="less" scoped>
  321. @import "../../less/admin.less";
  322. .updataData {
  323. position:absolute;
  324. right:20px;
  325. top:0;
  326. z-index:100;
  327. height:40px;
  328. line-height:40px;
  329. cursor:pointer;
  330. span {
  331. display:inline-block;
  332. border:1px solid #48c5d7;
  333. color:#48c5d7;
  334. margin-top:7px;
  335. padding:0 10px;
  336. height:24px;
  337. line-height:24px;
  338. border-radius: 3px;
  339. font-size:14px;
  340. }
  341. }
  342. .el-button+.el-button {
  343. margin-left: 0;
  344. }
  345. .content {
  346. min-width: auto;
  347. box-sizing: border-box;
  348. }
  349. .contents {
  350. box-sizing: border-box;
  351. box-sizing: border-box;
  352. }
  353. .addMedicalMultRelationWrapper {
  354. height: calc(100% - 70px);
  355. }
  356. .tree {
  357. margin-bottom: 230px;
  358. }
  359. .contents {
  360. height: 100%;
  361. padding-top: 120px;
  362. }
  363. .btn-box {
  364. position: absolute;
  365. left: 350px;
  366. }
  367. .btn-del {
  368. color: #8F8F8F;
  369. padding-left: 28px;
  370. }
  371. .addBtn {
  372. width: 66px;
  373. order: 1px solid #21CBC7;
  374. border-radius: 2px;
  375. }
  376. .conceptSearch {
  377. position: fixed;
  378. right: 20px;
  379. top: 180px;
  380. bottom: 10px;
  381. width: 300px;
  382. background: #fff;
  383. border: 1px solid #C9C9C9;
  384. text-align: center;
  385. z-index: 2;
  386. padding: 30px;
  387. box-sizing: border-box;
  388. .conceptTitle {
  389. width: 100%;
  390. text-align: center;
  391. padding: 20px 0;
  392. }
  393. .searchText {
  394. padding: 0 35px 0 15px;
  395. width: 100%;
  396. height: 34px;
  397. border: 1px solid #C9C9C9;
  398. box-sizing: border-box;
  399. }
  400. .conceptList {
  401. min-height: 200px;
  402. max-height:300px;
  403. margin: -2px auto 0;
  404. border: 1px solid #E1DFDF;
  405. overflow: hidden;
  406. overflow-y: auto;
  407. }
  408. .conceptItem {
  409. height: 34px;
  410. line-height: 34px;
  411. text-align: left;
  412. padding: 0 15px;
  413. cursor: pointer;
  414. }
  415. .conceptItem:hover {
  416. background: #f5f7fa;
  417. }
  418. .closeSearch {
  419. position: absolute;
  420. width: 30px;
  421. right: 0;
  422. top: 0;
  423. }
  424. .searchWrap {
  425. position: relative;
  426. .search {
  427. position: absolute;
  428. right: 7px;
  429. top:8px;
  430. }
  431. }
  432. }
  433. .delete {
  434. cursor: pointer;
  435. }
  436. .content{
  437. background: #fff;
  438. padding: 40px 20px 30px;
  439. color: #545455;
  440. }
  441. .btn {
  442. text-align: center;
  443. margin-top: 20px;
  444. }
  445. .custom-tree-node-name {
  446. display: inline-block;
  447. width: 270px;
  448. }
  449. .colorGray {
  450. color: #c1c1c1;
  451. }
  452. </style>