Label.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div class="label-wrap" 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)">
  4. <span>{{it.description||it.name}}</span>
  5. <!-- <span v-if="it.select==1" @click="deletSymp($event,it,index)"><img src="../images/delete.png" alt=""></span> -->
  6. <span v-if="it.select==1" @click="deletSymp($event,it,index)"><img src="../images/del.png" alt=""></span>
  7. </p>
  8. <Toast :message="delText"
  9. :show="showToast"
  10. @comfirn="comfirnDel"
  11. @cancel="cancelDel"/>
  12. </div>
  13. </template>
  14. <script type="text/javascript">
  15. import Toast from '../common/Toast.vue';
  16. import {moduleCP} from '@utils/tools';
  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. }
  28. },
  29. props:['item','moduleType','ppId'],
  30. created(){
  31. this.datas = this.item;
  32. // 回读互斥项标识
  33. const arr = this.datas.questionMapping;
  34. const filArr = arr.filter(it=>it.select==1);
  35. if(filArr.length > 0){
  36. this.exclusion = filArr[0].exclusionType;
  37. }
  38. },
  39. components:{
  40. Toast
  41. },
  42. methods:{
  43. handleClick(it,index){
  44. const arr = this.datas.questionMapping;
  45. const excluArr = arr.filter(it=>it.exclusionType==1);
  46. const filArr = arr.filter(it=>it.select==1);
  47. if(excluArr.length>0){//有互斥
  48. if(filArr.length>0){//有选中
  49. if(it.exclusionType !== filArr[0].exclusionType){
  50. return
  51. }
  52. }
  53. this.exclusion = it.exclusionType;
  54. }
  55. const newItem = Object.assign({},it,{select:1});
  56. const origMapping = this.item.questionMapping;
  57. let mapping = this.datas.questionMapping;
  58. for(let i in origMapping){
  59. if(origMapping[i].id==it.id){
  60. mapping.splice(i,1,newItem)
  61. }
  62. }
  63. // 存值到store
  64. this.$store.commit('setDatas',{type:this.moduleType,data:newItem,pId:this.datas.id,ppId:this.ppId});
  65. this.$store.commit('setText',{type:this.moduleType,text:it.name,pId:it.id});
  66. if(it.questionMapping&&it.questionMapping.length>0){//有明细
  67. this.$emit("setDetail",{detail:it,ppId:this.ppId})
  68. }
  69. },
  70. deletSymp(e,it,index){
  71. e.stopPropagation();
  72. // 删除互斥项(无)不弹窗提醒 7-18
  73. this.tempItem = it;
  74. if(it.exclusionType == 1){
  75. this.comfirnDel();
  76. return
  77. }
  78. this.showToast = true;
  79. },
  80. comfirnDel(){
  81. const temp = this.tempItem;
  82. // 从store中取origin的值
  83. let origin,newItem;
  84. if(this.moduleType==moduleCP['diagT']){
  85. origin = this.$store.state.diagnose.origin
  86. }else if(this.moduleType == moduleCP['other']){
  87. origin = this.$store.state.others.origin
  88. }
  89. if(origin){
  90. for(let i in origin){
  91. if(origin[i].id==this.ppId){
  92. let origItem = origin[i].questionMapping;
  93. for(let j in origItem){
  94. if(origItem[j].id==temp.id){
  95. newItem = origItem[j];
  96. }
  97. }
  98. }
  99. }
  100. let mapping = this.datas.questionMapping;
  101. for(let n in mapping){
  102. if(mapping[n].id==temp.id){
  103. mapping.splice(n,1,newItem)
  104. }
  105. }
  106. }
  107. // 是否解除互斥
  108. const arr = this.datas.questionMapping;
  109. const filArr = arr.filter(it=>it.select==1);
  110. if(filArr.length==0){
  111. this.exclusion = 999;
  112. }
  113. //存值
  114. this.$store.commit('setDatas',{type:this.moduleType,data:newItem,pId:this.datas.id,ppId:this.ppId});
  115. this.$store.commit('delText',{type:this.moduleType,pId:temp.id});
  116. this.cancelDel();
  117. },
  118. cancelDel(){
  119. this.showToast = false;
  120. this.tempItem = {};
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="less" scoped>
  126. .label-wrap{
  127. font-size: .3rem;
  128. .symp{
  129. // position: relative;
  130. display: inline-block;
  131. min-width:1.9rem;
  132. height: .72rem;
  133. span{
  134. display: inline-block;
  135. vertical-align: top;
  136. }
  137. span:first-child{
  138. // min-width:1.34rem;
  139. min-width:1.42rem;
  140. height: .72rem;
  141. line-height: .72rem;
  142. text-align: center;
  143. }
  144. img{
  145. // width:.56rem;
  146. width:.48rem;
  147. height: .70rem;
  148. vertical-align: top;
  149. z-index: 22;
  150. // position: absolute;
  151. // top:0;
  152. // right: 0;
  153. }
  154. }
  155. .symp:last-child{
  156. margin-right: 0;
  157. }
  158. .check{
  159. color: #fff;
  160. // background: linear-gradient(-270deg, #4F4FFF, #4F8BFF);
  161. background: linear-gradient(-270deg, #3638EE, #4E72FF);
  162. box-shadow: 0 .08rem .16rem 0 rgba(79,129,255,0.40);
  163. // padding-right: 0.57rem;
  164. }
  165. .exclu{
  166. // background:#f0f1f5;
  167. background:#E3E4E8;
  168. }
  169. }
  170. </style>