tabTemplate.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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('/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,sex) => { //保存为模板
  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. "sex":sex
  63. }
  64. return tmpObj;
  65. }
  66. return (dispatch) => {
  67. axios.json('/templateInfo/saveTemplateInfo', getdata()).then((res) => {
  68. const data = res.data;
  69. if (data.code == 0) {
  70. Notify.success('模板保存成功');
  71. dispatch(initItemList());
  72. dispatch(keepPushData(getdata(1),'part'));
  73. dispatch({
  74. type: DIAG_SHOW,
  75. data:false
  76. });
  77. } else {
  78. if(data.msg == '该模板名存在'){ //存在不关闭弹窗
  79. dispatch({
  80. type: DIAG_SHOW,
  81. data:true
  82. });
  83. }else{
  84. dispatch({
  85. type: DIAG_SHOW,
  86. data:false
  87. });
  88. }
  89. Notify.error(data.msg);
  90. }
  91. })
  92. }
  93. };
  94. export const delItem = (id) => { //删除
  95. return (dispatch) => {
  96. axios.json('/templateInfo/cancelTemplateInfos', {
  97. ids: id
  98. }).then((res) => {
  99. let data = res.data;
  100. if (data.code == 0) {
  101. dispatch(delItems(id));
  102. Notify.success('模板删除成功');
  103. } else {
  104. Notify.error(data.msg);
  105. }
  106. })
  107. }
  108. };
  109. export const delBatchItem = (ids) => { //批量删除
  110. return (dispatch) => {
  111. axios.json('/templateInfo/cancelTemplateInfos', {
  112. ids: ids.join(",")
  113. }).then((res) => {
  114. let data = res.data;
  115. if (data.code == 0) {
  116. dispatch(batchDelItems(ids));
  117. } else {
  118. Notify.error(data.msg);
  119. }
  120. })
  121. }
  122. };
  123. export const changeTitleAsync = (obj) => { //改标题
  124. let baseList = store.getState();
  125. let whichSign = baseList.typeConfig.typeConfig;
  126. let state = baseList.patInfo.message;
  127. if (obj.title == '') {
  128. Notify.success('请输入模板名称');
  129. return;
  130. }
  131. return (dispatch) => {
  132. axios.json('/templateInfo/updateByIdUsNames', {
  133. "doctorId": state.doctorId,
  134. "hospitalDeptId": state.hospitalDeptId,
  135. "hospitalId": state.hospitalId,
  136. "id": obj.id,
  137. "modeName": obj.title,
  138. "type": whichSign
  139. }).then((res) => {
  140. let data = res.data;
  141. if (data.code == 0) {
  142. dispatch(changeTitle(obj));
  143. Notify.success('标题修改成功');
  144. store.dispatch(changeVisible(false))
  145. } else {
  146. console.log(data)
  147. Notify.error(data.msg)
  148. }
  149. })
  150. }
  151. };