<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%@ include file="/WEB-INF/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link rel="stylesheet" href="/static/weChat/css/public.css">
    <link rel="stylesheet" href="/static/weChat/css/bai_basic.css">
    <link rel="stylesheet" href="/static/weChat/css/SG_area_select.css">

    <title>发票寄送</title>
</head>
<body id="container">
<%--过度动画--%>
<div id="mask">
    <div class="main">
        <div class="loading">
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </div>
    </div>
    <div class="black-mask-my"></div>
</div>
<div class="arment-head">
    <div class="arment-left">
        <a href="/weixin/order/zzx/zzx_order_make_sure?ins_insurance_slip_id=${p.ins_insurance_slip_id}">
            <img src="/static/weChat/images/arment-left.png"/>
        </a>
    </div>
    <p>发票寄送</p>
</div>
<span id="lm_ert">是否需要发票？</span>
<p class="select-bill" id="select-bill" val="doNotNeed">不需要发票</p>

<form id="defaultForm">
<div class="wed-policy">
    <div class="policy">
        <h2>发票信息</h2>
        <ul class="policy-s1">
            <li>
                <span>收票人姓名</span>
                <div class="dfg">
                    <input id="taker_name" name="taker_name" class="valid_taker_name myValid" placeholder="请填写收票人姓名" id="name_two">
                    <b></b>
                </div>
            </li>
            <li>
                <span>收票人电话</span>
                <div class="dfg">
                    <input id="taker_mobile" name="taker_mobile" class="valid_taker_mobile myValid" placeholder="请填写收票人电话" id="phone_two">
                    <b></b>
                </div>
            </li>
           <%-- <li>
                <span>所在城市</span>
                <div class="dfg">
                    <input type="register_address_invoice" placeholder="请选择" readonly="readonly" class="city" id="selectBtn_two">
                    <b></b>
                </div>
                <div class="ert-cont" style="display: none">
                    <input type="text" id="province-s1">
                    <input type="text" id="city-s1">
                    <input type="text" id="area-s1">
                </div>
            </li>--%>
            <li>
                <span>收票人地址</span>
                <div class="dfg">
                    <i id="ert_two" class="wert taker_address_detail  "></i>
                    <input  name="taker_address_detail" class="valid_taker_address_detail myValid"  id="data_two" style="display: none" >
                    <b></b>
                </div>
            </li>
            <li>
                <span>纳税人识别号</span>
                <div class="dfg">
                    <input  name="taxpayer_number_invoice" class="valid_taxpayer_number_invoice myValid" value="${zj_code}" placeholder="纳税人识别号/三证合一信用号" id="code_two">
                    <b></b>
                </div>
            </li>
        </ul>
        <ul class="policy-s2 policy-top">
          <%--  <li>
                <span>注册城市</span>
                <div class="dfg">
                    <input type="text" placeholder="请选择" readonly="readonly" class="city" id="city_two">
                    <b></b>
                </div>
                <div class="ert-cont" style="display: none">
                    <input type="text" id="province-s2">
                    <input type="text" id="city-s2">
                    <input type="text" id="area-s2">
                </div>
            </li>--%>
              <li>
                  <span>单位名称</span>
                  <div class="dfg">
                      <input name="receipt_head" class="valid_receipt_head myValid" placeholder="请填写单位名称" id="unit_two">
                      <b></b>
                  </div>
              </li>
            <li>
                <span>注册地址</span>
                <div class="dfg">
                    <i id="brt_two" class="wert register_address_invoice"></i>
                    <input name="register_address_invoice" class="valid_register_address_invoice myValid" id="address_two" style="display: none" value="">
                    <b></b>
                </div>
            </li>
            <li>
                <span>固定电话</span>
                <div class="dfg">
                    <input name="receipt_phone" class="valid_receipt_phone myValid" placeholder="请填写企业联系电话" id="dian_two">
                    <b></b>
                </div>
            </li>
            <li>
                <span>开户行所在地</span>
                <div class="dfg">
                    <input  placeholder="请选择" readonly="readonly" class="city bank_area valid_bank_area myValid" id="cheng_two">
                    <b></b>
                </div>
                <div class="ert-cont" style="display: none">
                    <input type="hidden" name="bank_province" id="province-s3">
                    <input type="hidden" name="bank_city" id="city-s3">
                </div>
            </li>
            <li>
                <span>开户银行</span>
                <div class="dfg">
                    <input name="bank_invoice"  class="valid_bank_invoice myValid" placeholder="请填写开户银行全称" id="hang_two">
                    <b></b>
                </div>
            </li>
            <li>
                <span>银行账号</span>
                <div class="dfg">
                    <input name="bank_account_invoice" class="valid_bank_account_invoice myValid" placeholder="请填写银行账号" id="account_two">
                    <b></b>
                </div>
            </li>
        </ul>
    </div>
</div>
</form>

