AddMedicinePrompt.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. <template>
  2. <div class="NoiseTemplateWrapper TemplateWrapper knowledgeWrapper">
  3. <crumbs
  4. :title="'医学术语静态知识维护-'+title"
  5. class="topBack"
  6. :param="$route.params"
  7. linkTo="MedicinePrompt"
  8. ></crumbs>
  9. <div class="info-container">
  10. <el-form :rules="rules"
  11. :model="form"
  12. label-width="160px"
  13. ref="groups">
  14. <el-form-item v-if="!isEdit" label="选择标准术语:" prop="selectedTerm">
  15. <el-select v-model="form.selectedTerm"
  16. filterable
  17. remote
  18. clearable
  19. :loading="showDrop"
  20. loading-text="加载中..."
  21. @change="changeWord"
  22. value-key="conceptId"
  23. @clear="handleClear"
  24. ref="termName"
  25. placeholder="搜索"
  26. :remote-method="searchTerms">
  27. <el-option v-for="(term,idx) in terms" :key="idx" :label="term.name+(term.typeName?'('+term.typeName+')':'')" :value="term" ></el-option>
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="已选择标准术语:" label-width="160px">
  31. {{form.selectedTermName}}
  32. </el-form-item>
  33. <el-form-item v-if="form.selectedTerm&&(form.typeId==1||form.typeId==3||form.typeId==4||form.typeId==5)" :label="titleChange" prop="titleChange" label-width="160px">
  34. <el-input v-model="form.titleChange"></el-input>
  35. </el-form-item>
  36. <p class="line"></p>
  37. <InfoParagraph v-for="(f,i) in form.prags"
  38. v-if="!upload"
  39. :key="i"
  40. :data="f"
  41. :index="i"
  42. :total="form.prags.length"
  43. :isEdit = "isEdit"
  44. ref="subForm"
  45. @add="addParagraph(i)"
  46. @del="delParagraph"
  47. @reOrder="reOrder"></InfoParagraph>
  48. <el-form-item v-if="upload" label="标题名称:" prop="fileTitle" label-width="160px">
  49. <el-input v-model="form.fileTitle"></el-input>
  50. </el-form-item>
  51. <el-form-item v-if="upload" label="上传文件:" ref="upload" prop="fileList" label-width="160px">
  52. <el-upload
  53. @mouseenter.native="handleMouseenter"
  54. @mouseleave.native="handleMouseleave"
  55. class="upload-demo"
  56. :action="config.urls.promptServer"
  57. name="upfile"
  58. :multiple=false
  59. :limit="1"
  60. :on-preview="handlePreview"
  61. :on-remove="handleRemove"
  62. :before-upload="handleBeforeUpLoad"
  63. :before-remove="beforeRemove"
  64. :on-change="handleChange"
  65. :on-success="handleSuccess"
  66. :show-file-list="showFileList"
  67. :file-list="form.fileList">
  68. <el-button size="small" type="primary" v-if="showUpLoad">点击上传</el-button>
  69. <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> -->
  70. </el-upload>
  71. <span class="tipInfo" v-show="isShowTip">{{form.fileList[0]&&form.fileList[0].name}}</span>
  72. <!-- <el-button size="small" type="primary" >点击上传</el-button> -->
  73. </el-form-item>
  74. <el-form-item label-width="160px"><div class="uploadInfo" v-if="isSuccessUpload===1">文件上传中,请稍等...</div></el-form-item>
  75. </el-form>
  76. <div class="btn">
  77. <el-button
  78. type="primary"
  79. :disabled = 'saveDisable'
  80. @click="submitForm"
  81. >确 定</el-button>
  82. </div>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. /**
  88. *
  89. */
  90. import api from '@api/icss.js';
  91. import InfoParagraph from './MedicineInfoPg';
  92. import config from '@api/config';
  93. export default {
  94. name: 'AddMedicinePrompt',
  95. components: {
  96. InfoParagraph
  97. },
  98. data() {
  99. return {
  100. isEdit:false,
  101. isCopy:false,
  102. title:'添加',
  103. termTypes:[],
  104. terms:[], //术语列表
  105. form:{
  106. conceptId:'', //术语id
  107. isTip:0, //是否要覆盖,0不覆盖,1覆盖
  108. selectedTerm:'', //术语标签
  109. termType:'',
  110. typeId:'',
  111. selectedTermName:'',
  112. selectedTermType:'',
  113. titleChange:'',
  114. fileList:[],
  115. name:'',
  116. prags:[{ //单个段落相关
  117. title:'',
  118. content:'',
  119. isReason:0,
  120. orderNo:0,
  121. position:[],
  122. text:''}
  123. ],
  124. fileTitle:'',
  125. titleChange:''
  126. },
  127. rules: {
  128. selectedTerm: [
  129. { required: true, message: '请选择术语标签', trigger: 'change' }
  130. ],
  131. fileTitle: [
  132. { required: true, message: '请输入标题名称', trigger: 'change' },
  133. { validator: (rule,value,callback)=>{
  134. if(value.length>30){
  135. callback(new Error('标题名称不能超过30字'));
  136. }else{
  137. callback();
  138. }
  139. }, trigger: 'change' }
  140. ],
  141. fileList: [
  142. { required: true, message: '请上传文件', trigger: 'change' },
  143. ]
  144. },
  145. saveDisable: false, //保存按钮禁止点击
  146. showDrop:false, //下拉框显示文字bug1774
  147. config:config,
  148. showUpLoad:true,
  149. showFileList: false,
  150. upload: false,
  151. showConfirm: true,
  152. isSuccessUpload: 0, //是否上传成功 0: 不在上传 1: 上传过程中 2: 上传成功
  153. isShowTip: false
  154. }
  155. },
  156. created:function(){
  157. const {isEdit,data,isCopy} = this.$route.params;
  158. if(isEdit||isCopy){
  159. this.isEdit = isEdit;
  160. this.isCopy = isCopy;
  161. this.title = isEdit?'编辑':(isCopy?'复制':'添加');
  162. isEdit&&this.changeWord(data);
  163. api.getTremList({id:data.id}).then((res) => {
  164. if (res.data.code == '0') {
  165. const data = res.data.data;
  166. if(this.form.typeId === 82 || this.form.typeId === 83){
  167. // console.log('data',data)
  168. this.form.fileList=data&&data.map((it)=>{
  169. return JSON.parse(it.content);
  170. });
  171. this.showFileList = true
  172. this.showUpLoad = false
  173. }else{
  174. this.conceptId = data.id
  175. this.form.typeId = data.type
  176. this.form.name = data.name
  177. this.form.titleChange = data.type==1?data.clinicalPathwayName:(data.type==3||data.type==4||data.type==5)?data.noticeName:''
  178. this.form.selectedTermName = data.name+(data.typeName?'('+data.typeName+')':'')
  179. this.form.selectedTerm = data.name+(data.typeName?'('+data.typeName+')':'')
  180. this.form.prags=data&&data.details.map((it)=>{
  181. return {
  182. title:it.title,
  183. position:this.mapStringToNum(it.contentType ),
  184. content:it.content.replace(/{imageUrlPrefix}/g,config.imgHost),
  185. // isReason:it.isReason,
  186. text:it.text,
  187. disabled:true};
  188. });
  189. }
  190. }
  191. }).catch((error) => {
  192. console.log(error);
  193. });
  194. }
  195. },
  196. mounted(){
  197. },
  198. beforeRouteLeave (to, from, next) {
  199. if(this.isSuccessUpload === 1 ) {
  200. this.$confirm('文件正在上传,是否确定返回?', '提示', {
  201. confirmButtonText: '确定',
  202. cancelButtonText: '取消',
  203. cancelButtonClass:'cancel',
  204. type: 'warning'
  205. }).then(() => {
  206. next()
  207. }).catch(() => {
  208. });
  209. // this.warning('还有未保存的文件,是否确定返回?');
  210. }else if( this.isSuccessUpload === 2) {
  211. this.$confirm('还有未保存的文件,是否确定返回?', '提示', {
  212. confirmButtonText: '确定',
  213. cancelButtonText: '取消',
  214. cancelButtonClass:'cancel',
  215. type: 'warning'
  216. }).then(() => {
  217. next()
  218. }).catch(() => {
  219. });
  220. }else {
  221. next()
  222. }
  223. },
  224. methods: {
  225. handleClear(){
  226. this.form.selectedTermName = ''
  227. this.form.selectedTerm = ''
  228. },
  229. handleMouseenter(){
  230. if(this.form.fileList.length !== 0 ){
  231. this.isShowTip = true
  232. }
  233. },
  234. handleMouseleave(){
  235. this.isShowTip = false
  236. },
  237. changeWord(newVal){
  238. const name = newVal.name;
  239. const typeName = newVal.typeName;
  240. const type = newVal.type;
  241. this.form.selectedTermName = name+(typeName?'('+typeName+')':'');
  242. this.form.selectedTerm=name+(typeName?'('+typeName+')':'');
  243. this.form.name=name
  244. this.form.fileList=[]
  245. this.showFileList = false
  246. this.form.typeId = type || ""
  247. this.showUpLoad = true
  248. this.titleChange = type==1?'临床路径标题:':type==3||type==4||type==5?'注意事项标题:':''
  249. this.form.fileTitle = ""
  250. if(newVal.typeId === 82 || newVal.typeId === 83){
  251. this.upload = true
  252. this.form.fileTitle = newVal.title
  253. }else{
  254. this.upload = false
  255. }
  256. },
  257. reOrder(isUp,i){
  258. let temp = {},it={};
  259. if(isUp===1){
  260. if(i===0){
  261. this.warning('已经是第一个,不能再升啦!');
  262. return ;
  263. }
  264. temp = Object.assign(this.form.prags[i-1]);
  265. it = Object.assign(this.form.prags[i]);
  266. this.form.prags.splice(i-1,2,it,temp);
  267. }else{
  268. if(i===this.form.prags.length-1){
  269. this.warning('已经是最后一个,不能再降啦!');
  270. return ;
  271. }
  272. temp = Object.assign(this.form.prags[i+1]);
  273. it = Object.assign(this.form.prags[i]);
  274. this.form.prags.splice(i,2,temp,it);
  275. }
  276. },
  277. addParagraph(i){
  278. this.form.prags.splice(i+1,0,{
  279. title:'',
  280. content:'',
  281. isReason:0,
  282. position:[],
  283. text:''});
  284. //添加段落光标自动落到新增的段落中
  285. setTimeout(()=>{
  286. this.$refs.subForm[i+1].$el.getElementsByClassName("el-input__inner")[0].focus()
  287. })
  288. },
  289. delParagraph(i){
  290. if(this.form.prags.length==1){
  291. this.warning('只剩一个段落,不能再删啦!');
  292. return;
  293. }
  294. this.showConfirmDialog('确定要删除该段落?', () => {
  295. this.form.prags.splice(i,1);
  296. });
  297. },
  298. back() { this.$router.go(-1) },
  299. searchTerms(query){
  300. if(!query.trim()){
  301. this.form.terms = []
  302. return;
  303. }
  304. //搜索术语列表
  305. this.showDrop = true;
  306. api.getAllConcept({inputStr:query.trim(),types:[0]}).then((res) =>{
  307. this.showDrop = false;
  308. if(res.data.code === '0') {
  309. this.terms = res.data.data;
  310. }else{
  311. this.warning("数据获取失败");
  312. }
  313. })
  314. },
  315. mapStringToNum(str){
  316. return str.split(",").map((it)=>{
  317. return +it;
  318. })
  319. },
  320. submitForm() {
  321. if(this.isSuccessUpload === 1) {
  322. this.warning('文件上传中,请稍等')
  323. return
  324. }
  325. //验证外层表单
  326. let goOn=true,it=null;
  327. this.$refs.groups.validate((valid) =>{
  328. if(!valid){
  329. goOn = false;
  330. return false;
  331. }
  332. });
  333. //验证段落表单
  334. if(this.form.typeId !== 82 && this.form.typeId !== 83){
  335. for(let i=0;i<this.$refs.subForm.length;i++){
  336. it=this.$refs.subForm[i];
  337. it.$refs.form.validate((valid) =>{
  338. if(!valid){
  339. goOn = false;
  340. }
  341. });
  342. };
  343. }
  344. if(!goOn){
  345. return;
  346. }
  347. //通过必填验证,提交保存
  348. const item=this.form.prags;
  349. let param= []
  350. if(this.form.typeId === 82 || this.form.typeId === 83){
  351. if(this.form.fileList.length === 0){
  352. this.warning("文件未上传,不存储数据")
  353. return
  354. }
  355. param.push(Object.assign({},{
  356. position: this.form.typeId === 82 ? "8" : "9",
  357. conceptId:this.form.conceptId,
  358. title: this.form.fileTitle,
  359. orderNo:0,
  360. content:JSON.stringify(this.form.fileList[0]),
  361. }))
  362. }else {
  363. let data = this.form.prags,tempArr=[],paramsAll={},types = this.form.typeId;
  364. for(let i = 0;i < data.length;i++){
  365. let obj = {}
  366. obj.content = data[i].content
  367. obj.text = data[i].text
  368. obj.conceptId = data[i].conceptId
  369. obj.orderNo = i
  370. obj.title = data[i].title
  371. obj.contentType = data[i].position.join(',')
  372. tempArr.push(obj)
  373. }
  374. paramsAll.clinicalPathwayName = types==1?this.form.titleChange:''
  375. paramsAll.id = this.conceptId
  376. paramsAll.name = this.form.name
  377. paramsAll.noticeName = types==3||types==4||types==5?this.form.titleChange:''
  378. paramsAll.type = this.form.typeId
  379. paramsAll.details = tempArr
  380. param = paramsAll
  381. }
  382. this.showSaveDialog(param,'是否'+(this.isEdit?'修改':'保存')+'该静态知识?');
  383. },
  384. showSaveDialog(param,msg) {
  385. this.showConfirmDialog(msg, () => {
  386. this.saveDisable = true //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  387. api.saveTermPrompts(param).then((res) => {
  388. if (res.data.code === '0') {
  389. this.isSuccessUpload = 0 // 修改文件上传状态为0
  390. this.warning(res.data.msg || '保存成功', 'success');
  391. //返回带搜索条件的首页
  392. this.$router.push({name:'MedicinePrompt',params:Object.assign({},this.$route.params,{currentPage:1})});
  393. } else {
  394. this.warning(res.data.msg)
  395. }
  396. this.saveDisable = false
  397. }).catch((err) => {
  398. this.saveDisable = false
  399. this.warning(err);
  400. })
  401. });
  402. },
  403. showConfirmDialog(msg, resolve) {
  404. this.$confirm(msg, '提示', {
  405. confirmButtonText: '确定',
  406. cancelButtonText: '取消',
  407. cancelButtonClass:'cancel',
  408. type: 'warning'
  409. }).then(() => {
  410. resolve();
  411. }).catch(() => {});
  412. },
  413. warning(msg, type) {
  414. this.$message({
  415. showClose: true,
  416. message: msg,
  417. type: type || 'warning'
  418. })
  419. },
  420. handleChange(file, fileList){
  421. // if(fileList&&fileList[0]&&fileList[0].response&&fileList[0].response.code==='0'){
  422. // this.showUpLoad = false
  423. // this.showFileList = true
  424. // }else{
  425. // this.showUpLoad = true
  426. // this.showFileList = false
  427. // }
  428. // console.log(fileList,this.form.fileList,'aa')
  429. },
  430. handleSuccess(response, file, fileList){
  431. if(response.code == "0"){
  432. this.showFileList=true
  433. this.form.fileList=[]
  434. this.form.fileList.push({
  435. name: response.data.title,
  436. url: response.data.url,
  437. size: response.data.size
  438. })
  439. this.showUpLoad = false
  440. if(!this.form.fileTitle){
  441. this.form.fileTitle = response.data.title
  442. }
  443. this.isSuccessUpload = 2 // 上传成功状态
  444. this.$refs.upload && this.$refs.upload.clearValidate() // 清除校验
  445. }else{
  446. this.warning(response.msg||'上传失败')
  447. // this.form.fileList = []
  448. this.showUpLoad = true
  449. this.showFileList=false
  450. this.form.fileList=[]
  451. }
  452. },
  453. handleRemove(file, fileList) {
  454. this.showUpLoad = true
  455. this.form.fileList=[]
  456. this.isSuccessUpload = 0
  457. },
  458. handleBeforeUpLoad(file){
  459. // 上传过程中 上传按钮 隐藏
  460. this.isSuccessUpload = 1 // 上传过程中
  461. this.showFileList = true // 新增 进度条 显示
  462. this.$refs.upload && this.$refs.upload.clearValidate() // 清除校验
  463. this.showUpLoad = false
  464. if(file.size/1024/1024 >= 500){
  465. this.warning('文件上传失败,超出大小限制500MB')
  466. this.form.fileList=[]
  467. this.showConfirm = false
  468. return false
  469. }else{
  470. this.showConfirm = true
  471. }
  472. },
  473. handlePreview(file) {
  474. },
  475. beforeRemove(file, fileList) {
  476. if(this.showConfirm ){
  477. return this.$confirm(`确定移除 ${ file.name }?`,'',{
  478. cancelButtonClass:"cacelBtn"
  479. });
  480. }
  481. }
  482. }
  483. }
  484. </script>
  485. <style lang="less">
  486. @import "../../less/common.less";
  487. .cell .el-button.delete:focus {
  488. color: red !important;
  489. }
  490. .topBack{
  491. top: 0;
  492. }
  493. .info-container{
  494. background: #fff;
  495. padding: 20px;
  496. margin: 70px 20px -20px 20px;
  497. .el-input__inner{
  498. width: 200px;
  499. }
  500. .el-form-item__label{
  501. text-align: left;
  502. }
  503. .add-prg .el-form-item{
  504. margin-bottom: 20px;
  505. }
  506. }
  507. .cancel span{
  508. color: #22ccc8;
  509. }
  510. .line{
  511. border-top:1px #dcdfe6 solid;
  512. margin-bottom: 25px;
  513. }
  514. .NoiseTemplateWrapper .info-container .el-input__inner{
  515. width: 250px;
  516. }
  517. // .NoiseTemplateWrapper .el-select .el-input .el-icon-circle-close{
  518. // display: inherit!important;
  519. // }
  520. .cacelBtn{
  521. color: #22ccc8!important;
  522. }
  523. .upload-demo{
  524. width: 300px;
  525. /deep/.el-upload-list__item .el-icon-close-tip{
  526. display: none !important;
  527. }
  528. /deep/.el-upload-list__item .el-upload-list__item-name {
  529. max-width: 250px;
  530. white-space:nowrap;
  531. overflow:hidden;
  532. text-overflow:ellipsis;
  533. }
  534. /deep/ .focusing{
  535. // border: 1px solid transparent !important;
  536. outline: transparent !important;
  537. }
  538. }
  539. .uploadInfo{
  540. margin-top: -20px;
  541. color: #606266;
  542. }
  543. .tipInfo{
  544. position: absolute;
  545. // position: relative;
  546. line-height: 24px;
  547. top: -56px;
  548. left: 20px;
  549. // background-color: transparent;
  550. // color: #606266;
  551. padding: 3px 10px;
  552. border-radius: 4px;
  553. margin: 100px auto;
  554. background-color: #4D4D4D;
  555. text-align: center;
  556. color: #fff;
  557. font-size: 14px;
  558. }
  559. .tipInfo:before{
  560. content: '';
  561. display: block;
  562. position: absolute;
  563. // bottom: 9px;
  564. top: -10px;
  565. left: 18px;
  566. border-bottom: 6px solid #4D4D4D;
  567. border-top: 6px solid transparent;
  568. border-left: 6px solid transparent;
  569. border-right: 6px solid transparent;
  570. // border-right: 6px solid #4D4D4D;
  571. }
  572. .btn {
  573. text-align: right;
  574. padding-right: 20px;
  575. }
  576. </style>