tabTemplate.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import axios from '@utils/ajax'
  2. import {
  3. initItems,
  4. delItems,
  5. batchDelItems,
  6. changeTitle,
  7. keepPushData,
  8. changeVisible
  9. } from '@store/actions/tabTemplate';
  10. import {DIAG_SHOW} from "@store/types/print";
  11. import Notify from '@commonComp/Notify';
  12. import store from '@store';
  13. import {
  14. getAllDataList,
  15. getAllDataStringList
  16. } from '@utils/tools';
  17. export const initItemList = (type) => { //初始化数据
  18. let baseList = store.getState();
  19. let whichSign = baseList.typeConfig.typeConfig;
  20. let state = baseList.patInfo.message;
  21. return (dispatch) => {
  22. axios.json('/api/icss/templateInfo/getByDoctorIdTemplates', {
  23. "doctorId": state.doctorId,
  24. "hospitalDeptId": state.hospitalDeptId,
  25. "hospitalId": state.hospitalId,
  26. "type": type || whichSign,
  27. }).then((res) => {
  28. const data = res.data;
  29. if (data.code == 0) {
  30. dispatch(initItems(data));
  31. } else {
  32. Notify.error(data.msg)
  33. }
  34. })
  35. }
  36. };
  37. export const saveTemplateDetail = (val) => { //保存为模板
  38. let baseList = store.getState();
  39. let jsonData = getAllDataList(baseList);
  40. let jsonStr = getAllDataStringList(baseList);
  41. let whichSign = baseList.typeConfig.typeConfig;
  42. let state = baseList.patInfo.message;
  43. let preview = {
  44. "chief": jsonStr.chief,
  45. "present": jsonStr.present,
  46. "other": jsonStr.other,
  47. "vital": jsonStr.vital,
  48. "lis": jsonStr.lis,
  49. "pacs": jsonStr.pacs,
  50. "diag": jsonStr.diag,
  51. "advice": jsonStr.advice,
  52. }
  53. function getdata(idx){
  54. let tmpObj = {
  55. "doctorId": state.doctorId,
  56. "hospitalDeptId": state.hospitalDeptId,
  57. "hospitalId": state.hospitalId,
  58. "dataJson": JSON.stringify(jsonData),
  59. "modeName": val,
  60. "modeType": whichSign,
  61. "preview": idx ? JSON.stringify(preview):preview
  62. }
  63. return tmpObj;
  64. }
  65. return (dispatch) => {
  66. axios.json('/api/icss/templateInfo/saveTemplateInfo', getdata()).then((res) => {
  67. const data = res.data;
  68. if (data.code == 0) {
  69. Notify.success('模板保存成功');
  70. dispatch(initItemList());
  71. dispatch(keepPushData(getdata(1),'part'));
  72. dispatch({
  73. type: DIAG_SHOW,
  74. data:false
  75. });
  76. } else {
  77. if(data.msg == '该模板名存在'){ //存在不关闭弹窗
  78. dispatch({
  79. type: DIAG_SHOW,
  80. data:true
  81. });
  82. }else{
  83. dispatch({
  84. type: DIAG_SHOW,
  85. data:false
  86. });
  87. }
  88. Notify.error(data.msg);
  89. }
  90. })
  91. }
  92. };
  93. export const delItem = (id) => { //删除
  94. return (dispatch) => {
  95. axios.json('/api/icss/templateInfo/cancelTemplateInfos', {
  96. ids: id
  97. }).then((res) => {
  98. let data = res.data;
  99. if (data.code == 0) {
  100. dispatch(delItems(id));
  101. Notify.success('模板删除成功');
  102. } else {
  103. Notify.error(data.msg);
  104. }
  105. })
  106. }
  107. };
  108. export const delBatchItem = (ids) => { //批量删除
  109. return (dispatch) => {
  110. axios.json('/api/icss/templateInfo/cancelTemplateInfos', {
  111. ids: ids.join(",")
  112. }).then((res) => {
  113. let data = res.data;
  114. if (data.code == 0) {
  115. dispatch(batchDelItems(ids));
  116. } else {
  117. Notify.error(data.msg);
  118. }
  119. })
  120. }
  121. };
  122. export const changeTitleAsync = (obj) => { //改标题
  123. let baseList = store.getState();
  124. let whichSign = baseList.typeConfig.typeConfig;
  125. let state = baseList.patInfo.message;
  126. if (obj.title == '') {
  127. Notify.success('请输入模板名称');
  128. return;
  129. }
  130. return (dispatch) => {
  131. axios.json('/api/icss/templateInfo/updateByIdUsNames', {
  132. "doctorId": state.doctorId,
  133. "hospitalDeptId": state.hospitalDeptId,
  134. "hospitalId": state.hospitalId,
  135. "id": obj.id,
  136. "modeName": obj.title,
  137. "type": whichSign
  138. }).then((res) => {
  139. let data = res.data;
  140. if (data.code == 0) {
  141. dispatch(changeTitle(obj));
  142. Notify.success('标题修改成功');
  143. store.dispatch(changeVisible(false))
  144. } else {
  145. console.log(data)
  146. Notify.error(data.msg)
  147. }
  148. })
  149. }
  150. };