Label.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="label-wrap bgques" v-if="item">
  3. <p v-for="(it,index) in datas.questionMapping" :key="it.id" :class="['symp',{'check':it.select==1},{'exclu':exclusion !==999 && it.exclusionType !== exclusion}]" @click="handleClick(it,index,true)">
  4. <span>{{it.description||it.name}}</span>
  5. <span v-if="it.select==1" @click="deletSymp($event,it,index)"><img src="../images/del.png" alt=""></span>
  6. </p>
  7. <Toast :message="delText"
  8. :show="showToast"
  9. @comfirn="comfirnDel"
  10. @cancel="cancelDel"/>
  11. </div>
  12. </template>
  13. <script>
  14. import Toast from '../common/Toast.vue';
  15. import {moduleCP} from '@utils/tools';
  16. import $ from 'jquery';
  17. export default {
  18. name:'Label',
  19. data(){
  20. return{
  21. datas:{},
  22. checkTxt:[],
  23. showToast:false,
  24. delText:"是否取消当前选中内容?",
  25. tempItem:{},
  26. exclusion:999, //互斥
  27. delIndx:null
  28. }
  29. },
  30. props:['item','moduleType','ppId','order'],
  31. created(){
  32. this.datas = this.item;
  33. // 回读互斥项标识
  34. const arr = this.datas.questionMapping;console.log(this.item,this.datas.questionMapping)
  35. const filArr = arr.filter(it=>it.select==1);
  36. if(filArr.length > 0){
  37. this.exclusion = filArr[0].exclusionType;
  38. }
  39. },
  40. components:{
  41. Toast
  42. },
  43. methods:{
  44. handleClick(it,index,flg){
  45. if(flg){
  46. document.activeElement.blur();
  47. document.activeElement.scrollIntoViewIfNeeded(true);
  48. setTimeout(()=>{
  49. document.activeElement.scrollIntoViewIfNeeded(true);
  50. },300)
  51. }
  52. const arr = this.datas.questionMapping;
  53. const excluArr = arr.filter(it=>it.exclusionType==1);
  54. const filArr = arr.filter(it=>it.select==1);
  55. if(excluArr.length>0){//有互斥
  56. if(filArr.length>0){//有选中
  57. if(it.exclusionType !== filArr[0].exclusionType){
  58. return
  59. }
  60. }
  61. this.exclusion = it.exclusionType;
  62. }
  63. const newItem = Object.assign({},it,{select:1});
  64. const origMapping = this.item.questionMapping;
  65. let mapping = this.datas.questionMapping;
  66. for(let i in origMapping){
  67. if(origMapping[i].id==it.id){
  68. mapping.splice(i,1,newItem)
  69. }
  70. }
  71. // 存值到store arrFlag:true说明要区分pId
  72. this.$store.commit('setDatas',{type:this.moduleType,data:newItem,pId:this.datas.id,ppId:this.ppId});
  73. this.$store.commit('setText',{type:this.moduleType,text:it.name,textP:(it.description||it.name),pId:it.id,order:this.order,index:index,arrFlag:true});
  74. if(it.questionMapping&&it.questionMapping.length>0){//有明细
  75. this.$store.commit('setDetail',{detail:it,ppId:this.ppId,moduleType:this.moduleType,order:this.order,index:index})
  76. }
  77. },
  78. deletSymp(e,it,index){
  79. e.stopPropagation();
  80. // 删除互斥项(无)不弹窗提醒 7-18
  81. this.delIndx = index;
  82. this.tempItem = it;
  83. if(it.exclusionType == 1){
  84. this.comfirnDel();
  85. return
  86. }
  87. this.showToast = true;
  88. $(".btscroll").css({'position':'fixed'})
  89. $(".foot").css({'position':'fixed','bottom':'0'})
  90. // 底部body不可滑动
  91. // const prehandler = function(e){e.preventDefault();}
  92. // document.body.addEventListener("touchmove",prehandler,false)
  93. },
  94. comfirnDel(){
  95. const temp = this.tempItem;
  96. // 从store中取origin的值
  97. let origin,newItem;
  98. if(this.moduleType==moduleCP['diagT']){
  99. origin = this.$store.state.diagnose.origin
  100. }else if(this.moduleType == moduleCP['other']){
  101. origin = this.$store.state.others.origin
  102. }
  103. if(origin){
  104. for(let i in origin){
  105. if(origin[i].id==this.ppId){
  106. let origItem = origin[i].questionMapping;
  107. for(let j in origItem){
  108. if(origItem[j].id==temp.id){
  109. newItem = origItem[j];
  110. }
  111. }
  112. }
  113. }
  114. let mapping = this.datas.questionMapping;
  115. for(let n in mapping){
  116. if(mapping[n].id==temp.id){
  117. mapping.splice(n,1,newItem)
  118. }
  119. }
  120. }
  121. // 是否解除互斥
  122. const arr = this.datas.questionMapping;
  123. const filArr = arr.filter(it=>it.select==1);
  124. if(filArr.length==0){
  125. this.exclusion = 999;
  126. }
  127. //存值
  128. this.$store.commit('setDatas',{type:this.moduleType,data:newItem,pId:this.datas.id,ppId:this.ppId});
  129. this.$store.commit('delText',{type:this.moduleType,pId:temp.id,order:this.order,index:this.delIndx});
  130. this.cancelDel();
  131. },
  132. cancelDel(){
  133. this.showToast = false;
  134. $(".btscroll").css({'position':'absolute','top':'0'})
  135. $(".foot").css({'position':'absolute','bottom':'0'})
  136. this.tempItem = {};
  137. this.delIndx = null;
  138. }
  139. }
  140. }
  141. </script>
  142. <style lang="less" scoped>
  143. @import '../less/base.less';
  144. .label-wrap{
  145. font-size: .3rem;
  146. .symp{
  147. display: inline-block;
  148. min-width:2.05rem;
  149. height: .72rem;
  150. border-radius: .08rem;
  151. span{
  152. display: inline-block;
  153. vertical-align: top;
  154. }
  155. span:first-child{
  156. min-width:1.42rem;
  157. height: .72rem;
  158. line-height: .72rem;
  159. text-align: center;
  160. }
  161. img{
  162. width:.48rem;
  163. height: .70rem;
  164. vertical-align: top;
  165. z-index: 22;
  166. }
  167. }
  168. .symp:last-child{
  169. margin-right: 0;
  170. }
  171. .check{
  172. color: #fff;
  173. background: #colors[btn];
  174. }
  175. .exclu{
  176. // background:#E3E4E8;
  177. }
  178. }
  179. </style>