<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>付费</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="${contextPath}/static/weixin/ssdb/css/sm.min.css">
    <link rel="stylesheet" href="${contextPath}/static/weixin/ssdb/css/sm-extend.min.css">
    <link rel="stylesheet" href="${contextPath}/static/weixin/ssdb/css/style.css">
    <link rel="stylesheet" href="${contextPath}/static/weixin/ssdb/css/common.css">
    <link rel="stylesheet" href="${contextPath}/static/weixin/ssdb/css/sprite.css">
    <style type="text/css">
	.imgDiv{
		display : inline-block;
		position : relative;
	}
	.imgDiv1{
		display : inline-block;
		position : relative;
	}
	.imgDiv .delete{
		position : absolute;
		top : 0px;
		right : 0px;
		width : 20px;
		height : 20px;
	}
	.imgDiv1 .delete{
		position : absolute;
		top : 0px;
		right : 0px;
		width : 20px;
		height : 20px;
	}
	.social1 {
	  display: block;
	  width: 50px;
	  height: 50px;
	  background-repeat: no-repeat;
	}
	.social11 {
	  display: block;
	  width: 50px;
	  height: 50px;
	  background-repeat: no-repeat;
	}
</style>
</head>
<body>
<from>
    <div class="page-group">
        <nav class="bar bar-tab">
            <div class="content-block">
                <input type="submit" id="submitForm" onclick="submitForm(this)" value="提交" class="button button-big button-fill">
            </div>
        </nav>
        <div class="content">
            <div class="pay pay-content">
                <h4 class="pay-cfont"><span id='stateName'></span></h4>
                <span>保费:<span id='stateDesc'></span></span>
            </div>
                <div class="pay-c" id="logPayHidden">
                <div class="pay-put item-content">
                    <span class="label">付款问题反馈</span>
                </div>
            <div><p id="logPaycontent"></p>
            </div>
            <div  align="right">
            <span id="logPaycreateDate"></span></div>
            </div>
            <div class="pay-c">
                <div class="pay-put item-content">
                    <span class="label">1.<span id='companyType1'></span></span>
                    <span class="link"><a href="#" class="open-services" id='companyType'></a></span>
                </div>
                <input type="file" id="social2" name="social1"  accept="image/*" onchange="handleFiles1(this)" style="visibility: hidden; position: absolute;">
            <label for="social2" class="s11" ><img  id="sourceImg1" class="icon-up" src="${contextPath}/static/weixin/ssdb/images/icon-updata-img.png"></label>
            <div id="filediv1" ><!-- class="imgDiv1" -->
            </div>
            </div>
            <div class="pay-c">
                <div class="label item-content">
                    <span> 2.选择配送方式</span>
                </div>
                <div class="row item-content" id='hidebh'>
                    <div class="col-33">保函</div>
                    <div class="col-33" id='hidebh1'><input type="radio" name="bh" id="bh1" class="open-bh"><span><label for="bh1">快递配送</label></span></div>
                    <div class="col-33" id='hidebh2'><input type="radio" name="bh" id="bh2" class="open-bd"><span><label for="bh2">上门配送</label></span></div>
                </div>
                <div class="row item-content">
                    <div class="col-33">保单发票</div>
                    <div class="col-33" id='hidebd1'><input type="radio" name="bd" id="bd1" class="open-bh"><span><label for="bd1">快递配送</label></span></div>
                    <div class="col-33" id='hidebd2'><input type="radio" name="bd" id="bd2" class="open-bd"><span><label for="bd2">上门配送</label></span></div>
                </div>
            </div>
            <div class="pay-c">
                <div class="label item-content">
                    <span> 3.选择配送方式</span>
                </div>
						<ul class="fs-16">
							<li class="pad-r-20 pad-tb-20 pad-l-25 pos-relate br-top1 ub ub-ac ub-pj">
								<div>
									<span class="icon icon-wechat1 icon-top1"  style="height:1rem;" ></span> 
									<span class="fc-xlgrey">微信</span>
								</div>
								<span class="radio-signle icon icon-radio-blue1" id="weixinID"  style="height:1.2rem;"  data-radio="pay" data-value="1"></span>
							</li>
							<li class="pad-r-20 pad-tb-20 pad-l-25 pos-relate br-top1 ub ub-ac ub-pj">
								<div>
									<span class="icon icon-xianxia icon-top1"  style="height:1rem;" ></span> 
									<span class="fc-xlgrey">线下转账</span>
								</div>
								<span class="radio-signle icon1 icon-radio-blue1 on " style="height:1.2rem;"  data-radio="pay" data-value="0"></span>
							</li>
							<input type="hidden" id="payTypeID" name="pay"  data-type="pay">
						</ul>
        </div><!-- /pay -->
        </div><!-- /pay -->
    </div><!-- /page-group -->
    <!-- 查看账户信息 Popup -->
    <div class="popup popup-about">
        <div class="content-block">
            <h4>账户信息</h4>
            <div class="pay pay-content">
                <div>账户: <span id='accountNum'></span></div>
                <div>开户行: <span id='accountBank'></span></div>
                <div>开户名: <span id='accountName'></span></div>
            </div>
            <div class="content-block">
            <h4>付款方式提示</h4>
            <div class="pay pay-content">
                <div>1.个人网银转账</div>
                <div>在电脑上或者手机app登陆个人网银输入账户信息进行转账</div>
                <div>2.线下银行转账</div>
            </div>
            </div>
            <div class="content-block">
                <p><a href="#" class="button button-fill close-popup">关闭</a></p>
            </div>
        </div>
    </div> <!-- /查看账户信息 Popup -->
    <!-- 下载投保单 Popup -->
    <div class="popup popup-services" id="popup-services">
        <div class="content-block">
            <div class="content">
                <div class="content-block-title">发送邮件</div>
                <div class="list-block">
                    <ul class="litigation">
                        <li>
                      <span  class="content-block-title">输入邮箱《<span id="emailContent"></span>》会发送到邮箱,<br/>当事人签字或者盖章后上传,作为出函依据!</span>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">邮箱：</div>
                                    <div class="item-input">
                                        <input type="text" id='email' data-required="true" data-descriptions="e-mail">
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div><!-- /list-block -->
                <div class="content-block">
                    <p><a href="#" class="button button-fill " id='mailSum'>提交</a></p><!--close-popup  -->
                    <p><a href="#" class="button button-fill close-popup">关闭</a></p>
                </div>
            </div><!-- /content -->
        </div>
    </div><!-- /下载投保单 Popup -->
    <!-- 保函 Popup -->
    <div class="popup popup-bh" >
        <div class="content-block" id='popupbhid'>
            <div class="content">
                <div class="content-block-title">快递配送</div>
                <div class="list-block">
                    <ul class="litigation">
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">姓名：</div>
                                    <div class="item-input">
                                        <input type="text" data-required="true" id="hanusername" data-descriptions="username">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">手机：</div>
                                    <div class="item-input">
                                        <input type="text" data-required="true" id="hanphone"  data-descriptions="phone">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">地址：</div>
                                    <div class="item-input">
                                        <input type="text" data-required="true" id="hanaddress" data-descriptions="address">
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div><!-- /list-block -->
                <div class="content-block">
                    <p><a href="#" id="bhclick" class="button button-fill">确定</a></p><!--  close-popup  -->
                    <p><a href="#" class="button button-fill close-popup" id="closebh">关闭</a></p>
                </div>
            </div><!-- /content -->
        </div>
    </div><!-- /保函 Popup -->
    <!--保单发票  Popup -->
    <div class="popup popup-bd">
        <div class="content-block">
            <div class="content">
                <div class="content-block-title">上门配送</div>
                <div class="list-block">
                    <ul class="litigation">
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">姓名：</div>
                                    <div class="item-input">
                                        <input type="text" data-required="true" id="danusername" data-descriptions="username">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">手机：</div>
                                    <div class="item-input">
                                        <input type="text" data-required="true" id="danphone" data-descriptions="phone">
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item-content">
                                <div class="item-inner">
                                    <div class="item-title label">地址：</div>
                                    <div class="item-input">
                                        <input type="text" data-required="true"  id="danaddress" data-descriptions="address">
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div><!-- /list-block -->
                <div class="content-block">
                    <p><a href="#" class="button button-fill " id="danclick">确定</a></p><!--close-popup  -->
                    <p><a href="#" class="button button-fill close-popup" id="closebd">关闭</a></p>
                </div>
            </div><!-- /content -->
        </div>
    </div><!-- /保单发票 Popup -->
