Detail.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. <Radio v-if="item.controlType==1"
  6. :item="item"
  7. :indx="index+1"
  8. :key="item.id"
  9. @updata="updataData"/>
  10. <CheckBox v-if="item.controlType==2" :item="item" :indx="index+1"/>
  11. <!-- 输入框 -->
  12. <div class="inp" v-if="item.controlType==6">
  13. <p class="name">{{index+1+'.'+item.name}}</p>
  14. <input type="" name="">
  15. </div>
  16. </div>
  17. </div>
  18. </template>
  19. <script type="text/javascript">
  20. import Radio from '../common/Radio.vue';
  21. import CheckBox from '../common/CheckBox.vue';
  22. // 将获取到的数据源转换成私有数据,处理选择事件。点击完成后统一存到store中,便于回读
  23. export default {
  24. name:'Detail',
  25. data(){
  26. return{
  27. checkDatas:{}
  28. }
  29. },
  30. props:['datas'],
  31. created(){
  32. this.checkDatas = JSON.parse(JSON.stringify(this.datas));
  33. },
  34. components:{
  35. Radio,
  36. CheckBox
  37. },
  38. methods:{
  39. updataData(data){
  40. const origMapping = this.datas.questionMapping;
  41. let mapping = this.checkDatas.questionMapping;
  42. for(let i in origMapping){
  43. if(origMapping[i].id==data.id){
  44. mapping.splice(i,1,data)
  45. }
  46. }
  47. },
  48. saveData(){//存值
  49. const datas = this.checkDatas.questionMapping;
  50. let text = "";
  51. for(let i in datas){
  52. if(datas[i].value){
  53. text += datas[i].value+',';
  54. }
  55. }
  56. let msg = this.checkDatas.name+ ',' + text;
  57. this.$store.commit('setDatas',{data:this.checkDatas,pId:this.checkDatas.id,type:"1"});
  58. this.$store.commit('setText',{text:msg,pId:this.checkDatas.id,type:"1"});
  59. }
  60. },
  61. /*watch:{
  62. checkDatas:{
  63. handler(newVal,oldVal){
  64. console.log("详情数据更新:",newVal,oldVal);
  65. },
  66. deep:true
  67. }
  68. },*/
  69. }
  70. </script>
  71. <style lang="less" scoped>
  72. .detail-wrap{
  73. padding: .3rem .5rem .3rem .6rem;
  74. }
  75. </style>