123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- import config from '@config/index.js';
- import {getLabelIndex,fullfillText} from '@common/js/func.js';
- //设置查体数据
- export function set(state,action){
- let res = Object.assign({},state);
- const {data} = action;
- res.data = [...data];
- res.saveText = fullfillText(res.data).saveText;//存逗号
- res.update = Math.random();
- res.isEmpty = false;
- return res;
- }
- //查体中数字键盘选中事件
- export function setNumberValue(state,action){
- let res = Object.assign({},state);
- const param = action.params;
- const ikey = param.ikey;
- let labelInx = getLabelIndex(ikey);
- const subInx = ikey.substr(ikey.length-1);
- let item = res.data[labelInx];
- 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] = hasValue?sub.join(''):'';
- }
- // 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] = hasValue?sub.join(''):'';
- }
- // res.saveText = fullfillText(res.data).saveText;
- 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+2,0,JSON.parse(data),textLabel);
- res.saveText.splice(+i+2,0,'','');
- res.selecteds.splice(+i+2,0,null,null);
- res.update = Math.random();
- return res;
- }
- //自由文本
- export function setCheckText(state,action) {
- let res = Object.assign({},state);
- const {i,text} = action;
- if(res.data[i]){
- res.data[i].value=text;
- //res.data[i].name=''; //默认显示的文字
- }
- res.saveText[i] = text;
- res.update = Math.random();
- return res;
- }
- //多选文字,如杂音
- export function setCheckBoxValue(state,action) {
- let res = Object.assign({},state);
- const {labelInx,excluName,existsName,nones,withsName} = action.data;
- let showText = (excluName||'')+(existsName||'')+(nones||'')+(withsName||'');
- // 若每个选项都有符号,去掉最后一个,因与标签间的符号有冲突
- let pattern = new RegExp(/\,+$|\,+$|\.+$|\。+$|\、+$/);//+ 一次或多次
- if(pattern.test(showText)){
- showText = showText.substr(0,showText.length-1);
- }
- res.data[labelInx].value = showText;
- res.saveText[labelInx] = showText;
- res.selecteds[labelInx] = action.data;
- res.saveText = fullfillText(res.data).saveText;
- res.update = Math.random();
- return res;
- }
- //搜索结果
- export function setSearchData(state,action){
- let res = Object.assign({},state);
- res.searchData = action.data;
- res.searchStr = action.inpStr;
- res.searchInEnd = action.isEnd;
- return res;
- }
- //插入标签数据-搜索
- export function insertLabelData(state,action){
- let res = Object.assign({},state);
- const text = Object.assign({},JSON.parse(config.textLabel));
- const searchStr = res.searchStr;
- const {index,data,isReplace,span,searchInEnd}=action;
- const showText = res.saveText[index];
- const spreadLabels = data;
- let reg = searchInEnd?new RegExp(searchStr+"$"):new RegExp("^"+searchStr);
- const newText=showText.replace(reg,'')||'';
- if(!isReplace){
- span.current.innerText = newText;
- const pText = Object.assign({},text,{value:newText});
- if(searchInEnd){
- res.data.splice(index,1,pText,spreadLabels,text);
- res.saveText.splice(index,1,newText,'','');
- res.selecteds.splice(index,1,null,null,null);
- }else{
- res.data.splice(index,1,text,spreadLabels,pText);
- res.saveText.splice(index,1,'','',newText);
- res.selecteds.splice(index,1,null,null,null);
- }
- }else{
- span.current.innerText = ' ';
- if(searchInEnd){
- res.data.splice(index+1,0,spreadLabels,text);
- res.saveText.splice(index+1,0,'','');
- res.selecteds.splice(index+1,0,null,null);
- }else{
- res.data.splice(index,0,text,spreadLabels);
- res.saveText.splice(index,0,'','');
- res.selecteds.splice(index,0,null,null);
- }
- }
- res.searchData = []; //选中清空搜索内容(即关闭搜索弹窗)
- res.update = Math.random();
- return res;
- }
- export const changeLabelVal = (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];
- // if(newVal && newVal.trim()){
- if(labText && labText.trim()){
- if(item){
- item.value = newVal;
- item.labelPrefix = prefix;
- item.labelSuffix = suffix;
- // res.saveText[index] = totalVal;
- res.saveText[index] = labText;
- }
- }else{//删除完标签内容则删除该标签
- res.data.splice(index,1);
- res.saveText = fullfillText(res.data).saveText;
- }
- 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 item = res.data[index];
- if(totalVal.trim()){
- if(item){
- item.value = newVal;
- item.labelPrefix = prefix;
- item.labelSuffix = suffix;
- }
- res.saveText[index] = totalVal;
- }else{//删除完标签内容则删除该标签
- res.data.splice(index,1);
- res.saveText = fullfillText(res.data).saveText;
- }
-
- res.update = Math.random();
- return res;
- }
- export function clearCheckBody(state,action){ //清空
- let res = Object.assign({},state);
- res.data = action.data;
- res.saveText = action.saveText;
- res.isEmpty = action.isEmpty;
- res.selecteds = action.selecteds?action.selecteds:[];
- 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].tagType==8 ||data[delIndex-1].flag&&data[delIndex-1].flag==3){
- // 前一个是文本标签或者子模板 不做处理
- }else{
- data.splice(delIndex-1,2);
- }
- res.saveText = fullfillText(data).saveText;
- res.update = Math.random();
- return res;
- }
|