AddDept.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <div class="AddChemicalAndCommonMappingWrapper clearfix">
  3. <crumbs
  4. :title="isEdit ? '科室关联维护--修改关联' : '科室关联维护--添加关联'"
  5. class="topBack"
  6. :param="$route.params"
  7. linkTo="DeptManage"
  8. ></crumbs>
  9. <el-form
  10. :model="form"
  11. :rules="rules"
  12. label-position="right"
  13. label-width="120px"
  14. ref="relationForm"
  15. >
  16. <div class="AddChemicalAndCommonMappingBox clearfix">
  17. <div class="titleBox clearfix">
  18. <p class="title">医院术语</p>
  19. <p class="title">标准术语</p>
  20. </div>
  21. <div class="leftBox clearfix">
  22. <el-row>
  23. <el-col :span="16">
  24. <el-form-item label="科室名称:" prop="hisName">
  25. <el-input v-model="form.hisName" clearable></el-input>
  26. </el-form-item>
  27. <el-form-item label="科室名称预览:">
  28. <span class="previewInfo">{{form.hisName}}</span>
  29. </el-form-item>
  30. <el-form-item label="科室编码:">
  31. <el-input v-model="form.hisCode" clearable></el-input>
  32. </el-form-item>
  33. </el-col>
  34. </el-row>
  35. </div>
  36. <div class="midBox">
  37. <img class="midLogo" src="../../../images/relation.png" alt />
  38. <p class="midTitle">相互关联</p>
  39. </div>
  40. <div class="rightBox">
  41. <el-row>
  42. <el-col :span="16">
  43. <el-form-item label="科室名称:" prop="searchText">
  44. <el-select
  45. style="width:100%"
  46. v-model="form.searchText"
  47. filterable
  48. remote
  49. clearable
  50. :loading="showDrop"
  51. loading-text="加载中..."
  52. @change="changeWord"
  53. @focus="handleFocus"
  54. placeholder="搜索"
  55. :remote-method="searchTerms"
  56. reserve-keyword
  57. >
  58. <el-option
  59. v-for="(item,idx) in uniqueNameList"
  60. :key="idx"
  61. :label="item"
  62. :value="item"
  63. ></el-option>
  64. </el-select>
  65. </el-form-item>
  66. <el-form-item label="科室名称预览:">
  67. <span class="previewInfo">{{form.searchText}}</span>
  68. </el-form-item>
  69. </el-col>
  70. </el-row>
  71. </div>
  72. </div>
  73. <div class="btn">
  74. <el-form-item>
  75. <el-button type="primary" :disabled="saveDisable" @click="submitForm">确定</el-button>
  76. </el-form-item>
  77. </div>
  78. </el-form>
  79. </div>
  80. </template>
  81. <script>
  82. import api from '@api/icss.js';
  83. export default {
  84. name: 'AddDept',
  85. data() {
  86. return {
  87. isEdit: false,
  88. editId: '',
  89. uniqueNameList: [],
  90. form: {
  91. searchText: '', //搜索字段
  92. hisName: '',
  93. hisCode: ''
  94. },
  95. rules: {
  96. hisName: [
  97. { required: true, message: '请输入科室名称', trigger: 'change' }
  98. ],
  99. searchText: [
  100. { required: true, message: '请选择科室名称', trigger: 'change' }
  101. ]
  102. },
  103. saveDisable: false, //保存按钮禁止点击
  104. showDrop: false //下拉框显示文字
  105. };
  106. },
  107. created() {
  108. //修改
  109. const { isEdit, data } = this.$route.params;
  110. // console.log(data, 'data');
  111. if (isEdit) {
  112. this.isEdit = isEdit;
  113. this.editId = data.id;
  114. this.form.hisName = data.hisName;
  115. this.form.searchText = data.uniqueName;
  116. this.form.hisCode = data.hisCode;
  117. }
  118. },
  119. methods: {
  120. // 搜索列表
  121. searchTerms(query) {
  122. if (!query) {
  123. this.uniqueNameList = []
  124. return;
  125. }
  126. this.showDrop = true;
  127. let params = {
  128. type: 7, //科室
  129. inputStr: query,
  130. sex: 3,
  131. age: 0
  132. };
  133. api.retrievalSearch(params).then(res => {
  134. this.showDrop = false;
  135. if (res.data.code === '0') {
  136. this.uniqueNameList = res.data.data.deptNames;
  137. }
  138. });
  139. },
  140. changeWord(newVal) {
  141. console.log(newVal);
  142. },
  143. // 获取焦点
  144. handleFocus() {},
  145. // 初始化表单数据
  146. initForm() {
  147. this.form.hisName = '';
  148. this.form.searchText = '';
  149. },
  150. // 建立关联-参数处理
  151. submitForm() {
  152. this.$refs.relationForm.validate(valid => {
  153. if (valid) {
  154. const { searchText, hisName, hisCode } = this.form;
  155. let params = {
  156. hisName: hisName,
  157. uniqueName: searchText,
  158. hisCode: hisCode
  159. };
  160. this.showSaveDialog(params);
  161. } else {
  162. console.log('error submit!!');
  163. return false;
  164. }
  165. });
  166. },
  167. // 建立关联-映射关系是否已存在
  168. showSaveDialog(params) {
  169. this.saveDisable = true; //提交保存按钮不可点击,返回结果时才可点击,防止频繁发送请求
  170. api
  171. .deptIsExistRecord(params)
  172. .then(res => {
  173. if (!res.data.data) {
  174. // 不存在,创建新的关联
  175. // 如果是编辑时,需要携带id
  176. if (this.isEdit) {
  177. params = { ...params, id: this.editId };
  178. }
  179. this.saveLisMapping(params, '保存成功', 'success');
  180. } else {
  181. // 已存在,提示修改
  182. this.warning('该条关联已存在,无法添加');
  183. this.saveDisable = false;
  184. }
  185. })
  186. .catch(err => {
  187. if (err.code === '900010001') {
  188. return false;
  189. }
  190. this.warning(err);
  191. });
  192. },
  193. // 映射关系不存在-建立关联
  194. saveLisMapping(params, msg, type) {
  195. api.saveOrUpdateDeptRecord(params).then(res => {
  196. if (res.data.code === '0') {
  197. this.warning(res.data.msg || msg, type);
  198. this.initForm();
  199. this.$router.push({
  200. name: 'DeptManage',
  201. params: Object.assign({}, this.$route.params, {
  202. currentPage: 1
  203. })
  204. });
  205. } else {
  206. this.warning(res.data.msg);
  207. }
  208. this.saveDisable = false;
  209. });
  210. },
  211. // 关联已存在模态框
  212. showConfirmDialog(msg, resolve) {
  213. this.$confirm(msg, '提示', {
  214. customClass: 'confirmRealation',
  215. confirmButtonText: '是',
  216. cancelButtonText: '否',
  217. cancelButtonClass: 'cancelButton',
  218. type: 'warning'
  219. })
  220. .then(() => {
  221. resolve();
  222. })
  223. .catch(() => {
  224. this.saveDisable = false;
  225. this.warning('建立失败', 'error');
  226. });
  227. },
  228. warning(msg, type) {
  229. this.$message({
  230. showClose: true,
  231. message: msg,
  232. type: type || 'warning'
  233. });
  234. }
  235. }
  236. };
  237. </script>
  238. <style lang="less">
  239. .AddChemicalAndCommonMappingWrapper {
  240. .AddChemicalAndCommonMappingBox {
  241. min-width: 940px;
  242. }
  243. color: #606266;
  244. .topBack {
  245. top: 0;
  246. }
  247. .titleBox {
  248. padding: 0 0 10px 0px;
  249. }
  250. .title {
  251. width: 50%;
  252. float: left;
  253. font-size: 14px;
  254. }
  255. .AddChemicalAndCommonMappingBox {
  256. padding: 20px 30px 20px 30px;
  257. margin: 70px 20px 0 20px;
  258. background: #fff;
  259. }
  260. .leftBox,
  261. .midBox,
  262. .rightBox {
  263. width: 40%;
  264. float: left;
  265. min-height: 200px;
  266. font-size: 14px;
  267. }
  268. .midBox {
  269. width: 6%;
  270. padding: 50px 0 0 0;
  271. text-align: center;
  272. }
  273. .midTitle {
  274. width: 40px;
  275. margin: 0 auto;
  276. }
  277. .midLogo {
  278. margin: 0 auto;
  279. }
  280. .leftBox,
  281. .rightBox {
  282. border: 1px solid #dcdfe6;
  283. padding: 20px 20px;
  284. }
  285. .itemLabel {
  286. width: 100%;
  287. min-height: 50px;
  288. line-height: 50px;
  289. position: relative;
  290. }
  291. .itemLabelName,
  292. .searchInput,
  293. .searchName {
  294. float: left;
  295. color: #606266;
  296. }
  297. .itemLabelName {
  298. width: 150px;
  299. }
  300. .isRequired::before {
  301. content: '*';
  302. color: red;
  303. }
  304. .searchInput,
  305. .mealNameItem {
  306. padding: 0 5px;
  307. }
  308. .searchInput,
  309. .searchName {
  310. display: inline-block;
  311. height: 32px;
  312. line-height: 32px;
  313. border: 1px solid #a9a9a9;
  314. margin: 8px 0 0 0;
  315. }
  316. .searchName {
  317. text-align: center;
  318. border-left: none;
  319. cursor: pointer;
  320. padding: 0 12px;
  321. font-size: 16px;
  322. }
  323. .itemList {
  324. position: absolute;
  325. background: #fff;
  326. width: 162px;
  327. max-height: 150px;
  328. border: 1px solid #a9a9a9;
  329. left: 150px;
  330. top: 42px;
  331. z-index: 2;
  332. overflow-y: auto;
  333. }
  334. .itemList {
  335. width: calc(100% - 131px);
  336. }
  337. .mealNameItem {
  338. height: 30px;
  339. line-height: 30px;
  340. font-size: 14px;
  341. cursor: pointer;
  342. }
  343. .mealNameItem:hover {
  344. background: #f5f7fa;
  345. }
  346. // .selectItemName {
  347. // padding-left: 4px;
  348. // display: inline-block;
  349. // margin-top: 8px;
  350. // // width: calc(100% - 160px);s
  351. // line-height: 24px;
  352. // overflow: hidden;
  353. // word-wrap: break-word;
  354. // word-break: break-all;
  355. // }
  356. .previewInfo {
  357. padding-left: 4px;
  358. display: inline-block;
  359. margin-top: 8px;
  360. // width: calc(100% - 160px);s
  361. line-height: 24px;
  362. overflow: hidden;
  363. word-wrap: break-word;
  364. word-break: break-all;
  365. }
  366. .btn {
  367. position: relative;
  368. background-color: #fff;
  369. margin: 0px 20px;
  370. padding: 20px;
  371. min-width: 960px;
  372. height: 80px;
  373. .el-button {
  374. position: absolute;
  375. right: 80px;
  376. top: 20px;
  377. }
  378. }
  379. .sumbit {
  380. position: absolute;
  381. display: inline-block;
  382. width: 80px;
  383. height: 30px;
  384. line-height: 30px;
  385. border: 1px solid #a9a9a9;
  386. text-align: center;
  387. right: 100px;
  388. }
  389. }
  390. .confirmRealation {
  391. .cancelButton {
  392. border: 1px solid #a9a9a9;
  393. span {
  394. color: #606266;
  395. }
  396. }
  397. }
  398. body {
  399. .el-select-dropdown {
  400. /deep/ .el-select-dropdown__item {
  401. span {
  402. color: #333;
  403. }
  404. }
  405. ul {
  406. max-width: 300px;
  407. }
  408. }
  409. }
  410. </style>