</from>
<!-- 阿里OSS  JSSDK -->
<script type="text/javascript" src="http://gosspublic.alicdn.com/aliyun-oss-sdk-4.3.0.min.js"></script>
<script type="text/javascript" src="${contextPath}/static/weixin/ssdb/js/uuid.js"></script>
<script type="text/javascript" src="${contextPath}/static/weixin/ssdb/js/ssdb.js"></script>
<script type='text/javascript' src='${contextPath}/static/weixin/ssdb/js/zepto.js' charset='utf-8'></script>
<script type='text/javascript' src='${contextPath}/static/weixin/ssdb/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='${contextPath}/static/weixin/ssdb/js/sm-extend.min.js' charset='utf-8'></script>
<script>
    $(document).on('click', '.radio-signle', function () {
    	var _this = $(this);
		var _thispar = _this.parent();
		var radio = _this.attr('data-radio');
		var value = _this.attr('data-value');
		if (!_this.hasClass('on')) {
			_this.addClass('on');
			_thispar.siblings().find('.radio-signle').removeClass('on');
			$('input[data-type='+radio+']').val(value);
			radio_if = false;
		}
    });
    
    $(document).on('click', '.open-about', function () {
        $.popup('.popup-about');
    });

    $(document).on('click', '.open-services', function () {
        $.popup('.popup-services');
    });
	var bhtype;
	var typejson=[];
    $(document).on('click', '.open-bh', function () {
     bhtype=$(this)[0].id;//保函类型
        $.popup('.popup-bh');
        typejson.push(bhtype);
    });
	var bdtype;
    $(document).on('click', '.open-bd', function () {
    	bdtype=$(this)[0].id;//保单类型
    	 typejson.push(bdtype);
        $.popup('.popup-bd');
    });
    
