assistCheck.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import {
  2. GET_ASSIST_SEARCH_LIST,
  3. GET_ASSIST_LABEL,
  4. DEL_ASSIST_LABEL,
  5. CHANGE_ASSIST_VAL,
  6. CHANGE_DATE,
  7. CLEAR_ASSIST_DATA,
  8. ADD_ASSIST_LABEL
  9. } from '../types/assistCheck';
  10. import store from '@store';
  11. const initSearchList = {
  12. list: [], //点击的结果
  13. assistLabel: [], //搜索的结果
  14. dataString:'', //结果拼接
  15. assistVal:''
  16. }
  17. function getCurrentDate() {
  18. let myDate = new Date();
  19. let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
  20. let mon = myDate.getMonth()-0+1; //获取当前月份(0-11,0代表1月)
  21. let day = myDate.getDate(); //获取当前日(1-31)
  22. let date = year+'-'+(mon<10?'0'+mon:mon)+'-'+(day<10?'0'+day:day);
  23. return date;
  24. }
  25. export default (state = initSearchList, action) => {
  26. if (action.type == ADD_ASSIST_LABEL) {
  27. const newState = Object.assign({}, state);
  28. let tempArr = newState.assistLabel,tmpString='';
  29. for(let i = 0;i <action.lis.length;i++){
  30. tempArr.push(action.lis[i]);
  31. }
  32. for (let i = 0; i < tempArr.length; i++) {
  33. if (i == action.idx) {
  34. tempArr[i].time = action.date
  35. newState.assistLabel = [...tempArr]
  36. }
  37. let tmpVal = tempArr[i].value?tempArr[i].value.trim():tempArr[i].value;
  38. tmpString += (tempArr[i].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArr[i].time?'报告日期:'+tempArr[i].time:'')+';')
  39. }
  40. newState.assistLabel=[...tempArr]
  41. newState.dataString = tmpString
  42. return newState;
  43. }
  44. if (action.type == GET_ASSIST_SEARCH_LIST) { //右侧推送添加到左侧
  45. const newState = Object.assign({}, state);
  46. newState.list = action.list
  47. newState.assistVal = action.val
  48. return newState;
  49. }
  50. if (action.type == GET_ASSIST_LABEL) { //默认
  51. const newState = Object.assign({}, state);
  52. const tempArrs = newState.assistLabel;
  53. let tempArr = [];
  54. let tmpString = '';
  55. let tmpCommonLis = store.getState().homePage.assistList;
  56. if(action.sign == 'common'){
  57. let tmpAssistList = JSON.parse(JSON.stringify(tmpCommonLis))
  58. tempArr = tmpAssistList;
  59. }else{
  60. tempArr = newState.list
  61. }
  62. for (let i = 0; i < tempArr.length; i++) {
  63. if (tempArr[i].questionId == action.id && i == action.idx) {
  64. tempArr[i].time = getCurrentDate();
  65. tempArrs.push(tempArr[i]);
  66. newState.assistLabel = [...tempArrs];
  67. }
  68. }
  69. for (let j = 0; j < tempArrs.length; j++) {
  70. let tmpVal = tempArrs[j].value?tempArrs[j].value.trim():tempArrs[j].value;
  71. tmpString += (tempArrs[j].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArrs[j].time?'报告日期:'+tempArrs[j].time:'')+';')
  72. }
  73. newState.dataString = tmpString
  74. return newState;
  75. }
  76. if (action.type == DEL_ASSIST_LABEL) { //删除
  77. const newState = Object.assign({}, state);
  78. let tempArr = newState.assistLabel,tempArrs=[];
  79. let tmpString = '';
  80. // tempArr.splice(action.idx, 1)
  81. // let tempArrs = tempArr.slice()
  82. for(let k = 0;k < tempArr.length;k++){
  83. if(k != action.idx){
  84. tempArrs.push(tempArr[k])
  85. }
  86. }
  87. if(tempArrs == []){
  88. tmpString == ''
  89. return
  90. }
  91. for (let i = 0; i < tempArrs.length; i++) {
  92. let tmpVal = tempArrs[i].value?tempArrs[i].value.trim():tempArrs[i].value;
  93. tmpString += (tempArrs[i].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArrs[i].time?'报告日期:'+tempArrs[i].time:'')+';')
  94. }
  95. newState.assistLabel = [...tempArrs]
  96. newState.dataString = tmpString
  97. return newState;
  98. }
  99. if (action.type == CHANGE_ASSIST_VAL) { //改变输入值
  100. const newState = Object.assign({}, state);
  101. const tempArr = newState.assistLabel;
  102. let tmpString = '';
  103. for (let i = 0; i < tempArr.length; i++) {
  104. if (i == action.idx) {
  105. tempArr[i].value = action.val
  106. newState.assistLabel = [...tempArr]
  107. }
  108. let tmpVal = tempArr[i].value?tempArr[i].value.trim():tempArr[i].value;
  109. tmpString += (tempArr[i].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArr[i].time?'报告日期:'+tempArr[i].time:'')+';')
  110. }
  111. newState.dataString = tmpString
  112. return newState;
  113. }
  114. if (action.type == CHANGE_DATE) { //新增
  115. const newState = Object.assign({}, state);
  116. const tempArr = newState.assistLabel;
  117. let tmpString = '';
  118. for (let i = 0; i < tempArr.length; i++) {
  119. if (i == action.idx) {
  120. tempArr[i].time = action.date
  121. newState.assistLabel = [...tempArr]
  122. }
  123. let tmpVal = tempArr[i].value?tempArr[i].value.trim():tempArr[i].value;
  124. tmpString += (tempArr[i].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArr[i].time?'报告日期:'+tempArr[i].time:'')+';')
  125. }
  126. newState.dataString = tmpString
  127. return newState;
  128. }
  129. if (action.type == CLEAR_ASSIST_DATA) {
  130. const newState = Object.assign({}, state);
  131. newState.assistLabel = [...action.data];
  132. newState.dataString = action.saveText;
  133. return newState;
  134. }
  135. return state;
  136. }