<div class="policy-save on">
    <a href="javascript:;" id="sure">确定</a>
</div>


<!--是否需要发票-->
<div class="business-select" id="bill-model">
    <h2>请选择发票类型</h2>
    <ul>
        <li>
            <p  val="doNotNeed">不需要发票</p>
        </li>
        <li>
            <p id="common_ticker" val="0">增值税普通发票（电子发票）</p>
        </li>
        <li>
            <p id="special_ticker" val="1">增值税专用发票（纸质发票）</p>
        </li>
    </ul>
</div>

<!--增值税专用发票 具体地址1弹窗-->
<div class="business-select" id="cont-three">
    <h2>请填写具体地址</h2>
    <textarea></textarea>
    <div class="sure">
        <p class="ding">确定</p>
        <p class="xiao">取消</p>
    </div>
</div>

<!--增值税专用发票 具体地址2弹窗-->
<div class="business-select" id="cont-four">
    <h2>请填写具体地址</h2>
    <textarea></textarea>
    <div class="sure">
        <p class="ding">确定</p>
        <p class="xiao">取消</p>
    </div>
</div>

<!--黑色蒙版-->
<div class="black-mask"></div>

</body>
<script src="/static/weChat/js/jquery-1.8.3.min.js"></script>

<script src="/static/weChat/js/jquery.formHelper.js"></script>
<script src="/static/weChat/common/layer_mobile/layer.js"></script>
<link rel="stylesheet" href="/static/weChat/common/layer_mobile/need/right.css"/>
<script src="/static/weChat/js/weixin_g.js"></script>

