MultSelect.vue 5.5 KB

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