wrapModalBody.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import {
  2. SEARCH_HOSPITAL_INSPECT,
  3. SEARCH_HOSPITAL_INSPECT_SON,
  4. SET_ALLCHECK_INS,
  5. SELECT_ONNY_CHECK,
  6. SELECT_WARING,
  7. SHOW_IN_ICSS_INS
  8. } from '../types/wrapModalBody';
  9. import store from '@store';
  10. import { getStringPlus, getPushLists, getPushList} from '@utils/tools.js';
  11. const initWrapModal = {
  12. list: [], //搜索的结果
  13. getExcelData: {}, //导入的数据
  14. hospitalInspect:[],//医院检索到的
  15. hospitalInspectObj:{},//组对应的明细(单选多选全选)
  16. selectGroupList:[],//选的组的明细可能有多个组
  17. allCheck:false,//全选反选
  18. checkedList:[],//选中的小项
  19. btnMsg:'选中全部异常值数据'
  20. }
  21. export default (state = initWrapModal, action) => {
  22. if (action.type == SHOW_IN_ICSS_INS) {
  23. let allState = store.getState().inspect
  24. const newState = Object.assign({}, state);
  25. let tmpGroup = JSON.parse(JSON.stringify(newState.selectGroupList))
  26. let tmpArr = JSON.parse(JSON.stringify(allState.getExcelDataList));
  27. let tmpArr2 = allState.labelList;
  28. let excelDataLis = {
  29. lisExcelRes:[],
  30. messages:[]
  31. }
  32. for(let i = 0;i < tmpGroup.length;i++){
  33. let tmpObj = {//excelDataLis.lisExcelRes[0]
  34. menus:'',
  35. lisExcelItem:[]
  36. }
  37. for(let k = 0;k < tmpGroup[i].lisExcelWrapper.length;k++){
  38. tmpGroup[i].lisExcelWrapper[k].time = tmpGroup[i].Rtime
  39. }
  40. tmpObj.menus = tmpGroup[i].groupName
  41. tmpObj.lisExcelItem = tmpGroup[i].lisExcelWrapper
  42. excelDataLis.lisExcelRes.push(tmpObj)
  43. }
  44. newState.getExcelData = excelDataLis
  45. tmpArr.push(excelDataLis)
  46. newState.hospitalInspect = [] //医院检索到的
  47. newState.hospitalInspectObj = {} //组对应的明细(单选多选全选)
  48. newState.selectGroupList = [] //选的组的明细可能有多个组
  49. newState.allCheck = false //全选反选
  50. newState.checkedList = [] //选中的小项
  51. allState.getExcelDataList = [...tmpArr]
  52. allState.pushItem = getPushList(tmpArr,tmpArr2);
  53. allState.pushItems = getPushLists(tmpArr,tmpArr2);
  54. allState.inspectStrPlus = getStringPlus(getPushLists(tmpArr,tmpArr2))
  55. return newState;
  56. }
  57. if (action.type == SELECT_WARING) {//选中异常值
  58. const newState = Object.assign({}, state);
  59. let listWrap = JSON.parse(JSON.stringify(newState.hospitalInspectObj))
  60. let listWrapLen = listWrap&&listWrap.lisExcelWrapper.length
  61. let tmpGroup = JSON.parse(JSON.stringify(newState.selectGroupList))
  62. let tmpCheckedLis = JSON.parse(JSON.stringify(newState.checkedList))
  63. let warArr = [],checked = [],numS=0,selectNum=0;
  64. // console.log(action,listWrap,tmpCheckedLis)
  65. for(let m =0;m < listWrap.lisExcelWrapper.length;m++){
  66. let tmpName = listWrap.lisExcelWrapper[m].itemName
  67. let tmpType = listWrap.lisExcelWrapper[m].type
  68. for(let n = 0;n < tmpCheckedLis.length;n++){
  69. if(tmpType == 0 && tmpName == tmpCheckedLis[n]){//已选的正常的选项要保留
  70. warArr.push(listWrap.lisExcelWrapper[m])
  71. checked.push(tmpName)
  72. }
  73. }
  74. if(tmpType != 0 && (tmpCheckedLis.filter(item=>item == tmpName)).length == 0){
  75. ++selectNum
  76. }
  77. }
  78. // console.log(selectNum)
  79. for(let m =0;m < listWrap.lisExcelWrapper.length;m++){
  80. let tmpName = listWrap.lisExcelWrapper[m].itemName
  81. let tmpType = listWrap.lisExcelWrapper[m].type
  82. if(selectNum>0){
  83. if(listWrap.lisExcelWrapper[m].type != 0){//没有选中的选项要加上,有一个异常未选中就选中
  84. warArr.push(listWrap.lisExcelWrapper[m])
  85. checked.push(tmpName)
  86. }
  87. newState.btnMsg = "取消选中全部异常值数据"
  88. }else{//全部的选中就去掉所有异常选中的
  89. for(let n = 0;n < tmpCheckedLis.length;n++){
  90. if(tmpType == 0 && tmpName == tmpCheckedLis[n]){//已选的正常的选项要保留
  91. checked=[]
  92. warArr=[]
  93. warArr.push(listWrap.lisExcelWrapper[m])
  94. checked.push(tmpName)
  95. }
  96. }
  97. newState.btnMsg = "选中全部异常值数据"
  98. }
  99. }
  100. for(let i = 0;i < tmpGroup.length;i++){
  101. if(tmpGroup[i].groupName == listWrap.groupName){//右侧有选中相同组的明细
  102. if(warArr.length == 0){
  103. tmpGroup.splice(i,1)
  104. }else{
  105. tmpGroup[i].lisExcelWrapper = warArr
  106. }
  107. }else{//右侧没有选中相同组的明细
  108. ++numS
  109. }
  110. }
  111. if(numS == tmpGroup.length){//直接添加到右侧
  112. if(warArr.length > 0){
  113. listWrap.lisExcelWrapper = warArr
  114. tmpGroup.push(listWrap)
  115. }
  116. }
  117. if(checked.length == listWrapLen){
  118. newState.allCheck = true;
  119. }else{
  120. newState.allCheck = false;
  121. }
  122. newState.selectGroupList = [...tmpGroup]//右侧已选中的项目
  123. newState.checkedList = [...checked]
  124. return newState;
  125. }
  126. if (action.type == SELECT_ONNY_CHECK) {
  127. const newState = Object.assign({}, state);
  128. let listWrap = JSON.parse(JSON.stringify(newState.hospitalInspectObj))
  129. let tmpLen = listWrap.lisExcelWrapper.length;
  130. let tmpGroup = JSON.parse(JSON.stringify(newState.selectGroupList))
  131. let tmpCheckedLis = JSON.parse(JSON.stringify(newState.checkedList))
  132. let numS = 0;
  133. if (tmpCheckedLis.indexOf(action.name) == -1) {//添加选中
  134. let tempArr = newState.checkedList;
  135. tempArr.push(action.name);
  136. newState.checkedList = [...tempArr]
  137. for(let m = 0;m < tmpGroup.length;m++){
  138. if(tmpGroup[m].groupName == action.groupName){//右侧有选中相同组的明细
  139. tmpGroup[m].lisExcelWrapper.push(action.item)
  140. }else{
  141. ++numS
  142. }
  143. }
  144. if(numS == tmpGroup.length){//直接添加到右侧
  145. listWrap.lisExcelWrapper = []
  146. listWrap.lisExcelWrapper.push(action.item)
  147. tmpGroup.push(listWrap)
  148. }
  149. newState.selectGroupList = [...tmpGroup]//右侧已选中的项目
  150. if(tempArr.length == tmpLen){
  151. newState.allCheck = true;
  152. }else{
  153. newState.allCheck = false;
  154. }
  155. } else {//去除选中
  156. let tempArr = newState.checkedList;
  157. tempArr.splice(tempArr.findIndex(item => item === action.name), 1)
  158. newState.checkedList = [...tempArr]
  159. for(let i = 0;i < tmpGroup.length;i++){
  160. if(tmpGroup[i].groupName == action.groupName){//右侧肯定有相同组的
  161. let tmpArr = []
  162. for(let k = 0;k < tmpGroup[i].lisExcelWrapper.length;k++){
  163. if(action.name != tmpGroup[i].lisExcelWrapper[k].itemName){
  164. tmpArr.push(tmpGroup[i].lisExcelWrapper[k])
  165. }
  166. }
  167. if(tmpArr.length == 0){
  168. tmpGroup.splice(i,1)
  169. }else{
  170. tmpGroup[i].lisExcelWrapper = [...tmpArr]
  171. }
  172. }
  173. }
  174. newState.selectGroupList = tmpGroup//右侧已选中的项目
  175. if(tempArr.length == listWrap.lisExcelWrapper.length){
  176. newState.allCheck = true;
  177. }else{
  178. newState.allCheck = false;
  179. }
  180. }
  181. let selectNum=0;
  182. let tmpCheckedList = JSON.parse(JSON.stringify(newState.checkedList))
  183. let tmpListWrap = JSON.parse(JSON.stringify(newState.hospitalInspectObj))
  184. for(let m =0;m < tmpListWrap.lisExcelWrapper.length;m++){
  185. let tmpName = tmpListWrap.lisExcelWrapper[m].itemName
  186. let tmpType = tmpListWrap.lisExcelWrapper[m].type
  187. if(tmpType != 0&& (tmpCheckedList.filter(item=>item == tmpName)).length == 0){
  188. selectNum = selectNum+1
  189. }
  190. }
  191. if(selectNum>0){//说明有没选中的
  192. newState.btnMsg = "选中全部异常值数据"
  193. }else{
  194. newState.btnMsg = "取消选中全部异常值数据"
  195. }
  196. return newState;
  197. }
  198. if (action.type == SET_ALLCHECK_INS) {
  199. const newState = Object.assign({}, state);
  200. let flg = newState.allCheck
  201. let listWrap = newState.hospitalInspectObj
  202. let tmpGroup = newState.selectGroupList
  203. let tmpCheckedLis = []
  204. newState.allCheck = !flg
  205. if(!flg){//全选
  206. let numFst=0
  207. for(let i = 0;i < tmpGroup.length;i++){
  208. if(listWrap.groupName == tmpGroup[i].groupName){
  209. ++numFst
  210. tmpGroup[i].lisExcelWrapper = listWrap.lisExcelWrapper
  211. }
  212. }
  213. for(let m =0;m < listWrap.lisExcelWrapper.length;m++){
  214. tmpCheckedLis.push(listWrap.lisExcelWrapper[m].itemName)
  215. }
  216. if(numFst==0){
  217. tmpGroup.push(listWrap)
  218. }
  219. newState.btnMsg = "取消选中全部异常值数据"
  220. newState.checkedList=[...tmpCheckedLis]
  221. newState.selectGroupList = [...tmpGroup]
  222. }else{//反选
  223. for(let j = 0;j < tmpGroup.length;j++){
  224. if(listWrap.groupName == tmpGroup[j].groupName){
  225. tmpGroup.splice(j,1)
  226. }
  227. }
  228. newState.btnMsg = "选中全部异常值数据"
  229. newState.checkedList=[]
  230. newState.selectGroupList = [...tmpGroup]
  231. }
  232. return newState;
  233. }
  234. if (action.type == SEARCH_HOSPITAL_INSPECT) {
  235. const newState = Object.assign({}, state);
  236. newState.hospitalInspect = action.list
  237. newState.allCheck = false
  238. newState.hospitalInspectObj={}
  239. return newState;
  240. }
  241. if (action.type == SEARCH_HOSPITAL_INSPECT_SON) {
  242. const newState = Object.assign({}, state);
  243. let tmpArr = action.list
  244. let tmpSelect = newState.selectGroupList
  245. let tmpSelectSon = []
  246. for(let i = 0;i < tmpSelect.length;i++){
  247. if(tmpSelect[i].groupName == action.name){
  248. for(let k = 0;k < tmpSelect[i].lisExcelWrapper.length;k++){
  249. tmpSelectSon.push(tmpSelect[i].lisExcelWrapper[k].itemName)
  250. }
  251. }
  252. }
  253. newState.checkedList = [...tmpSelectSon]
  254. if(tmpSelectSon.length == tmpArr.lisExcelWrapper.length){
  255. newState.allCheck = true;
  256. }else{
  257. newState.allCheck = false;
  258. }
  259. tmpArr.Rtime = action.time
  260. newState.hospitalInspectObj = tmpArr
  261. return newState;
  262. }
  263. return state;
  264. }