<script src="/static/weChat/js/flexible.js"></script>
<script src="/static/weChat/js/basic.js"></script>
<script src="/static/weChat/js/iscroll.js"></script>
<script src="/static/weChat/js/SG_area_select.js"></script>
<script src="/static/weChat/js/SG_area_select-two.js"></script>
<script src="/static/weChat/js/invoice_sent.js"></script>
<script>

    //统一验证
    var allright=true;
    function isWrong(el,obj, msg){
        if(el){
            $(obj).nextAll("b").remove();
            if(msg!="") $(obj).after("<b style='display:block'>"+msg+"</b>");
            allright=false;
            return false;
        }else{
            $(obj).nextAll("b").remove();
            return true;
        }
    }
    function clearErr(obj){
        $(obj).nextAll("b").remove();
    }

    $(".valid_taker_name").bind("blur keyup",function(){ //收票人名称
        var r1 = isWrong($(this).val().trim()=="",this,"请输入收票人姓名"); if(!r1) return r1;
        var r2 = isWrong(!/^[\u4e00-\u9fa5a-zA-Z0-9]{2,24}$/.test($(this).val()),this,"请输入2-24个中英文字母数字");
    });
    $(".valid_taker_mobile").bind("blur keyup",function(){ //收票人电话
        var r1 = isWrong($(this).val().trim()=="",this,"请输入收票人电话"); if(!r1) return r1;
        var r2 = isWrong(!/^\d{11}$/.test($(this).val()),this,"请输入11位手机号码");
    });
    $(".valid_taker_address_detail").bind("change",function(){ //具体地址
        var r1 = isWrong($(this).val().trim()=="",this,"请输入收票人地址"); if(!r1) return r1;
        var r2 = isWrong( !($(this).val().length<=50 && $(this).val().length>=5),this,"要求5-50个字符长度");
    });
    $(".valid_taxpayer_number_invoice").bind("blur keyup",function(){ //纳税人识别号
        var r1 = isWrong($(this).val().trim()=="",this,"请输入纳税人识别号"); if(!r1) return r1;
        var r2 = isWrong(!/^[a-zA-Z0-9]{5,50}$/.test($(this).val()),this,"请输入5-50个英文数字");
    });
    $(".valid_receipt_head").bind("blur keyup",function(){ //单位名称
        var r1 = isWrong($(this).val().trim()=="",this,"请输入单位名称"); if(!r1) return r1;
        var r2 = isWrong(!/^[\u4e00-\u9fa5a-zA-Z]{2,24}$/.test($(this).val()),this,"请输入2-24个中英文字母");
    });
    $(".valid_register_address_invoice").bind("change",function(){ //注册地址
        var r1 = isWrong($(this).val().trim()=="",this,"请输入注册地址"); if(!r1) return r1;
        var r2 = isWrong( !($(this).val().length<=50 && $(this).val().length>=5),this,"要求5-50个字符长度");
    });
    $(".valid_receipt_phone").bind("blur keyup",function(){ //企业联系电话
        var r1 = isWrong($(this).val().trim()=="",this,"请输入固定电话"); if(!r1) return r1;
        var r2 = isWrong(!/^0\d{2,3}-\d{7,8}(-\d{1,6})?$/.test($(this).val()),this,"请输入正确的固定电话，如：0591-1234567");
    });
    $(".valid_bank_area").bind("change",function(){ //开户行所在地
        var r1 = isWrong($(this).val().trim()=="",this,"请选择开户行所在地"); if(!r1) return r1;
    });
    $(".valid_bank_invoice").bind("blur keyup",function(){ //开户银行名称
        var r1 = isWrong($(this).val().trim()=="",this,"请输入开户银行"); if(!r1) return r1;
        var r2 = isWrong(!/^[\u4e00-\u9fa5a-zA-Z0-9\（\）]{2,40}$/.test($(this).val()),this,"请输入2-40个中英文字母数字");
    });
    $(".valid_bank_account_invoice").bind("blur keyup",function(){ //银行帐号
        var r1 = isWrong($(this).val().trim()=="",this,"请输入银行账号"); if(!r1) return r1;
        var r2 = isWrong(!/^[0-9]{8,20}$/.test($(this).val()),this,"请输入8-20个数字");
    });



    $('#sure').click(function () {
        allright=true;
        $(".myValid").each(function(){
            if ($(this).parent().is(":hidden")) return;
            $(this).trigger("blur"); $(this).trigger("change");
        }); //校验表单
        console.log(allright);
        if(allright){
            if("${row.order_status}"!=""){
                if("${row.order_status}"!="1" && "${row.order_status}"!="2"){
                    layer.open({content:"订单已生效不可以修改",btn: '我知道了'}); return;
                }
            }
            var p  = $("#defaultForm").serializeJson();
            p.ins_mail_policy_id = "${row.ins_mail_policy.ins_mail_policy_id}";
            p.ins_insurance_slip_id = "${p.ins_insurance_slip_id}";
            p.need_insur_bill = '${row.ins_mail_policy.need_insur_bill}';
            //是否需要发票，发票类型的设置
            var val  = $("#select-bill").attr("val");
            if(val=="doNotNeed"){
                p.need_receipt=0; p.invoice_type=0;
            }else if(val=="0"){
                p.need_receipt=1; p.invoice_type=0;
            }else if(val=="1"){
                p.need_receipt=1; p.invoice_type=1;
            }
            $("#mask").show();
            g_ajax("/weixin/order/save/insMailPolicy",p,function(json){
                if (json.success == true) {
                    location.href =  "/weixin/order/zzx/zzx_order_make_sure?ins_insurance_slip_id=${p.ins_insurance_slip_id}";
                } else {
                    layer.open({content:json.msg,btn: '我知道了'})
                    $("#mask").hide();
                }
            },true);
        }else{
            layer.open({content:"请认真填写表单，再点击下一步",btn: '我知道了'})
        }
    });


    //debug
    $(document).ready(function () {
        g_ajax("/weixin/order/detail/debug/",{ins_insurance_slip_id:'${p.ins_insurance_slip_id}'},function(json){
            console.log(json);

            //联系人名
            if(json.ins_mail_policy!=undefined && json.ins_mail_policy.receiver_name!=undefined){
                $("#taker_name").val(json.ins_mail_policy.receiver_name);
            }else if(json.applicant!=undefined && json.applicant.link_name!=undefined){
                $("#taker_name").val(json.applicant.link_name);
            }

            //手机
            if(json.ins_mail_policy!=undefined && json.ins_mail_policy.receiver_mobile!=undefined){
                $("#taker_mobile").val(json.ins_mail_policy.receiver_mobile);
            }else if(json.applicant!=undefined && json.applicant.link_tel!=undefined){
                $("#taker_mobile").val(json.applicant.link_tel==undefined?"":json.applicant.link_tel);
            }

            //邮寄地址
            if(json.ins_mail_policy!=undefined && json.ins_mail_policy.receiver_address_detail!=undefined){
                $("#data_two").val(json.ins_mail_policy.receiver_address_detail);
                $("#ert_two").html(json.ins_mail_policy.receiver_address_detail);
            }else{
                var s = (json.area==undefined?"":json.area)+"  "+ (json.applicant.reg_address==undefined?"":json.applicant.reg_address);
                $("#data_two").val(s);
                $("#ert_two").html(s);
            }

            if(json.ins_mail_policy!=undefined){
                if(json.ins_mail_policy.need_receipt!=undefined){
                    if(json.ins_mail_policy.need_receipt=="1" && json.ins_mail_policy.invoice_type=="0"){ //普通
                        $("#common_ticker").trigger("click");
                    }else if(json.ins_mail_policy.need_receipt=="1" && json.ins_mail_policy.invoice_type=="1"){ //增值
                        $("#special_ticker").trigger("click");
                    }
                }
                $("#defaultForm").setForm(json.ins_mail_policy);
                $(".taker_address_detail").html(json.ins_mail_policy.taker_address_detail);
                $(".register_address_invoice").html(json.ins_mail_policy.register_address_invoice);
                $(".bank_area").val(json.ins_mail_policy.bank_area);
            }
            $("#mask").hide();
        },true);
    })
</script>
</html>