$("#closebh").click(function(e){
$('#bh1').attr('checked',false);
$('#bh2').attr('checked',false);
	var danV=$("#hanusername").val();
	if(!danV){//没有填值
	$('input[name=bh]:checked').attr('checked',false);
	}
});
$("#closebd").click(function(e){
});
</script>
<script type="text/javascript">
var orderId="${order.orderId}";
var token="${token}";
var step=3;
//正式
var basePath="<%=com.fadu.app.util.AppConfig.url_duowenapp_b %>"+'/B/android';
var curl="<%=com.fadu.app.util.AppConfig.url_duowenapp_c %>"+'/C/android';
var imageSrc="<%=com.fadu.app.util.AppConfig.url_duowenapp_c %>"+"/ssdbOrderPic?orderAttachId=";//图片
var ssdbupload="<%=com.fadu.app.util.AppConfig.url_duowenapp_c %>"+"/ssdbUpload?companyId=";
//测试
/* 
var basePath="http://localhost:8080/duowenapp_b/B/android";
var curl="http://localhost:8080/duowenapp_c/C/android";
var imageSrc="http://localhost:8080/duowenapp_c/ssdbOrderPic?orderAttachId=";//图片 
var ssdbupload="http://localhost:8080/duowenapp_c/ssdbUpload?companyId=";
  */
