AddMedicalMultRelation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. :disabled = 'saveDisable'
  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:'AddMedicalMultRelation',
  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. relationConceptId: '', //关联父类ID
  126. level: 0, //层级(修改时只能显示三级)
  127. saveDisable: false //保存按钮禁止点击
  128. }
  129. },
  130. created(){
  131. const { isEdit, data } = this.$route.params
  132. if(isEdit) {
  133. // console.log('dataa', data)
  134. this.isEdit = isEdit
  135. this.minTitle = '医学术语多层关联维护-修改'
  136. const item = JSON.parse(JSON.stringify(data))
  137. item.level = 0
  138. item.nodeList = this.IteraNodeList(item.nodeList, [], 1)
  139. this.list[0] = item
  140. }
  141. },
  142. watch:{
  143. conceptText(nextVal, prevVal) {
  144. if(!nextVal.trim()) {
  145. this.conceptList = []
  146. }
  147. if(nextVal.trim() &&nextVal != prevVal) {
  148. this.searchConcept()
  149. }
  150. }
  151. },
  152. methods:{
  153. addConcept(e) {
  154. this.addLevel = 0;
  155. this.openSearch(e);
  156. },
  157. confirm() {
  158. if(!this.list[0] || this.list[0].nodeList.length == 0) {
  159. this.message('请输入数据信息');
  160. return
  161. }
  162. const param = {
  163. conceptId: this.list[0].conceptId,
  164. sonRelationId: 17,
  165. isOrderBy: 1
  166. }
  167. const nodeListResult = []
  168. this.IteraNodeList(this.list[0].nodeList, nodeListResult, 0)
  169. param.nodeList = nodeListResult
  170. this.saveDisable = true //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  171. api.addMultRelation(param).then((res) => {
  172. const { data } = res
  173. if(data.code == '0') {
  174. this.message(res.data.msg||'术语建立成功','success');
  175. setTimeout(() => {
  176. this.$router.push({name:'MedicalMultRelation'});
  177. }, 2000);
  178. } else {
  179. this.message(data.msg);
  180. }
  181. this.saveDisable = false;
  182. })
  183. },
  184. IteraNodeList(nodeList, nodeListResult, type, level = 1) {
  185. this.level= level + 1
  186. for(let i = 0; i <nodeList.length; i++) {
  187. let newChild;
  188. if(type == '0') { //添加的时候保存所有的id列表
  189. newChild = {conceptId: nodeList[i].conceptId, relationId: 17,nodeList:[]}
  190. } else if(type == '1') { //修改的时候添加层级
  191. const item = JSON.parse(JSON.stringify(nodeList[i]))
  192. newChild = Object.assign(item, {level: level, nodeList: []})
  193. } else if(type == '2') { //移除节点的时候同时移除节点(搜索时排除的id列表)
  194. newChild = nodeList[i].conceptId
  195. }
  196. if(nodeList[i].nodeList &&nodeList[i].nodeList.length > 0&&level < 3) {
  197. if(type == '0' || type =='1') {
  198. this.IteraNodeList(nodeList[i].nodeList, newChild.nodeList, type, level+1)
  199. } else if(type == '2') {
  200. this.IteraNodeList(nodeList[i].nodeList, nodeListResult, type, level+1)
  201. }
  202. }
  203. nodeListResult.push(newChild)
  204. }
  205. return nodeListResult
  206. },
  207. searchConcept() {
  208. let excludedConceptIds = [];
  209. if(this.list[0]) {
  210. excludedConceptIds.push(this.list[0].conceptId)
  211. this.excludedConceptIds = this.IteraNodeList(this.list[0].nodeList,excludedConceptIds, 2)
  212. }
  213. const param = {
  214. "name": this.conceptText,
  215. "excludedConceptIds": this.excludedConceptIds,
  216. "relationId": 17,
  217. "relationPosition": 1,
  218. }
  219. if(this.addLevel == '1') {
  220. param.relationPosition = 2
  221. param.relationConceptId = this.relationConceptId
  222. }
  223. api.getConceptInfoAssay(param).then((res) => {
  224. const { data } = res
  225. if(data.code == '0') {
  226. this.conceptList = data.data
  227. }
  228. })
  229. },
  230. selectConcept(item) {
  231. if(this.addLevel == 0) {
  232. this.list.push(Object.assign({}, item, {nodeList: [], level: 0, conceptId: item.conceptId, conceptNameType: item.conceptNameType, sonRelationId: 17}))
  233. this.list = JSON.parse(JSON.stringify(this.list))
  234. }else {
  235. const data = this.operaList
  236. const newChild = Object.assign({}, item, {nodeList: [], level: data.level+1, conceptId: item.conceptId, conceptNameType: item.conceptNameType, relationId: 17});
  237. // const newChild = { id: id++, label: 'nodeList', level: data.level+1, children: [] };
  238. if (!data.nodeList) {
  239. this.$set(data, 'nodeList', []);
  240. }
  241. data.nodeList.push(newChild);
  242. }
  243. this.conceptList = [];
  244. this.closeSearch();
  245. },
  246. openSearch(e) {
  247. this.$refs['conceptSearch'].style.top= e.pageY - 120 + 'px';
  248. this.$refs['conceptSearch'].style.display= 'block'
  249. this.$refs['conceptInput'].focus();
  250. },
  251. closeSearch() {
  252. this.conceptText = ''
  253. this.$refs['conceptSearch'].style.display = "none";
  254. },
  255. append(data, e) {
  256. this.addLevel = 1;
  257. this.relationConceptId = data.conceptId
  258. this.operaList = data;
  259. this.openSearch(e);
  260. // const newChild = { id: id++, label: 'testtest', level: data.level+1, nodeList: [] };
  261. // if (!data.nodeList) {
  262. // this.$set(data, 'nodeList', []);
  263. // }
  264. // data.nodeList.push(newChild);
  265. },
  266. remove(node, data) {
  267. const parent = node.parent;
  268. const nodeList = parent.data.nodeList || parent.data;
  269. const index = nodeList.findIndex(d => d.conceptId === data.conceptId);
  270. nodeList.splice(index, 1);
  271. },
  272. message(msg,type){
  273. this.$message({
  274. showClose: true,
  275. message:msg,
  276. type:type||'warning'
  277. })
  278. },
  279. }
  280. }
  281. </script>
  282. <style lang="less" scoped>
  283. @import "../../less/admin.less";
  284. .addMedicalMultRelationWrapper {
  285. height: calc(100% - 70px);
  286. }
  287. .tree {
  288. margin-bottom: 230px;
  289. }
  290. .contents {
  291. height: 100%;
  292. }
  293. .btn-box {
  294. position: absolute;
  295. left: 350px;
  296. }
  297. .btn-del {
  298. color: #8F8F8F;
  299. }
  300. .addBtn {
  301. width: 66px;
  302. order: 1px solid #21CBC7;
  303. border-radius: 2px;
  304. }
  305. .conceptSearch {
  306. position: absolute;
  307. left: 560px;
  308. width: 301px;
  309. height: 300px;
  310. display: none;
  311. background: #fff;
  312. border: 1px solid #ccc;
  313. text-align: center;
  314. z-index: 2;
  315. }
  316. .conceptTitle {
  317. width: 100%;
  318. text-align: center;
  319. padding: 20px 0;
  320. }
  321. .searchText {
  322. padding: 0 15px;
  323. width: 191px;
  324. height: 34px;
  325. }
  326. .conceptList {
  327. width: 221px;
  328. height: 170px;
  329. margin: -2px auto 0;
  330. border: 2px solid #E1DFDF;
  331. overflow: hidden;
  332. overflow-y: auto;
  333. }
  334. .conceptItem {
  335. height: 34px;
  336. line-height: 34px;
  337. text-align: left;
  338. padding: 0 15px;
  339. cursor: pointer;
  340. }
  341. .conceptItem:hover {
  342. background: #f5f7fa;
  343. }
  344. .closeSearch {
  345. position: absolute;
  346. width: 30px;
  347. right: 0;
  348. top: 0;
  349. }
  350. .delete {
  351. cursor: pointer;
  352. }
  353. .content{
  354. background: #fff;
  355. padding: 20px 20px 30px;
  356. color: #545455;
  357. }
  358. .btn {
  359. text-align: right;
  360. margin-top: 20px;
  361. }
  362. .custom-tree-node-name {
  363. display: inline-block;
  364. width: 270px;
  365. }
  366. </style>