KnowledgeAll.vue 12 KB

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