AddMedicinePrompt.vue 19 KB

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