Select.vue 5.9 KB

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