AddDrug.vue 10 KB

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