123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import {
- GET_ASSIST_SEARCH_LIST,
- GET_ASSIST_LABEL,
- DEL_ASSIST_LABEL,
- CHANGE_ASSIST_VAL,
- CHANGE_DATE,
- CLEAR_ASSIST_DATA,
- ADD_ASSIST_LABEL
- } from '../types/assistCheck';
- import store from '@store';
- const initSearchList = {
- list: [], //点击的结果
- assistLabel: [], //搜索的结果
- dataString:'', //结果拼接
- assistVal:''
- }
- function getCurrentDate() {
- let myDate = new Date();
- let year = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
- let mon = myDate.getMonth()-0+1; //获取当前月份(0-11,0代表1月)
- let day = myDate.getDate(); //获取当前日(1-31)
- let date = year+'-'+(mon<10?'0'+mon:mon)+'-'+(day<10?'0'+day:day);
- return date;
- }
- export default (state = initSearchList, action) => {
- if (action.type == ADD_ASSIST_LABEL) {
- const newState = Object.assign({}, state);
- let tempArr = newState.assistLabel,tmpString='';
- for(let i = 0;i <action.lis.length;i++){
- tempArr.push(action.lis[i]);
- }
-
- for (let i = 0; i < tempArr.length; i++) {
- if (i == action.idx) {
- tempArr[i].time = action.date
- newState.assistLabel = [...tempArr]
- }
- let tmpVal = tempArr[i].value?tempArr[i].value.trim():tempArr[i].value;
- tmpString += (tempArr[i].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArr[i].time?'报告日期:'+tempArr[i].time:'')+';')
- }
- newState.assistLabel=[...tempArr]
- newState.dataString = tmpString
- return newState;
- }
- if (action.type == GET_ASSIST_SEARCH_LIST) { //右侧推送添加到左侧
- const newState = Object.assign({}, state);
- newState.list = action.list
- newState.assistVal = action.val
- return newState;
- }
- if (action.type == GET_ASSIST_LABEL) { //默认
- const newState = Object.assign({}, state);
- const tempArrs = newState.assistLabel;
- let tempArr = [];
- let tmpString = '';
- let tmpCommonLis = store.getState().homePage.assistList;
- if(action.sign == 'common'){
- let tmpAssistList = JSON.parse(JSON.stringify(tmpCommonLis))
- tempArr = tmpAssistList;
- }else{
- tempArr = newState.list
- }
- for (let i = 0; i < tempArr.length; i++) {
- if (tempArr[i].questionId == action.id && i == action.idx) {
- tempArr[i].time = getCurrentDate();
- tempArrs.push(tempArr[i]);
- newState.assistLabel = [...tempArrs];
- }
- }
- for (let j = 0; j < tempArrs.length; j++) {
- let tmpVal = tempArrs[j].value?tempArrs[j].value.trim():tempArrs[j].value;
- tmpString += (tempArrs[j].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArrs[j].time?'报告日期:'+tempArrs[j].time:'')+';')
- }
- newState.dataString = tmpString
- return newState;
- }
- if (action.type == DEL_ASSIST_LABEL) { //删除
- const newState = Object.assign({}, state);
- let tempArr = newState.assistLabel,tempArrs=[];
- let tmpString = '';
- // tempArr.splice(action.idx, 1)
- // let tempArrs = tempArr.slice()
- for(let k = 0;k < tempArr.length;k++){
- if(k != action.idx){
- tempArrs.push(tempArr[k])
- }
- }
- if(tempArrs == []){
- tmpString == ''
- return
- }
- for (let i = 0; i < tempArrs.length; i++) {
- let tmpVal = tempArrs[i].value?tempArrs[i].value.trim():tempArrs[i].value;
- tmpString += (tempArrs[i].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArrs[i].time?'报告日期:'+tempArrs[i].time:'')+';')
- }
- newState.assistLabel = [...tempArrs]
- newState.dataString = tmpString
- return newState;
- }
- if (action.type == CHANGE_ASSIST_VAL) { //改变输入值
- const newState = Object.assign({}, state);
- const tempArr = newState.assistLabel;
- let tmpString = '';
- for (let i = 0; i < tempArr.length; i++) {
- if (i == action.idx) {
- tempArr[i].value = action.val
- newState.assistLabel = [...tempArr]
- }
- let tmpVal = tempArr[i].value?tempArr[i].value.trim():tempArr[i].value;
- tmpString += (tempArr[i].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArr[i].time?'报告日期:'+tempArr[i].time:'')+';')
- }
- newState.dataString = tmpString
- return newState;
- }
- if (action.type == CHANGE_DATE) { //新增
- const newState = Object.assign({}, state);
- const tempArr = newState.assistLabel;
- let tmpString = '';
- for (let i = 0; i < tempArr.length; i++) {
- if (i == action.idx) {
- tempArr[i].time = action.date
- newState.assistLabel = [...tempArr]
- }
- let tmpVal = tempArr[i].value?tempArr[i].value.trim():tempArr[i].value;
- tmpString += (tempArr[i].name+(tmpVal?(':'+tmpVal)+', ':': ')+(tempArr[i].time?'报告日期:'+tempArr[i].time:'')+';')
- }
- newState.dataString = tmpString
- return newState;
- }
- if (action.type == CLEAR_ASSIST_DATA) {
- const newState = Object.assign({}, state);
- newState.assistLabel = [...action.data];
- newState.dataString = action.saveText;
- return newState;
- }
- return state;
- }
|