AddMedicalMultRelation.vue 10 KB

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