<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<div id="modal-orderDetail" class="modal fade" tabindex="-1" data-backdrop="static">
	<div class="modal-dialog" style="min-width: 650px;">
		<div class="modal-content">
			<div class="modal-header">
      			<div class="table-header text-center">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button>
					订单详情
				</div>
	      	</div>
	      	<div class="modal-body" id="modal-orderDetail-body">
      			
	      	</div>
			<textarea style="resize:none;overflow:hidden; width: 0.01px;height: 0.01px;border:none;opacity: 0" id="foo">.</textarea>
		</div>
	</div>
</div>

<div id="modal-order-Remark" class="modal fade" tabindex="-1" data-backdrop="static">
	<div class="modal-dialog" style="min-width: 650px;">
		<div class="modal-content">
			<div class="modal-header">
				<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button>
					修改备注
				</div>
			</div>
			<div class="modal-body" id="modal-orderRemark-body">
						<div class="modal-body" >
							<div id="mod-edit-tip" class="red clearfix"></div>
							<input type="hidden" id="modal-remark-orderid" value="">
							<input type="hidden" id="modal-remark-tableid" value="">
							<div class="form-group" style="margin-left: 30px;">
								<label class="control-label">请输入备注：</label>
							</div>
							<div class="form-group" style="margin-left: 30px;">
						     <textarea id="modal-orderRemark-text" rows="6" cols="70"
								  placeholder="请输入备注"></textarea>
							</div>
						</div>
						<div class="modal-footer no-margin-top">
							<div class="text-center">
								<button id="mod-check-success" type="button" class="btn btn-sm btn-primary" onclick="savaRemark();">
									保存
								</button>
								<button class="btn btn-sm" data-dismiss="modal">
									取消
								</button>
							</div>
						</div>
			</div>
		</div>
	</div>
</div>


<div id="modal-orderAttachs" class="modal fade" tabindex="-1" data-backdrop="static">
	<div class="modal-dialog" style="min-width: 650px;">
		<div class="modal-content">
			<div class="modal-header">
      			<div class="table-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						<span class="white">&times;</span>
					</button>
					订单文件
				</div>
	      	</div>
	      	<div class="modal-body" id="modal-orderAttachs-body">
      			
	      	</div>
		</div>
	</div>
</div>

