Detail.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.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. </div>
  24. </div>
  25. </template>
  26. <script type="text/javascript">
  27. import Radio from '../common/Radio.vue';
  28. import CheckBox from '../common/CheckBox.vue';
  29. import Input from '../common/Input.vue';
  30. import ComTextArea from '../common/ComTextArea.vue';
  31. // 将获取到的数据源转换成私有数据,处理选择事件。点击完成后统一存到store中,便于回读
  32. export default {
  33. name:'Detail',
  34. data(){
  35. return{
  36. checkDatas:{},
  37. finished:false
  38. }
  39. },
  40. props:['datas','type','ppId'],
  41. created(){
  42. this.checkDatas = JSON.parse(JSON.stringify(this.datas));
  43. },
  44. components:{
  45. Radio,
  46. CheckBox,
  47. Input,
  48. ComTextArea
  49. },
  50. methods:{
  51. updataData(data){
  52. const origMapping = this.datas.questionMapping;
  53. let mapping = this.checkDatas.questionMapping;
  54. for(let i in origMapping){
  55. if(origMapping[i].id==data.id){
  56. mapping.splice(i,1,data)
  57. }
  58. }
  59. },
  60. saveData(){//存值
  61. this.finished = true;
  62. this.checkDatas = Object.assign({},this.checkDatas,{select:1});
  63. const datas = this.checkDatas.questionMapping;
  64. let text = "";
  65. for(let i in datas){
  66. if(datas[i].value){
  67. text += datas[i].value+',';
  68. }
  69. }
  70. // let msg = this.checkDatas.name+ ',' + text.substring(0,text.length-1);
  71. let msg = this.checkDatas.name+ ',' + text;
  72. let newMsg = "";
  73. if(msg[msg.length-1] == ','){
  74. newMsg = msg.substring(0,msg.length-1);
  75. }else{
  76. newMsg = msg
  77. }
  78. this.$store.commit('setDatas',{data:this.checkDatas,pId:this.checkDatas.id,type:this.type,ppId:this.ppId});
  79. // flag是区分点开已选症状 未点完成
  80. this.$store.commit('setText',{text:newMsg,pId:this.checkDatas.id,type:this.type,flag:true});
  81. },
  82. clearData(){//清空
  83. const datas = this.checkDatas.questionMapping;
  84. for(let i in datas){
  85. datas[i].value = "";
  86. let detaiList = datas[i].questionDetailList;
  87. if(detaiList.length>0){
  88. for(let k in detaiList){
  89. detaiList[k].select = 0;
  90. if(detaiList[k].value){
  91. detaiList[k].value = "";
  92. }
  93. }
  94. }
  95. }
  96. this.checkDatas = Object.assign({},this.checkDatas,{questionMapping:datas});
  97. let msg = this.checkDatas.name;
  98. this.$store.commit('setDatas',{data:this.checkDatas,pId:this.checkDatas.id,type:this.type,ppId:this.ppId});
  99. this.$store.commit('setText',{text:msg,pId:this.checkDatas.id,type:this.type,flag:true});
  100. }
  101. },
  102. }
  103. </script>
  104. <style lang="less" scoped>
  105. .detail-wrap{
  106. padding: .3rem .5rem 1.2rem .6rem;
  107. font-size: .3rem;
  108. .quest{
  109. color:#000;
  110. margin-bottom: .2rem;
  111. }
  112. }
  113. </style>