//图片原始尺寸
var sourcesHeight=$("#sourceImg1").get(0).clientHeight; ;
var sourcesWidth=$("#sourceImg1").get(0).clientWidth; 
if(sourcesHeight){
}else{
sourcesHeight=70;
}
if(sourcesWidth){
}else{
sourcesWidth=78;
}
//进入页面加载
$(function(){
	$("#logPayHidden").hide();
	var bParameters={"orderId":orderId,"step":step,"actionCode":"B511","encryptCode":"","time":0,"token":token};
	postData(basePath,bParameters,bSucc,bfail);
});
//成功的方法
var bSuccE;
function showBD(e){
 		//配送方式选择 显示
	  deliver1=e.deliver1;//保函配送方式(-1:没有;0:上门配送;1:快递配送;2:上门配送和快递配送)
	  deliver2=e.deliver2;//保单发票配送方式(0:上门配送;1:快递配送;2:上门配送和快递配送)
	if(deliver1=='-1'){
		$("#hidebh").hide();
	}
	if(deliver1=='0'){
		$("#hidebh1").hide();
	}
	if(deliver1=='1'){
		$("#hidebh2").hide();
	}
	
	if(deliver2=='0'){
		$("#hidebd1").hide();
	}
	if(deliver2=='1'){
		$("#hidebd2").hide();
	}
		$("#stateDesc").text(e.stateDesc);
		$("#stateName").text(e.stateName);
		$("#accountNum").text(e.accountNum);
		$("#accountBank").text(e.accountBank);
		$("#accountName").text(e.accountName);
	if(e.companyType==1){
		$("#companyType").html("如何签订合同?")
		$("#emailContent").html("投保单")
		$("#companyType1").text("签订投保单并上传")
	}
	if(e.companyType==0){
		$("#companyType").html("如何签订合同?")
		$("#emailContent").html("服务合同")
		$("#companyType1").text("签订合同并上传")
	}
}
function payWay(e){
	//3.5.0新增支付方式 选择
	var payT=e.payType;
	var _this=$("#weixinID");
	var _thispar = _this.parent();
	if(payT==1){//支付方式(-1:表示未选择;0:转账;1:微信;2:支付宝)(3.4添加)
		if (!_this.hasClass('on')) {
				_this.addClass('on');
				_thispar.siblings().find('.radio-signle').removeClass('on');
		}
	}
}
	function maxStepReturn(e){
		if(e.maxStep==4){
			var url="${contextPath}/web/ssdb/toLetter?orderId="+orderId;
			location.href=url;
		}
	}
	function bSucc(e){
		console.log(e);
		bSuccE=e;
		showBD(e);//
		maxStepReturn(e);//出函页面 判断
		companyId=e.companyId;
	 
	//$("#bh1").attr('checked', 'checked');//it works
	//fileType;//0:保函；1：保单（发票）
	//sendType;//0:上门配送;1:快递配送
	var wls=e.wls;
	for(var i in wls){
	var val=wls[i];
	var fileType=val.fileType;
	var sendType=val.sendType;
	var receiver=val.receiver;
	var mobile=val.mobile;
	var address=val.address;
	if(fileType=='0'){//保函
	//选中
	if(sendType=='1'){
	$("#bh2").attr('checked', 'checked');//it works
	$("#danusername").val(receiver);
	$("#danphone").val(mobile);
	$("#danaddress").val(address);
	}
	if(sendType=='0'){
	$("#bh1").attr('checked', 'checked');//it works
	$("#hanusername").val(receiver);
	$("#hanphone").val(mobile);
	$("#hanaddress").val(address);
		}
	}
	if(fileType=='1'){//
		if(sendType=='1'){
		$("#danusername").val(receiver);
		$("#danphone").val(mobile);
		$("#danaddress").val(address);
		$("#bd2").attr('checked', 'checked');//it works
		}
		if(sendType=='0'){
		$("#hanusername").val(receiver);
		$("#hanphone").val(mobile);
		$("#hanaddress").val(address);
		$("#bd1").attr('checked', 'checked');//it works
				}
			}
	}
	//22;//审核成功（等待付款）
	//30;//等待付款确认（上传转账证明，投保单）
	if(e.orderState==30||e.orderState==31){//上传了资料了 需要显示资料
		//图片处理
		var pay=e.attachPays;//上传付款
		if(pay.length>0){
		$.each(pay,function(index,value){
			var img5=new Image();  
			img5.height=sourcesHeight;
		    img5.width=sourcesWidth;
		    img5.onload=function(){console.log("img is loaded")};  
		    img5.onerror=function(){console.log("error!")};  
		    img5.src=value.path;//imageSrc+value.id 之前的显示
			fileList1.appendChild(img5);
		});
		}
		var attach=e.attachExms;//上传合同
		if(attach.length>0){
		$.each(attach, function (index, value) {
			var img4=new Image();  
			img4.height=sourcesHeight;
		    img4.width=sourcesWidth;
		    img4.onload=function(){console.log("img is loaded")};  
		    img4.onerror=function(){console.log("error!")};  
		    img4.src=value.path;//imageSrc+value.id
			fileList1.appendChild(img4);
		});
	}
	var logPay=e.logPays;
	if(e.orderState==31&&logPay.length>0){
		//有错误 需要重新填写并 显示错误内容：
		$("#submitForm").show();
		$("#sourceImg").show();
		$("#sourceImg1").show();
		$("#submitForm").val("重新提交");
		$("#logPayHidden").show();
		//错误内容展示
		for(var log in logPay){
		var content=logPay[0];
		$("#logPaycontent").text(content.content);
		$("#logPaycreateDate").html(content.createDate);
		}
	}else{
		//提交按钮处理
		$("#submitForm").hide();
		$("#sourceImg").hide();
		$("#sourceImg1").hide();
				}
			}
		}
	function bfail(e){
		console.log(e);
		$.toast("加载失败");
	}
