Detail.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <div class="detail-wrap">
  3. <!-- <div v-for="(item,index) in datas"> -->
  4. <div v-for="(item,index) in checkDatas.questionMapping">
  5. <p class="quest"><span v-show="item.required==1" style="color: red;">*</span>{{index + 1 +'.' + (item.description || item.name)}}</p>
  6. <img class="questionImg" :src="item.url.replace('{imageUrlPrefix}',imgUrl)" v-if="item.url">
  7. <Radio v-if="item.controlType==1"
  8. :item="item"
  9. :key="item.id"
  10. @updata="updataData"/>
  11. <RadioSelect v-if="item.controlType==8"
  12. :item="item"
  13. :key="item.id"
  14. @updata="updataData"/>
  15. <CheckBox v-if="item.controlType==2"
  16. :item="item"
  17. :key="item.id"
  18. @updata="updataData"/>
  19. <!-- 文本域 -->
  20. <ComTextArea v-if="item.controlType == 5"
  21. :item="item"
  22. @updata="updataData"/>
  23. <!-- 输入框 -->
  24. <Input v-if="item.controlType==6 || item.controlType==7"
  25. :item="item"
  26. :key="item.id"
  27. @updata="updataData"/>
  28. <template
  29. v-if="item.controlType == 3"
  30. v-for="(part,index) in item.questionDetailList"
  31. >
  32. <MultiLineInput
  33. v-if="item.controlType == 3"
  34. :msg="part.description||part.name"
  35. :part="part"
  36. @updata="updataData($event,item)"
  37. ></MultiLineInput>
  38. </template>
  39. </div>
  40. </div>
  41. </template>
  42. <script type="text/javascript">
  43. import Radio from '../common/Radio.vue';
  44. import CheckBox from '../common/CheckBox.vue';
  45. import Input from '../common/Input.vue';
  46. import ComTextArea from '../common/ComTextArea.vue';
  47. import RadioSelect from '../common/RadioSelect.vue';
  48. import MultiLineInput from '../common/MultiLineInput.vue';
  49. import {patt,trimDots,imageUrlPrefix} from '@utils/tools.js'
  50. // 将获取到的数据源转换成私有数据,处理选择事件。点击完成后统一存到store中,便于回读
  51. export default {
  52. name:'Detail',
  53. data(){
  54. return{
  55. checkDatas:{},
  56. imgUrl:imageUrlPrefix,
  57. }
  58. },
  59. props:['datas','data'],
  60. created(){
  61. this.checkDatas = JSON.parse(JSON.stringify(this.datas));
  62. },
  63. components:{
  64. Radio,
  65. CheckBox,
  66. Input,
  67. ComTextArea,
  68. MultiLineInput,
  69. RadioSelect
  70. },
  71. methods:{
  72. updataData(data,item){
  73. const origMapping = this.datas.questionMapping;
  74. let mapping = this.checkDatas.questionMapping;
  75. for(let i in origMapping){
  76. if(data.controlType==3){//多列类型多一层
  77. if(mapping[i].id == item.id){
  78. let tempVal = '';
  79. let tempValP = '';
  80. let detList = mapping[i].questionDetailList;
  81. for(let k in detList){//替换
  82. if(detList[k].id==data.id){
  83. detList.splice(k,1,data)
  84. }
  85. }
  86. for(let n in detList){//给父级赋值
  87. if(detList[n].value){
  88. tempVal += detList[n].name.replace(patt,detList[n].value)+',';
  89. tempValP += (detList[n].description||detList[n].name).replace(patt,detList[n].value)+',';
  90. // 去掉最后一个逗号
  91. mapping[i].value = tempVal.substring(0,tempVal.length-1);
  92. mapping[i].valueP = tempValP.substring(0,tempValP.length-1);
  93. }
  94. }
  95. }
  96. }else{
  97. if(origMapping[i].id==data.id){
  98. mapping.splice(i,1,data)
  99. }
  100. }
  101. }
  102. // 实时更新清空样式
  103. if(data.value){
  104. this.$emit('check',true)
  105. }else{
  106. let flag = this.check();
  107. if(flag){
  108. this.$emit('check',true)
  109. }else{
  110. this.$emit('check',false)
  111. }
  112. }
  113. // 更新完成样式
  114. let checkReq = this.checkReq();
  115. if(checkReq){
  116. this.$emit('checkReq',true)
  117. }else{
  118. this.$emit('checkReq',false)
  119. }
  120. },
  121. saveData(){//存值
  122. this.checkDatas = Object.assign({},this.checkDatas,{select:1});
  123. const datas = this.checkDatas.questionMapping;
  124. const id = this.checkDatas.id;
  125. let chooseSymp = this.$store.state.symptom.choose;
  126. let text = ""; //医生
  127. let textP = "";//患者
  128. let special = ""; //拼到主诉
  129. let specialP = "";
  130. for(let i in datas){
  131. // 校验必填项
  132. /* if(datas[i].required==1 && !datas[i].value){
  133. alert("请先将必填项填完");
  134. return
  135. }*/
  136. // 拼到主诉
  137. if(datas[i].specFlag==1 && datas[i].value){
  138. special += datas[i].value;
  139. specialP += datas[i].valueP;
  140. }
  141. if(datas[i].value){
  142. text += datas[i].value+',';
  143. textP += datas[i].valueP+',';
  144. }
  145. }
  146. if(special){//拼接到主诉的内容存到chooseSymp
  147. for(let k in chooseSymp){
  148. if(id == (chooseSymp[k].id ||chooseSymp[k].questionId)){
  149. chooseSymp[k].special = special;
  150. chooseSymp[k].specialP = specialP;
  151. }
  152. }
  153. }
  154. let msg = this.checkDatas.name+ ',' + text;
  155. let msgP = (this.checkDatas.description || this.checkDatas.name)+ ',' + textP;
  156. let newMsg = "";
  157. let newMsgP = "";
  158. if(msg[msg.length-1] == ','){
  159. newMsg = msg.substring(0,msg.length-1);
  160. newMsgP = msgP.substring(0,msgP.length-1);
  161. }else{
  162. newMsg = msg;
  163. newMsgP = msgP;
  164. }
  165. this.$store.commit('setDatas',{data:this.checkDatas,pId:id,type:this.data.moduleType,ppId:this.data.ppId});
  166. // flag是区分点开已选症状 未点完成
  167. this.$store.commit('setText',{text:trimDots(newMsg),textP:trimDots(newMsgP),pId:id,type:this.data.moduleType,flag:true,order:this.data.order,arrFlag:true,index:this.data.index});
  168. // 关闭详情
  169. this.$store.commit('setDetail',{detail:{}})
  170. },
  171. clearData(){//清空
  172. // const datas = this.checkDatas.questionMapping;
  173. const datas = JSON.parse(JSON.stringify(this.checkDatas.questionMapping))
  174. let reqFlag = false;//必填项标识
  175. for(let i in datas){
  176. datas[i].value = "";
  177. datas[i].valueP = "";
  178. if(datas[i].required==1){
  179. reqFlag = true;
  180. }
  181. let detaiList = datas[i].questionDetailList;
  182. if(detaiList.length>0){
  183. for(let k in detaiList){
  184. detaiList[k].select = 0;
  185. if(detaiList[k].value){
  186. detaiList[k].value = "";
  187. detaiList[k].valueP = "";
  188. }
  189. }
  190. }
  191. }
  192. this.checkDatas = Object.assign({},this.checkDatas,{questionMapping:datas});
  193. // 已有选中内容重新进来,点清空时并非真的清空
  194. if(this.checkDatas.select ==1){return}
  195. let msg = this.checkDatas.name;
  196. let msgP = (this.checkDatas.description||this.checkDatas.name);
  197. // 没有点过完成直接选择然后清空,外层不会处于选中状态,故没有必填项时添加{select:1}
  198. if(reqFlag){
  199. this.$store.commit('setDatas',{data:this.checkDatas,pId:this.checkDatas.id,type:this.data.moduleType,ppId:this.data.ppId});
  200. }else{
  201. this.$store.commit('setDatas',{data:Object.assign({},this.checkDatas,{select:1}),pId:this.checkDatas.id,type:this.data.moduleType,ppId:this.data.ppId});
  202. }
  203. this.$store.commit('setText',{text:msg,textP:msgP,pId:this.checkDatas.id,type:this.data.moduleType,flag:true,order:this.data.order,arrFlag:true,index:this.data.index});
  204. },
  205. check(){// 校验是否有已填项
  206. const datas = this.checkDatas.questionMapping;
  207. let checkArr = [];
  208. for(let i in datas){
  209. if(datas[i].value){
  210. checkArr.push(datas[i]);
  211. }
  212. let detaiList = datas[i].questionDetailList;
  213. if(detaiList.length>0){
  214. for(let k in detaiList){
  215. if(detaiList[k].select == 1){
  216. checkArr.push(detaiList[k]);
  217. }
  218. }
  219. }
  220. }
  221. if(checkArr.length>0){
  222. return true;
  223. }
  224. return false;
  225. },
  226. checkReq(){// 校验必填项
  227. const datas = this.checkDatas.questionMapping;
  228. for(let k in datas){
  229. if(datas[k].required==1 && !datas[k].value){
  230. return false;
  231. }
  232. }
  233. return true;
  234. }
  235. },
  236. }
  237. </script>
  238. <style lang="less" scoped>
  239. @import '../less/base.less';
  240. .detail-wrap{
  241. // padding: .3rem .5rem 1.2rem .6rem;
  242. padding: .3rem .4rem 1rem ;
  243. font-size: .3rem;
  244. .quest{
  245. color:#colors[quest];
  246. margin-bottom: .2rem;
  247. }
  248. .questionImg {
  249. width: 100%;
  250. }
  251. }
  252. </style>