AddCombineFeild.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <template>
  2. <div>
  3. <crumbs :title="title" :param="$route.params" linkTo="CombineFeild"></crumbs>
  4. <div class="contents">
  5. <div class="content">
  6. <el-form ref="form" :label-position="labelPosition" label-width="118px" :model="form" :rules="rules">
  7. <el-form-item label="所属医院:" prop="hospitalId">
  8. <el-select v-model="form.hospitalId"
  9. placeholder="请选择"
  10. :disabled="isCopy || isEdit"
  11. size="small">
  12. <el-option
  13. v-for="item in hisTypes"
  14. :key="item.val"
  15. :label="item.name"
  16. :value="Number(item.val)">
  17. </el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="所属模块:" prop="modeId">
  21. <el-select v-model="form.modeId"
  22. placeholder="请选择"
  23. :disabled="isCopy || isEdit"
  24. size="small">
  25. <el-option
  26. v-for="item in fieldTypes"
  27. :key="item.val"
  28. :label="item.name"
  29. :value="Number(item.val)">
  30. </el-option>
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="备注:" prop="tagName">
  34. <el-input type="text" placeholder="请输入备注" v-model="form.tagName"></el-input>
  35. </el-form-item>
  36. <el-form-item label="显示名称:" prop="name">
  37. <el-input type="text" placeholder="请输入显示名称" v-model="form.name"></el-input>
  38. </el-form-item>
  39. <el-form-item label="组合内容:" prop="moduleInfo" class="formItem isRequired">
  40. <div class="moduleInfoItem" v-for="(item,index) in combineInfoList">
  41. <div class="searchBox">
  42. <el-input v-model.trim="item.searchName" placeholder="搜索字段单元" @input="searchFiled(index)">
  43. </el-input>
  44. <ul v-if="searchIndex == index && item.searchResult.length > 0" class="searchResultBox">
  45. <li class="searchItem"
  46. v-for="searchItem in item.searchResult"
  47. :title="searchItem.tagName"
  48. @click="selectSearchFiled(searchItem,index)"
  49. >
  50. {{searchItem.tagName}}
  51. </li>
  52. </ul>
  53. </div>
  54. <div>
  55. <p>已选择字段:</p>
  56. <div class="selectFiledBox">
  57. <div class="orderBox">
  58. <span class="el-icon-arrow-up order" @click="upFiled(index)"></span>
  59. <span class="el-icon-arrow-down order" @click="downFiled(index)"></span>
  60. </div>
  61. <div class="selectFiled" v-for="(it,ii) in item.selectFiled">
  62. <span class="filedName" :class="{activeFiledName: item.activeIndex == ii}" @click="setActiveIndex(index,ii)">{{it.tagName}}
  63. <span class="el-icon-circle-close delFiled" @click="delSelected(ii,index)"></span>
  64. </span>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </el-form-item>
  70. <el-button class="disclButn" size="small" type="primary" :disabled = 'saveDisable' @click="comfirn('form')">确定</el-button>
  71. </el-form>
  72. </div>
  73. </div>
  74. </div>
  75. </template>
  76. <script type="text/javascript">
  77. import api from '@api/qualityControl.js';
  78. export default {
  79. name:'FieldMatch',
  80. data(){
  81. return{
  82. // data:{},
  83. list:[],
  84. labelPosition:'left',
  85. isFirst:true,
  86. isEdit: false,
  87. isCopy:false,
  88. title:'组合字段维护-添加组合字段',
  89. form:{
  90. modeId:"",
  91. hospitalId:"",
  92. name:'',
  93. tagType:4, //固定
  94. controlType: 0,
  95. name:'',
  96. val:'',
  97. tagName:'',
  98. addLine:0,
  99. bold:0,
  100. position:0,
  101. retract:0,
  102. casesEntryIds:'',
  103. questionMappings:[]
  104. },
  105. id:null,
  106. rules:{
  107. hospitalId:{ required: true, message: '请选择所属医院', trigger: ['blur', 'change']},
  108. modeId:{ required: true, message: '请选择所属模块', trigger: ['blur', 'change']},
  109. tagName:{ required: true, message: '请输入备注', trigger: ['blur', 'change']},
  110. /*name:[{ required: true, message: '请输入显示名称',trigger: ['blur', 'change'] }],*/
  111. },
  112. saveDisable: false, //保存按钮禁止点击
  113. fieldTypes:[],
  114. hisTypes:[],
  115. searchIndex: -1,
  116. combineInfoList:[
  117. {
  118. searchName:"",
  119. activeIndex: -1,
  120. searchResult:[
  121. ],
  122. selectFiled:[
  123. ]
  124. }
  125. ]
  126. }
  127. },
  128. created(){
  129. this.getAllTypes();
  130. let {isCopy,isEdit,data} = this.$route.params;
  131. if(isEdit || isCopy){
  132. if(isEdit){
  133. this.title='组合字段维护-修改组合字段';
  134. this.id = data.id
  135. this.isEdit = isEdit
  136. }
  137. this.form = Object.assign({},data);
  138. if(isCopy){
  139. this.isCopy = isCopy
  140. this.form.tagName = ""
  141. this.form.id=""
  142. }
  143. let questionMappings = this.form.questionMapping ||[]
  144. let selectFiled = []
  145. for(let i = 0; i < questionMappings.length; i++){
  146. selectFiled.push(questionMappings[i])
  147. }
  148. this.combineInfoList[0].selectFiled = selectFiled
  149. this.form.questionMapping = []
  150. }
  151. },
  152. methods:{
  153. getAllTypes(){
  154. if(localStorage.getItem("qcModuleTypes")){
  155. this.hisTypes = JSON.parse(localStorage.getItem("qcHospitalTypes"));
  156. this.fieldTypes = JSON.parse(localStorage.getItem("qcModuleTypes"));
  157. return ;
  158. }
  159. //获取枚举信息
  160. api.getQcTypes().then((res)=>{
  161. if(res.data.code==="0"){
  162. const data = res.data.data;
  163. localStorage.setItem("qcFieldTypes",JSON.stringify(data[11]));
  164. localStorage.setItem("qcModuleTypes",JSON.stringify(data[12]));
  165. localStorage.setItem("qcHospitalTypes",JSON.stringify(data[13]));
  166. }else{
  167. this.warning("获取枚举信息失败");
  168. }
  169. });
  170. },
  171. searchFiled(index){
  172. this.searchIndex = index
  173. const searchName = this.combineInfoList[index].searchName
  174. if(!searchName){
  175. return
  176. }
  177. if(this.form.hospitalId === ''){
  178. this.warning("请选择所属医院")
  179. return
  180. }
  181. if(this.form.modeId === ''){
  182. this.warning("请选择所属模块")
  183. return
  184. }
  185. const param = {
  186. tagName: searchName,
  187. hospitalId: this.form.hospitalId,
  188. modeId: [this.form.modeId],
  189. tagType: [1]
  190. }
  191. api.getQCName(param).then(res =>{
  192. if(res.data.code == '0'){
  193. this.combineInfoList[index].searchResult = []
  194. this.combineInfoList[index].searchResult.push(...res.data.data)
  195. }
  196. }).catch(e =>{
  197. console.log(e)
  198. })
  199. },
  200. selectSearchFiled(searchItem,index){
  201. this.combineInfoList[index].selectFiled.push(searchItem)
  202. this.searchIndex = -1
  203. this.combineInfoList[index].searchName=""
  204. this.combineInfoList[index].searchResult = []
  205. },
  206. upFiled(index){
  207. let activeIndex = this.combineInfoList[index].activeIndex
  208. if(activeIndex == 0 || activeIndex == -1){
  209. return
  210. }
  211. const current = this.combineInfoList[index].selectFiled[activeIndex]
  212. const currentPre = this.combineInfoList[index].selectFiled[activeIndex-1]
  213. this.combineInfoList[index].selectFiled.splice(activeIndex-1,2,current,currentPre)
  214. this.combineInfoList[index].activeIndex--
  215. },
  216. downFiled(index){
  217. let activeIndex = this.combineInfoList[index].activeIndex
  218. if(activeIndex == this.combineInfoList[index].selectFiled.length -1 || activeIndex == -1){
  219. return
  220. }
  221. const current = this.combineInfoList[index].selectFiled[activeIndex]
  222. const currentNext = this.combineInfoList[index].selectFiled[activeIndex+1]
  223. this.combineInfoList[index].selectFiled.splice(activeIndex,2,currentNext,current)
  224. this.combineInfoList[index].activeIndex++
  225. },
  226. setActiveIndex(index, ii){
  227. let activeIndex = this.combineInfoList[index].activeIndex
  228. if( ii === activeIndex) {
  229. this.combineInfoList[index].activeIndex = -1
  230. } else {
  231. this.combineInfoList[index].activeIndex = ii
  232. }
  233. },
  234. delSelected(ii,index){
  235. this.combineInfoList[index].selectFiled.splice(ii,1)
  236. },
  237. comfirn(form){
  238. /*if(!this.form.name.trim() || !this.form.refreshTime.trim()){
  239. this.$message({
  240. message:'请填写相关内容',
  241. type:'warning'
  242. });
  243. return
  244. }*/
  245. this.$refs[form].validate((valid) => {
  246. if (valid) {
  247. let questionMappings = []
  248. const combineInfoList = this.combineInfoList
  249. for(let i = 0; i < combineInfoList.length; i++){
  250. const selectFiledList = combineInfoList[i].selectFiled
  251. for(let j = 0; j < selectFiledList.length; j++){
  252. questionMappings.push({
  253. sonQuestion: selectFiledList[j].id
  254. })
  255. }
  256. }
  257. if(questionMappings.length === 0){
  258. this.warning('请添加组合内容')
  259. return
  260. }
  261. this.form = Object.assign({}, this.form,{questionMappings: questionMappings})
  262. if(this.id && !this.isCopy){//修改
  263. const param = Object.assign({},this.form,{id:this.id})
  264. this.saveDisable = true //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  265. api.addFieldMatch({questionWrapper:param}).then((res)=>{
  266. if(res.data.code==0){
  267. this.$message({
  268. message:"修改成功",
  269. type:'success'
  270. });
  271. //返回带搜索条件的首页
  272. this.$router.push({
  273. name: 'CombineFeild',
  274. params: Object.assign({}, this.$route.params, {currentPage: 1})
  275. });
  276. }else{
  277. this.$message({
  278. message:res.data.msg,
  279. type:'warning'
  280. });
  281. }
  282. this.saveDisable = false
  283. })
  284. }else{//添加
  285. const params = Object.assign({},this.form);
  286. this.saveDisable = true; //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  287. api.addFieldMatch({questionWrapper:params}).then((res)=>{
  288. if(res.data.code==0){
  289. this.$message({
  290. message:"添加成功",
  291. type:'success'
  292. })
  293. this.$router.push({name: 'CombineFeild'});
  294. }else{
  295. this.$message({
  296. message:res.data.msg,
  297. type:'warning'
  298. });
  299. }
  300. this.saveDisable = false
  301. })
  302. }
  303. } else {
  304. return false;
  305. }
  306. });
  307. },
  308. warning(msg, type,time) {
  309. this.$message({
  310. showClose: true,
  311. message: msg,
  312. type: type || 'warning',
  313. duration:time || '3000'
  314. })
  315. },
  316. }
  317. }
  318. </script>
  319. <style lang="less" scoped>
  320. .content {
  321. background: #fff;
  322. padding: 20px 20px 50px;
  323. color: #545455;
  324. min-width: 980px;
  325. position: relative;
  326. }
  327. .el-form-item{
  328. width: 600px;
  329. }
  330. /deep/.el-input__inner {
  331. height: 30px;
  332. line-height: 30px;
  333. }
  334. .moduleInfoItem{
  335. width: 500px;
  336. min-height: 200px;
  337. padding: 0 50px 0 50px;
  338. border: 1px solid #dcdfe6;
  339. border-radius: 5px;
  340. margin-bottom: 20px;
  341. position: relative;
  342. }
  343. .searchBox{
  344. width: 500px;
  345. position: relative;
  346. }
  347. .searchResultBox{
  348. position: absolute;
  349. width: 500px;
  350. box-sizing: border-box;
  351. max-height: 200px;
  352. overflow-y: auto;
  353. background: #fff;
  354. z-index: 2;
  355. border: 1px solid #48c5d7;
  356. }
  357. .searchItem{
  358. height: 40px;
  359. line-height: 40px;
  360. padding: 0 20px;
  361. cursor: pointer;
  362. overflow: hidden;
  363. white-space: nowrap;
  364. text-overflow: ellipsis;
  365. }
  366. .searchItem:hover{
  367. background-color: #F5F7FA;
  368. }
  369. .selectFiled{
  370. position: relative;
  371. }
  372. .orderBox{
  373. position: absolute;
  374. left: -50px;
  375. top: 50%;
  376. width: 50px;
  377. height: 84px;
  378. margin-top: -42px;
  379. }
  380. .selectFiledBox{
  381. position: relative;
  382. min-height: 120px;
  383. }
  384. .order{
  385. display: inline-block;
  386. width: 30px;
  387. height: 30px;
  388. font-size: 30px;
  389. margin-left: 5px;
  390. border: 1px solid #dcdfe6;
  391. cursor: pointer;
  392. }
  393. .delFiled{
  394. position: absolute;
  395. top: -8px;
  396. right: -6px;
  397. cursor: pointer;
  398. }
  399. .delFiled{
  400. top: -7px;
  401. right: -9px;
  402. }
  403. .filedName{
  404. position: relative;
  405. border: 1px solid #dcdfe6;
  406. border-radius: 4px;
  407. padding: 5px 10px;
  408. }
  409. .activeFiledName{
  410. border: 1px solid #48C5D7;
  411. }
  412. .isRequired::before{
  413. content: '*';
  414. color: #F56C6C;
  415. margin-right: 4px;
  416. float: left;
  417. line-height: 36px;
  418. font-size: 14px;
  419. position: relative;
  420. top: 2px;
  421. }
  422. </style>