<script src="${contextPath}/static/js/plugins/lazyload/jquery.lazyload.js"></script>
<script type="text/javascript" src="${contextPath}/static/js/plugins/copyplugins/clipboard.min.js"></script>
<script type="text/javascript">
	var hiddenModalBody = null;
    var thum = '${oss_bucket_ssdb_url_img}';

	$(function(){

	    /*审核资料*/
		hiddenModalBody = '<div class="row">'
                                + '<div class="col-sm-9 text-left"><h5>审核资料</h5></div>'
                                + '<div class="col-sm-3 text-right" id="wl-sendType0"></div>'
			             + '</div>'
		                 +'<div class="row">'
			                   + '<label class="col-sm-3 control-label">提交的审核资料:</label>'
                               + '<div class="col-sm-9 text-left" id="lawyer-Check"></div>'
			             + '</div>'
                         +'<div class="row">'
                                + '<label class="col-sm-6 control-label">审核反馈补充的资料:</label>'
                                + '<div class="col-sm-6 text-left"></div>'
			            + '</div>'
			            + '<div class="hr-line-dashed"></div>';

		/*投保单*/
        hiddenModalBody += '<div class="row">'
                                 + '<label class="col-sm-3 control-label">投保单原件:</label>'
                                 + '<div class="col-sm-9 text-left" id = "company-Example2"></div>'
                         + '</div>'
                         +'<div class="row">'
                                + '<div class="col-sm-9 text-left"><h5>付款账号信息</h5></div>'
                                + '<div class="col-sm-3 text-right" id="wl-sendType0"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">账户名:</label>'
                              + '<div class="col-sm-9 text-left" id="account_name"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">账号:</label>'
                              + '<div class="col-sm-9 text-left" id="account_num"></div>'
                         + '</div>'
                         +'<div class="row">'
			                  + '<label class="col-sm-3 control-label">开户行:</label>'
                              + '<div class="col-sm-9 text-left" id="account_bank"></div>'
                         + '</div>'
                         + '<div class="hr-line-dashed"></div>';

        /*付款信息*/
        hiddenModalBody += '<div class="row">'
                               + '<div class="col-sm-9 text-left"><h5>付款资料</h5></div>'
                               + '<div class="col-sm-3 text-right" id="wl-sendType0"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">投保单照片:</label>'
                              + '<div class="col-sm-9 text-left" id="lawyer-Example2"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">付款凭证:</label>'
                              + '<div class="col-sm-9 text-left" id="lawyer-Pay"></div>'
                         + '</div>'
			             + '<div class="hr-line-dashed"></div>';

        /*开票信息*/
        /*付款信息*/
        hiddenModalBody += '<div class="row">'
                               + '<div class="col-sm-3 text-left"><h5>开票信息</h5></div>'
                               + '<div class="col-sm-9 text-left" id="wl-sendType0"><button class="copybtn" data-clipboard-action="copy" data-clipboard-target="#foo" > 复制开票信息 </button></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">发票类型:</label>'
                              + '<div class="col-sm-9 text-left " id="fp-invoType"></div>'
			             + '</div>'
                         +'<div class="row">'
                               + '<label class="col-sm-3 control-label">发票抬头:</label>'
                               + '<div class="col-sm-9 text-left" id="fp-name"></div>'
                         + '</div>'
                         +'<div class="row">'
                               + '<label class="col-sm-3 control-label">纳税人识别号:</label>'
                               + '<div class="col-sm-9 text-left" id="fp-taxNum"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">公司地址:</label>'
                              + '<div class="col-sm-9 text-left" id="fp-addr"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">电话:</label>'
                              + '<div class="col-sm-9 text-left" id="fp-tel"></div>'
                         + '</div>'
                         +'<div class="row">'
			                 + '<label class="col-sm-3 control-label">开户名:</label>'
                             + '<div class="col-sm-9 text-left" id="fp-name"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">开户账号:</label>'
                              + '<div class="col-sm-9 text-left" id="fp-bankAccount"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">开户行:</label>'
                              + '<div class="col-sm-9 text-left" id="fp-bankName"></div>'
                         + '</div>'
                         +'<div class="row">'
                             + '<label class="col-sm-3 control-label">开户行行号:</label>'
                             + '<div class="col-sm-9 text-left"></div>'
                         + '</div>'
                         + '<div class="hr-line-dashed"></div>';

        /*保险公司出函资料*/
        hiddenModalBody += '<div class="row">'
                               + '<div class="col-sm-9 text-left"><h5>保险公司出函资料</h5></div>'
                               + '<div class="col-sm-3 text-right" id="wl-sendType0"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">保函:</label>'
                              + '<div class="col-sm-9 text-left" id="company-Example1"></div>'
                         + '</div>'
                         +'<div class="row">'
                              + '<label class="col-sm-3 control-label">发票:</label>'
                              + '<div class="col-sm-9 text-left" id="company-Invoice"></div>'
			             + '</div>';

        /*结束*/
        hiddenModalBody += '<div class="modal-footer no-margin-top" style="margin-bottom: -36px">'
								+ '<div class="text-center">'
				                   + '<button class="btn btn-sm" data-dismiss="modal">'
		                           + '关闭'
								+ '</button>'
								+ '</div>'
			             + '</div>' ;
	});

    function copyFp(){

	}


	
	function formatStr(str){
		var result = '';
		if(str != undefined && str != null){
			result = str;
		}
		return result;
	}

	function initModalTableBody(){
		$('#modal-orderDetail-body').html(hiddenModalBody);
	}
	
	function isNotBlank(obj){
		var result = true;
		if(obj == undefined || obj == null || obj == 'null' || obj.length < 1){
			result = false;
		}
		return result;
	}

    function showRemark(remark,id,tableId){
	    if (remark != 'null') {
            $('#modal-orderRemark-text').val(remark);
		} else {
            $('#modal-orderRemark-text').val("");
		}
        $("#modal-remark-tableid").val(tableId);
		$("#modal-remark-orderid").val(id);
        $("#modal-order-Remark").modal("toggle");
	}

	function savaRemark() {
		var id = $("#modal-remark-orderid").val();
		var remark = $("#modal-orderRemark-text").val();
		var tableId = $("#modal-remark-tableid").val();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/order/updateOrderRemark",
            type : "post",
            data : {
                'orderId' : id,
				'remark':remark
            },
            complete : function(ret) {
                $("#modal-order-Remark").modal("toggle");
                jQuery(tableId).trigger("reloadGrid");
            }
    });
	}
	
	function showdetail(id){
		$('#modal-orderDetail-body').html('');
        var html = '';
        initModalTableBody();

        $.ajax({
            dataType : "json",
            url : "${contextPath}/order/getOrderAllDetail",
            type : "post",
            data : {
                'orderId' : id
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                if(ret.success) {
                    var sum = 0 ;
					sum = parseInt(ret["lawyerCheck"]);
					/*提交审核的资料*/
					if (sum > 0) {
					    html = '<button onclick=\"window.open(\'${contextPath}/order/downloadOrderAttachsByType?id=' + id + '&key=' + 31 + '\')\" > 下载 </button>';
                    }
                    $('#lawyer-Check').html(html);

					/*投保单原件*/
                    sum = parseInt(ret["companyNosignExample2"]);
                    html = '';
                    if (sum > 0) {
                        html = '<button onclick=\"window.open(\'${contextPath}/order/downloadOrderAttachsByType?id=' + id + '&key=' + 74 + '\')\" > 下载 </button>';
                    }
                    $('#company-Example2').html(html);
                    $("#modal-orderDetail").modal("toggle");

                    /*付款资料*/
                    /*投保单照片*/
                    sum = parseInt(ret["lawyerExample2"]);
                    if (sum > 0) {
                        var arr = ret["lawyerExample2Urls"];
                        arr = arr.substring(1,arr.length-1);
                        var list = arr.split(',');
                        var html = '';
                        for(var i = 0 ; i < list.length; i ++){
                            var url = list[i].trim();
                            html +='<a href="' + thum +'/'+ url + '" target="_blank">';
                            html += '<img src="' + thum +'/'+ url + '" class="img-thumbnail" style="height: 84px;width: 84px;margin-left: 20px">';
                            html +='</a>&nbsp;';
                        }
                        $('#lawyer-Example2').html(html);
                    }

                    /*付款照片*/
                    sum = parseInt(ret["lawyerPay"]);
                    if (sum > 0) {
                        var arr = ret["lawyerPayUrls"];
                        arr = arr.substring(1,arr.length-1);
                        var list = arr.split(',');
                        var html = '';
                        for(var i = 0 ; i < list.length; i ++){
                            var url = list[i].trim();
                            html +='<a href="' + thum +'/'+ url + '" target="_blank">';
                            html += '<img src="' + thum +'/'+ url + '" class="img-thumbnail" style="height: 84px;width: 84px;margin-left: 20px;margin-top: 10px">';
                            html +='</a>&nbsp;';
                        }
                        $('#lawyer-Pay').html(html);
                    }

                    /*开票信息*/
					var fp = ret.fp ;
					if (fp != null) {
					    var copyStr = "";
					    if (fp.invoType == '0') {
					        $("#fp-invoType").html("普通发票");
                        } else if (fp.invoType == '1') {
                            $("#fp-invoType").html("增值税发票");
                        }
						$("#fp-name").html(fp.name);
                        $("#fp-taxNum").html(fp.taxNum);
                        $("#fp-addr").html(fp.addr);
                        $("#fp-tel").html(fp.tel);

                        $("#fp-bankAccount").html(fp.bankAccount);
                        $("#fp-bankName").html(fp.bankName);
						copyStr = $("#fp-invoType").html() + "\r\n"+fp.name +"\r\n"+ fp.taxNum +"\r\n"+ fp.addr + "\r\n"+fp.tel + "\r\n"+fp.bankAccount + "\r\n"+fp.bankName ;
                        $("#foo").text(copyStr);
                    }

                    /*保函 & 发票*/
                    sum = parseInt(ret["companyExample1"]);
                    if (sum > 0) {
                        var arr = ret["companyExample1Urls"];
                        arr = arr.substring(1,arr.length-1);
                        var list = arr.split(',');
                        var html = '';
                        for(var i = 0 ; i < list.length; i ++){
                            var url = list[i].trim();
                            html +='<a href="' + thum +'/'+ url + '" target="_blank">';
                            html += '<img src="' + thum +'/'+ url + '" class="img-thumbnail" style="height: 84px;width: 84px;margin-left: 20px;margin-top: 10px">';
                            html +='</a>&nbsp;';
                        }
                        $('#company-Example1').html(html);
                    }

                    sum = parseInt(ret["companyInvoice"]);
                    if (sum > 0) {
                        var arr = ret["companyInvoiceUrls"];
                        arr = arr.substring(1,arr.length-1);
                        var list = arr.split(',');
                        var html = '';
                        for(var i = 0 ; i < list.length; i ++){
                            var url = list[i].trim();
                            html +='<a href="' + thum +'/'+ url + '" target="_blank">';
                            html += '<img src="' + thum +'/'+ url + '" class="img-thumbnail" style="height: 84px;width: 84px;margin-left: 20px;margin-top: 10px">';
                            html +='</a>&nbsp;';
                        }
                        $('#company-Invoice').html(html);
                    }

                } else {
                    alert(ret.message);
                }
            }
		});


        /*获取公司付款账号信息*/
        $.ajax({
            dataType : "json",
            url : "${contextPath}/order/getOrderAccount",
            type : "post",
            data : {
                'orderId' : id
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText + ")");
                if(ret.success) {
                   $("#account_name").html(ret.accountName);
                   $("#account_bank").html(ret.accountBank);
                   $("#account_num").html(ret.accountNum);
                }
            }
        });
	}

	function showOrderFilesByType(id,type){
		$('#modal-orderAttachs-body').html('');
		$.ajax({
			dataType : "json",
			url : "${contextPath}/order/getOrderAttachsByAttachType",
			type : "post",
			data : {
				'orderId' : id,
				'attachType' : type
			},
			complete : function(ret) {
				var ret = eval("(" + ret.responseText + ")");
				if(ret.success){
					var attachs = ret.attachs;
					var aBean,name,oa = null;
					var html = '';
					var i = 1;
					var url = '${oss_bucket_ssdb_url}';
					var thum = '${oss_bucket_ssdb_url_img}';
					var size = '${oss_bucket_ssdb_url_img_size}';
					for(var j=0;j<attachs.length;j++){
						aBean = attachs[j];
						name = formatStr(aBean.name);
						if(name.length > 0){
							html += '<div class="row">'
									+ '<div class="col-md-2">' + i + '、' + name + '</div>'
									+ '<div class="col-md-10">';
							for(var m in aBean.attachs){
								oa = aBean.attachs[m];
								html +='<a href="' + url + oa.path + '" target="_blank">';
								html += '<img class="lazy" src="${contextPath}/static/img/loading.gif" data-original="' + thum + oa.path + size + oa.suffix.toLowerCase() + '" height="100" width="100">';
								html +='</a>&nbsp;';
							}			
							html +=   '</div>'
								  + '</div>'
								  + '<div class="hr-line-dashed"></div>';
							i++;
						}else{
							html += '<div class="row">'
									+ '<div class="col-md-12">';
							for(var m in aBean.attachs){
								oa = aBean.attachs[m];
								if('74' == type){
									html +='<a href="' + url + oa.path + '" target="_blank">';
									html +=oa.name;
									html +='</a>&nbsp;';
								}else{
									html +='<a href="' + url + oa.path + '" target="_blank">';
									html += '<img class="lazy" src="${contextPath}/static/img/loading.gif" data-original="' + thum + oa.path + size + oa.suffix.toLowerCase() + '" height="100" width="100">';
									html +='</a>&nbsp;';
								}
							}			
							html +=   '</div>'
								  + '</div>';
						}
					}
					$('#modal-orderAttachs-body').html(html);
					$("#modal-orderAttachs").modal("toggle");
					setTimeout(function () {
						$("img.lazy").lazyload({
							threshold : 200
						});
					}, 200);
				}else{
					alert(ret.message);
				}
			}
		});
	}
</script>
<script>
    var clipboard = new Clipboard('.copybtn');

    clipboard.on('success', function(e) {
        console.log("success");
        console.log(e);
        console.log(e.text);
    });

    clipboard.on('error', function(e) {
        console.log(e);
    });

</script>