<?php require APPPATH_MVC.'views/header.php'; ?>
<script type='text/javascript' src='http://nj.publish.house365.com/swfupload/swfupload.js'></script>
<script type='text/javascript' src='<?php echo USER_CENTER;?>js/swfu.js'></script>
<script type="text/javascript" src="<?php echo USER_CENTER;?>js/handlers.js"></script>
<script src="http://newrent.house365.com/js/jquery.min.js"></script>
<link href="<?php echo USER_CENTER;?>css/upload/jquery.upload.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo USER_CENTER;?>js/upload/jquery.upload.js"></script>
<style>
    .upload-box{
        padding: 0 20px;
        margin: 0 auto;
        margin-top: 40px;
    }

    .upload-box .upload-tip{
        margin-bottom: 20px;
        font-size: 16px;
        color: #555;
    }

</style>
<script>
    $(function() {
        //领取发票    2017-12-14
        $(".checkli .radiop").on("click", function() {
            $(this).parent(".cf").siblings(".cf").children(".radiop").removeClass("radiopon");
            $(this).parent(".cf").siblings(".cf").find("input").removeAttr("checked");
            $(this).addClass("radiopon");
            $(this).children("input").attr("checked", "checked");
            $(this).children("input").change();
        });

        $('.check1,.check2,.check3,.check4').focus(function(){
            $(this).parent().find('span').hide();
        });

        $("input[name=send_type]").change(function(){
            var send_type = $(this).val();
            var user_type =  $('input[name="user_type"]:checked').val();
            var city = "<?php echo GB_CITY; ?>";
            if ( city == 'nj' ) {
                if (user_type == 2) {
                    $('.invoice_collection_div').show();
                    if (send_type == 1) {
                        $('.invoice').show();
                    } else {
                        $('.invoice').hide();
                    }
                }
            } else {
                if (send_type == 1) {
                    $('.invoice').show();
                } else {
                    $('.invoice').hide();
                }
            }
        });
        <?php if (!empty($oldInvoice)) {
            echo 'doradio($("#user_type_'. $oldInvoice['user_type'] .'"));';
            echo 'doradio($("#type_'. $oldInvoice['type'] .'"));';
            echo '$("#send_type_'. $oldInvoice['send_type'] .'").click();';
        } ?>
        var base_path = "<?php echo USER_CENTER; ?>";
        var picArr = eval('<?php echo json_encode( $oldInvoice['pic'] );?>');
        $(".image-box1").ajaxImageUpload({
            fileInput : 'file_name',
            postUrl : 'http://newrent.house365.com/ajax-action/upload-file', //上传的服务器地址
            width : 50,
            height : 50,
            postData : { csrf:'token1' },
            imageUrl: picArr,
            // imageUrl:['http://user.house365.com/images/upload/demo1.jpg'],
            maxNum : 2, //允许上传图片数量
            allowZoom : true, //允许放大
            allowType : ['png','jpg'], //允许上传图片的类型
            maxSize :5, //允许上传图片的最大尺寸，单位M
            appendMethod : 'before',
            before: function () {
                //上传前回调函数1
            },
            success : function(json){
                //上传成功回调函数1
            },
            complete : function () {
                alert('上传成功');
            },
            error : function (e) {
                alert(e.msg + '(' + e.code + ')');
            }
        });
    });
    //单位切换  发票类型切换
    function doradio(obj){
        var city = "<?php echo GB_CITY; ?>";
        if($(obj).children("input").attr("id")==5){
            $(".personl").hide();
            $(".person").show();
            $(".special").hide();
            $("input[id='1']").attr("checked", "checked");
            $("input[id='2']").attr("checked", false);
            $("input[id='5']").attr("checked", "checked");
            $("input[id='6']").attr("checked", false);
            $(obj).addClass("radiopon");
            $("input[id='6']").parent("label").removeClass("radiopon");
            $("input[id='1']").parent("label").addClass("radiopon");
            $(".payshow").hide();
            if ( city == 'nj') {
                $('.invoice_collection_div').hide();
                $('.invoice').hide();
            }
            $('.cf-5').show();
        }else if($(obj).children("input").attr("id")==6){
            $(".special").show();
            $(".person").hide();
            $(".personl").show();
            $(obj).addClass("radiopon");$("input[id='1']").attr("checked", "checked");
            $("input[id='5']").attr("checked", false);
            $("input[id='6']").attr("checked", "checked");
            $("input[id='5']").parent("label").removeClass("radiopon");
            $(".payshow").hide();
            $("input[id='2']").parent("label").removeClass("radiopon");

            var send_type =  $('input[name="send_type"]:checked').val();
            if ( city == 'nj') {
                $('.invoice_collection_div').show();
                if (send_type == 1) {
                    $('.invoice').show();
                }
            }

            var type =  $('input[name="type"]:checked').val();
            if ( type == 1 ) {
                $('.cf-5').show();
            } else {
                $('.cf-5').hide();
            }
        }else if($(obj).children("input").attr("id")==1){
            $(".payshow").hide();
            $(obj).addClass("radiopon");
            $(".paypic").hide();
            $("input[id='2']").attr("checked", false);
            $("input[id='1']").attr("checked", "checked");
            $("input[id='2']").parent("label").removeClass("radiopon");
            $('.cf-5').show();
        }else if($(obj).children("input").attr("id")==2){
            $(".payshow").show();
            $(obj).addClass("radiopon");
            $(".paypic").show();
            $("input[id='1']").attr("checked", false);
            $("input[id='2']").attr("checked", "checked");
            $("input[id='1']").parent("label").removeClass("radiopon");
            $('.cf-5').hide();
        }
    }

    function checka(option){
        if(option == 1){
            $('#submits').attr('disabled','disabled');
            $('#submits').html('提交中...');
        }else{
            $('#submits').removeAttr('disabled');
            $('#submits').html('提交');
        }
    }

    function checkInvoiceForm(){
        var type = $('input[name=type]:checked').val();
        var user_type = $('input[name=user_type]:checked').val();
        if(type == 2 && user_type == 1){
            alert('数据错误！');
        }
        var flag = true;
        var input;
        checka(1)
        if(type == 1 && user_type == 1) {
            $('.check1').each(function () {
                input = $.trim($(this).val());
                if ( input == "") {
                    $(this).parent().find('span').show();
                    flag = false;
                }

                if($(this).attr('name') == 'identity_card'){
                    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                    if(!reg.test(input)){
                        $(this).parent().find('span').html('身份证格式错误！');
                        $(this).parent().find('span').show();
                        flag = false;
                    }
                    if(input == ""){
                        $(this).parent().find('span').html('必填！');
                        $(this).parent().find('span').show();
                        flag = false;
                    }
                }
            });
        }
        if(user_type == '2'){
            $('.check2').each(function(){
                input = $.trim($(this).val());
                if ( input == "") {
                    $(this).parent().find('span').show();
                    flag = false;
                }
            });
            var pic = $("input[name='file_name[]']").val();
            if(pic == '' || pic == undefined){
                $('#pic_error').show();
                flag = false;
            }
            if(type == '2'){
                $('.check3').each(function(){
                    input = $.trim($(this).val());
                    if ( input == "") {
                        $(this).parent().find('span').show();
                        flag = false;
                    }
                });
            }
        }
        var sendType = $("input[name=send_type]:checked").val();
        if(sendType == 1){
            $('.check4').each(function () {
                input = $.trim($(this).val());
                if ( input == "") {
                    $(this).parent().find('span').show();
                    flag = false;
                }
            });
        }

        var city = "<?php echo GB_CITY; ?>";
        if ( city == 'nj' && type != 2 ) {
            $('.check5').each(function () {
                input = $.trim($(this).val());
                if ( input == "") {
                    $(this).parent().find('span').show();
                    flag = false;
                }

                if($(this).attr('name') == 'telno'){
                    if(!check_mobile(input)){
                        $(this).parent().find('span').html('手机号格式错误！');
                        $(this).parent().find('span').show();
                        flag = false;
                    }
                    if(input == ""){
                        $(this).parent().find('span').html('必填！');
                        $(this).parent().find('span').show();
                        flag = false;
                    }
                }

                if($(this).attr('name') == 'email'){
                    if(!check_email(input)){
                        $(this).parent().find('span').html('邮箱格式错误！');
                        $(this).parent().find('span').show();
                        flag = false;
                    }
                    if(input == ""){
                        $(this).parent().find('span').html('必填！');
                        $(this).parent().find('span').show();
                        flag = false;
                    }
                }
            });
        }

        if(!flag){
            checka(0)
        }
        return flag;
    }

    function check_mobile(mobile){
        if(mobile.length != 11 || isNaN(mobile)){
            return false;
        }
        mobile = mobile.substr(0,3);
        //号段
        var hd = new Array('130','131','132','133','134','135','136','137','138','139','150','151','152','153','154','155','156','157','158','159','180','181','182','183','184','185','186','187','188','189');
        var i = hd.length;
        while (i--) {
            if (hd[i] == mobile) {
                return true;
            }
        }
        return false;
    }

    //验证邮箱是否正确
    function check_email(email){
        var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        if(!reg.test(email)){
            return false;
        }else{
            return true;
        }
    }
