AddMedicalMultRelation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="addMedicalMultRelationWrapper">
  3. <crumbs :title="minTitle" linkTo="/admin/LT-YXSYKWH-YXSYDCGLWH"></crumbs>
  4. <div class="contents">
  5. <div class="content">
  6. <div class="addBtn" v-if="list.length == 0">
  7. <el-button
  8. @click="addConcept"
  9. >+ 新 增</el-button>
  10. </div>
  11. <div class="conceptSearch" ref="conceptSearch">
  12. <h4 class="conceptTitle">术语(概念ID)搜索</h4>
  13. <img class="closeSearch" src="../../images/close-icon.png" @click="closeSearch" alt="">
  14. <input v-model="conceptText" type="text" ref="conceptInput" class="searchText" placeholder="请输入关键词搜索">
  15. <!-- <span class="searchName" @click="searchConcept">搜索</span> -->
  16. <ul class="conceptList" ref="conceptList">
  17. <li
  18. v-for="item in conceptList"
  19. class="conceptItem ellipsis"
  20. :title="item.conceptNameType"
  21. @click="selectConcept(item)"
  22. :key="item.conceptId">
  23. {{item.conceptNameType}}
  24. </li>
  25. </ul>
  26. </div>
  27. <div class="tree">
  28. <el-tree
  29. :data="list"
  30. :props="defaultProps"
  31. node-key="conceptId"
  32. default-expand-all
  33. :expand-on-click-node="false">
  34. <span class="custom-tree-node" slot-scope="{ node, data }">
  35. <span class="custom-tree-node-name ellipsis" :title="node.label">{{ node.label }}</span>
  36. <span class="btn-box">
  37. <el-button
  38. class="btn-add fl"
  39. v-if="data.level < 2"
  40. type="text"
  41. size="mini"
  42. @click="(e) => append(data, e)">
  43. + 增加
  44. </el-button>
  45. <el-button
  46. class="btn-del fr"
  47. v-if="!isEdit|| isEdit&&data.level != 0"
  48. type="text"
  49. size="mini"
  50. @click="() => remove(node, data)">
  51. 删除
  52. </el-button>
  53. </span>
  54. </span>
  55. </el-tree>
  56. </div>
  57. <div class="btn">
  58. <el-button
  59. type="primary"
  60. @click="confirm"
  61. >确 定</el-button>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <script type="text/javascript">
  68. import api from '@api/icss.js';
  69. export default {
  70. name:'AddMedicalName',
  71. data(){
  72. const data = [
  73. // {
  74. // id: 1,
  75. // label: '一级 1',
  76. // children: [{
  77. // id: 4,
  78. // label: '二级 1-1',
  79. // children: [{
  80. // id: 9,
  81. // label: '三级 1-1-1'
  82. // }, {
  83. // id: 10,
  84. // label: '三级 1-1-2'
  85. // }]
  86. // }]
  87. // },
  88. // {
  89. // id: 2,
  90. // label: '一级 2',
  91. // children: [{
  92. // id: 5,
  93. // label: '二级 2-1'
  94. // }, {
  95. // id: 6,
  96. // label: '二级 2-2'
  97. // }]
  98. // },
  99. // {
  100. // id: 3,
  101. // label: '一级 3',
  102. // children: [{
  103. // id: 7,
  104. // label: '二级 3-1'
  105. // }, {
  106. // id: 8,
  107. // label: '二级 3-2'
  108. // }]
  109. // }
  110. ];
  111. return{
  112. minTitle:'医学术语多层关联维护-添加',
  113. list: JSON.parse(JSON.stringify(data)),
  114. defaultProps: {
  115. children: 'nodeList',
  116. label: 'conceptNameType'
  117. },
  118. conceptText: '',
  119. conceptList: [], //概念列表
  120. addLevel: 0, //添加级别
  121. excludedConceptIds:[],
  122. operaList: [],
  123. isEdit: false, //是否为修改
  124. relationConceptId: '', //关联父类ID
  125. level: 0, //层级(修改时只能显示三级)
  126. }
  127. },
  128. created(){
  129. const { isEdit, data } = this.$route.params
  130. if(isEdit) {
  131. // console.log('dataa', data)
  132. this.isEdit = isEdit
  133. this.minTitle = '医学术语多层关联维护-修改'
  134. const item = JSON.parse(JSON.stringify(data))
  135. item.level = 0
  136. item.nodeList = this.IteraNodeList(item.nodeList, [], 1)
  137. this.list[0] = item
  138. }
  139. },
  140. watch:{
  141. conceptText(nextVal, prevVal) {
  142. if(!nextVal.trim()) {
  143. this.conceptList = []
  144. }
  145. if(nextVal.trim() &&nextVal != prevVal) {
  146. this.searchConcept()
  147. }
  148. }
  149. },
  150. methods:{
  151. addConcept(e) {
  152. this.addLevel = 0;
  153. this.openSearch(e);
  154. },
  155. confirm() {
  156. if(!this.list[0] || this.list[0].nodeList.length == 0) {
  157. this.message('请输入数据信息');
  158. return
  159. }
  160. const param = {
  161. conceptId: this.list[0].conceptId,
  162. sonRelationId: 17,
  163. isOrderBy: 1
  164. }
  165. const nodeListResult = []
  166. this.IteraNodeList(this.list[0].nodeList, nodeListResult, 0)
  167. param.nodeList = nodeListResult
  168. api.addMultRelation(param).then((res) => {
  169. const { data } = res
  170. if(data.code == '0') {
  171. this.message(res.data.msg||'术语建立成功','success');
  172. setTimeout(() => {
  173. this.$router.push({name:'MedicalMultRelation'});
  174. }, 2000);
  175. } else {
  176. this.message(data.msg);
  177. }
  178. })
  179. },
  180. IteraNodeList(nodeList, nodeListResult, type, level = 1) {
  181. this.level= level + 1
  182. for(let i = 0; i <nodeList.length; i++) {
  183. let newChild;
  184. if(type == '0') { //添加的时候保存所有的id列表
  185. newChild = {conceptId: nodeList[i].conceptId, relationId: 17,nodeList:[]}
  186. } else if(type == '1') { //修改的时候添加层级
  187. const item = JSON.parse(JSON.stringify(nodeList[i]))
  188. newChild = Object.assign(item, {level: level, nodeList: []})
  189. } else if(type == '2') { //移除节点的时候同时移除节点(搜索时排除的id列表)
  190. newChild = nodeList[i].conceptId
  191. }
  192. if(this.level === 4) {
  193. return
  194. }
  195. if(nodeList[i].nodeList &&nodeList[i].nodeList.length > 0) {
  196. if(type == '0' || type =='1') {
  197. this.IteraNodeList(nodeList[i].nodeList, newChild.nodeList, type, level+1)
  198. } else if(type == '2') {
  199. this.IteraNodeList(nodeList[i].nodeList, nodeListResult, type, level+1)
  200. }
  201. }
  202. nodeListResult.push(newChild)
  203. }
  204. return nodeListResult
  205. },
  206. searchConcept() {
  207. let excludedConceptIds = [];
  208. if(this.list[0]) {
  209. excludedConceptIds.push(this.list[0].conceptId)
  210. this.excludedConceptIds = this.IteraNodeList(this.list[0].nodeList,excludedConceptIds, 2)
  211. }
  212. const param = {
  213. "name": this.conceptText,
  214. "excludedConceptIds": this.excludedConceptIds,
  215. "relationId": 17,
  216. "relationPosition": 1,
  217. }
  218. if(this.addLevel == '1') {
  219. param.relationPosition = 2
  220. param.relationConceptId = this.relationConceptId
  221. }
  222. api.getConceptInfoAssay(param).then((res) => {
  223. const { data } = res
  224. if(data.code == '0') {
  225. this.conceptList = data.data
  226. }
  227. })
  228. },
  229. selectConcept(item) {
  230. if(this.addLevel == 0) {
  231. this.list.push(Object.assign({}, item, {nodeList: [], level: 0, conceptId: item.conceptId, conceptNameType: item.conceptNameType, sonRelationId: 17}))
  232. this.list = JSON.parse(JSON.stringify(this.list))
  233. }else {
  234. const data = this.operaList
  235. const newChild = Object.assign({}, item, {nodeList: [], level: data.level+1, conceptId: item.conceptId, conceptNameType: item.conceptNameType, relationId: 17});
  236. // const newChild = { id: id++, label: 'nodeList', level: data.level+1, children: [] };
  237. if (!data.nodeList) {
  238. this.$set(data, 'nodeList', []);
  239. }
  240. data.nodeList.push(newChild);
  241. }
  242. this.conceptList = [];
  243. this.closeSearch();
  244. },
  245. openSearch(e) {
  246. this.$refs['conceptSearch'].style.top= e.pageY - 120 + 'px';
  247. this.$refs['conceptSearch'].style.display= 'block'
  248. this.$refs['conceptInput'].focus();
  249. },
  250. closeSearch() {
  251. this.conceptText = ''
  252. this.$refs['conceptSearch'].style.display = "none";
  253. },
  254. append(data, e) {
  255. this.addLevel = 1;
  256. this.relationConceptId = data.conceptId
  257. this.operaList = data;
  258. this.openSearch(e);
  259. // const newChild = { id: id++, label: 'testtest', level: data.level+1, nodeList: [] };
  260. // if (!data.nodeList) {
  261. // this.$set(data, 'nodeList', []);
  262. // }
  263. // data.nodeList.push(newChild);
  264. },
  265. remove(node, data) {
  266. const parent = node.parent;
  267. const nodeList = parent.data.nodeList || parent.data;
  268. const index = nodeList.findIndex(d => d.conceptId === data.conceptId);
  269. nodeList.splice(index, 1);
  270. },
  271. message(msg,type){
  272. this.$message({
  273. showClose: true,
  274. message:msg,
  275. type:type||'warning'
  276. })
  277. },
  278. }
  279. }
  280. </script>
  281. <style lang="less" scoped>
  282. @import "../../less/admin.less";
  283. .addMedicalMultRelationWrapper {
  284. height: calc(100% - 70px);
  285. }
  286. .tree {
  287. margin-bottom: 230px;
  288. }
  289. .contents {
  290. height: 100%;
  291. }
  292. .btn-box {
  293. position: absolute;
  294. left: 350px;
  295. }
  296. .btn-del {
  297. color: #8F8F8F;
  298. }
  299. .addBtn {
  300. width: 66px;
  301. order: 1px solid #21CBC7;
  302. border-radius: 2px;
  303. }
  304. .conceptSearch {
  305. position: absolute;
  306. left: 560px;
  307. width: 301px;
  308. height: 300px;
  309. display: none;
  310. background: #fff;
  311. border: 1px solid #ccc;
  312. text-align: center;
  313. z-index: 2;
  314. }
  315. .conceptTitle {
  316. width: 100%;
  317. text-align: center;
  318. padding: 20px 0;
  319. }
  320. .searchText {
  321. padding: 0 15px;
  322. width: 191px;
  323. height: 34px;
  324. }
  325. .conceptList {
  326. width: 221px;
  327. height: 170px;
  328. margin: -2px auto 0;
  329. border: 2px solid #E1DFDF;
  330. overflow: hidden;
  331. overflow-y: auto;
  332. }
  333. .conceptItem {
  334. height: 34px;
  335. line-height: 34px;
  336. text-align: left;
  337. padding: 0 15px;
  338. cursor: pointer;
  339. }
  340. .conceptItem:hover {
  341. background: #f5f7fa;
  342. }
  343. .closeSearch {
  344. position: absolute;
  345. width: 30px;
  346. right: 0;
  347. top: 0;
  348. }
  349. .delete {
  350. cursor: pointer;
  351. }
  352. .content{
  353. background: #fff;
  354. padding: 20px 20px 30px;
  355. color: #545455;
  356. }
  357. .btn {
  358. text-align: right;
  359. margin-top: 20px;
  360. }
  361. .custom-tree-node-name {
  362. display: inline-block;
  363. width: 270px;
  364. }
  365. </style>