AddMedicinePrompt.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <div class="NoiseTemplateWrapper TemplateWrapper">
  3. <crumbs
  4. :title=" isEdit? '医学术语静态知识维护-修改':'医学术语静态知识维护-添加'"
  5. class="topBack"
  6. linkTo="/admin/LT-YXSYKWH-YXSYJTZSWH"
  7. ></crumbs>
  8. <div class="info-container">
  9. <el-form :rules="rules"
  10. :model="form"
  11. label-width="160px"
  12. ref="groups">
  13. <el-form-item v-if="!isEdit" label="选择标准术语:" prop="selectedTerm">
  14. <el-select v-model="form.selectedTerm"
  15. filterable
  16. remote
  17. clearable
  18. @change="changeWord"
  19. no-data-text=" "
  20. value-key="conceptId"
  21. ref="termName"
  22. placeholder="搜索"
  23. :remote-method="searchTerms">
  24. <el-option v-for="term in terms" :key="term.conceptId" :label="term.nameType" :value="term" ></el-option>
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="已选择标准术语:" label-width="160px">
  28. {{form.selectedTermName}}
  29. </el-form-item>
  30. <p class="line"></p>
  31. <InfoParagraph v-for="(f,i) in form.prags"
  32. :data="f"
  33. :index="i"
  34. :total="form.prags.length"
  35. :isEdit = "isEdit"
  36. ref="subForm"
  37. @add="addParagraph(i)"
  38. @del="delParagraph"
  39. @reOrder="reOrder"></InfoParagraph>
  40. </el-form>
  41. <div class="btn">
  42. <el-button
  43. type="primary"
  44. :disabled = 'saveDisable'
  45. @click="submitForm"
  46. >确 定</el-button>
  47. </div>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. /**
  53. *
  54. */
  55. import api from '@api/icss.js';
  56. import InfoParagraph from './MedicineInfoPg';
  57. import config from '@api/config';
  58. export default {
  59. name: 'AddMedicinePrompt',
  60. components: {
  61. InfoParagraph
  62. },
  63. data() {
  64. return {
  65. isEdit:false,
  66. isCopy:false,
  67. termTypes:[],
  68. terms:[], //术语列表
  69. editData:{
  70. selectedTerm:'',
  71. prags:[]
  72. },
  73. form:{
  74. conceptId:'', //术语id
  75. isTip:0, //是否要覆盖,0不覆盖,1覆盖
  76. selectedTerm:'', //术语标签
  77. termType:'',
  78. selectedTermName:'',
  79. selectedTermType:'',
  80. prags:[{ //单个段落相关
  81. title:'',
  82. content:'',
  83. isReason:0,
  84. orderNo:0,
  85. position:[],
  86. text:''}]
  87. },
  88. rules: {
  89. selectedTerm: [
  90. { required: true, message: '请选择术语标签', trigger: 'change' }
  91. ]
  92. },
  93. saveDisable: false //保存按钮禁止点击
  94. }
  95. },
  96. /*watch:{
  97. 'form.selectedTerm':function(newVal){
  98. const name = newVal.nameType;console.log(newVal)
  99. this.form.selectedTermName = name;
  100. this.form.conceptId = newVal.conceptId;
  101. }
  102. },*/
  103. created:function(){
  104. const {isEdit,data,isCopy} = this.$route.params;
  105. if(isEdit||isCopy){
  106. this.isEdit = isEdit;
  107. this.isCopy = isCopy;
  108. this.changeWord(data);
  109. //this.form.selectedTerm = data;
  110. //this.form.selectedTermName = data.libName;
  111. //this.form.conceptId = data.conceptId;
  112. api.getTremList({conceptId:data.conceptId}).then((res) => {
  113. if (res.data.code == '0') {
  114. const data = res.data.data;
  115. this.form.prags=data&&data.map((it)=>{
  116. return {
  117. title:it.title,
  118. position:this.mapStringToNum(it.position),
  119. content:it.content.replace(/{imageUrlPrefix}/g,config.imgHost),
  120. isReason:it.isReason,
  121. text:it.text,
  122. disabled:true};
  123. });
  124. }
  125. }).catch((error) => {
  126. console.log(error);
  127. });
  128. }
  129. },
  130. methods: {
  131. changeWord(newVal){
  132. const name = newVal.nameType;
  133. this.form.selectedTermName = name;
  134. this.form.selectedTerm=name;
  135. this.form.conceptId = newVal.conceptId;
  136. },
  137. reOrder(isUp,i){
  138. let temp = {},it={};
  139. if(isUp===1){
  140. if(i===0){
  141. this.warning('已经是第一个,不能再升啦!');
  142. return ;
  143. }
  144. temp = Object.assign(this.form.prags[i-1]);
  145. temp.orderNo = temp.orderNo+1;
  146. it = Object.assign(this.form.prags[i]);
  147. it.orderNo = it.orderNo-1;
  148. this.form.prags.splice(i-1,2,it,temp);
  149. }else{
  150. if(i===this.form.prags.length-1){
  151. this.warning('已经是最后一个,不能再降啦!');
  152. return ;
  153. }
  154. temp = Object.assign(this.form.prags[i+1]);
  155. temp.orderNo = temp.orderNo-1;
  156. it = Object.assign(this.form.prags[i]);
  157. it.orderNo = it.orderNo+1;
  158. this.form.prags.splice(i,2,temp,it);
  159. }
  160. },
  161. addParagraph(i){
  162. this.form.prags.splice(i+1,0,{
  163. title:'',
  164. content:'',
  165. isReason:0,
  166. orderNo:i+1,
  167. position:[],
  168. text:''});
  169. /*this.form.prags.push({
  170. title:'',
  171. content:'',
  172. isReason:0,
  173. orderNo:this.form.prags.length,
  174. position:[],
  175. text:''});*/
  176. },
  177. delParagraph(i){
  178. if(this.form.prags.length==1){
  179. this.warning('只剩一个段落,不能再删啦!');
  180. return;
  181. }
  182. this.showConfirmDialog('确定要删除该段落?', () => {
  183. this.form.prags.splice(i,1);
  184. });
  185. },
  186. back() { this.$router.go(-1) },
  187. searchTerms(query){
  188. //搜索术语列表
  189. api.getAllConcept({name:query}).then((res) =>{
  190. if(res.data.code === '0') {
  191. this.terms = res.data.data;
  192. }else{
  193. this.warning("数据获取失败");
  194. }
  195. })
  196. },
  197. mapStringToNum(str){
  198. return str.split(",").map((it)=>{
  199. return +it;
  200. })
  201. },
  202. submitForm() {
  203. //验证外层表单
  204. let goOn=true,it=null;
  205. this.$refs.groups.validate((valid) =>{
  206. if(!valid){
  207. goOn = false;
  208. return false;
  209. }
  210. });
  211. //验证段落表单
  212. for(let i=0;i<this.$refs.subForm.length;i++){
  213. it=this.$refs.subForm[i];
  214. it.$refs.form.validate((valid) =>{
  215. if(!valid){
  216. goOn = false;
  217. }
  218. });
  219. };
  220. if(!goOn){
  221. return;
  222. }
  223. //通过必填验证,提交保存
  224. const item=this.form.prags;
  225. const param =item.map((it)=>{
  226. return Object.assign({},it,{
  227. position:typeof it.position=='string'?it.position:it.position.join(","),
  228. conceptId:this.form.conceptId,
  229. content:it.content.replace(new RegExp(config.imgHost,'g'),'{imageUrlPrefix}')});
  230. });
  231. this.showSaveDialog(param,'是否保存该静态知识?');
  232. },
  233. showSaveDialog(param,msg) {
  234. this.showConfirmDialog(msg, () => {
  235. this.saveDisable = true //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  236. api.saveTermPrompts(param).then((res) => {
  237. if (res.data.code === '0') {
  238. this.warning(res.data.msg || '保存成功', 'success');
  239. this.$router.push("/admin/LT-YXSYKWH-YXSYJTZSWH");
  240. } else {
  241. this.warning(res.data.msg)
  242. }
  243. this.saveDisable = false
  244. }).catch((err) => {
  245. this.warning(err);
  246. })
  247. });
  248. },
  249. showConfirmDialog(msg, resolve) {
  250. this.$confirm(msg, '提示', {
  251. confirmButtonText: '确定',
  252. cancelButtonText: '取消',
  253. cancelButtonClass:'cancel',
  254. type: 'warning'
  255. }).then(() => {
  256. resolve();
  257. }).catch(() => {});
  258. },
  259. warning(msg, type) {
  260. this.$message({
  261. showClose: true,
  262. message: msg,
  263. type: type || 'warning'
  264. })
  265. },
  266. }
  267. }
  268. </script>
  269. <style lang="less">
  270. @import "../../less/common.less";
  271. .topBack{
  272. top: 0;
  273. }
  274. .info-container{
  275. background: #fff;
  276. padding: 20px;
  277. margin: 70px 20px -20px 20px;
  278. .el-input__inner{
  279. width: 200px;
  280. }
  281. .el-form-item__label{
  282. text-align: left;
  283. }
  284. .add-prg .el-form-item{
  285. margin-bottom: 20px;
  286. }
  287. }
  288. .cancel span{
  289. color: #22ccc8;
  290. }
  291. .line{
  292. border-top:1px #dcdfe6 solid;
  293. margin-bottom: 25px;
  294. }
  295. .NoiseTemplateWrapper .info-container .el-input__inner{
  296. width: 250px;
  297. }
  298. .NoiseTemplateWrapper .el-select .el-input .el-icon-circle-close{
  299. display: inherit!important;
  300. }
  301. </style>