Select.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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" @click="selectResult(item,idx)">{{item.description||item.name}}</span>
  11. <OptionInp v-else :item="item" @handleInp="inpVal" :inx="idx" @handleSelect="selectResult(item,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. import api from '@utils/api.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:0 //已选答案个数
  34. };
  35. },
  36. mounted() {
  37. //this.numPlus = this.num
  38. //console.log(this.symptomResult.questionDetailList)
  39. this.result = this.symptomResult.questionDetailList;
  40. },
  41. watch:{
  42. result: {
  43. handler(newArr) {
  44. let num = 0,sldNum=0;
  45. for(let i = 0;i < newArr.length;i++){
  46. if(!newArr[i].select){
  47. ++num;
  48. }else{
  49. newArr[i].exclusion!=1&&sldNum++;
  50. }
  51. }
  52. this.numPlus =sldNum;
  53. if(num == newArr.length){
  54. this.sure = false
  55. }else{
  56. this.sure = true
  57. }
  58. },
  59. immediate: true,
  60. deep:true
  61. }
  62. },
  63. methods: {
  64. inpVal(val,index){//输入框失焦处理
  65. // 输入框回读
  66. let detailList = this.result;
  67. let currItem = detailList[index];
  68. currItem.value = val;
  69. },
  70. /*handleClick(it,index,flg,ipt){
  71. if(flg){
  72. document.activeElement.blur();
  73. document.activeElement.scrollIntoViewIfNeeded(true);
  74. setTimeout(()=>{
  75. document.activeElement.scrollIntoViewIfNeeded(true);
  76. },300)
  77. }
  78. },*/
  79. getExtQa(ids){
  80. const userInfo = this.$store.state.pathInfo;
  81. const param = {
  82. age:userInfo.patientAge,
  83. ids:ids,
  84. sexType:userInfo.sexType
  85. };
  86. return new Promise((resolve,reject)=>{
  87. api.getByIds(param).then((res)=>{
  88. resolve(res);
  89. });
  90. })
  91. },
  92. async makeSuer() {
  93. if(!this.sure){return}
  94. let result = this.result;
  95. // if(this.numPlus == 1){
  96. let tmpResult=[],tmpResultp=[],subQas='';
  97. for (let i = 0; i < result.length; i++) {
  98. const text=result[i].name;
  99. const textp=result[i].description||result[i].name;
  100. const msg = getExpStr(text);
  101. const msgp = getExpStr(textp);
  102. if(result[i].select){
  103. subQas = subQas+","+result[i].subQuestion;
  104. if(result[i].name.indexOf("${")!==-1){
  105. if(!result[i].value){
  106. this.$emit("warning","选中项输入框必填");
  107. return;
  108. }
  109. tmpResult.push(msg.prefix+(result[i].value||"")+msg.suffix);
  110. tmpResultp.push(msgp.prefix+(result[i].value||"")+msgp.suffix);
  111. }else {
  112. //tmpIds=tmpIds.concat(result[i].connectId)
  113. tmpResult.push(text);
  114. tmpResultp.push(textp);
  115. }
  116. }
  117. }
  118. subQas=subQas.replace(/^,|,$/g,'').replace(/,+/g,',');
  119. const subQs=subQas.split(",");
  120. if(subQas){
  121. await this.getExtQa(subQs).then((res)=>{
  122. this.$emit("getExtQa",res.data.data,this.num,subQs.length);
  123. });
  124. }
  125. //tmpIds=tmpIds.concat(staticArr)
  126. //this.connectResult = tmpIds
  127. //this.contentResult = tmpResult.join('、')
  128. // }else{
  129. // }
  130. if(+this.symptomResult.flag===2){ //为诱因控件
  131. const orgChoose = this.$store.state.symptom.choose;
  132. orgChoose[0].reason = tmpResult;
  133. orgChoose[0].reasonP = tmpResultp;
  134. this.$store.commit('setChoose', { choose: orgChoose, type: 1 });
  135. }
  136. let number = this.num;
  137. this.$emit("updataResult", this.symptomResult, {val:tmpResult.join('、'),valp:tmpResultp.join('、')},++number);
  138. },
  139. selectResult(item,idx) {
  140. const { exclusion, select, value } = item;
  141. let result = JSON.parse(JSON.stringify(this.result));
  142. if (select&&!value) {//判断是否选中,选中的取消,关联id删除,未选中判断是否互斥
  143. for (let i = 0; i < result.length; i++) {
  144. if(i == idx){
  145. result[i].select = false
  146. }
  147. }
  148. }else{
  149. if(+exclusion === 1){
  150. for (let i = 0; i < result.length; i++) {
  151. if(i == idx){
  152. result[i].select = true
  153. }else{
  154. result[i].select = false
  155. }
  156. }
  157. }else{
  158. for (let i = 0; i < result.length; i++) {
  159. if(result[i].select&&+result[i].exclusion === 1){
  160. result[i].select=false
  161. }else{
  162. if(i == idx&&value){
  163. result[i].select = true
  164. }
  165. }
  166. }
  167. }
  168. }
  169. this.result = result
  170. }
  171. },
  172. components:{
  173. OptionInp
  174. }
  175. };
  176. </script>
  177. <style lang="less" scoped>
  178. @import "../less/base.less";
  179. .select {
  180. background-color: #fff;
  181. padding: 0.28rem 0 0 0;
  182. position: fixed;
  183. width: 100%;
  184. bottom: 0;
  185. box-sizing: border-box;
  186. box-shadow: 0 0 30px -10px rgba(104, 124, 189, 0.25);
  187. li {
  188. padding: 0.14rem 0.2rem;
  189. border:1px #DFE0E4 solid;
  190. border-radius: 0.36rem;
  191. font-size: #font[select];
  192. margin: 0.15rem;
  193. float: left;
  194. color: #colors[text];
  195. }
  196. .liSelect {
  197. color: #fff;
  198. background-color: #colors[btn];
  199. border-color: #colors[btn];
  200. }
  201. .noBorder{
  202. border: none;
  203. width: 100%;
  204. padding: 0 0.2rem;
  205. margin: 0 0.15rem;
  206. &.liSelect{
  207. background: none;
  208. }
  209. }
  210. }
  211. </style>