AddPlan.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <div class="AddPlanWrapper clearfix" @click="close">
  3. <crumbs
  4. :title="isEdit ? '电子病历方案配置-修改方案' : '电子病历方案配置-添加方案'"
  5. class="topBack"
  6. :param="$route.params"
  7. linkTo="Plan"
  8. ></crumbs>
  9. <div class="AddPlanBox">
  10. <el-row :gutter="20">
  11. <el-col :span="16">
  12. <el-form ref="form" :model="form" label-width="80px" :rules="rules">
  13. <el-form-item label="方案名称" prop="planName">
  14. <el-input v-model="form.planName" placeholder="2-30位,可输入汉字、字母、数字和下划线"></el-input>
  15. </el-form-item>
  16. <el-form-item label="方案编码" prop="planCode">
  17. <el-input v-model="form.planCode" placeholder="4-10位,可输入字母、数字和下划线"></el-input>
  18. </el-form-item>
  19. <el-form-item label="方案配置">
  20. <ul>
  21. <li>
  22. <div class="title">
  23. <div class="handleIcon" @click="openPlanItems">
  24. <img
  25. src="../../../images/multi.png"
  26. alt="辅助信息"
  27. :class="{'open' : isOpenCloseItems}"
  28. />
  29. </div>
  30. <h4>辅助信息</h4>
  31. <div class="titlwSwitch">
  32. <el-switch
  33. v-model="switchSubStatus"
  34. :active-value="1"
  35. :inactive-value="0"
  36. active-color="#4BC4D7"
  37. inactive-color="#BBBBBB"
  38. ></el-switch>
  39. <span class="titlwSwitchStatus">{{switchSubStatus === 1 ? '启用中' : '未启用'}}</span>
  40. </div>
  41. </div>
  42. <transition name="plus-icon">
  43. <div v-if="isOpenCloseItems">
  44. <ul class="sub" v-for="(item,index) in planDefaultList" :key="item.id">
  45. <li class="planItem">
  46. <div class="sort">
  47. <div class="top">
  48. <img
  49. :src="isTopLight !== index ? require('../../../images/icon_default_top.png') : require('../../../images/icon_hover_top.png')"
  50. alt="上升"
  51. v-if="index !== 0"
  52. @click="sortPlan(item,index,'top')"
  53. @mouseover="handleMouseEnter1(index)"
  54. @mouseleave="handleMouseLeave1(index)"
  55. />
  56. </div>
  57. <div class="down">
  58. <img
  59. :src="isDownLight !== index ? require('../../../images/icon_default_down.png') : require('../../../images/icon_hover_down.png')"
  60. alt="下降"
  61. v-if="index !== planDefaultList.length - 1"
  62. @click="sortPlan(item,index,'down')"
  63. @mouseover="handleMouseEnter(index)"
  64. @mouseleave="handleMouseLeave(index)"
  65. />
  66. </div>
  67. </div>
  68. <div class="openOrClose">
  69. <span class="planInfo">{{item.name}}</span>
  70. <div class="switch">
  71. <el-switch
  72. v-model="item.status"
  73. :active-value="1"
  74. :inactive-value="0"
  75. active-color="#4BC4D7"
  76. inactive-color="#BBBBBB"
  77. ></el-switch>
  78. </div>
  79. <span class="planStatus">{{item.status === 1 ? '启用中' : '未启用'}}</span>
  80. </div>
  81. <div class="showNum" v-if="item.number">
  82. <span style="marginRight:8px;">默认显示个数</span>
  83. <el-select v-model="item.number" placeholder="请选择" size="small" :disabled="item.status !== 1 ? true: false">
  84. <el-option label="1" value="1"></el-option>
  85. <el-option label="2" value="2"></el-option>
  86. <el-option label="3" value="3"></el-option>
  87. <el-option label="4" value="4"></el-option>
  88. <el-option label="5" value="5"></el-option>
  89. <el-option label="6" value="6"></el-option>
  90. </el-select>
  91. </div>
  92. </li>
  93. </ul>
  94. </div>
  95. </transition>
  96. </li>
  97. <li>
  98. <div class="title">
  99. <div class="handleIcon">
  100. <img src="../../../images/multi.png" alt="医学知识" />
  101. </div>
  102. <h4>医学知识</h4>
  103. <div class="titlwSwitch">
  104. <el-switch
  105. v-model="switchMedStatus"
  106. :active-value="1"
  107. :inactive-value="0"
  108. active-color="#4BC4D7"
  109. inactive-color="#BBBBBB"
  110. ></el-switch>
  111. <span class="titlwSwitchStatus">{{switchMedStatus === 1 ? '启用中' : '未启用'}}</span>
  112. </div>
  113. </div>
  114. </li>
  115. </ul>
  116. </el-form-item>
  117. <el-form-item>
  118. <el-button type="primary" @click="onSubmit" :disabled="saveDisable">确定添加</el-button>
  119. </el-form-item>
  120. </el-form>
  121. </el-col>
  122. </el-row>
  123. </div>
  124. </div>
  125. </template>
  126. <script>
  127. import api from '@api/icss.js';
  128. export default {
  129. name: 'AddPlan',
  130. data() {
  131. return {
  132. form: {
  133. planName: '',
  134. planCode: ''
  135. },
  136. saveDisable: false, //保存按钮禁止点击
  137. rules: {
  138. planName: [
  139. { required: true, message: '方案名称不能为空', trigger: 'change' }
  140. ],
  141. planCode: [
  142. { required: true, message: '方案编码不能为空', trigger: 'change' }
  143. ]
  144. },
  145. planDefaultList: [],
  146. hospitalId: '',
  147. isEdit: false, // 是否处于编辑页面 false--新增 true--编辑
  148. switchSubStatus: 0, // 辅助信息
  149. switchMedStatus: 0, // 医学知识
  150. isOpenCloseItems: true, // 是否展开方案配置项
  151. isDownLight: -1,
  152. isTopLight: -1,
  153. flag: 1
  154. };
  155. },
  156. watch: {
  157. planDefaultList: {
  158. handler(newName, oldName) {},
  159. immediate: true
  160. }
  161. },
  162. async created() {
  163. const { isEdit, data } = this.$route.params;
  164. // console.log(data, '编辑页传递的data');
  165. let res = await api.getHospitalInfo(); // 同步获取医院信息
  166. this.hospitalId = res.data.data.id;
  167. if (isEdit) {
  168. // 编辑页面
  169. this.isEdit = true;
  170. let params = {
  171. hospitalId: res.data.data.id,
  172. id: data.id
  173. };
  174. this._getPlanInfoIds(params);
  175. } else {
  176. // 新增页面
  177. this._getDefaultPlans(); // 获取默认配置信息
  178. }
  179. },
  180. methods: {
  181. close() {},
  182. // 方案配置排序
  183. sortPlan(item, index, type) {
  184. // console.log('排序', item, index, type);
  185. let tempList = [...this.planDefaultList];
  186. if (type === 'down') {
  187. // 降序
  188. let plan = tempList.find(item => {
  189. return item.orderNo === index + 1;
  190. });
  191. let tempPlan = { ...plan };
  192. let planNext = tempList.find(item => {
  193. return item.orderNo === index + 2;
  194. });
  195. let tempPlanNext = { ...planNext };
  196. plan = tempPlanNext;
  197. plan.orderNo -= 1;
  198. planNext = tempPlan;
  199. planNext.orderNo += 1;
  200. let arr = tempList.map((i, idx) => {
  201. if (idx === index) {
  202. return { ...plan };
  203. } else if (idx === index + 1) {
  204. return { ...planNext };
  205. } else {
  206. return i;
  207. }
  208. });
  209. this.planDefaultList = [...arr];
  210. } else {
  211. // 升序
  212. let plan = tempList.find(item => {
  213. return item.orderNo === index + 1;
  214. });
  215. let tempPlan = { ...plan };
  216. let planPre = tempList.find(item => {
  217. return item.orderNo === index;
  218. });
  219. let tempPlanPre = { ...planPre };
  220. plan = tempPlanPre;
  221. plan.orderNo += 1;
  222. planPre = tempPlan;
  223. planPre.orderNo -= 1;
  224. let arr = tempList.map((i, idx) => {
  225. if (idx === index) {
  226. return { ...plan };
  227. } else if (idx === index - 1) {
  228. return { ...planPre };
  229. } else {
  230. return i;
  231. }
  232. });
  233. this.planDefaultList = [...arr];
  234. }
  235. },
  236. // 展开列表项
  237. openPlanItems() {
  238. this.isOpenCloseItems = !this.isOpenCloseItems;
  239. },
  240. // 鼠标移入
  241. handleMouseEnter(index) {
  242. this.isDownLight = index;
  243. },
  244. // 鼠标移除
  245. handleMouseLeave(index) {
  246. this.isDownLight = -1;
  247. },
  248. // 鼠标移入
  249. handleMouseEnter1(index) {
  250. this.isTopLight = index;
  251. },
  252. // 鼠标移除
  253. handleMouseLeave1(index) {
  254. this.isTopLight = -1;
  255. },
  256. // 获取默认方案配置
  257. _getDefaultPlans() {
  258. api.getDefaultPlans().then(res => {
  259. // console.log(res, '获取默认的方案配置');
  260. if (res.data.code === '0') {
  261. this.planDefaultList =
  262. res.data.data &&
  263. res.data.data.planDetailDefault.length !== 0 &&
  264. res.data.data.planDetailDefault[0].planDetails;
  265. this.switchSubStatus =
  266. res.data.data &&
  267. res.data.data.planDetailDefault.length !== 0 &&
  268. res.data.data.planDetailDefault[0].status;
  269. this.switchMedStatus =
  270. res.data.data &&
  271. res.data.data.planDetailDefault.length !== 0 &&
  272. res.data.data.planDetailDefault[1].status;
  273. }
  274. });
  275. },
  276. // 编辑页面 根据id获取方案配置
  277. async _getPlanInfoIds(params) {
  278. // 先获取默认的所有方案
  279. let tempArr = [];
  280. let newPlan = [];
  281. let res = await api.getDefaultPlans();
  282. if (res.data.code === '0') {
  283. tempArr =
  284. res.data.data &&
  285. res.data.data.planDetailDefault.length !== 0 &&
  286. res.data.data.planDetailDefault[0].planDetails;
  287. }
  288. let res1 = await api.getPlanInfoIds(params);
  289. if (res1.data.code === '0') {
  290. newPlan = res1.data.data[0].sysSetInfo[0].planDetails;
  291. this.form.planName = res1.data.data[0].planName;
  292. this.form.planCode = res1.data.data[0].planCode;
  293. this.switchSubStatus = res1.data.data[0].sysSetInfo[0].status;
  294. this.switchMedStatus = res1.data.data[0].sysSetInfo[1].status;
  295. // this.planDefaultList = res1.data.data[0].sysSetInfo[0].planDetails;
  296. }
  297. let arr = [];
  298. let arrTemp = [];
  299. let arrTemp1 = []; // 不同index
  300. for (var i = 0; i < tempArr.length; i++) {
  301. arrTemp.push(i);
  302. }
  303. for (var i = 0; i < tempArr.length; i++) {
  304. for (var j = 0; j < newPlan.length; j++) {
  305. if (tempArr[i].code === newPlan[j].code) {
  306. arr.push(i);
  307. }
  308. }
  309. }
  310. arrTemp1 = arr
  311. .filter(x => arrTemp.indexOf(x) == -1)
  312. .concat(arrTemp.filter(x => arr.indexOf(x) == -1));
  313. let endArr = [...newPlan]
  314. for (var j = 0; j < arrTemp1.length; j++) {
  315. let temp = tempArr[arrTemp1[j]]
  316. temp.orderNo = arr.length + j + 1
  317. temp.status = 0
  318. endArr.push(temp)
  319. }
  320. // console.log(endArr,'-=-=-=-=-=');
  321. this.planDefaultList = endArr
  322. },
  323. // format处理细项数据
  324. handleSendData() {
  325. let TempPlanDetail = [];
  326. TempPlanDetail = this.planDefaultList.map((item, index) => {
  327. return {
  328. code: item.code,
  329. hospitalId: this.hospitalId,
  330. name: item.name,
  331. number: item.number,
  332. orderNo: item.orderNo,
  333. planId: item.planId,
  334. remark: item.remark,
  335. status: item.status,
  336. value: item.value
  337. };
  338. });
  339. return TempPlanDetail;
  340. // console.log(TempPlanDetail, 'TempPlanDetail');
  341. },
  342. // 处理保存活动信息参数
  343. _getParams() {
  344. let params = {
  345. hospitalId: this.hospitalId,
  346. planCode: this.form.planCode,
  347. planDetailParent: [
  348. {
  349. code: 'auxiliary',
  350. hospitalId: this.hospitalId,
  351. name: '辅助信息',
  352. number: 0,
  353. orderNo: 1,
  354. planDetailSub: this.handleSendData(),
  355. status: this.switchSubStatus
  356. },
  357. {
  358. code: 'medical',
  359. hospitalId: this.hospitalId,
  360. name: '医学知识',
  361. orderNo: 3,
  362. planDetailSub: [{}],
  363. status: this.switchMedStatus
  364. }
  365. ], // 方案配置信息
  366. planName: this.form.planName,
  367. planStatus: 0
  368. };
  369. if (this.isEdit) {
  370. // 编辑状态,需要额外添加ID
  371. const { data } = this.$route.params;
  372. params = { ...params, id: data.id };
  373. }
  374. return params;
  375. },
  376. onSubmit() {
  377. this.$refs.form.validate(valid => {
  378. if (valid) {
  379. this.saveDisable = true;
  380. let params = this._getParams();
  381. api.savePlanInfoDatas(params).then(res => {
  382. if (res.data.code === '0') {
  383. this.$message({
  384. showClose: true,
  385. message: '操作成功',
  386. type: 'success',
  387. duration: 1000
  388. });
  389. } else if (res.data.code === '00020007') {
  390. // 方案名/方案编码已存在
  391. this.$message({
  392. showClose: true,
  393. message: res.data.msg,
  394. type: 'error',
  395. duration: 1000
  396. });
  397. }
  398. this.saveDisable = false;
  399. });
  400. } else {
  401. this.saveDisable = false;
  402. return false;
  403. }
  404. });
  405. }
  406. }
  407. };
  408. </script>
  409. <style lang="less">
  410. .AddPlanWrapper {
  411. min-width: 940px;
  412. .AddPlanBox {
  413. padding: 20px 60px 120px 60px;
  414. margin: 70px 20px 0 20px;
  415. background: #fff;
  416. }
  417. color: #606266;
  418. .topBack {
  419. top: 0;
  420. }
  421. .title {
  422. background-color: #f2f2f2;
  423. display: flex;
  424. .handleIcon {
  425. width: 30px;
  426. cursor: pointer;
  427. height: 40px;
  428. display: flex;
  429. justify-content: center;
  430. align-items: center;
  431. img {
  432. width: 20px;
  433. height: 20px;
  434. }
  435. .open {
  436. transform: rotate(180deg);
  437. }
  438. .close {
  439. transform: rotate(0deg);
  440. }
  441. }
  442. .titlwSwitch {
  443. width: 120px;
  444. }
  445. h4 {
  446. flex: 1;
  447. }
  448. .titlwSwitchStatus {
  449. margin-left: 16px;
  450. }
  451. }
  452. .sub {
  453. .planItem {
  454. display: flex;
  455. .sort {
  456. width: 60px;
  457. display: flex;
  458. .top {
  459. display: flex;
  460. justify-content: center;
  461. align-items: center;
  462. width: 30px;
  463. cursor: pointer;
  464. img {
  465. width: 10px;
  466. height: 14px;
  467. }
  468. }
  469. .down {
  470. width: 30px;
  471. cursor: pointer;
  472. display: flex;
  473. justify-content: center;
  474. align-items: center;
  475. img {
  476. width: 10px;
  477. height: 14px;
  478. }
  479. }
  480. }
  481. .openOrClose {
  482. display: flex;
  483. flex: 1;
  484. .planInfo {
  485. width: 140px;
  486. }
  487. .switch {
  488. }
  489. .planStatus {
  490. margin-left: 16px;
  491. }
  492. }
  493. .showNum {
  494. display: flex;
  495. width: 160px;
  496. /deep/.el-input--small {
  497. width: 60px;
  498. }
  499. }
  500. }
  501. }
  502. .el-button {
  503. float: right;
  504. }
  505. .plus-icon-enter-active {
  506. transition: all 0.8s;
  507. }
  508. .plus-icon-enter {
  509. opacity: 0;
  510. margin-top: 12px;
  511. }
  512. .plus-icon-leave-active {
  513. transition: all 0.8s;
  514. }
  515. .plus-icon-leave-active {
  516. opacity: 0;
  517. margin-top: 12px;
  518. }
  519. }
  520. </style>