<?php
use \common\libs\MyLib;
use \common\models\PriceT;

$my = $this->context->my;
?>
<link href="/css/tabs.css" rel="stylesheet" type="text/css">
<link href="/js/addr/addr.css" rel="stylesheet" type="text/css">
<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/datepicker/WdatePicker.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<script type="text/javascript" language="javascript" src="/js/common2.js"></script>

<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <tr>
        <td height="22" colspan="2" class="td_bg">
            <table width="100%" align="center" height="120" border="0" cellpadding="0" cellspacing="0" id="mainTable">
                <tr>
                    <td height="120" valign="top" class="td_bg">
                        <!--预约信息-->
                        <table>
                            <tbody>
                            <tr>
                                <TD height="30" align="center" class=tab-on id=navcell onclick=open_up(1) name="navcell">▼预约信息</TD>
                            </tr>
                            </tbody>
                        </table>
                        <TABLE id=tb1 cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb">
                            <TR>
                                <TD vAlign=top>
                                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">车牌号</td>
                                            <td height="25" class="td_bg"><?=$car_info->car_no?></td>
                                            <td width="100" height="25" class="bg_tr">厂牌型号</td>
                                            <td height="25" class="td_bg"><?=$car_info->factory_model?></td>
                                            <td width="100" height="25" class="bg_tr">品牌</td>
                                            <td height="25" class="td_bg"><?=$car_info->brand?$car_info->brand->name:''?></td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">发动机号</td>
                                            <td height="25" class="td_bg"><?=$car_info->engine_no?></td>
                                            <td width="100" height="25" class="bg_tr">车架号</td>
                                            <td height="25" class="td_bg"><?=$car_info->car_frame_no?></td>
                                            <td width="100" height="25" class="bg_tr">初登日期</td>
                                            <td height="25" class="td_bg"><?=$car_info->register_date?></td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">车辆类型</td>
                                            <td height="25" class="td_bg"><?=$car_info->carType?$car_info->carType->name:''?></td>
                                            <td width="100" height="25" class="bg_tr">运营性质</td>
                                            <td height="25" class="td_bg"><?=$car_info->carUse?$car_info->carUse->name:''?></td>
                                            <td width="100" height="25" class="bg_tr">座位数</td>
                                            <td height="25" class="td_bg">
                                                <?=$car_info->seats?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">车系</td>
                                            <td height="25" class="td_bg"><?=$car_info->series?$car_info->series->name:''?></td>
                                            <td width="100" height="25" class="bg_tr">排量</td>
                                            <td height="25" class="td_bg"><?=$car_info->displacement?$car_info->displacement->name:''?></td>
                                            <td width="100" height="25" class="bg_tr">年份</td>
                                            <td height="25" class="td_bg"><?=$car_info->car_year?></td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">车主</td>
                                            <td height="25" class="td_bg"><?=$car_info->car_man?></td>
                                            <td width="100" height="25" class="bg_tr">联系电话</td>
                                            <td height="25" class="td_bg">
                                                <form id="myform">
                                                    <input type="hidden" name="car_id" value="<?=$car_info->id?>" />
                                                    <input type="text" value="<?=$car_info->phone?>" name="phone" class="phone"/>
                                                    <div onclick="tpy_call_in('<?= $car_info->phone?>')" class="act1">拨号</div>
                                                    <div onclick="tpy_call_out()" class="act1">挂机</div>
                                                    <span class="insurantPo_ad">
                                                    <input type="text" value="<?=$car_info->phone1?>" name="phone1" class="phone1" onblur="inphone()"/>
                                                         <div onclick="tpy_call_in('<?= $car_info->phone1 ?>')" class="act1 butPhone1">拨号</div>
                                                        <div onclick="tpy_call_out()" class="act1">挂机</div>
                                                    </span>
                                                    <span class="insurantPo_ad1">
                                                         <input type="text" value="<?=$car_info->phone2?>" name="phone2" class="phone2" onblur="inphone1()"/>
                                                         <div onclick="tpy_call_in('<?= $car_info->phone2 ?>')" class="act1 butPhone2">拨号</div>
                                                        <div onclick="tpy_call_out()" class="act1">挂机</div>
                                                    </span>
                                                </form>

                                            </td>
                                            <style>
                                                .insurantPo_ad,.insurantPo_ad1{
                                                    display: inline-block;
                                                    margin-top:5px;
                                                }
                                                .act1{
                                                    display: inline-block;
                                                    text-align: center;
                                                    width: 42px;
                                                    line-height:26px;
                                                    background: #e5e5e5;
                                                    border: 1px solid #ccc;
                                                    color: #000;
                                                }
                                            </style>
                                            <script>
                                                $(function(){
//                                                    var intnum=0
//                                                    $('.insurantPo').click(function(){
////                                                        intnum++;
////                                                        alert(intnum);
//                                                        var ht='<input type="text" value="<?//=$car_info->phone2?>//" name="phone2" class="phone2" onblur="inphone1()"/> <button onclick="tpy_call_in("<?//=$car_info->phone2?>//")" class="butPhone2">拨号</button><button onclick="tpy_call_out()">挂机</button>'
//                                                        $('.insurantPo_ad1').html(ht);
//
//
//                                                    })

                                                })

                                                function inphone(){
//                                                    Number($('#total1').val())
                                                    var phone1=$('.phone1').val();
                                                    $('.butPhone1').attr('onclick','tpy_call_in("'+phone1+'")');

                                                }
                                                function inphone1(){
//                                                    Number($('#total1').val())
                                                    var phone2=$('.phone2').val();
                                                    $('.butPhone2').attr('onclick','tpy_call_in("'+phone2+'")');
                                                }
                                            </script>
                                            <td width="100" height="25" class="bg_tr">车主证件号码</td>
                                            <td height="25" class="td_bg">
                                                <?=$car_info->car_man_number?>
                                            </td>
                                        </tr>
                                        <tr>
                                                <td width="100" height="25" class="bg_tr">商业止保日期</td>
                                                <td height="25" class="td_bg"><?=$car_info->insurer1_date?></td>
                                                <td width="100" height="25" class="bg_tr">交强止保日期</td>
                                                <td height="25" class="td_bg"><?=$car_info->insurer2_date?></td>
                                                <td width="100" height="25" class="bg_tr">保险公司</td>
                                                <td height="25" class="td_bg"><?=$car_info->company?></td>

                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">备注</td>
                                            <td colspan="5" height="25" class="td_bg"><?=$car_info->remark?></td>
                                        </tr>
                                        <tr>
                                            <td height="22" colspan="6" align="center" class="td_bg">
                                                <input type=button class="ACT_btn baocun" name="next-btn" value=" 保存 "/>
                                            </td>
                                        </tr>
                                    </table>


                                    <h3>预约</h3>
                                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table" style="table-layout: fixed;">
                                        <form id="appointmentFrm">
                                            <input type="hidden" name="car_id" class="car_id" value="<?=$car_info->id?>">

                                            <tr>
                                                <td height="22" colspan="8" align="center" class="td_bg">
