AddQualityControlTemp.vue 15 KB

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