//向后台请求数据
function postData(url, parameters, successCallback, errorCallback){
	$.ajax({
	    type : "POST",
	    url : url,
	    data : JSON.stringify(parameters),
	    dataType : "json",
	    success : function(data) {
	    	successCallback(data); 
	    },
	    error : function(data) {
	    	errorCallback(data);
	    }
    }); 
}
function successCallback(e){
console.log(e);
}
function errorCallback(e){
console.log(e);
}
</script>
//处理邮件发送
<script type="text/javascript">
$("#bhclick").click(function(e){
var hanusername= $("#hanusername").val();
var hanphone= $("#hanphone").val();
var address=$("#hanaddress").val();
if(!hanusername){
$.toast("姓名不能为空");
return;
}
if(!hanphone){
$.toast("手机号码不能为空");
return;
}
if(!address){
$.toast("地址不能为空");
return;
}
if(!hanphone.match(/^[0-9]{11}$/)){
$.toast("请填写正确的手机号码");
return;
}
$.closeModal(".popup-bh");
});
$("#danclick").click(function(){
var danusername= $("#danusername").val();
var danphone= $("#danphone").val();
var danaddress=$("#danaddress").val();
if(!danusername){
$.toast("姓名不能为空");
return;
}
if(!danphone){
$.toast("手机号码不能为空");
return;
}
if(!danaddress){
$.toast("地址不能为空");
return;
}
$.closeModal(".popup-bd");
});

