AddMedicalMultRelation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. 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" :class="{colorGray: data.isDeletedConcept == 'Y'}" :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. //返回带搜索条件的首页
  177. this.$router.push({name:'MedicalMultRelation',params:Object.assign({},this.$route.params,{currentPage:1})});
  178. }, 2000);
  179. } else {
  180. this.message(data.msg);
  181. }
  182. this.saveDisable = false;
  183. })
  184. },
  185. IteraNodeList(nodeList, nodeListResult, type, level = 1) {
  186. this.level= level + 1
  187. for(let i = 0; i <nodeList.length; i++) {
  188. let newChild;
  189. if(type == '0') { //添加的时候保存所有的id列表
  190. newChild = {conceptId: nodeList[i].conceptId, relationId: 17,nodeList:[]}
  191. } else if(type == '1') { //修改的时候添加层级
  192. const item = JSON.parse(JSON.stringify(nodeList[i]))
  193. newChild = Object.assign(item, {level: level, nodeList: []})
  194. } else if(type == '2') { //移除节点的时候同时移除节点(搜索时排除的id列表)
  195. newChild = nodeList[i].conceptId
  196. }
  197. if(nodeList[i].nodeList &&nodeList[i].nodeList.length > 0&&level < 3) {
  198. if(type == '0' || type =='1') {
  199. this.IteraNodeList(nodeList[i].nodeList, newChild.nodeList, type, level+1)
  200. } else if(type == '2') {
  201. this.IteraNodeList(nodeList[i].nodeList, nodeListResult, type, level+1)
  202. }
  203. }
  204. nodeListResult.push(newChild)
  205. }
  206. return nodeListResult
  207. },
  208. searchConcept() {
  209. let excludedConceptIds = [];
  210. if(this.list[0]) {
  211. excludedConceptIds.push(this.list[0].conceptId)
  212. this.excludedConceptIds = this.IteraNodeList(this.list[0].nodeList,excludedConceptIds, 2)
  213. }
  214. const param = {
  215. "name": this.conceptText,
  216. "excludedConceptIds": this.excludedConceptIds,
  217. "relationId": 17,
  218. "relationPosition": 1,
  219. }
  220. if(this.addLevel == '1') {
  221. param.relationPosition = 2
  222. param.relationConceptId = this.relationConceptId
  223. }
  224. api.getConceptInfoAssay(param).then((res) => {
  225. const { data } = res
  226. if(data.code == '0') {
  227. this.conceptList = data.data
  228. }
  229. })
  230. },
  231. selectConcept(item) {
  232. if(this.addLevel == 0) {
  233. this.list.push(Object.assign({}, item, {nodeList: [], level: 0, conceptId: item.conceptId, conceptNameType: item.conceptNameType, sonRelationId: 17}))
  234. this.list = JSON.parse(JSON.stringify(this.list))
  235. }else {
  236. const data = this.operaList
  237. const newChild = Object.assign({}, item, {nodeList: [], level: data.level+1, conceptId: item.conceptId, conceptNameType: item.conceptNameType, relationId: 17});
  238. // const newChild = { id: id++, label: 'nodeList', level: data.level+1, children: [] };
  239. if (!data.nodeList) {
  240. this.$set(data, 'nodeList', []);
  241. }
  242. data.nodeList.push(newChild);
  243. }
  244. this.conceptList = [];
  245. this.closeSearch();
  246. },
  247. openSearch(e) {
  248. this.$refs['conceptSearch'].style.top= e.pageY - 120 + 'px';
  249. this.$refs['conceptSearch'].style.display= 'block'
  250. this.$refs['conceptInput'].focus();
  251. },
  252. closeSearch() {
  253. this.conceptText = ''
  254. this.$refs['conceptSearch'].style.display = "none";
  255. },
  256. append(data, e) {
  257. this.addLevel = 1;
  258. this.relationConceptId = data.conceptId
  259. this.operaList = data;
  260. this.openSearch(e);
  261. // const newChild = { id: id++, label: 'testtest', level: data.level+1, nodeList: [] };
  262. // if (!data.nodeList) {
  263. // this.$set(data, 'nodeList', []);
  264. // }
  265. // data.nodeList.push(newChild);
  266. },
  267. remove(node, data) {
  268. const parent = node.parent;
  269. const nodeList = parent.data.nodeList || parent.data;
  270. const index = nodeList.findIndex(d => d.conceptId === data.conceptId);
  271. nodeList.splice(index, 1);
  272. },
  273. message(msg,type){
  274. this.$message({
  275. showClose: true,
  276. message:msg,
  277. type:type||'warning'
  278. })
  279. },
  280. }
  281. }
  282. </script>
  283. <style lang="less" scoped>
  284. @import "../../less/admin.less";
  285. .addMedicalMultRelationWrapper {
  286. height: calc(100% - 70px);
  287. }
  288. .tree {
  289. margin-bottom: 230px;
  290. }
  291. .contents {
  292. height: 100%;
  293. }
  294. .btn-box {
  295. position: absolute;
  296. left: 350px;
  297. }
  298. .btn-del {
  299. color: #8F8F8F;
  300. }
  301. .addBtn {
  302. width: 66px;
  303. order: 1px solid #21CBC7;
  304. border-radius: 2px;
  305. }
  306. .conceptSearch {
  307. position: absolute;
  308. left: 560px;
  309. width: 301px;
  310. height: 300px;
  311. display: none;
  312. background: #fff;
  313. border: 1px solid #ccc;
  314. text-align: center;
  315. z-index: 2;
  316. }
  317. .conceptTitle {
  318. width: 100%;
  319. text-align: center;
  320. padding: 20px 0;
  321. }
  322. .searchText {
  323. padding: 0 15px;
  324. width: 191px;
  325. height: 34px;
  326. }
  327. .conceptList {
  328. width: 221px;
  329. height: 170px;
  330. margin: -2px auto 0;
  331. border: 2px solid #E1DFDF;
  332. overflow: hidden;
  333. overflow-y: auto;
  334. }
  335. .conceptItem {
  336. height: 34px;
  337. line-height: 34px;
  338. text-align: left;
  339. padding: 0 15px;
  340. cursor: pointer;
  341. }
  342. .conceptItem:hover {
  343. background: #f5f7fa;
  344. }
  345. .closeSearch {
  346. position: absolute;
  347. width: 30px;
  348. right: 0;
  349. top: 0;
  350. }
  351. .delete {
  352. cursor: pointer;
  353. }
  354. .content{
  355. background: #fff;
  356. padding: 20px 20px 30px;
  357. color: #545455;
  358. }
  359. .btn {
  360. text-align: right;
  361. margin-top: 20px;
  362. }
  363. .custom-tree-node-name {
  364. display: inline-block;
  365. width: 270px;
  366. }
  367. .colorGray {
  368. color: #c1c1c1;
  369. }
  370. </style>