AddMedicalMultRelation.vue 12 KB

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