</script>
<form method="post" action="<?php echo USER_CENTER.'user/createOrderInvoice'?>" onsubmit="return checkInvoiceForm();">
<div class="paywrite">
    <div class="cf plr10">
        <div class="fl f24">
            发票在线填写
        </div>
        <div class="fr">
            <span class="f16">服务热线：</span>
            <span class="f18 colore">

                <?php if(!empty($telno_config)):?>
                    <?php if(!empty($telno_config['telno'])):?>
                    <?=$telno_config['telno']?>
                    <?php endif;?>

                    <?php if(!empty($telno_config['telno2'])):?>
                        <?=$telno_config['telno2']?>
                    <?php endif;?>
                <?php endif;?></span>
        </div>
    </div>
    <div class="tip">发票一经开取不支持"个人"抬头换"企业"抬头方式；放弃开票，网站以后将不再补开；发票均以到付费方式邮寄或用户上我司自行领取</div>
    <div class="tit">
        <span>发票填写 </span>
        <div class="closes"></div>
    </div>
    <div class="poplist">
        <div class="cf">
            <div class="paylabel">发票金额：</div>
            <div class="payli red bold"><?=$orderData['price']?>元</div>
            <input name="order_id"  type="hidden" value="<?=$orderData['id']?>" />
        </div>
        <div class="cf">
            <div class="paylabel">付款单位：</div>
            <div class="payli comli cf">
                <label for="5" class="radiop radiopon" id="user_type_1" onclick="doradio(this)">
                    <input name="user_type" value="1" id="5" <?php if($oldInvoice['user_type'] == 1){ echo 'checked';}?> type="radio" checked="checked" />
                </label>
                <label for="5">个人</label>
                <label for="6" class="radiop ml40" id="user_type_2" onclick="doradio(this)">
                    <input class="payr"  name="user_type" <?php if($oldInvoice['user_type'] == 2){ echo 'checked';}?> value="2" id="6" type="radio" />
                </label>
                <label for="6">单位</label>
            </div>
        </div>
        <div class="cf">
            <div class="paylabel">发票类型：</div>
            <div class="payli cf styleli">
                <label for="1" class="radiop radiopon" id="type_1" onclick="doradio(this)">
                    <input name="type" value="1" id="1" <?php if($oldInvoice['type'] == 1){ echo 'checked';}?> type="radio" checked="checked" />
                </label>
                <label for="1">增值税普通发票</label>

                <label for="2" class="radiop special ml40" id="type_2" style="display: none;" onclick="doradio(this)">
                    <input class="payr" value="2" <?php if($oldInvoice['type'] == 2){ echo 'checked';}?> name="type" id="2" type="radio" />
                </label>
                <label for="2" class="special" style="display: none;">增值税专用发票</label>

            </div>
        </div>
        <div class="cf person">
            <div class="paylabel"><span class="red">*</span>姓名：</div>
            <div class="payli cf"><input name="username" value="<?=$oldInvoice['username']?>" class="payi check1" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <div class="cf person">
            <div class="paylabel"><span class="red">*</span>身份证号：</div>
            <div class="payli cf"><input name="identity_card" value="<?=$oldInvoice['identity_card']?>" class="payi check1" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <?php if(GB_CITY == 'nj') { ?>
        <div class="cf cf-5">
            <div class="paylabel"><span class="red">*</span>手机号：</div>
            <div class="payli cf"><input name="telno" value="<?=$oldInvoice['telno']?>" class="payi check5" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <div class="cf cf-5">
            <div class="paylabel"><span class="red">*</span>邮箱：</div>
            <div class="payli cf"><input name="email" value="<?=$oldInvoice['email']?>" class="payi check5" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <?php  } ?>
        <div class="cf personl" style="display: none;">
            <div class="paylabel"><span class="red">*</span>纳税人抬头：</div>
            <div class="payli cf"><input name="invoice_title" value="<?=$oldInvoice['invoice_title']?>" class="payi check2" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <div class="cf personl" style="display: none;">
            <div class="paylabel"><span class="red">*</span>统一纳税人识别号：</div>
            <div class="payli cf"><input name="invoice_number" value="<?=$oldInvoice['invoice_number']?>" class="payi check2" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <div class="payshow" style="display: none;">

            <div class="cf">
                <div class="paylabel"><span class="red">*</span>开户银行：</div>
                <div class="payli cf"><input name="bank" value="<?=$oldInvoice['bank']?>" class="payi check3" type="text"><span style="display: none;" class="red">必填！</span></div>
            </div>
            <div class="cf">
                <div class="paylabel"><span class="red">*</span>开户账号：</div>
                <div class="payli cf"><input name="bank_account" value="<?=$oldInvoice['bank_account']?>" class="payi check3" type="text"><span style="display: none;" class="red">必填！</span></div>
            </div>

            <div class="cf">
                <div class="paylabel"><span class="red">*</span>公司注册地址：</div>
                <div class="payli cf"><input name="address" value="<?=$oldInvoice['address']?>" class="payi check3" type="text"><span style="display: none;" class="red">必填！</span></div>
            </div>
            <div class="cf">
                <div class="paylabel"><span class="red">*</span>公司注册电话：</div>
                <div class="payli cf"><input name="phone" value="<?=$oldInvoice['phone']?>" class="payi check3" type="text"><span style="display: none;" class="red">必填！</span></div>
            </div>
        </div>
        <div class="cf personl pre" style="display: none;">
            <div id="thumbnails" class="picname">
                <?php
                if (!empty($oldInvoice['pic'])) {
                    foreach ($oldInvoice['pic'] as $key => $value) {
                ?>
<!--                        <div id="image_action_--><?//=$key+1?><!--" class="li deltextFg3Img deltextFg3ImgIndex0" flag="--><?//=$value?><!--" flag_file_url="--><?//=$value?><!--" flag_id="0" flag_tbl="sell" flag_rowid="0" flag_width="690" flag_height="517" onmouseover="showdelBtn(this)" onmouseout="hidedelBtn(this)">-->
<!--                            <div class="li-img">-->
<!--                                <a href="--><?//=$value?><!--" target="_blank">图片</a>-->
<!--                                <input class="p_filename" name="p_filename[]" value="--><?//=$value?><!--" type="hidden">-->
<!--                                <div class="evns">-->
<!--                                    <div class="e-l" style="display: none;"></div>-->
<!--                                    <div class="e-c" style="display: none;"></div>-->
<!--                                    <div class="e-r" onclick="prevOrNextFun(this)"></div>-->
<!--                                </div>-->
<!--                                <div class="rotate rotate_cut"></div>-->
<!--                            </div>-->
<!--                            <input name="p_sort[]" class="jsVal" value="2" type="hidden"><div class="sel" onclick="delImg(this);" style="display: none;">-->
<!---->
<!--                            </div>-->
<!--                        </div>-->
                <?php
                    }
                }
                ?>
            </div>
            <div class="paylabel line34"><span class="red">*</span>上传营业执照：</div>
            <div class="pre fl cf aupload">
                <div class="fl">