<!--                                                    <input id="return-btn" type=button class="ACT_btn" name="return-btn" value="恢复数据"/>-->
<!--                                                    <input id="appointment-save-btn" type=button class="ACT_btn" name="appointment-save-btn" value=" 预约保存 "/>-->
                                                    <select name="invalid_id" id="invalid_id">
                                                        <option value="0">请选择理由</option>
                                                        <?php foreach($failure_items as $item) {?>
                                                            <option value="<?=$item->id?>"><?=$item->name?></option>

                                                        <?php  }?>

                                                    </select>
                                                    <input type=button class="ACT_btn zjbaocun-btn" name="zjbaocun-btn" value=保存 "/>
                                                    <input type="button" class="ACT_btn back-btn" name="back-btn" value=" 返回 ">
<!--                                                    <input type=button class="ACT_btn invalid-btn" name="invalid-btn" value=" 无效数据 "/>-->
<!--                                                    <input type=button class="ACT_btn right-btn" name="right-btn" value="保存准确列表"/>-->
<!--                                                    <input type=button class="ACT_btn next-btn" name="next-btn" value="下一个" id="next-btn"/>-->
                                                </td>
                                            </tr>
                                        </form>
                                    </table>
                                    <div class="xtop">
                                        <div class="xchide">
                                            <div class="qbox">
                                                商业起保日期: <input class="act_date ac1" type="text" name="insurer1_date" value="<?=$car_info->register_date?>" onclick="WdatePicker()">
                                            </div>

                                            <div class="qbox">
                                                交强起保日期: <input class="act_date ac2" type="text"  name="insurer2_date" value="" onclick="WdatePicker()">
                                            </div>

                                            <!--                                            <div class="qbox">-->
                                            <!--                                                保险公司:<select name="company" class="cpys" style="width:100px;">-->
                                            <!--                                                    <option value="">---请选择---</option>-->
                                            <!--                                                    --><?php
                                            //                                                    foreach($insurer_company2_items as $item) {
                                            //                                                        echo '<option value="'.$item->name.'"';
                                            //
                                            //                                                        echo '>'.$item->name.'</option>';
                                            //                                                    }
                                            //                                                    ?>
                                            <!--                                                </select>-->
                                            <!--                                            </div>-->
                                            <div class="qbox">
                                                <button class="queding">确定</button>
                                                <button class="qux">取消</button>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="appointment_list"></div>


                                </TD>
                            </TR>
                        </TABLE>
                        <style>
                            .qbox{
                                margin-top:10px;
                                margin-left: 10px;
                            }
                            .xtop{
                                position: relative;
                            }
                            .xchide{
                                background: #e4f1fa;
                                width: 200px;
                                height: 110px;
                                margin: auto;
                                left: 0;
                                top: 0px;
                                border:1px solid #a5d0e1;
                                position: absolute;
                                display: none;
                                bottom: 0; right: 0;
                            }

                        </style>



                        <!--操作记录-->
                        <table>
                            <tbody>
                            <tr>
                                <TD height="30" align="center" class=tab-off id=navcell onclick=open_up(3) name="navcell">▲操作记录</TD>
                            </tr>
                            </tbody>
                        </table>
                        <TABLE id=tb3 cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb" class="hide-table">
                            <TR>
                                <TD vAlign=top>
                                    <div id="car_history_list"></div>
                                </TD>
                            </TR>
                            <tr>
                                <td align="center">
                                    <input type="button" class="ACT_btn back-btn" name="Submit3" value=" 返回 ">
                                </td>
                            </tr>
                        </TABLE>


                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

