<?php
use common\models\PriceT;
?>
<div id="insurer-tabs">
    <div title="报价信息" style="padding:20px;">
        <form id="priceFrm" method="post">
            <table cellpadding="5" width="100%">
                <tbody>
                <tr>
                    <td valign="top" style="padding: 10px;width:auto;">
                        <table cellpadding="5" >
                            <thead>
                            <tr>
                                <th>险种</th>
                                <th>代码</th>
                                <th>内容</th>
                                <th>不计免赔</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            foreach($insurer_type_items as $item) {
                                $order_id = $info->id;
                                if(!$order_id)
                                    $order_id = 0;
                                $tmp_row = PriceT::find()
                                    ->where('order_id='.$order_id.' and type_id='.$item->id)
                                    ->one();
                                ?>
                                <tr>
                                    <td width="120"><?=$item->name?></td>
                                    <td width="50"><?=$item->code?></td>
                                    <td><?php
                                        if($item->content != '') {
                                            echo '<select class="easyui-combo" name="types['.$item->id.']">';
                                            $tmp_items = explode(',',$item->content);
                                            foreach($tmp_items as $tmp_item) {
                                                echo '<option';
                                                if(!empty($tmp_row) && $tmp_row->val == $tmp_item)
                                                    echo ' selected ';
                                                echo '>'.$tmp_item.'</option>';
                                            }
                                            echo '</select>';
                                        } else {
                                            echo '<input class="easyui-textbox" name="types['.$item->id.']" style="width:100px;" type="text"';
                                            if(!empty($tmp_row))
                                                echo ' value="'.$tmp_row->val.'" ';
                                            echo '>';
                                        }
                                        ?>
                                    </td>
                                    <td><?php
                                        if($item->has_nopay) {
                                            echo '<input type="checkbox" value="1" name="nopays['.$item->id.']"';
                                            if(!empty($tmp_row) && $tmp_row->is_nopay == 1)
                                                echo ' checked ';
                                            echo '>';
                                        }
                                        ?>
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                            </tbody>
                        </table>
                    </td>
                    <td valign="top" style="padding: 10px;width:auto; vertical-align: top;">
                        <table cellpadding="5" >
                            <tbody>
                            <tr>
                                <td width="75">商业保费</td>
                                <td><input class="easyui-textbox" style="width: 80%;" type="text" name="total1" id="total1" value="<?=$info->total1?>">元</td>
                            </tr>
                            <tr>
                                <td width="75">交强保费</td>
                                <td><input class="easyui-textbox" style="width: 80%;" type="text" name="total2" id="total2" value="<?=$info->total2?>">元</td>
                            </tr>
                            <tr>
                                <td width="75">车船税</td>
                                <td><input class="easyui-textbox" style="width: 80%;" type="text" name="total3" id="total3" value="<?=$info->total3?>">元</td>
                            </tr>
                            <tr>
                                <td width="75">总保费</td>
                                <td><input class="easyui-textbox" style="width: 80%;" type="text" name="total_all" id="total_all" value="<?=$info->total_all?>">元</td>
                            </tr>
                            <tr>
                                <td width="75">优惠</td>
                                <td><input class="easyui-textbox" style="width: 80%;" type="text" name="total_dis" id="total_dis" value="<?=$info->total_dis?>">元</td>
                            </tr>
                            <tr>
                                <td width="75">应收</td>
                                <td><input class="easyui-textbox" style="width: 80%;" type="text" name="total_real" id="total_real" value="<?=$info->total_real?>">元</td>
                            </tr>
                            <tr>
                                <td width="75" valign="top">报价备注</td>
                                <td><textarea style="width:100%;" name="price_remark"><?=$info->price_remark?></textarea></td>
                            </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div title="保单信息" style="overflow:auto;padding:20px;">
        <form id="orderFrm" method="post">
            <input type="hidden" name="order_id" value="<?=$info->id?>">
            <input type="hidden" name="car_id" value="<?=$info->car_id?>">
            <input name="_csrf" type="hidden" id="_csrf" value="<?=Yii::$app->request->csrfToken ?>">
            <table cellpadding="5" width="100%">
                <tbody>
                <tr>
                    <td width="75">车牌号</td>
                    <td>
                        <input class="easyui-textbox" style="width:100%;" type="text" id="car_no" name="car_no" value="<?=$info->car_no?>">
                    </td>
                    <td width="75">发动机号</td>
                    <td>
                        <input class="easyui-textbox" style="width:100%;" type="text" id="engine_no" name="engine_no" value="<?=$info->engine_no?>">
                    </td>
                    <td width="75">车架号</td>
                    <td>
                        <input class="easyui-textbox" style="width:100%;" type="text" id="car_frame_no" name="car_frame_no" value="<?=$info->car_frame_no?>">
                    </td>
                </tr>
                <tr>
                    <td width="75">车主</td>
                    <td>
                        <input class="easyui-textbox" style="width:100%;" type="text" id="car_man" name="car_man" value="<?=$info->car_man?>">
                    </td>
                    <td width="75">被保险人</td>
                    <td>
                        <input class="easyui-textbox" style="width:100%;" type="text" id="id_man" name="id_man" value="<?=$info->id_man?>">
                    </td>
                    <td width="75">证件号码</td>
                    <td>
                        <input class="easyui-textbox" style="width:100%;" type="text" id="id_number" name="id_number" value="<?=$info->id_number?>">
                    </td>
                </tr>
                <tr>
                    <td width="75">联系人</td>
                    <td>
                        <input class="easyui-textbox" style="width:100%;" type="text" id="link_man" name="link_man" value="<?=$info->link_man?>">
                    </td>
                    <td width="75">联系电话</td>
                    <td>
                        <input class="easyui-textbox" style="width:100%;" type="text" id="link_phone" name="link_phone" value="<?=$info->link_phone?>">
                    </td>
                    <td width="75">送单日期</td>
                    <td>
                        <input class="easyui-datebox" style="width:100px;" type="text" id="send_date" name="send_date" value="<?=$info->send_date?>">
                    </td>
                </tr>
                <tr>
                    <td width="75">保险公司</td>
                    <td>
                        <select class="easyui-combo" name="company_id" id="company_id">
                            <option value="0">---请选择---</option>
                            <?php
                            foreach($insurer_company_items as $item) {
                                echo '<option value="'.$item->id.'"';
                                if($item->id == $info->company_id)
                                    echo ' selected ';
                                echo '>'.$item->name.'</option>';
                            }
                            ?>
                        </select>
                    </td>
                    <td width="75">付款方式</td>
                    <td colspan="3">
                        <select class="easyui-combo" name="pay_type_id" id="pay_type_id">
                            <option value="0">---请选择---</option>
                            <?php
                            foreach($pay_type_items as $item) {
                                echo '<option value="'.$item->id.'"';
                                if($item->id == $info->pay_type_id)
                                    echo ' selected ';
                                echo '>'.$item->name.'</option>';
                            }
                            ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td width="75">商业日期</td>
                    <td colspan="2">
                        <input class="easyui-datebox" style="width:100px;" type="text" id="insurer1_begin_date" name="insurer1_begin_date" value="<?=$info->insurer1_begin_date?>">
                        -
                        <input class="easyui-datebox" style="width:100px;" type="text" id="insurer1_end_date" name="insurer1_end_date" value="<?=$info->insurer1_end_date?>">
                    </td>
                    <td width="75">交强日期</td>
                    <td colspan="2">
                        <input class="easyui-datebox" style="width:100px;" type="text" id="insurer2_begin_date" name="insurer2_begin_date" value="<?=$info->insurer2_begin_date?>">
                        -
                        <input class="easyui-datebox" style="width:100px;" type="text" id="insurer2_end_date" name="insurer2_end_date" value="<?=$info->insurer2_end_date?>">
                    </td>
                </tr>
                <tr>
                    <td width="75">送单地址</td>
                    <td colspan="5">
                        <input id="cc" class="easyui-combobox" name="direction1_id" style="width:80px;"
                               data-options="valueField:'id',textField:'name',url:'/direction/json-list',method:'get',editable:false,value:'<?=$info->direction1_id?>'" />
                        <input id="cc" class="easyui-combobox" name="range1_id" style="width:80px;"
                               data-options="valueField:'id',textField:'name',url:'/range/json-list',method:'get',editable:false,value:'<?=$info->range1_id?>'" />
                        <input id="cc" class="easyui-combobox" name="city1_id" style="width:80px;"
                               data-options="valueField:'id',textField:'name',url:'/city/json-list',method:'get',editable:false,value:'<?=$info->city1_id?>'" />
                        <input id="cc" class="easyui-combobox" name="district1_id" style="width:80px;"
                               data-options="valueField:'id',textField:'name',url:'/district/json-list',method:'get',editable:false,value:'<?=$info->district1_id?>'" />
                        <input class="easyui-textbox" style="width:300px;" type="text" id="send_address1" name="send_address1" value="<?=$info->send_address1?>">
                    </td>
                </tr>
                <tr>
                    <td width="75">正本送单地址</td>
                    <td colspan="5">
                        <input id="cc" class="easyui-combobox" name="direction2_id" style="width:80px;"
                               data-options="valueField:'id',textField:'name',url:'/direction/json-list',method:'get',editable:false,value:'<?=$info->direction2_id?>'" />
                        <input id="cc" class="easyui-combobox" name="range2_id" style="width:80px;"
                               data-options="valueField:'id',textField:'name',url:'/range/json-list',method:'get',editable:false,value:'<?=$info->direction2_id?>'" />
                        <input id="cc" class="easyui-combobox" name="city2_id" style="width:80px;"
                               data-options="valueField:'id',textField:'name',url:'/city/json-list',method:'get',editable:false,value:'<?=$info->direction2_id?>'" />
                        <input id="cc" class="easyui-combobox" name="district2_id" style="width:80px;"
                               data-options="valueField:'id',textField:'name',url:'/district/json-list',method:'get',editable:false,value:'<?=$info->district2_id?>'" />
                        <input class="easyui-textbox" style="width:300px;" type="text" id="send_address2" name="send_address2" value="<?=$info->send_address2?>">
                    </td>
                </tr>
                <tr>
                    <td width="75">赠品</td>
                    <td colspan="5">
                        <input class="easyui-textbox" style="width:100%;" type="text" id="gift_other" name="gift_other" value="<?=$info->gift_other?>">
                    </td>
                </tr>
                <tr>
                    <td width="75">备注</td>
                    <td colspan="5">
                        <textarea style="width:100%; height: 50px;" name="remark" id="remark"><?=$info->remark?></textarea>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div title="审核意见" style="overflow:auto;padding:20px;">
        <form id="logFrm" method="post">
            <table cellpadding="5" width="100%">
                <tbody>
                <tr>
                    <td width="75">操作员</td>
                    <td><?=$this->context->my->getShowName()?></td>
                    <td width="75">审核时间</td>
                    <td><?=date('Y-m-d H:i:s')?></td>
                </tr>
                <tr>
                    <td width="75" valign="top">审核意见</td>
                    <td colspan="3"><textarea style="width:100%;" name="log_remark" id="log_remark"></textarea></td>
                </tr>
                </tbody>
            </table>
        </form>
        <table id="insurer-log-grid" ></table>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $('#insurer-tabs').tabs({
            border:false,
            fit:true
        });
        $('#insurer1_begin_date').datebox({
            onSelect:function(date) {
                date.setFullYear(date.getFullYear() + 1);
                date.setDate(date.getDate()-1);
                var tmp_val = dateformatter(date);
                $('#insurer1_end_date').datebox('setValue',tmp_val);
            }
        });
        $('#insurer2_begin_date').datebox({
            onSelect:function(date) {
                date.setFullYear(date.getFullYear() + 1);
                date.setDate(date.getDate()-1);
                var tmp_val = dateformatter(date);
                $('#insurer2_end_date').datebox('setValue',tmp_val);
            }
        });

        //自动计算
        $("#total1").blur(function(){
            $("#total_all").blur();
        });
        $("#total2").blur(function(){
            $("#total_all").blur();
        });
        $("#total3").blur(function(){
            $("#total_all").blur();
        });
        $("#total_all").blur(function(){
            var total1 = Number($('#total1').val());
            var total2 = Number($('#total2').val());
            var total3 = Number($('#total3').val());
            var total_dis = Number($('#total_dis').val());
            var total_all = total1 + total2 + total3;
            var total_real = total_all - total_dis;
            $('#total_all').val(total_all.toFixed(2));
            $('#total_real').val(total_real.toFixed(2));
        });
        $("#total_dis").blur(function(){
            var total_dis = Number($('#total_dis').val());
            var total_all = Number($('#total_all').val());
            var total_real = total_all - total_dis;
            $('#total_real').val(total_real.toFixed(2));
        });
        $("#total_real").blur(function(){
            var total_real = Number($('#total_real').val());
            var total_all = Number($('#total_all').val());
            var total_dis = total_all - total_real;
            $('#total_dis').val(total_dis.toFixed(2));
        });

        //操作记录
        $('#insurer-log-grid').datagrid({
//            url: '/insurer/office-mng-json-data',
            method:'GET',
            idField: 'id',
            pagination: true,
            singleSelect: true,
            rownumbers: true,
            pageSize: 20,
            pageList: [20,30,50],
            fitColumns: true,
            striped: true,
            toolbar: [{
                iconCls: 'icon-reload',
                text:'刷新',
                handler: function() {
                    $('#insurer-log-grid').datagrid('reload');
                }
            }],
            columns: [[
                { title: '操作员', width:100 },
                { title: '岗位', width:200 },
                { title: '审核时间', width:100 },
                { title: '审核内容', width:200 },
                { title: '审核意见', width:200 }
            ]]
        });
    });
</script>