<!--                    <div id="spanButtonPlaceholder" style="display:none;"></div>-->
                    <div class="image-box1"></div>
                </div><span class="fl font13 line34 ml10">营业执照需加盖合同章或公章，最多2张，支持jpg、png，单张5M以内。</span>
            </div>
            <div class="pre fl cf auploadn" style="display: none;">
                <div class="fl abg"></div><span class="fl font13 line34 ml10">营业执照需加盖合同章与公章，最多2张,支持jpg、png，单张5M以内。</span>
            </div>
            <div class="payli cf">
                <span style="display: none; left: 0px; top: 8px;" id="pic_error" class="red">必填！</span>
            </div>
            <?php  if (!empty($oldInvoice['pic'])) {?>
                <script>
                    $(".aupload .ml10").removeClass("line34");
                    $(".auploadn .ml10").removeClass("line34");
                    var picNum = $(".deltextFg3Img").length;
                    if (picNum<2) {
                        $(".aupload").show();
                        $(".auploadn").hide();
                    } else if (picNum>=2) {
                        $(".aupload").hide();
                        $(".auploadn").show();
                    }
                </script>
            <?php  }?>
        </div>
        <div class="cf invoice_collection_div" style="<?php if ( $oldInvoice['send_type_show'] != 1 ) echo 'display:none'; ?>">
            <div class="paylabel"><span class="red">*</span>发票领取：</div>
            <div class="checkli cf fl">
                <div class="cf">
                    <label for="3" class="radiop " id="send_type_1">
                        <input name="send_type" <?php if($oldInvoice['send_type'] == 1){ echo 'checked';}?> value="1" id="3" type="radio" />
                    </label>
                    <label for="3">发票邮寄,资费自理。</label>
                </div>
                <div class="cf mt10">
                    <label for="4" class="radiop fl radiopon" id="send_type_2">
                        <input class="payr"  value="2" name="send_type" <?php if($oldInvoice['send_type'] == 2){ echo 'checked';}?> id="4" type="radio" checked="checked" />
                    </label>
                    <label for="4" class="fl checkadd">上门领取:<?=$address_config?>


                        <?php if(!empty($telno_config)):?>
                        <p>
                            （电话：
                            <?php if(!empty($telno_config['telno'])):?>
                                <?=$telno_config['telno']?>
                            <?php endif;?>

                            <?php if(!empty($telno_config['telno2'])):?>
                                <?=$telno_config['telno2']?>
                            <?php endif;?>
                            ）
                        </p>
                        <?php endif;?>


                </div>
            </div>
        </div>
        <div class="cf invoice" style="margin-top: 20px; <?php if ( $oldInvoice['send_type_more_show'] != 1 ) echo 'display:none'; ?>">
            <div class="paylabel"><span class="red">*</span>收货人：</div>
            <div class="payli cf"><input name="mailing_username" value="<?=$oldInvoice['mailing_username']?>" class="payi check4" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <div class="cf invoice" style="<?php if ( $oldInvoice['send_type_more_show'] != 1 ) echo 'display:none'; ?>">
            <div class="paylabel"><span class="red">*</span>地址：</div>
            <div class="payli cf"><input name="mailing_address" value="<?=$oldInvoice['mailing_address']?>" class="payi check4" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <div class="cf invoice" style="<?php if ( $oldInvoice['send_type_more_show'] != 1 ) echo 'display:none'; ?>">
            <div class="paylabel"><span class="red">*</span>电话：</div>
            <div class="payli cf"><input name="mailing_phone" value="<?=$oldInvoice['mailing_phone']?>" class="payi check4" type="text"><span style="display: none;" class="red">必填！</span></div>
        </div>
        <div class="cf">
            <div class="paylabel"></div>
            <div class="popbtn fl"><button id="submits">提交</button></div>
        </div>
    </div>
    <div class="checkmemo">
        <p class="title">温馨提示：</p>
        <p>1、如需开取发票，发票均以到付费方式邮寄或用户上我司自行领取；</p>
        <p>2、发票一经开取不支持"个人"抬头换“企业”抬头方式；</p>
        <p>3、发票若遗失，将无法再次补开，请亲们妥善保管；</p>
        <p>4、放弃开票，网站以后将不再补开；</p>
        <p>5、本页面信息仅供增值税普通发票与增值税专用发票开取业务，切勿进行支付相关业务，谨防上当受骗。</p>

    </div>
</div>
</form>
<!--2017-11-28 end-->
<?php require APPPATH_MVC.'views/footer.php'; ?>
