Radio.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <!-- <portal to="notification-outlet">-->
  3. <div class="select">
  4. <ul class="clearfix">
  5. <li
  6. v-for="(item,idx) in result"
  7. :class="[{'liSelect':item.select,'noBorder':((item.description||item.name).indexOf('${'))!=-1}]"
  8. :key="item.id"
  9. @click="selectResult(item,idx)"
  10. >
  11. <span v-if="((item.description||item.name).indexOf('${'))==-1">{{item.description||item.name}}</span>
  12. <OptionInp v-else :item="item" @handleInp="inpVal" :inx="idx" @handleSelec="handleClick(item,idx,false,true)"/>
  13. </li>
  14. </ul>
  15. <div :class="sure?'realSure sure':'sure'" @click="makeSuer">
  16. 确定
  17. </div>
  18. </div>
  19. <!--</portal>-->
  20. </template>
  21. <script>
  22. import OptionInp from '../common/OptionInp.vue';
  23. import {concatVal,getExpStr} from '../utils/tools.js';
  24. export default {
  25. props: ["symptomResult","num"],
  26. data() {
  27. return {
  28. result: [], //答案结果
  29. connectResult: [], //id
  30. contentResult: "", //name
  31. rules: [], //规则所需数据value
  32. sure:false,
  33. numPlus:1
  34. };
  35. },
  36. mounted() {
  37. this.numPlus = this.num;
  38. const list = this.symptomResult.questionDetailList;
  39. this.result = list.length>0?list:this.symptomResult.questionMapping;
  40. },
  41. watch:{
  42. result: {
  43. handler(newArr) {
  44. let num = 0;
  45. for(let i = 0;i < newArr.length;i++){
  46. if(!newArr[i].select){
  47. ++num
  48. }
  49. }
  50. if(num == newArr.length){
  51. this.sure = false
  52. }else{
  53. this.sure = true
  54. }
  55. },
  56. immediate: true,
  57. deep:true
  58. }
  59. },
  60. methods: {
  61. inpVal(val,index){//输入框失焦处理
  62. // 输入框回读
  63. let detailList = this.result;
  64. let currItem = detailList[index];
  65. currItem.value = val;
  66. },
  67. handleClick(it,index,flg,ipt){
  68. if(flg){
  69. document.activeElement.blur();
  70. document.activeElement.scrollIntoViewIfNeeded(true);
  71. setTimeout(()=>{
  72. document.activeElement.scrollIntoViewIfNeeded(true);
  73. },300)
  74. }
  75. /*let data = it.questionDetailList&&it.questionDetailList.slice(0); //数组深拷贝
  76. if(ipt){//输入框单选,输入了内容才算选中,删除内容算取消
  77. for(let i=0;i<data.length; i++){
  78. if(i==index){
  79. data[i].select=data[i].value?1:0;
  80. }else{
  81. data[i].select = 0
  82. }
  83. }
  84. }else{
  85. for(let i=0;i<data.length; i++){
  86. if(i==index){
  87. data[i].select = data[i].select==1?0:1;
  88. }else{
  89. data[i].select = 0
  90. }
  91. }*/
  92. /*}
  93. let temp = concatVal(data);
  94. const newData = Object.assign({},this.datas,{questionDetailList:data,value:temp.value,valueP:temp.valueP});
  95. this.$emit("updata",newData);*/
  96. },
  97. makeSuer() {
  98. if(!this.sure){return}
  99. let result = this.result;
  100. let number = this.numPlus,tmpResult='',tmpResultp='';
  101. for (let i = 0; i < result.length; i++) {
  102. const textp=result[i].description||result[i].name;
  103. const text=result[i].name;
  104. const msg = getExpStr(text);
  105. const msgp = getExpStr(text);
  106. if(result[i].select){
  107. if(result[i].name.indexOf("${input")!==-1){
  108. tmpResult=msg.prefix+(result[i].value||"")+msg.suffix;
  109. tmpResultp=msgp.prefix+(result[i].value||"")+msgp.suffix;
  110. }else{
  111. tmpResult=text;
  112. tmpResultp=textp;
  113. }
  114. }
  115. }
  116. if(+this.symptomResult.flag===2){ //为诱因控件
  117. const orgChoose = this.$store.state.symptom.choose;
  118. orgChoose[0].reason = tmpResult;
  119. orgChoose[0].reasonP = tmpResultp;
  120. this.$store.commit('setChoose', { choose: orgChoose, type: 1 });
  121. }
  122. //this.contentResult = tmpResult;
  123. this.$emit("updataResultSingle", this.symptomResult, {val:tmpResult,valp:tmpResultp,flag:this.symptomResult.flag},++number);
  124. },
  125. selectResult(item,idx) {
  126. const { select } = item;
  127. let result = JSON.parse(JSON.stringify(this.result));
  128. if (select) {//判断是否选中,选中的取消,关联id删除
  129. for (let i = 0; i < result.length; i++) {
  130. if(i == idx){
  131. result[i].select = false
  132. }
  133. }
  134. }else{
  135. for (let i = 0; i < result.length; i++) {
  136. if(i == idx){
  137. result[i].select = true;
  138. }else{
  139. /*if(result[i].name.indexOf("${input")!==-1){ //被取消的输入框有内容则
  140. }*/
  141. result[i].select = false
  142. }
  143. }
  144. }
  145. this.result = result
  146. }
  147. },
  148. components:{
  149. OptionInp
  150. }
  151. };
  152. </script>
  153. <style lang="less" scoped>
  154. @import "../less/base.less";
  155. .select {
  156. background-color: #fff;
  157. padding: 0.3rem 0 0;
  158. position: fixed;
  159. width: 100%;
  160. bottom: 0;
  161. box-sizing: border-box;
  162. li {
  163. padding: 0.14rem 0.2rem;
  164. border:1px #DFE0E4 solid;
  165. border-radius: 0.36rem;
  166. font-size: 0.26rem;
  167. margin: 0.15rem;
  168. float: left;
  169. color: #666;
  170. }
  171. .liSelect {
  172. color: #fff;
  173. background-color: #colors[btn];
  174. border-color: #colors[btn];
  175. }
  176. .noBorder{
  177. border: none;
  178. width: 100%;
  179. &.liSelect{
  180. background: none;
  181. span{
  182. color: #DFE0E4;
  183. }
  184. }
  185. }
  186. }
  187. </style>