$("#mailSum").click(function(){
var email=$("#email").val();
if(!email){
$.toast("请填写邮箱");
return;
}
//验证邮箱格式
if(!email.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)){
$.toast("请填写正确的邮箱地址");
return;
}

var parm={"companyId":companyId,"email":email,"actionCode":"C101","encryptCode":"","time":0,"token":token};
	postData(curl,parm,cSucc,cfail);
});
function cSucc(e){
$.closeModal(".popup-services");
$.toast("发送成功!");
}
function cfail(e){
$.toast("邮件发送失败");
console.log(e);
}
//文件上传 提交按钮逻辑
//fileType;//0:保函；1：保单（发票）
//sendType;//0:上门配送;1:快递配送
function uploadFile(file,type){
var result="";
var formData = new FormData();
formData.append('file',file );
 //attachType;//附件类型(41:转账;52:保单;61:其他资料)
var attachType=parseInt(52);
var attachTypePay=parseInt(41);
  $.ajax({
    url: ssdbupload+companyId,
    type: 'POST',
    cache: false,
    data: formData,
    async: false,
    processData: false,
    contentType: false,
    success: function(data){
      result = data; 
    }
});
return  result; 
}
		function cSuccF(e){
		console.log(e);
		if(e.success=true){//提交成功
		if(payType==0){
			var url="${contextPath}/web/ssdb/ssdbpayend/"+orderId+"/"+token+"/";
			location.href=url;//付款页面
			return;
		}
		var payUrl=e.payUrl;
		var accountName=e.accountName;
		var act=e.act;
		var bankAccount=e.bankAccount;
		var bankName=e.bankName;
		var goodsAmount=e.goodsAmount;
		var goodsName=e.goodsName;
		var insurerName=e.insurerName;
		var notifyUrl=e.notifyUrl;
		var orderSn=e.orderSn;
		var payCode=e.payCode;
		var sign=e.sign;
		var userName=e.userName;
		var url=payUrl+"&accountName="+accountName
		+"&act="+act+"&bankAccount="+bankAccount+"&bankName="+bankName+"&goodsAmount="+goodsAmount
		+"&goodsName="+goodsName+"&insurerName="+insurerName
		+"&notifyUrl="+notifyUrl+"&orderSn="+orderSn+"&payCode="+payCode
		+"&sign="+sign
		+"&userName="+userName
		;
		console.log(url);
		location.href=url;
			}
		}
		function cfailF(e){
		//$.hideIndicator();
		 $.hidePreloader();
			console.log(e);
			$.toast(e);
		}
		//提交处理   ：点击提交按钮之后的操作
		var fileall=[];
		var filesocial2=[];
		function loadImage(e,type){
		//attachType;//附件类型(41:转账;52:保单;61:其他资料)
		var file1=e.files[0];
		if(file1){
			fileall.push(file1);
		}
	}
		function loadImage1(e,type){
			//attachType;//附件类型(41:转账;52:保单;61:其他资料)
			var file2=e.files[0];
			if(file2){
			filesocial2.push(file2);
			}
			}
		//删除图标后删除对应的图
		function loadImageDelete(e,_this){
		var fileArray = new Array();
		$.each(fileall, function (index, value) {
		fileArray.push(value.name);
		});
		var index=$.inArray(_this, fileArray);
		fileall.remove(index);
		}
		/** 
		*删除数组指定下标或指定对象 
		*/ 
		Array.prototype.remove=function(obj){ 
		for(var i =0;i <this.length;i++){ 
		var temp = this[i]; 
		if(!isNaN(obj)){ 
		temp=i; 
		} 
		if(temp == obj){ 
		for(var j = i;j <this.length;j++){ 
		this[j]=this[j+1]; 
		} 
		this.length = this.length-1; 
				} 
			} 
		} 
		function loadImageDelete1(e,_this){
		var fileArray = new Array();
		$.each(filesocial2, function (index, value) {
		fileArray.push(value.name);
		});
		var index=$.inArray(_this, fileArray);
		filesocial2.remove(index);
		}
		 appServer = 'http://b.duowenlvshi.com/oss/token?name=ssdb';
		 bucket = '${oss_bucket_ssdb}';
		 region = 'oss-cn-shenzhen';
		 Buffer = OSS.Buffer;
		 OSS = OSS.Wrapper;
		 STS = OSS.STS;
		//提交按钮操作
		function submitForm(){
		var loginBtn = this;
		$("#submitForm").prop('disabled', true);
			payType=$("#payTypeID").val();
			
			//配送方式选中判断:
		 	var bh1=$("#bh1").is(':checked');
			var bh2=$("#bh2").is(':checked');
			var bd1=$("#bd1").is(':checked');
			var bd2=$("#bd2").is(':checked');
			var danusername= $("#danusername").val();
			var danphone= $("#danphone").val();
			var danaddress=$("#danaddress").val();
			var hanusername= $("#hanusername").val();
			var hanphone= $("#hanphone").val();
			var address=$("#hanaddress").val();
			if(bSuccE.orderState!==31){
		
		if(deliver1!='-1'){
				$("#submitForm").val('数据提交中');
			}
		} 
				//$.showIndicator();
				//$.showPreloader('加载中...')
				var wlsJson={};
				var wlsJson1={};
				var wlsJsonArray=[];
				if(bh1 || bh2){
				wlsJson.sendType=0;
				wlsJson.fileType=0;
				wlsJson.address=address;
				wlsJson.mobile=hanphone;
				wlsJson.receiver=hanusername;
				if(bh2){
				wlsJson.address=danaddress;
				wlsJson.mobile=danphone;
				wlsJson.receiver=danusername;
				wlsJson.sendType=1;
				wlsJson.fileType=0;
				}
				wlsJsonArray.push(wlsJson);
				}
				if(bd1||bd2){
				wlsJson1.sendType=0;
				wlsJson1.fileType=1;
				wlsJson1.address=address;
				wlsJson1.mobile=hanphone;
				wlsJson1.receiver=hanusername;
				if(bd2){
				wlsJson1.address=danaddress;
				wlsJson1.mobile=danphone;
				wlsJson1.receiver=danusername;
				wlsJson1.sendType=1;
				wlsJson1.fileType=1;
				}
				wlsJsonArray.push(wlsJson1);
			}
			console.log(wlsJsonArray);
			//TODO
			//companyAttachId 是companyAttachId 里面的 attachType;//附件类型(41:转账;52:保单;61:其他资料)
			var attachs={};
			$.each(fileall,function(index,value){
	 		if(value){
       			ossUp(value,41,1);
			}
	});
	function ossUp(value,type,typeKey){
		 jsonArry=new Array();
	   var url = appServer;
        $.ajax({
            type: "POST",
            url: url,
            dataType: "jsonp",
           	async:false,
            success: function(e) {
                var client = new OSS({
                    region: region,
                    accessKeyId: e.AccessKeyId,
                    accessKeySecret: e.AccessKeySecret,
                    stsToken: e.SecurityToken,
                    bucket: bucket
                });
                var fileName = UUIDjs.create().hex;
    	 		var fileType = getFileType(value.name);
         		var key = "ssdb/order/"+companyId+"/"+new Date().getFullYear()+"/"+new Date().getMonth()+"/"+fileName+"."+fileType;
                client.multipartUpload(key, value, {
            	progress: progress
        		}).then(function(res) {
        		path=res.name;
				attachs1.attachType=type;
				attachs1.isNew=false;
				attachs1.name=value.name;
				attachs1.path=path;
				var suffix=path.substring(path.lastIndexOf('.') + 1) ; 
				attachs1.suffix=suffix;
				jsonArry.push(attachs1);
				console.log(jsonArry);
				if(jsonArry.length>=filesocial2.length){
				var wls=wlsJsonArray;
				console.log(wls);
				if(!payType){
					payType=0;
				}
				var cParameters={"payType":payType,"attachs":jsonArry,"deletes":[],"orderId":orderId,"wls":wls,"actionCode":"B514","encryptCode":"","time":0,"token":token}
				console.log(cParameters);
				postData(basePath,cParameters,cSuccF,cfailF);
					}
       			});
            },
            error: function(data) {
                console.log(data);
            }
        	});
	}
	var attachs1={};
	$.each(filesocial2,function(index,value){
	if(value){
	console.log(value.name);
		ossUp(value,52,2);
	}
});
	}
	//根据文件名 获取后缀
	function getFileType(fileName){
    	var ldot = fileName.lastIndexOf('.')
    	if(ldot>=0)
    		return fileName.substring(ldot + 1);
    	else
    		return "";
    }
    var progress = function(p) {//上传成功的进度条
    	return function (done) {
  	 		 done();
  		};
    }
    ;
