define(['zepto','medtap'],function($,medtap){
	var detail = {
		orderSn: medtap.getRequest('id'),
		wechatId: medtap.getRequest('wechatId'),
		orderDoctorId:'',
		orderDoctorname:'',
		init:function(){
			detail.getDetail();
			detail.bindEve();
		},
		bindEve: function() {
			$('.pay').unbind().bind('click', function() {
				medtap.pushWindow(
					'https://review-formal.iplusmed.com/wechatForLungCancer/dev/wechat_lung_wxPay/wxPay.html?orderType=pmd&orderId=' +
					detail.orderSn + '&wechatId=' + detail.wechatId + '&wxLungToken=' + localStorage.wxLungToken)
			});
		
			$('.cancel').unbind().bind('click', function() {
				detail.cancelOrder();
			});
			$('.cancel_btn').unbind().bind('click', function() {
				detail.cancelOrder();
			});
			
		},
		cancelOrder: function() {
			if (!confirm('确定要取消订单吗?')) {
				return;
			}
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/trade/order/cancelOrder',
				type: 'post',
				contentType: "application/json",
				async: false,
				data: {
					orderSn: detail.orderSn
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {
						medtap.toast({
							message: '取消订单成功',
							time: 1500
						});
						setTimeout(function() {
							window.location.reload();
						}, 1500);
					}
				}
			})
		},
		getDetail: function() {
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/trade/order/getOrderByOrderSn',
				type: 'get',
				async: false,
				data: {
					orderSn: detail.orderSn
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {
						var detail = res.content.order;
						var pmd = detail.pmdConsultOrder;
						detail.orderDoctorId = pmd.doctorId;
						detail.orderDoctorname = pmd.doctorName;
						$('.service_type').html(detail.payDesc);
						$('.service_doctor').html(pmd.doctorName);
						$('.service_price').html(detail.payFee + '元');
						var sex = '';
						if (pmd.sex == 'M') {
							sex = '男';
						} else {
							sex = '女';
						}
						$('.patient_name').html(pmd.patientName + ' (' + sex + ' ' + pmd.age + '岁' + ')');
						$('.patient_disease').html(pmd.diseaseDiagnosisDesc);
						$('.patient_disease_type').html(pmd.pathologyTypeDesc);
						/* $('.disease_area').html(pmd.describe);
						$('.help_area').html(pmd.expectationHelp); */
						if (detail.status.key == '0') {
							$('.order_status_type').html(detail.status.value);
							$('.pay_btn').show();
						} else {
							$('.order_status_type').html(pmd.serviceStatus.value);
							if (detail.status.key == '1' && pmd.serviceStatus.key == '0' || pmd.serviceStatus.key ==
								'1' || pmd.serviceStatus.key == '2') {
								$('.cancel_btn').show();
							} else if (detail.status.key == '1' && pmd.serviceStatus.key == '3') {
								$('.consult_now').show();
							}
		
						}
						$('.order_orderSn').html(detail.orderSn);
						$('.order_time').html(detail.createTime.substring(0, 16));
						if (detail.hasOwnProperty('payTime')) {
							$('.pay_box').show();
							$('.order_pay_time').html(detail.payTime)
						} else {
							$('.pay_box').hide();
						}
						$('.imgConsult').unbind().bind('click',function(){
							//medtap.pushWindow('../../wechat_lung_imgConsult/index.html?doctorId=' + medtap.getRequest('doctorId') + '&pmdOrderSn=' + detail.orderSn + '&wechatId=' + detail.wechatId)
							if(!medtap.getRequest('doctorId')){
								//console.log(2)
								medtap.pushWindow('../../wechat_lung_imgConsult/index.html?doctorId=' + detail.orderDoctorId + '&pmdOrderSn=' + detail.orderSn + '&wechatId=' + medtap.getRequest('wechatId'))
							}else{
								medtap.pushWindow('../../wechat_lung_imgConsult/index.html?doctorId=' + medtap.getRequest('doctorId') + '&pmdOrderSn=' + detail.orderSn + '&wechatId=' + medtap.getRequest('wechatId'))
							}
						});
						$('.consult').unbind().bind('click',function(){
							if(!medtap.getRequest('doctorId')){
								medtap.pushWindow('../../wechat_lung_consult/rukou.html?doctorId=' + detail.orderDoctorId + '&pmdOrderSn=' + detail.orderSn + '&wechatId=' +  medtap.getRequest('wechatId') + '&doctorname=' + detail.orderDoctorname)
							}else{
								medtap.pushWindow('../../wechat_lung_consult/rukou.html?doctorId=' + medtap.getRequest('doctorId') + '&pmdOrderSn=' + detail.orderSn + '&wechatId=' +  medtap.getRequest('wechatId') + '&doctorname=' + detail.orderDoctorname)
							}
						});
						$('.consult').html('电话咨询('+pmd.consultCount +'次)');
					}
				}
			})
		}
	}
	detail.init()
})