Detail.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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">{{index + 1 +'.' + (item.description || item.name)}}</p>
  6. <Radio v-if="item.controlType==1"
  7. :item="item"
  8. :key="item.id"
  9. @updata="updataData"/>
  10. <CheckBox v-if="item.controlType==2"
  11. :item="item"
  12. :key="item.id"
  13. @updata="updataData"/>
  14. <!-- 文本域 -->
  15. <ComTextArea v-if="item.controlType == 5"
  16. :item="item"
  17. @updata="updataData"/>
  18. <!-- 输入框 -->
  19. <Input v-if="item.controlType==6 || item.controlType==7"
  20. :item="item"
  21. :key="item.id"
  22. @updata="updataData"/>
  23. <template
  24. v-if="item.controlType == 3"
  25. v-for="(part,index) in item.questionDetailList"
  26. >
  27. <MultiLineInput
  28. v-if="item.controlType == 3"
  29. :msg="part.description||part.name"
  30. :part="part"
  31. @updata="updataData($event,item)"
  32. ></MultiLineInput>
  33. </template>
  34. </div>
  35. </div>
  36. </template>
  37. <script type="text/javascript">
  38. import Radio from '../common/Radio.vue';
  39. import CheckBox from '../common/CheckBox.vue';
  40. import Input from '../common/Input.vue';
  41. import ComTextArea from '../common/ComTextArea.vue';
  42. import MultiLineInput from '../common/MultiLineInput.vue';
  43. import {patt} from '@utils/tools.js'
  44. // 将获取到的数据源转换成私有数据,处理选择事件。点击完成后统一存到store中,便于回读
  45. export default {
  46. name:'Detail',
  47. data(){
  48. return{
  49. checkDatas:{},
  50. finished:false
  51. }
  52. },
  53. props:['datas','type','ppId'],
  54. created(){
  55. this.checkDatas = JSON.parse(JSON.stringify(this.datas));
  56. },
  57. components:{
  58. Radio,
  59. CheckBox,
  60. Input,
  61. ComTextArea,
  62. MultiLineInput
  63. },
  64. methods:{
  65. updataData(data,item){
  66. const origMapping = this.datas.questionMapping;
  67. let mapping = this.checkDatas.questionMapping;
  68. for(let i in origMapping){
  69. if(data.controlType==3){//多列类型多一层
  70. if(mapping[i].id == item.id){
  71. mapping[i].value = '';
  72. mapping[i].valueP = '';
  73. let detList = mapping[i].questionDetailList;
  74. for(let k in detList){//替换
  75. if(detList[k].id==data.id){
  76. detList.splice(k,1,data)
  77. }
  78. }
  79. for(let n in detList){//给父级赋值
  80. if(detList[n].value){
  81. mapping[i].value += detList[n].value+',';
  82. mapping[i].valueP += detList[n].valueP+',';
  83. }
  84. }
  85. }
  86. }else{
  87. if(origMapping[i].id==data.id){
  88. mapping.splice(i,1,data)
  89. }
  90. }
  91. }
  92. // 实时更新清空样式
  93. if(data.value){
  94. this.$emit('check',true)
  95. }else{
  96. let flag = this.check();
  97. if(flag){
  98. this.$emit('check',true)
  99. }else{
  100. this.$emit('check',false)
  101. }
  102. }
  103. },
  104. saveData(){//存值
  105. this.finished = true;
  106. this.checkDatas = Object.assign({},this.checkDatas,{select:1});
  107. const datas = this.checkDatas.questionMapping;
  108. let text = ""; //医生
  109. let textP = "";//患者
  110. for(let i in datas){
  111. if(datas[i].value){
  112. text += datas[i].value+',';
  113. textP += datas[i].valueP+',';
  114. }
  115. }
  116. let msg = this.checkDatas.name+ ',' + text;
  117. let msgP = (this.checkDatas.description || this.checkDatas.name)+ ',' + textP;
  118. let newMsg = "";
  119. let newMsgP = "";
  120. if(msg[msg.length-1] == ','){
  121. newMsg = msg.substring(0,msg.length-1);
  122. newMsgP = msgP.substring(0,msgP.length-1);
  123. }else{
  124. newMsg = msg;
  125. newMsgP = msgP;
  126. }
  127. this.$store.commit('setDatas',{data:this.checkDatas,pId:this.checkDatas.id,type:this.type,ppId:this.ppId});
  128. // flag是区分点开已选症状 未点完成
  129. // this.$store.commit('setText',{text:newMsg.replace(patt,''),pId:this.checkDatas.id,type:this.type,flag:true});
  130. // 输入框的值用占位符#{}标识,便于修改
  131. this.$store.commit('setText',{text:newMsg.replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,''),textP:newMsgP.replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,''),pId:this.checkDatas.id,type:this.type,flag:true});
  132. },
  133. clearData(){//清空
  134. const datas = this.checkDatas.questionMapping;
  135. for(let i in datas){
  136. datas[i].value = "";
  137. datas[i].valueP = "";
  138. let detaiList = datas[i].questionDetailList;
  139. if(detaiList.length>0){
  140. for(let k in detaiList){
  141. detaiList[k].select = 0;
  142. if(detaiList[k].value){
  143. detaiList[k].value = "";
  144. detaiList[k].valueP = "";
  145. }
  146. }
  147. }
  148. }
  149. this.checkDatas = Object.assign({},this.checkDatas,{questionMapping:datas});
  150. let msg = this.checkDatas.name;
  151. let msgP = (this.checkDatas.description||this.checkDatas.name);
  152. this.$store.commit('setDatas',{data:this.checkDatas,pId:this.checkDatas.id,type:this.type,ppId:this.ppId});
  153. this.$store.commit('setText',{text:msg,textP:msgP,pId:this.checkDatas.id,type:this.type,flag:true});
  154. },
  155. check(){// 校验是否有已填项
  156. const datas = this.checkDatas.questionMapping;
  157. let checkArr = [];
  158. for(let i in datas){
  159. if(datas[i].value){
  160. checkArr.push(datas[i]);
  161. }
  162. let detaiList = datas[i].questionDetailList;
  163. if(detaiList.length>0){
  164. for(let k in detaiList){
  165. if(detaiList[k].select == 1){
  166. checkArr.push(detaiList[k]);
  167. }
  168. }
  169. }
  170. }
  171. if(checkArr.length>0){
  172. return true;
  173. }
  174. return false;
  175. }
  176. },
  177. }
  178. </script>
  179. <style lang="less" scoped>
  180. .detail-wrap{
  181. // padding: .3rem .5rem 1.2rem .6rem;
  182. padding: .3rem .5rem 2rem .6rem;
  183. font-size: .3rem;
  184. .quest{
  185. color:#000;
  186. margin-bottom: .2rem;
  187. }
  188. }
  189. </style>