assistCheck.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. } from '../types/assistCheck';
  9. const initSearchList = {
  10. list: [], //点击的结果
  11. assistLabel: [], //搜索的结果
  12. dataString:'', //结果拼接
  13. }
  14. function getCurrentDate() {
  15. let myDate = new Date();
  16. let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
  17. let mon = myDate.getMonth()-0+1; //获取当前月份(0-11,0代表1月)
  18. let day = myDate.getDate(); //获取当前日(1-31)
  19. let date = year+'-'+(mon<10?'0'+mon:mon)+'-'+(day<10?'0'+day:day);
  20. return date;
  21. }
  22. export default (state = initSearchList, action) => {
  23. if (action.type == GET_ASSIST_SEARCH_LIST) {
  24. const newState = Object.assign({}, state);
  25. newState.list = action.list
  26. return newState;
  27. }
  28. if (action.type == GET_ASSIST_LABEL) { //默认
  29. const newState = Object.assign({}, state);
  30. const tempArr = newState.list;
  31. const tempArrs = newState.assistLabel;
  32. let tmpString = '';
  33. for (let i = 0; i < tempArr.length; i++) {
  34. if (tempArr[i].questionId == action.id) {
  35. tempArr[i].time = getCurrentDate();
  36. tempArrs.push(tempArr[i]);
  37. newState.assistLabel = [...tempArrs];
  38. }
  39. }
  40. for (let j = 0; j < tempArrs.length; j++) {
  41. tmpString += (tempArrs[j].name+(tempArrs[j].value?(':'+tempArrs[j].value):'')+(tempArrs[j].time?',报告日期:'+tempArrs[j].time:'')+';')
  42. }
  43. newState.dataString = tmpString
  44. return newState;
  45. }
  46. if (action.type == DEL_ASSIST_LABEL) { //删除
  47. const newState = Object.assign({}, state);
  48. const tempArr = newState.assistLabel;
  49. let tmpString = '';
  50. tempArr.splice(action.idx, 1)
  51. if(tempArr == []){
  52. tmpString == ''
  53. return
  54. }
  55. for (let i = 0; i < tempArr.length; i++) {
  56. tmpString += (tempArr[i].name+(tempArr[i].value?(':'+tempArr[i].value):'')+(tempArr[i].time?',报告日期:'+tempArr[i].time:'')+';')
  57. }
  58. newState.assistLabel = [...tempArr]
  59. newState.dataString = tmpString
  60. return newState;
  61. }
  62. if (action.type == CHANGE_ASSIST_VAL) { //改变输入值
  63. const newState = Object.assign({}, state);
  64. const tempArr = newState.assistLabel;
  65. let tmpString = '';
  66. for (let i = 0; i < tempArr.length; i++) {
  67. if (i == action.idx) {
  68. tempArr[i].value = action.val
  69. newState.assistLabel = [...tempArr]
  70. }
  71. tmpString += (tempArr[i].name+(tempArr[i].value?(':'+tempArr[i].value):'')+(tempArr[i].time?',报告日期:'+tempArr[i].time:'')+';')
  72. }
  73. newState.dataString = tmpString
  74. return newState;
  75. }
  76. if (action.type == CHANGE_DATE) { //新增
  77. const newState = Object.assign({}, state);
  78. const tempArr = newState.assistLabel;
  79. let tmpString = '';
  80. for (let i = 0; i < tempArr.length; i++) {
  81. if (i == action.idx) {
  82. tempArr[i].time = action.date
  83. newState.assistLabel = [...tempArr]
  84. }
  85. tmpString += (tempArr[i].name+(tempArr[i].value?(':'+tempArr[i].value):'')+(tempArr[i].time?',报告日期:'+tempArr[i].time:'')+';')
  86. }
  87. newState.dataString = tmpString
  88. return newState;
  89. }
  90. if (action.type == CLEAR_ASSIST_DATA) {
  91. const newState = Object.assign({}, state);
  92. newState.assistLabel = [...action.data];
  93. newState.dataString = action.saveText;
  94. return newState;
  95. }
  96. return state;
  97. }