<script type="text/javascript" language="javascript">

    function getData() {
        var back_params = '<?=$back_params?>';
        $.get('/database/ajax-a-data-next', function (obj) {
            alert(obj.msg);
            if (obj.success) {
//                window.location.href = '/filtrationt/info?id=' + obj.data;
                window.location.href = '/filtrationt/info?id=' + obj.data+'&back_params='+encodeURIComponent(back_params);
            }
        }, 'json');
    }


    //太平洋测试拨号挂断
    function tpy_call_in(mobile){
        var tpy_phone = mobile;
//        alert(tpy_phone);
//        return;
        if(tpy_phone == ""){
            alert("请输入号码");
            return false;
        }
        var ext_phone = '<?=$this->context->my->ext_phone?>';
//        return;
        $.post('/tpy-phone/call-to',{ext_phone:ext_phone,phone_num:tpy_phone},function(obj){
            if(obj.success) {
                //$('#tpy_call_in').attr('disabled',true);
                //$('#tpy_call_out').removeAttr('disabled');
                alert(obj.msg);
            }else{
                alert(obj.msg);
            }
        },'json');
    }
    //太平洋测试挂断电话
    function tpy_call_out(){
        var ext_phone = '<?=$this->context->my->ext_phone?>';
        $.post('/tpy-phone/hang-up',{ext_phone:ext_phone},function(obj){
            if(obj.success) {
                //$('#tpy_call_out').attr('disabled',true);
                //$('#tpy_call_in').removeAttr('disabled');
                alert(obj.msg);
            }else{
                alert(obj.msg);
            }
        },'json');
    }
    //报价计算
      //商业含税逆向算总净保费



    //判断是否填写了选项
    function isNull(data){

        if(data == "" || data == undefined || data == null){
            return true;
        }else{
            return false;
        }
    }




    $(function(){







        $('.zjbaocun-btn').click(function(){
            var car_id = $('.car_id').val();
            var invalid_id = $('#invalid_id').val();
//            var invalid_id = $('#invalid_id').val();
            if(invalid_id == 0) {
                alert('必须选择理由!');
                return;
            }
//            alert(car_id)


                $.post('/database/zhongji-xuanze',{car_id:car_id,invalid_id:invalid_id},function(obj){
                    alert(obj.msg);
                    if(obj.success) {

                        $('.zjbaocun-btn').attr('disabled',true);


                        getData();

                    }
                },'json');

        });
        $('.invalid-btn').click(function(){
            var car_id = $('.car_id').val();
            var invalid_id = $('#invalid_id').val();
//            var invalid_id = $('#invalid_id').val();
            if(invalid_id == 0) {
                alert('必须选择无效理由!');
                return;
            }
//            alert(car_id)
            if(confirm('是否无效这条数据?')) {

                $.post('/database/mistake',{car_id:car_id,invalid_id:invalid_id},function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        $('.xchide').hide()
                        $('#appointment-save-btn').attr('disabled',true);
                        $('.save-btn').attr('disabled',true);
                        $('.right-btn').attr('disabled',true);

                        $('.invalid-btn').attr('disabled',true);

                    }
                },'json');
            }
        });
        $('.right-btn').click(function(){
            var car_id = $('.car_id').val();

//            alert(car_id)
            if(confirm('是否分配到数据准确库?')) {
//                actionCleanToRight
                $.post('/database/clean-to-right',{car_id:car_id},function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        $('.xchide').hide()
                        $('#appointment-save-btn').attr('disabled',true);
                        $('.save-btn').attr('disabled',true);
                        $('.invalid-btn').attr('disabled',true);
                        $('.right-btn').attr('disabled',true);

                    }
                },'json');
            }
        });
