Detail.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class="detail-wrap">
  3. <!-- <div v-for="(item,index) in datas"> -->
  4. <div v-for="(item,index) in checkDatas.questionMapping">
  5. <p class="quest"><span v-show="item.required==1" style="color: red;">*</span>{{index + 1 +'.' + (item.description || item.name)}}</p>
  6. <img class="questionImg" :src="item.url.replace('{imageUrlPrefix}',imgUrl)" v-if="item.url">
  7. <Radio v-if="item.controlType==1"
  8. :item="item"
  9. :key="item.id"
  10. @updata="updataData"/>
  11. <RadioSelect v-if="item.controlType==8"
  12. :item="item"
  13. :key="item.id"
  14. @updata="updataData"/>
  15. <CheckBox v-if="item.controlType==2"
  16. :item="item"
  17. :key="item.id"
  18. @updata="updataData"/>
  19. <!-- 文本域 -->
  20. <ComTextArea v-if="item.controlType == 5"
  21. :item="item"
  22. @updata="updataData"/>
  23. <!-- 输入框 -->
  24. <Input v-if="item.controlType==6 || item.controlType==7"
  25. :item="item"
  26. :key="item.id"
  27. @updata="updataData"/>
  28. <template
  29. v-if="item.controlType == 3"
  30. v-for="(part,index) in item.questionDetailList"
  31. >
  32. <MultiLineInput
  33. v-if="item.controlType == 3"
  34. :msg="part.description||part.name"
  35. :part="part"
  36. @updata="updataData($event,item)"
  37. ></MultiLineInput>
  38. </template>
  39. <PickTime v-if="item.controlType == 9"
  40. @updata="updataData"
  41. :item="item"/>
  42. </div>
  43. </div>
  44. </template>
  45. <script type="text/javascript">
  46. import Radio from '../common/Radio.vue';
  47. import CheckBox from '../common/CheckBox.vue';
  48. import Input from '../common/Input.vue';
  49. import ComTextArea from '../common/ComTextArea.vue';
  50. import RadioSelect from '../common/RadioSelect.vue';
  51. import MultiLineInput from '../common/MultiLineInput.vue';
  52. import PickTime from '../common/PickTime.vue';
  53. import {patt,trimDots,imageUrlPrefix} from '@utils/tools.js'
  54. // 将获取到的数据源转换成私有数据,处理选择事件。点击完成后统一存到store中,便于回读
  55. export default {
  56. name:'Detail',
  57. data(){
  58. return{
  59. checkDatas:{},
  60. imgUrl:imageUrlPrefix,
  61. }
  62. },
  63. props:['datas','data'],
  64. created(){
  65. this.checkDatas = JSON.parse(JSON.stringify(this.datas));
  66. },
  67. components:{
  68. Radio,
  69. CheckBox,
  70. Input,
  71. ComTextArea,
  72. MultiLineInput,
  73. RadioSelect,
  74. PickTime
  75. },
  76. methods:{
  77. updataData(data,item){
  78. const origMapping = this.datas.questionMapping;
  79. let mapping = this.checkDatas.questionMapping;
  80. for(let i in origMapping){
  81. if(data.controlType==3){//多列类型多一层
  82. if(mapping[i].id == item.id){
  83. let tempVal = '';
  84. let tempValP = '';
  85. let detList = mapping[i].questionDetailList;
  86. for(let k in detList){//替换
  87. if(detList[k].id==data.id){
  88. detList.splice(k,1,data)
  89. }
  90. }
  91. for(let n in detList){//给父级赋值
  92. if(detList[n].value){
  93. tempVal += detList[n].name.replace(patt,detList[n].value)+',';
  94. tempValP += (detList[n].description||detList[n].name).replace(patt,detList[n].value)+',';
  95. // 去掉最后一个逗号
  96. mapping[i].value = tempVal.substring(0,tempVal.length-1);
  97. mapping[i].valueP = tempValP.substring(0,tempValP.length-1);
  98. }
  99. }
  100. }
  101. }else{
  102. if(origMapping[i].id==data.id){
  103. mapping.splice(i,1,data)
  104. }
  105. }
  106. }
  107. // 实时更新清空样式
  108. if(data.value){
  109. this.$emit('check',true)
  110. }else{
  111. let flag = this.check();
  112. if(flag){
  113. this.$emit('check',true)
  114. }else{
  115. this.$emit('check',false)
  116. }
  117. }
  118. // 更新完成样式
  119. let checkReq = this.checkReq();
  120. if(checkReq){
  121. this.$emit('checkReq',true)
  122. }else{
  123. this.$emit('checkReq',false)
  124. }
  125. },
  126. saveData(){//存值
  127. this.checkDatas = Object.assign({},this.checkDatas,{select:1});
  128. const datas = this.checkDatas.questionMapping;
  129. const id = this.checkDatas.id;
  130. let chooseSymp = this.$store.state.symptom.choose;
  131. let text = ""; //医生
  132. let textP = "";//患者
  133. let special = ""; //拼到主诉
  134. let specialP = "";
  135. for(let i in datas){
  136. // 校验必填项
  137. /* if(datas[i].required==1 && !datas[i].value){
  138. alert("请先将必填项填完");
  139. return
  140. }*/
  141. // 拼到主诉
  142. if(datas[i].specFlag==1 && datas[i].value){
  143. special += datas[i].value;
  144. specialP += datas[i].valueP;
  145. }
  146. if(datas[i].value){
  147. text += datas[i].value+',';
  148. textP += datas[i].valueP+',';
  149. }
  150. }
  151. if(special){//拼接到主诉的内容存到chooseSymp
  152. for(let k in chooseSymp){
  153. if(id == (chooseSymp[k].id ||chooseSymp[k].questionId)){
  154. chooseSymp[k].special = special;
  155. chooseSymp[k].specialP = specialP;
  156. }
  157. }
  158. }
  159. let msg = this.checkDatas.name+ ',' + text;
  160. let msgP = (this.checkDatas.description || this.checkDatas.name)+ ',' + textP;
  161. let newMsg = "";
  162. let newMsgP = "";
  163. if(msg[msg.length-1] == ','){
  164. newMsg = msg.substring(0,msg.length-1);
  165. newMsgP = msgP.substring(0,msgP.length-1);
  166. }else{
  167. newMsg = msg;
  168. newMsgP = msgP;
  169. }
  170. this.$store.commit('setDatas',{data:this.checkDatas,pId:id,type:this.data.moduleType,ppId:this.data.ppId});
  171. // flag是区分点开已选症状 未点完成
  172. this.$store.commit('setText',{text:trimDots(newMsg),textP:trimDots(newMsgP),pId:id,type:this.data.moduleType,flag:true,order:this.data.order,arrFlag:true,index:this.data.index});
  173. // 关闭详情
  174. this.$store.commit('setDetail',{detail:{}})
  175. },
  176. clearData(){//清空
  177. // const datas = this.checkDatas.questionMapping;
  178. const datas = JSON.parse(JSON.stringify(this.checkDatas.questionMapping))
  179. let reqFlag = false;//必填项标识
  180. for(let i in datas){
  181. // 时间控件需要清除缓存的index
  182. if(datas[i].controlType ==9){
  183. if(datas[i].pickIndex){
  184. datas[i].pickIndex = [];
  185. }
  186. }
  187. datas[i].value = "";
  188. datas[i].valueP = "";
  189. if(datas[i].required==1){
  190. reqFlag = true;
  191. }
  192. let detaiList = datas[i].questionDetailList;
  193. if(detaiList.length>0){
  194. for(let k in detaiList){
  195. detaiList[k].select = 0;
  196. if(detaiList[k].value){
  197. detaiList[k].value = "";
  198. detaiList[k].valueP = "";
  199. }
  200. }
  201. }
  202. }
  203. this.checkDatas = Object.assign({},this.checkDatas,{questionMapping:datas});
  204. // 已有选中内容重新进来,点清空时并非真的清空
  205. if(this.checkDatas.select ==1){return}
  206. let msg = this.checkDatas.name;
  207. let msgP = (this.checkDatas.description||this.checkDatas.name);
  208. // 没有点过完成直接选择然后清空,外层不会处于选中状态,故没有必填项时添加{select:1}
  209. if(reqFlag){
  210. this.$store.commit('setDatas',{data:this.checkDatas,pId:this.checkDatas.id,type:this.data.moduleType,ppId:this.data.ppId});
  211. }else{
  212. this.$store.commit('setDatas',{data:Object.assign({},this.checkDatas,{select:1}),pId:this.checkDatas.id,type:this.data.moduleType,ppId:this.data.ppId});
  213. }
  214. this.$store.commit('setText',{text:msg,textP:msgP,pId:this.checkDatas.id,type:this.data.moduleType,flag:true,order:this.data.order,arrFlag:true,index:this.data.index});
  215. },
  216. check(){// 校验是否有已填项
  217. const datas = this.checkDatas.questionMapping;
  218. let checkArr = [];
  219. for(let i in datas){
  220. if(datas[i].value){
  221. checkArr.push(datas[i]);
  222. }
  223. let detaiList = datas[i].questionDetailList;
  224. if(detaiList.length>0){
  225. for(let k in detaiList){
  226. if(detaiList[k].select == 1){
  227. checkArr.push(detaiList[k]);
  228. }
  229. }
  230. }
  231. }
  232. if(checkArr.length>0){
  233. return true;
  234. }
  235. return false;
  236. },
  237. checkReq(){// 校验必填项
  238. const datas = this.checkDatas.questionMapping;
  239. for(let k in datas){
  240. if(datas[k].required==1 && !datas[k].value){
  241. return false;
  242. }
  243. }
  244. return true;
  245. }
  246. },
  247. }
  248. </script>
  249. <style lang="less" scoped>
  250. @import '../less/base.less';
  251. .detail-wrap{
  252. // padding: .3rem .5rem 1.2rem .6rem;
  253. padding: .3rem .4rem 1rem ;
  254. font-size: .3rem;
  255. .quest{
  256. color:#colors[quest];
  257. margin-bottom: .2rem;
  258. }
  259. .questionImg {
  260. width: 100%;
  261. }
  262. }
  263. </style>