123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- import {getLabelIndex,fullfillText,getIds} from '@common/js/func.js';
- import config from '@config/index.js';
- function insertPro(data,processModule){//插入添加病情变化模板
- let index;
- for(let i=0; i<data.length; i++){
- if(data[i].flag && data[i].flag==3 ){
- index = i;
- }
- }
- for(let j=0; j<processModule.length; j++){
- let pos = index + j;
- data.splice(pos,0,processModule[j]);
- }
- return data;
- }
- //获取主诉模板
- export const setMainMoudle = (state,action) => {
- const res = Object.assign({},state);
- // const emptySpan = JSON.parse(config.textLabel);
- // let data = action.data.push(emptySpan);
- res.moduleData = action.data;
- res.saveText = res.save||[];
- res.addSmoduleData = action.addSymptom;
- res.addModuleName = action.addModuleName;
- res.update=Math.random();
- return res;
- }
- //获取常见症状
- export const getCommSymptoms = (state,action) => {
- const res = Object.assign({},state);
- res.CommonSymptoms = action.data;
- return res;
- }
- //清除常见症状
- export const clearCommSymptoms = (state,action) => {
- const res = Object.assign({},state);
- res.CommonSymptoms = [];
- return res;
- }
- //获取大数据推送症状
- export const getBigSymptom = (state,action) => {
- const res = Object.assign({},state);
- res.showDrop = !res.showDrop;
- res.bigDataSymptom = action.data;//推送数据
- let inlineDatas = res.data;
- const index = action.info.ikey;
- let labelInx = getLabelIndex(index);
- // 添加症状 暂时剔除没有id、questionMapping字段的数据
- let pushDataList = action.data;
- /*let pushDataList = action.data.filter(function(item){
- return item.id
- });*/
- let dataList = inlineDatas[labelInx].questionMapping;
- for(let k=0; k<dataList.length; k++){
- if(dataList[k].controlType == 99){
- dataList[k].questionDetailList = pushDataList;
- }
- }
- return res;
- }
- //点击插入新模板--添加病程变化
- export const handleTailClick = (state,action)=>{
- const res = Object.assign({},state);
- res.showDrop = !res.showDrop;
- let num = res.moduleNum.num;
- num++;
- const addSmoduleData = JSON.parse(JSON.stringify(res.addSmoduleData));
- // const addDatas = JSON.parse(JSON.stringify(fullfillText(action.info).newArr));
- let datas = JSON.parse(JSON.stringify(res.data));
- let leng = datas.length;
- for(let i=0; i<addSmoduleData.length; i++){
- addSmoduleData[i].pos = num;
- // let pos = leng-1+i;
- /* let pos = leng-2+i;
- datas.splice(pos,0,addDatas[i]);*/
- }
- res.data = insertPro(datas,addSmoduleData);
- res.saveText = fullfillText(res.data).saveText;
- res.moduleNum.num = num;
- return res;
- }
- //将选择的常见症状插入
- export const insertMain = (state,action) => {
- const res = Object.assign({},state);
- const item = action.item.name;
- const id = action.item.questionId;
- // 将选中的id存起,现病史时获取模板
- let data = JSON.parse(JSON.stringify(res.moduleData));
- const text = {id:id,name:item,value:item,tagType:config.tagType,exist:1};
- let inserIndx = null;
- data.map((it,i)=>{
- if(it.flag == 1){//在此处插入主诉数据
- inserIndx = i;
- }
- })
- data.splice(inserIndx-1,1,text);
- // data[inserIndx-1] = text;//替换空标签
- res.data = data;
- res.saveText = [];//将手动输入的值清掉
- // res.saveText[inserIndx] = text.name;
- res.saveText = fullfillText(res.data).saveText;
- res.mainIds.push(id);
- res.editClear = false;//主诉框编辑状态
- res.update=Math.random();
- return res;
- }
- function getTextLabel(id,name,flag){
- // exist 主症状1,伴随2
- return {id:id,name:name,value:name,tagType:config.tagType,exist:flag};
- }
- //多选标签选中确定处理
- export const confirm = (state,action) =>{
- const res = Object.assign({},state);
- let arr = res.data;
- let saveText = JSON.parse(JSON.stringify(res.saveText));
- const {exists,withs,ikey,withsName,existsName,ban} = action.data;
- let banText = JSON.stringify(ban) == "{}" ? '':{id:ban.id,name:ban.name,value:ban.name,tagType:config.tagType};
- let length = exists.length;
- let labelIndx = parseInt(ikey);//当前点击标签的index
- // 取第一个添加症状的主症状和伴随
- if(!arr[labelIndx].pos){
- let existsId = getIds(exists);
- let withsId = getIds(withs);
- res.mainIds = res.mainIds?res.mainIds.concat(existsId,withsId):[];
- }
- // 第二病程-伴位置处理
- let forwardId;
- let text;
- for(let n=labelIndx-1; n>0; n--){
- if(arr[n].id==8){
- forwardId = n;
- continue;
- }
- }
- if(forwardId){
- text = saveText.slice(forwardId,labelIndx);
- let index = text.indexOf('伴');
- if(index==-1){//没有伴,直接插入ikey前
- if(exists.length > 0){
- for(let i=0; i<exists.length; i++){
- let pos = labelIndx + i;
- arr.splice(pos,0,getTextLabel(exists[i].id,exists[i].name,1));
- res.saveText[pos] = exists[i].name;
- }
- }
- if(withs.length > 0){
- let newWiths = JSON.parse(JSON.stringify(withs));
- if(banText){
- newWiths.unshift(banText);
- }
- for(let j=0; j<newWiths.length; j++){
- let withsPos = labelIndx +length + j;
- arr.splice(withsPos,0,getTextLabel(newWiths[j].id,newWiths[j].name,2));
- res.saveText[withsPos] = newWiths[j].name;
- }
- }
- }else{//有伴
- if(exists.length > 0){
- for(let i=0; i<exists.length; i++){
- let pos = index + i;
- arr.splice(pos,0,getTextLabel(exists[i].id,exists[i].name,1));
- res.saveText[pos] = exists[i].name;
- }
- }
-
- if(withs.length>0){//有伴插到ikey前既可
- for(let j=0; j<withs.length; j++){
- // let withsPos = labelIndx + j;
- let withsPos = labelIndx +length + j;
- arr.splice(withsPos,0,getTextLabel(withs[j].id,withs[j].name,2));
- res.saveText[withsPos] = withs[j].name;
- }
- }
- }
- }else{
- let text = saveText.slice(0,labelIndx);
- let index = text.indexOf('伴');
- if(index==-1){//没有伴,直接插入ikey前
- if(exists.length > 0){
- for(let i=0; i<exists.length; i++){
- let pos = labelIndx + i;
- arr.splice(pos,0,getTextLabel(exists[i].id,exists[i].name,1));
- res.saveText[pos] = exists[i].name;
- }
- }
- if(withs.length > 0){
- let newWiths = JSON.parse(JSON.stringify(withs));
- if(banText){
- newWiths.unshift(banText);
- }
- for(let j=0; j<newWiths.length; j++){
- let withsPos = labelIndx +length + j;
- arr.splice(withsPos,0,getTextLabel(newWiths[j].id,newWiths[j].name,2));
- res.saveText[withsPos] = newWiths[j].name;
- }
- }
- }else{//有伴
- if(exists.length > 0){
- for(let i=0; i<exists.length; i++){
- let pos = index + i;
- arr.splice(pos,0,getTextLabel(exists[i].id,exists[i].name,1));
- res.saveText[pos] = exists[i].name;
- }
- }
-
- if(withs.length>0){//有伴插到ikey前既可
- for(let j=0; j<withs.length; j++){
- // let withsPos = labelIndx + j;
- let withsPos = labelIndx +length + j;
- arr.splice(withsPos,0,getTextLabel(withs[j].id,withs[j].name,2));
- res.saveText[withsPos] = withs[j].name;
- }
- }
- }
- }
-
- res.data = arr;
- res.saveText = fullfillText(arr).saveText;
- res.update=Math.random();
- return res;
- };
- // 普通多选确定事件
- export const commConfirm=(state,action)=>{
- const res = Object.assign({},state);
- const {exists,ikey,existsName} = action.data;
- // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
- let names=existsName;
- let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
- if(pattern.test(existsName)){
- names = existsName.substr(0,existsName.length-1);
- }
- let arr = res.data;
- arr[ikey].value = names;
- res.saveText[ikey] = names;
- res.selecteds[ikey] = action.data;
- res.update=Math.random();
- return res;
- }
- export const setSearch = (state,action)=>{
- const res = Object.assign({},state);
- res.showDrop = !res.showDrop;//防止不更新
- let searchData = action.data;
- res.searchDatas = searchData;
- res.searchStr = action.inpStr;
- return res;
- }
- //将选中的搜索结果插入
- export const insertSearch = (state,action)=>{
- // 如果没有模板就插入模板,有模板则只插入所传文字
- const res = Object.assign({},state);
- let data = res.data;
- let moduleData = JSON.parse(JSON.stringify(res.moduleData));
- let searchData = action.info.name;
- const id = action.info.questionId;
- let focusIndex = res.focusIndex;
- let span = action.span;
- let text = {id:id,name:searchData,value:searchData,tagType:config.tagType};
- const emptySpan = JSON.parse(config.textLabel);
- if(data.length==0){
- let inserIndx = null;
- moduleData.map((it,i)=>{
- if(it.flag == 1){//在此处插入主诉数据
- inserIndx = i;
- }
- })
- // flag=1前是文本标签就替换,否则插入
- const iftext = moduleData[inserIndx-1].tagType;
- if(iftext==config.tagType){
- moduleData.splice(inserIndx-1,1,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1});
- }else{
- moduleData.splice(inserIndx,0,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1});
- }
- // moduleData.splice(inserIndx,0,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1},emptySpan);
- res.saveText = [];//将手动输入的值清掉
- res.data = moduleData;
- // res.saveText[inserIndx] = searchData;
- res.saveText = fullfillText(res.data).saveText;
- res.mainIds.push(id);
- res.editClear = false;//主诉框编辑状态
- }else{
- // 替换
- /*span.current.innerText = '';
- res.data.splice(focusIndex,1,text);
- res.saveText[focusIndex] = searchData;
- res.mainIds.push(id);*/
- // 追加--前or后?searchStr
- /*const searchStr = res.searchStr;
- let innerText = span.current.innerText;
- let index = innerText.indexOf(searchStr);
- let value;
- if(index <= 1){//前
- value = innerText.replace(searchStr,searchData);
- }else{
- let temp = innerText.substring(0,innerText.lastIndexOf(searchStr));
- value = temp + searchData;
- }
- // let value = innerText + searchData;
- span.current.innerText = value;
- res.data[focusIndex].value = value;
- res.saveText[focusIndex] = value;*/
- /*******************第一病程搜索结果也移植到现病史修改(2-18)********************/
- // 位置判断-第一病程-主症状还是伴随 前一个标签存在 并且没有pos;
- // 判断在伴的前面还是后面:前exist=1(主),后exist=2(伴)
- let nText = {};
- if(focusIndex==0){
- nText = Object.assign({},text,{exist:1});
- }else{
- if(!data[focusIndex-1].pos){//第一病程
- const preText = res.saveText.slice(0,focusIndex);
- const ind = preText.indexOf("伴");
- if(ind != -1){
- nText = Object.assign({},text,{exist:2});
- }else{
- nText = Object.assign({},text,{exist:1});
- }
- }else{//第二及以上病程
- nText = Object.assign({},text);
- }
- }
-
- // 从新插入一个span标签
- const searchStr = res.searchStr;
- let innerText = span.current.innerText;
- const value = innerText.replace(searchStr,"");
- let index = innerText.indexOf(searchStr);
- if(index < 1){//前
- res.data.splice(focusIndex,0,nText);
- res.saveText.splice(focusIndex,0,searchData);
- res.data[focusIndex+1].value = value;
- res.saveText[focusIndex+1] = value;
- }else{
- res.data.splice(focusIndex+1,0,nText);
- res.saveText.splice(focusIndex+1,0,searchData);
- res.data[focusIndex].value = value;
- }
- span.current.innerText = value;
- res.mainIds.push(id);
- }
- // console.log(456,res,action);
- res.update=Math.random();
- return res;
- }
- //数字键盘选中事件
- export function setNumberValue(state,action){
- let res = Object.assign({},state);
- const param = action.params;
- const index = param.ikey;
- let labelInx = getLabelIndex(index);
- const subInx = index.substr(index.length-1);
- let item = res.data[labelInx];
- // if(param.text.trim()){
- if(+item.tagType===1){
- item.value = param.text;
- res.saveText[labelInx] = param.text?item.labelPrefix+param.text+item.labelSuffix:'';
- }else{
- item.questionMapping[subInx].value = param.text;
- let hasValue = false;
- const sub = item.questionMapping.map((it)=>{
- if(it.value){ //至少有一个子值才黑显
- hasValue = true;
- }
- return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
- });
- // res.saveText[labelInx] = sub.join(',');
- res.saveText[labelInx] = hasValue?sub.join(''):'';
- item.value = sub.join('');
- }
- /*}else{//删除完标签内容则删除该标签
- res.data.splice(labelInx,1);
- res.saveText = fullfillText(res.data).saveText;
- }*/
- res.update = Math.random();
- return res;
- }
- //单选下拉选中
- export function setRadioValue(state,action){
- let res = Object.assign({},state);
- const {ikey,id,text} = action;
- let labelInx = getLabelIndex(ikey);
- const subInx = ikey.substr(ikey.length-1);
- let item = res.data[labelInx];
- if(typeof text != 'string'){ //需要展开项--有无治疗类型
- const len = +item.copyType === 0?1:0;
- res.data.splice(labelInx,len,text);
- return res;
- }
- if(+item.tagType===1){
- item.value = text;
- res.saveText[labelInx] = item.labelPrefix+text+item.labelSuffix;
- item.questionDetailList.map((its)=>{
- if(its.id === id){
- its.selected = true;
- }else{
- its.selected = false;
- }
- });
- }else{
- item.questionMapping[subInx].value = text;
- let hasValue = false;
- const sub = item.questionMapping.map((it)=>{
- //添加选中状态
- it.questionDetailList.map((its)=>{
- if(its.id === id){
- its.selected = true;
- }else{
- its.selected = false;
- }
- });
- if(it.value){ //至少有一个子值才黑显
- hasValue = true;
- }
- return (it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||'');
- });
- // res.saveText[labelInx] = sub.join(',');
- res.saveText[labelInx] = hasValue?sub.join(''):'';
- item.value = sub.join('');
- }
- res.update = Math.random();
- return res;
- }
- //双击标签输入改变值
- export const changeLabelVal = (state,action)=>{
- const res = Object.assign({},state);
- const index = parseInt(action.data.ikey);
- const newVal = action.data.changeVal;
- let data = res.data;
- let item = data[index];
- const next = res.data[+index+1];
- const nextVal = next.value||next.name;
- //标签后是不是标点符号标签,是的话删除本标签时一起删除
- let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
- if(newVal&&newVal.trim()){
- if(item){
- item.value = newVal;
- res.saveText[index] = newVal;
- }
- }else{//删除完标签内容则删除该标签
- const num = nextIsDot?2:1;
- data.splice(index,num);
- // data[index].value = "";
- // res.data.splice(index,1);
- res.saveText.splice(index,1);
- // res.saveText[index] = "";
- }
- res.update = Math.random();
- return res;
- }
- // 数字键盘较特殊,有直接输入
- export const changeNumLabelVal = (state,action)=>{
- const res = Object.assign({},state);
- const {changeVal,totalVal,ikey,prefix,suffix} = action.data;
- const index = ikey;
- const newVal = changeVal;
- let labText = totalVal?totalVal:newVal; //如单选没有前后缀
- let item = res.data[index];
- const next = res.data[+index+1];
- const nextVal = next.value||next.name;
- //标签后是不是标点符号标签,是的话删除本标签时一起删除
- let nextIsDot = +next.tagType===8&&!nextVal.match(config.punctuationReg);
- if(labText.trim()){
- if(item){
- item.value = newVal;
- item.labelPrefix = prefix||'';
- item.labelSuffix = suffix||'';
- res.saveText[index] = labText;
- }
- }else{//删除完标签内容则删除该标签
- const num = nextIsDot?2:1;
- res.data.splice(index,num);
- res.saveText = fullfillText(res.data).saveText;
- }
- res.update = Math.random();//console.log(44,action,res);
- return res;
- }
- // 保存自由输入文本--无模板
- export const saveFreeVal = (state,action)=>{
- const res = Object.assign({},state);
- let data = action.data;
- res.saveText[0] = data;
- /*if(data.trim()){
- res.saveText[0] = data;
- }else{
- res.saveText = [];
- }*/
- res.update = Math.random();
- return res;
- }
- export const clearMainSuit = (state,action)=>{//回读和清除
- const res = Object.assign({},state);
- res.data = action.data;
- res.saveText = action.saveText;
- // res.saveText = fullfillText(action.data).saveText;//解决删除data里的值保存,回读后页面上有内容saveText里没有的情况
- res.selecteds = action.selecteds?action.selecteds:[];
- res.mainIds = action.mainIds;
- if(action.editClear){
- res.editClear = action.editClear;
- }
- if(res.data.length > 0){//回读
- res.editClear = false;
- }
- return res;
- }
- //文本模式下值保存
- export const setTextModeValue = (state,action)=>{
- const res = Object.assign({},state);
- res.saveText[0] = action.text;
- return res;
- };
- //自由文本
- export function setCheckText(state,action) {
- let res = Object.assign({},state);
- const {i,text} = action;
- res.data[i].value=text;
- res.saveText[i] = text;
- /*if(res.data[i]){
- res.data[i].value=text;
- }
- res.saveText[i] = text;*/
- res.update = Math.random();
- return res;
- }
- //复制标签(如血压)事件
- export function addLabelItem(state,action){
- let res = Object.assign({},state);
- const {data,i} = action;
- const textLabel = JSON.parse(config.textLabel);
- //使用Object.assign({},data)拷贝操作时复制项和原项会同步修改
- if(!data) return res;
- res.data.splice(i+1,0,JSON.parse(data),textLabel);
- res.update = Math.random();
- return res;
- }
- //文本输入标签
- export function setInputLabel(state,action){
- let res = Object.assign({},state);//console.log(state,action)
- const {i,text,prefix,suffix,subIndex} = action;
- const item = res.data[i];
- if(+item.tagType===3){ //multSpred标签
- item.questionMapping[subIndex].value = text;
- let texts = item.questionMapping.map((it)=>{
- return it.value?(it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''):'';
- });
- res.saveText[i] = texts.join('');
- res.update = Math.random();
- return res;
- }else{
- if(item){
- item.value=text;
- }
- }
- res.saveText[i] = prefix+text+suffix;//console.log(res)
- res.update = Math.random();
- return res;
- }
- // backspace删除
- export function backspaceText(state,action){
- let res = Object.assign({},state);
- const {delIndex} = action;
- const data = res.data;
- if(data[delIndex-1].flag&&data[delIndex-1].flag==3){
- // if(data[delIndex-1].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
- // 前一个是文本标签或者子模板 不做处理
- }else if(data[delIndex-1].tagType==8){
- data.splice(delIndex,1);
- res.saveText.splice(delIndex,1);
- }
- else{
- data.splice(delIndex-1,2);
- res.saveText.splice(delIndex-1,2);
- }
- // res.saveText = fullfillText(data).saveText;
- res.update = Math.random();
- return res;
- }
- //删除后移除id
- export function removeId(state,action){
- let res = Object.assign({},state);
- const {index,text} = action;
- const data = res.data;
- const id = data[index].id;
- let ids = res.mainIds;
- if(ids.includes(id)){
- ids.splice(ids.indexOf(id),1);
- }
- if(!data[index].value && data[index-1].tagType==8){
- data.splice(index,1);
- res.saveText.splice(index,1);
- }else{
- data[index].id = "";
- data[index].name = text;
- data[index].value = text;
- }
- res.update = Math.random();
- return res;
- }
- // 单列多选
- export function multipleComfirn(state,action){
- let res = Object.assign({},state);
- const {ikey,seleData} = action.data;
- let data = res.data;
- data[ikey].value = seleData;
- res.saveText[ikey] = seleData;
- res.selecteds[ikey] = action.data;
- res.update = Math.random();console.log(123,action,res);
- return res;
- }
|