geneDetection.js 13.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
define(['zepto', 'medtap', 'mui', 'mui.picker'], function($, medtap, mui) { 
  var geneDetection = {
		// 问卷id
		followUpId: medtap.getRequest('followUpId'),
		// 获取本题序号
		questionNo: medtap.getRequest('questionNo')||'',
		//  获取本题id
		questionId: medtap.getRequest('questionId')||'',
		// 修改人员id
    adminId: medtap.getRequest('adminId')||'',
		//  获取parentId
    parentId: medtap.getRequest('parentId')||'',
    // EGFR检测数据
    EGFRpicker: '',
    // 突变部位
		Positionpicker: '',
		// 选择有或者无
		flag: true,
		// 图片集合
		imgList: [],
		serverId: "",
		// 
		localIds: '',
		// 图片https://地址
		imgKey: '',
		// EGFR值
		EGFRval: '',
		// 突变位置的值
		positionVal: '',
		// 医生对检测结果的说明
		testDescription:'',
    init: function(){
			// 点击删除图片
			$('#ImgUp').on('click', '.image_del', function() {
				var src = $(this).siblings('img').attr('src')
				var index	= geneDetection.imgList.findIndex(function(item){
					return item = src
				})
				if (confirm('确定要删除图片吗?')) {
					geneDetection.imgList.splice(index,1)
					$(this).parent().remove();	
				}
			});
			// 用户点击了无
				$('.noHas').on('tap',function(){
				geneDetection.flag=false
				console.log(geneDetection.flag)
			})
			// 用户点击了有
			$('.has').on('tap',function(){
				geneDetection.flag=true
				
				console.log(geneDetection.flag)
			})
       // 点击下一题
      $('.next').on('click',function(){
				if(geneDetection.flag){
					geneDetection.EGFRval = $('.input_item_EGFR').val()
					geneDetection.positionVal = $('.input_item_position').val()
					geneDetection.testDescription =$.trim($('#content_body_fill').val()) 
					// 如果没选EGFR检测结果
					if(geneDetection.EGFRval==''){
						medtap.winPop('请选择EGFR检测结果')
						return
					}
					switch(geneDetection.EGFRval){
						case '突变':
						// 如果没选突变位置
						if(geneDetection.positionVal==''){
						medtap.winPop('请选择突变部位')
						return
						}
						break;
					}
					
					var dataHas = {
					 "questionId":geneDetection.questionId,
					 "parentId":geneDetection.parentId,
					 "answer":{
						 'EGFRval':geneDetection.EGFRval,
						 'positionVal': geneDetection.positionVal,
						 'testDescription':geneDetection.testDescription,
						 'imgList': geneDetection.imgList,
						 "status": 1
					 },
					 "questionNo":Number(geneDetection.questionNo),
					 "followUpId": geneDetection.followUpId
					}
				  geneDetection.getNextQuestion(dataHas)		
				}else{
					var dataNo = {
						"questionId":geneDetection.questionId,
						"parentId":geneDetection.parentId,
						"answer":{
						 'EGFRval':'',
						 'positionVal': '',
						 'testDescription': '',
						 'imgList': '',
							"status": 0
						},
						"questionNo":Number(geneDetection.questionNo),
						"followUpId": geneDetection.followUpId
					 }
					 geneDetection.getNextQuestion(dataNo)	
				}
			})
			 // 点击上一题
			$('.pre').on('click',function(){
				geneDetection.getPreQuestion()
        
      })
      $(".tabbox li").click(function ()
    {
      //获取点击的元素给其添加样式,讲其兄弟元素的样式移除
      $(this).addClass("active").siblings().removeClass("active");
      //获取选中元素的下标
      var index = $(this).index();
      $(this).parent().siblings().children().eq(index).addClass("active")
      .siblings().removeClass("active");
    });
     geneDetection.getWechatTicket();
     geneDetection.inintEGFRpicker();
     geneDetection.inintPositionpicker();
     geneDetection.selectItems();
    },

    // 初始化EGFR检测picker数据
    inintEGFRpicker:function(){
    geneDetection.EGFRpicker = new mui.PopPicker();
    geneDetection.EGFRpicker.setData([
      {value:'1',text:'突变'},
      {value:'2',text:'未突变'},
      {value:'3',text:'不知道'}
    ]);
    },
    // 初始化突变部位picker数据
    inintPositionpicker:function(){
    geneDetection.Positionpicker = new mui.PopPicker();
    geneDetection.Positionpicker.setData([
      {value:'1',text:'EXON20_T790M'},
      {value:'2',text:'EXON18_G719X'},
      {value:'3',text:'EXON19_19_DEL'},
      {value:'4',text:'EXON20_S768I'},
      {value:'5',text:'EXON20_20-Ins'},
      {value:'6',text:'EXON21_L858R'},
      {value:'7',text:'EXON21_L861Q'},
      {value:'8',text:'不知道'}
    ])
    },
    // 点击picker后的事件注册
    selectItems:function(){
        // 点击EGFR检测
    $('.content_body_EGFR').click(function(){
      geneDetection.EGFRpicker.show(function (Items) {
				 console.log(Items[0].text);
        console.log(Items[0].value);
        $('.input_item_EGFR').val(Items[0].text)
        if(Items[0].value=='1'){
          $('.content_body_position').show()
        }else{
          $('.content_body_position').hide()
          $('.input_item_position').val('')
        }
      })
    })
    // 点击突变部位
    $('.content_body_position').click(function(){
      geneDetection.Positionpicker.show(function (Items) {
        console.log(Items[0].text);
        console.log(Items[0].value);
        $('.input_item_position').val(Items[0].text)
      })
    })
    },
    getWechatTicket: function() {
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/wechat/lung/fetchWechatTicket',
				type: 'GET',
				async: false,
				data: {
					url: window.location.href
				},
				success: function(res) {
					var data = res.content;
					wx.config({
						debug: false,
						appId: data.appId, // 必填,公众号的唯一标识
						timestamp: data.timestamp, // 必填,生成签名的时间戳
						nonceStr: data.nonceStr, // 必填,生成签名的随机串
						signature: data.signature, // 必填,签名,见附录1
						jsApiList: [
							'chooseImage',
							'previewImage',
							'uploadImage'
						]
					})
				}
			})
		},
		//选择图片
		choseImage: function() {
			$('.upload_img').on('click', function() {
        console.log('点击了选择图片')
				var html = '';
				wx.ready(function() {
					var syncUpload = function(localIds) {
						localId = localIds[0];
						localIds = localIds.length > 1 ? localIds.slice(1) : localIds[0];
						wx.uploadImage({
							localId: localId,
							isShowProgressTips: 1,
							success: function(res) {
								var serverId = res.serverId; // 返回图片的服务器端ID
								//其他对serverId做处理的代码
								geneDetection.upLoadImg(serverId, localId);
								if (localIds.length > 0) {
									syncUpload(localIds);
								}
							}
						});
					};
					wx.chooseImage({
						count: 9,
						sizeType: ['original', 'compressed'],
						sourceType: ['album', 'camera'],
						success: function(res) {
							geneDetection.localIds = res.localIds;
							//所有需要上传到图片预览
							syncUpload(geneDetection.localIds);
						}
					})
				})
			})
		},
		//图片预览
		previewImage: function() {
			$('#ImgUp').on('click', '.image_files_img', function() {
				var imgArray = [];
				var curImageSrc = $(this).attr('src');
				if (curImageSrc) {
					$('#ImgUp .image_files_img').each(function(index, el) {
						var itemSrc = $(this).attr('src');
						imgArray.push(itemSrc);
					});
					wx.previewImage({
						current: curImageSrc,
						urls: imgArray
					});
				}
			});
			$('#ImgUp').on('click', '.image_del', function() {
				if (confirm('确定要删除图片吗?')) {
					$(this).parent().remove();
					console.log($(this))
				}
			});
		},
		//上传图片
		upLoadImg: function(serverId, localId) {
			$.ajax({
				url: 'https://gateway.medtap.cn/common/uploadWechatFile',
				type: 'POST',
				async: false,
				data: {
					bizType: "3",
					folder: 'bbs',
					mediaId: serverId,
					ext: 'jpg'
				},
				headers:{
					'apptype':'wechat_lung',
					'user-os':'wechat'
				},
				success: function(data) {
					if (data.success == true) {
						var res = data.content;
						var imgKey = res.url;
						geneDetection.imgList.push(imgKey);
						console.log('上传后图片的imgKey',imgKey)
						var html = '<div class="image_files_item">' +
							'<img src="' + localId + '" class="image_files_img" imgkey="' + imgKey + '">' +
							'<img src="../images/post_delete_btn@2x.png" class="image_del" >' +
							'</div>';
						$('#ImgUp').append(html);
					}
				}

			})
		},
		 // 获取答案
		 getQuestionAnswer: function(){
			var crm = geneDetection.adminId==''? '':'/crm'
      medtap.submitAjax({
        url: 'https://gateway.medtap.cn/operation/followUp'+crm+'/getAnswer',
        type: 'post',
        async: false,
        contentType: 'application/json',
        data: {
          "followUpId": geneDetection.followUpId,
          "questionId": geneDetection.questionId,
        },
        success: function(res) {
          console.log(res) 
					if(!res.success) return medtap.winPop('获取数据失败')
					if(!res.content.followAnswer.answer) {
            geneDetection.flag=true
            return
          }
					if(res.content.followAnswer.answer.status=='0'){
						geneDetection.flag=false
						$('.noHas').addClass('active').siblings('.has').removeClass('active')
            $('.content_select_no').addClass('active').siblings('.content_select').removeClass('active')
						$('.input_item_EGFR').val('')
						$('.input_item_position').val('')
						$('#content_body_fill').val('')
						return
					}
          if(res.content.followAnswer.answer.status=='1'){
						geneDetection.flag=true
						if(res.content.followAnswer.answer.EGFRval=="突变"){
							$('.content_body_position').show()
					}
          $('.input_item_EGFR').val(res.content.followAnswer.answer.EGFRval || '')
					$('.input_item_position').val(res.content.followAnswer.answer.positionVal || '')
					$('#content_body_fill').val(res.content.followAnswer.answer.testDescription || '')
					// 图片。。
					var imgList = res.content.followAnswer.answer.imgList
					geneDetection.imgList = res.content.followAnswer.answer.imgList
					var html =''
					if(imgList.length>0){
						for(var i = 0;i<imgList.length;i++){
						html+='<div class="image_files_item">' +
							'<img src="' + imgList[i] + '" class="image_files_img">' +
							'<img src="../images/post_delete_btn@2x.png" class="image_del" >' +
							'</div>';
						}
						$('#ImgUp').append(html)
					}
					}
				
         
        }
      })
    },
      // 上一题
		getPreQuestion:function(){
			var crm = geneDetection.adminId==''? '':'/crm'
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/operation/followUp'+crm+'/previousQuestion',
				type: 'post',
				async: false,
				contentType: 'application/json',
				data: {
					"questionId":geneDetection.questionId,
					"questionNo":geneDetection.questionNo,
					"followUpId":geneDetection.followUpId,
				},
				success: function(res) {
          console.log(res)
          if(!res.success) return medtap.winPop('获取数据失败')
          var parentId = res.content.previousQuestion.parentId||''
					var questionId = res.content.previousQuestion.questionId||''
					var questionNo = res.content.previousQuestion.questionNo||''
					switch(questionId){
						case 5:
						medtap.pushWindow('examination.html?followUpId='+geneDetection.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&adminId='+geneDetection.adminId)
						break;
						case 6:
						medtap.pushWindow('generalPage.html?followUpId='+geneDetection.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&backChecks='+questionId+'&adminId='+geneDetection.adminId)
						break;
						case 7:
						medtap.pushWindow('generalPage.html?followUpId='+geneDetection.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&backChecks='+questionId+'&adminId='+geneDetection.adminId)
						break;
						case 8:
						medtap.pushWindow('generalPage.html?followUpId='+geneDetection.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&backChecks='+questionId+'&adminId='+geneDetection.adminId)
						break;
						case 9:
						medtap.pushWindow('generalPage.html?followUpId='+geneDetection.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&backChecks='+questionId+'&adminId='+geneDetection.adminId)
						break;
						case 10:
						medtap.pushWindow('generalPage.html?followUpId='+geneDetection.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&backChecks='+questionId+'&adminId='+geneDetection.adminId)
						break;
						case 11:
						medtap.pushWindow('generalPage.html?followUpId='+geneDetection.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&backChecks='+questionId+'&adminId='+geneDetection.adminId)
						break;
						case 12:
						medtap.pushWindow('generalPage.html?followUpId='+geneDetection.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&backChecks='+questionId+'&adminId='+geneDetection.adminId)
						break;
					}
					
				}
			})
		},
		// 提交答案获取下一题id
		getNextQuestion:function(data,url){
			var crm = geneDetection.adminId==''? '':'/crm'
			medtap.submitAjax({
				url: 'https://gateway.medtap.cn/operation/followUp'+crm+'/nextQuestion',
				type: 'post',
				async: false,
				contentType: 'application/json',
				data: data,
				success: function(res) {
					console.log(res)
					if(!res.success) return medtap.winPop('获取数据失败')
					var parentId = res.content.nextQuestion.parentId||''
          var nextquestionNo = res.content.nextQuestion.questionNo||''
          var nextquestionId = res.content.nextQuestion.questionId||''
					medtap.pushWindow('discomfort.html'+'?followUpId=' + geneDetection.followUpId+'&questionNo='+nextquestionNo+'&questionId='+nextquestionId+'&parentId='+parentId+'&adminId='+geneDetection.adminId)
				}
			})
		}
  }
  geneDetection.init();
  geneDetection.getQuestionAnswer();
  geneDetection.choseImage();
  geneDetection.previewImage();
  })