AddDrug.vue 11 KB

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