//        $('#return-btn').click(function(){
//            var car_id = $('.car_id').val();
//
////            alert(car_id)
//            if(confirm('是否恢复数据?')) {
////                actionCleanToRight
//                $.post('/database/ajax-a-return',{id:car_id},function(obj){
//                    alert(obj.msg);
//                    if(obj.success) {
//                        <?php
//                        $url = '';
//
//                        $url = '/database/clean-index?'.$back_params;
//                        echo 'window.location.href = "'.$url.'"';
//                        ?>
//
//                    }
//                },'json');
//            }
//        });
        $('.qux').click(function(){
            $('.xchide').hide()
        })
        $('.queding').click(function(){
            var ac1=$('.ac1').val();
            var ac2=$('.ac2').val();
//            var ac3=$('.cpys').val();
            var car_id = $('#car_id').val();
            var invalid_id = $('#invalid_id').val();
            if(ac1==''|| ac2==''){
                alert('请填写保险日期')
                return false;
            }else{
                if(confirm('是否无效这条数据?')) {

                    $.post('/car/invalid-new-man',{car_id:car_id,invalid_id:invalid_id,ac1:ac1,ac2:ac2},function(obj){
                        alert(obj.msg);
                        if(obj.success) {
                            $('.xchide').hide()
                            $('#appointment-save-btn').attr('disabled',true);
                            $('.save-btn').attr('disabled',true);
                            $('.invalid-btn').attr('disabled',true);
                            next_index = next_index - 1;
                            if(next_index < 0) next_index = 0;
                        }
                    },'json');


                }
            }

        })


        //操作历史
        gotoPage('/car/ajax-history-index?car_id=<?=$car_info->id?>&page=1&t='+Math.random(),'car_history_list');
        //添加自费礼品
        $('#gift-add-btn').click(function(){
            var params = $('#giftFrm').serialize();
            $.post('/gift/car-add-save',params,function(obj){
                alert(obj.msg);
                if(obj.success) {
                    $('#giftFrm')[0].reset();
                    gotoPage('/gift/ajax-car-index?car_id=<?=$car_info->id?>&t='+Math.random(),'gift_list');
                }
            },'json');
        });

        //预约人数
        $('#pdate').blur(function(){
            var params = $("#appointmentFrm").serialize();
            $.post('/appointment/count',params,function(obj){
                if(obj.success) {
                    $('#day_count').html(obj.count);
                }
            },'json');
        });
        //添加预约
        $('#appointment-save-btn').click(function(){
            if(confirm('是否确认提交?')) {
                var params = $("#appointmentFrm").serialize();
                $.post('/filtrationt/save',params,function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        $('#appointmentFrm')[0].reset();
                        $('.invalid-btn').attr('disabled',true);
                        $('.right-btn').attr('disabled',true);


                        gotoPage('/filtrationt/ajax-index?car_id=<?=$car_info->id?>&page=1&t='+Math.random(),'appointment_list');
                    }
                },'json');
            }
        });
        gotoPage('/filtrationt/ajax-index?car_id=<?=$car_info->id?>&page=1&t='+Math.random(),'appointment_list');


        $('#brand_id').change(function(){
            var brand_id = $(this).val();
            $('#series_id').html('<option value="0">---请选择---</option>');
            $('#displacement_id').html('<option value="0">---请选择---</option>');
            if(brand_id > 0) {
                $.get('/car/series',{brand_id:brand_id},function(obj){
                    if(obj.success) {
                        $('#series_id').html(obj.html);
                    }
                },'json');
            }
        });
        $('#series_id').change(function(){
            var series_id = $(this).val();
            $('#displacement_id').html('<option value="0">---请选择---</option>');
            if(series_id > 0) {
                $.get('/car/displacement',{series_id:series_id},function(obj){
                    if(obj.success) {
                        $('#displacement_id').html(obj.html);
                    }
                },'json');
            }
        });
        $('#total1_clear').blur(function(){
            calc();
            refreshCompanyGift();
        });
        $('#total2_clear').blur(function(){
            calc();
        });
        $('#total3').blur(function(){
            calc();
        });
        $('#total1_dis').blur(function(){
            calc();
        });
        $('#total1_real').blur(function(){
            calc();
        });

        //保存
        $('.save-btn').click(function(){
            SaveOrder(1);
        });
        //提交


        //返回
        $('.back-btn').click(function(){
            <?php
            $url = '';
//            if($type == 1)
//                $url = '/appointment/first?'.$back_params;
//            if($type == 2)
//                $url = '/appointment/today?'.$back_params;
//            if($type == 3)
//                $url = '/appointment/all?'.$back_params;
//            if($type == 4)
                $url = '/database/clean-index?'.$back_params;
            echo 'window.location.href = "'.$url.'"';
            ?>
        });
        //下一个
        $('.next-btn').click(function(){
            var wuxiao = $(".invalid-btn").is(":disabled");
            var right = $(".right-btn").is(":disabled");
            if(!wuxiao && !right){
                alert('请操作无效数据或保存准确列表才能进行下一个')
                return
            }
            $.get('/database/ajax-a-data-next', function (obj) {
                alert(obj.msg);
                if (obj.success) {
                    window.location.href = '/filtrationt/info?id=' + obj.data;
                }
            }, 'json');
        });
        //生成短信内容
        $('.sms-make-btn').click(function(){
            var params = $('#orderFrm').serialize();
            $.post('/car/sms-make',params,function(obj){
                if(obj.success) {
                    $('#sms-msg').val(obj.msg);
                } else {
                    alert(obj.msg);
                }
            },'json');
        });
        //发送短信内容
        $('.sms-send-btn').click(function(){
            var tel = $('#sms-tel').val();
            var msg = $('#sms-msg').val();
            $.post('/car/sms-send',{tel:tel,msg:msg},function(obj){
                alert(obj.msg);
            },'json');
        });

        //保存
        $(".baocun").click(function(){
            var params = $('#myform').serialize();
//            console.log(params);
//            return;
            $.post('/car/phone-baocun',params,function(obj){
                alert(obj.msg);
                if(obj.success){

                    window.location.reload();
                }
            },'json');
        });

        //判断礼品

        $('input[name="types[1]"]').change(function(){
            $('#total1_clear').change();
        });

    });
</script>