</script>
<script>
			window.URL = window.URL || window.webkitURL;
			var fileElem = document.getElementById("fileElem"),
			fileList = document.getElementById("filediv");
			fileList1 = document.getElementById("filediv1");
			function handleFiles(obj) {
			var divTag = document.createElement("div");
			 divTag.className = "imgDiv"; 
			 var files = obj.files,
			 img = new Image();
			 img1 = new Image();
			img.width = sourcesWidth;//sourcesWidth
			img.height = sourcesHeight;//sourcesHeight;
			if(window.URL){
			//File API
			if(files[0].size/1024/1024>4){
			$.toast("图片过大，请选择小于4M的文件");
			return;
			}
			console.log(files[0].name + "," + files[0].size + " bytes");
			img.src = window.URL.createObjectURL(files[0]); //创建一个object URL，并不是你的本地路径
			img.id='img1'
			img.name=files[0].name;
			img1.src ="${contextPath}/static/weixin/ssdb/images/delete.png"; //创建一个object URL，并不是你的本地路径
			img1.className="delete";
			img1.onclick= function(){
			divTag.removeChild(img);
			divTag.removeChild(this);
			fileList.removeChild(divTag);
			loadImageDelete(obj,img.name);
			};
			img.onload = function(e) {
			window.URL.revokeObjectURL(this.src); //图片加载后，释放object URL
			loadImage(obj,41);
			}
			divTag.appendChild(img);
			divTag.appendChild(img1);
			fileList.appendChild(divTag);
			}else if(window.FileReader){
			//opera不支持createObjectURL/revokeObjectURL方法。我们用FileReader对象来处理
			var reader = new FileReader();
			reader.readAsDataURL(files[0]);
			reader.onload = function(e){
			img.src = this.result;
			fileList.appendChild(img);
				}
			}else{
			//ie
			obj.select();
			obj.blur();
			var nfile = document.selection.createRange().text;
			document.selection.empty();
			img.src = nfile;
			img.onload=function(){
			}
			fileList.appendChild(img);
			//fileList.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src='"+nfile+"')";
			}
		}
		//
		function handleFiles1(obj) {
			var divTag1 = document.createElement("div");
			divTag1.className = "imgDiv1"; 
			var files = obj.files;
			var img2 = new Image();
			var img3 = new Image();
			img2.width =sourcesWidth;
			img2.height =sourcesHeight;
			if(window.URL){
			//File API
			if(files[0].size/1024/1024>4){
			$.toast("图片过大，请选择小于4M的文件");
			return;
			}
			img2.src = window.URL.createObjectURL(files[0]); //创建一个object URL，并不是你的本地路径
			img2.name=files[0].name;
			img3.src ="${contextPath}/static/weixin/ssdb/images/delete.png"; //创建一个object URL，并不是你的本地路径
			img3.className="delete";
			img3.onclick= function(e){
			divTag1.removeChild(img2);
			divTag1.removeChild(this);
			loadImageDelete1(obj,img2.name);
			fileList1.removeChild(divTag1);
			}
			img2.onload = function(e) {
			window.URL.revokeObjectURL(this.src); //图片加载后，释放object URL
			loadImage1(obj,52);
			}
			divTag1.appendChild(img2);
			divTag1.appendChild(img3);
			fileList1.appendChild(divTag1);
			}else if(window.FileReader){
			//opera不支持createObjectURL/revokeObjectURL方法。我们用FileReader对象来处理
			var reader = new FileReader();
			reader.readAsDataURL(files[0]);
			reader.onload = function(e){
			img.src = this.result;
			fileList1.appendChild(img);
				}
			}else{
			//ie
			obj.select();
			obj.blur();
			var nfile = document.selection.createRange().text;
			document.selection.empty();
			img.src = nfile;
			img.onload=function(){
			console.log(nfile+","+img.fileSize + " bytes");
			}
			fileList1.appendChild(img);
			//fileList.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src='"+nfile+"')";
			}
		}
</script>
</body>
</html>
