<link href="/css/tabs.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>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <tr>
        <td colspan="13" height="22" class="td_bg">
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
                <TBODY>
                <TR>
                    <TD height="30" align="center" class=tab-on id=navcell onclick=switchCell(1) name="navcell">
                        提单详情
                    </TD>
                    <TD height="30" align="center" class=tab-off id=navcell onclick=switchCell(2) name="navcell">
                        操作记录
                    </TD>
                    <TD height="30" class=tab-none>&nbsp;</TD>
                </TR>
                </TBODY>
            </TABLE>
        </td>
    </tr>
    <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 id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb">
                            <TR>
                                <TD valign="top">
                                    <form id="theForm">
                                        <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1"
                                               class="table" style="table-layout: fixed;">
                                            <input type="hidden" id="id" name="id" value="<?= $info->id ?>">
                                            <input type="hidden" name="car_id" value="<?= $info->car_id ?>">
                                            <tr>
                                                <td width="100" height="25" class="bg_tr"><span
                                                            style="color:#ff0000">*</span>
                                                    车牌号
                                                </td>
                                                <td height="25" class="td_bg" nowrap>
                                                    <input name="car_no" type="text" id="car_no"
                                                           value="<?= $info->car_no ?>"
                                                           style="width:100px;"/>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">发动机号</td>
                                                <td height="25" class="td_bg">
                                                    <input name="engine_no" type="text" id="engine_no"
                                                           value="<?= $info->engine_no ?>" style="width:100px;"/>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">车架号</td>
                                                <td height="25" class="td_bg">
                                                    <input name="car_frame_no" type="text" id="car_frame_no"
                                                           value="<?= $info->car_frame_no ?>" style="width:100px;"/>
                                                </td>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>新车购置价</td>
                                                <td height="25" class="td_bg">
                                                    <input name="new_price" type="text" id="car_frame_no"
                                                           value="<?= $info->new_price ? $info->new_price : '' ?>" size="2"/>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr"><span
                                                            style="color:#ff0000">*</span>
                                                    品牌
                                                </td>
                                                <td height="25" class="td_bg">
                                                    <select id="brand_id" name="brand_id">
                                                        <option value="">---请选择---</option>
                                                        <?php foreach ($brand_items as $item): ?>
                                                            <option value="<?= $item->id ?>" <?= $info->brand_id == $item->id ? 'selected' : '' ?>><?= $item->name ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">车系
                                                </td>
                                                <td height="25" class="td_bg">
                                                    <select name="series_id" id="series_id">
                                                        <option>---请选择---</option>
                                                        <?php foreach ($series_items as $item): ?>
                                                            <option value="<?= $item->id ?>" <?= $info->series_id == $item->id ? 'selected' : '' ?>><?= $item->name ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">排量</td>
                                                <td height="25" class="td_bg">
                                                    <select name="displacement_id" id="displacement_id">
                                                        <option>---请选择---</option>
                                                        <?php foreach ($displacement_items as $item): ?>
                                                            <option value="<?= $item->id ?>" <?= $info->displacement_id == $item->id ? 'selected' : '' ?>><?= $item->name ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">年份</td>
                                                <td height="25" class="td_bg">
                                                    <input type="text" id="car_year" name="car_year"
                                                           onclick="WdatePicker({dateFmt:'yyyy'})" readonly
                                                           value="<?= $info->car_year ?>" style="width:100px;">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr"><span
                                                            style="color:#ff0000">*</span>
                                                    联系人
                                                </td>
                                                <td height="25" class="td_bg">
                                                    <input name="link_man" type="text" id="company"
                                                           value="<?= $info->link_man ?>"
                                                           style="width:100px;"/>
                                                </td>
                                                <td width="100" height="25" class="bg_tr"><span
                                                            style="color:#ff0000">*</span>
                                                    电话
                                                </td>
                                                <td height="25" class="td_bg" colspan="5">
                                                    <input type="text" name="link_phone" value="<?= $info->link_phone ?>">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>被保险人</td>
                                                <td height="25" class="td_bg">
                                                    <input name="id_man" type="text" id="company"
                                                           value="<?= $info->id_man ?>"
                                                           style="width:100px;"/>
                                                </td>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>电话</td>
                                                <td height="25" class="td_bg">
                                                    <input type="text" name="id_phone" value="<?= $info->id_phone ?>">
                                                </td>
                                                <td width="100" height="25" class="bg_tr">事故类型</td>
                                                <td height="25" class="td_bg">
                                                    <select name="accident_type" id="accident_type">
                                                        <option value="单方" <?= "单方" == $info->accident_type ? 'selected' : '' ?>>单方</option>
                                                        <option value="双方" <?= "双方" == $info->accident_type ? 'selected' : '' ?>>双方</option>
                                                        <option value="多方" <?= "多方" == $info->accident_type ? 'selected' : '' ?>>多方</option>
                                                        <option value="自费维修" <?= "自费维修" == $info->accident_type ? 'selected' : '' ?>>自费维修</option>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">
                                                    责任
                                                </td>
                                                <td height="25" class="td_bg">
                                                    <select name="responsibility" id="responsibility">
                                                        <option value="全责" <?= "全责" === $info->responsibility ? 'selected' : '' ?>>全责</option>
                                                        <option value="无责" <?= "无责" === $info->responsibility ? 'selected' : '' ?>>无责</option>
                                                        <option value="主要责任" <?= "主要责任" === $info->responsibility ? 'selected' : '' ?>>主要责任</option>
                                                        <option value="次要责任" <?= "次要责任" === $info->responsibility ? 'selected' : '' ?>>次要责任</option>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>保险公司</td>
                                                <td height="25" class="td_bg">
                                                    <select name="company" id="company">
                                                        <option value="1" <?= '1' === $info->company ? 'selected' : '' ?>>人保</option>
                                                        <option value="2" <?= '2' === $info->company ? 'selected' : '' ?>>平安</option>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>商业保单号</td>
                                                <td height="25" class="td_bg">
                                                    <input type="text" name="insurer1_no" value="<?= $info->insurer1_no ?>">
                                                </td>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>交强保单号</td>
                                                <td height="25" class="td_bg">
                                                    <input type="text" name="insurer2_no" value="<?= $info->insurer2_no ?>">
                                                </td>
                                                <td width="100" height="25" class="bg_tr">
                                                    险项
                                                </td>
                                                <td height="25" class="td_bg">
                                                    <input type="text" name="insurer_type" value="<?= $info->insurer_type ?>">
                                                </td>
                                            </tr>
                                        </table>
                                        <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"><span style="color:#ff0000">*</span>接车日期</td>
                                                <td height="25" class="td_bg">
                                                    <input name="receive_date" type="text" id="receive_date"
                                                           value="<?= $info->receive_date ?>" readonly
                                                           onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})"/>
                                                </td>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>接车方式</td>
                                                <td height="25" class="td_bg">
                                                    <select name="receive_type" id="receive_type">
                                                        <option value="">--请选择--</option>
                                                        <option value="上门接车" <?= $info->receive_type === '上门接车' ? 'selected' : '' ?>>上门接车</option>
                                                        <option value="客户自送" <?= $info->receive_type === '客户自送' ? 'selected' : '' ?>>客户自送</option>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">代步车</td>
                                                <td height="25" class="td_bg" colspan="4">
                                                    <select name="replace_car_id">
                                                        <option value="0">--请选择--</option>
                                                        <option value="1" <?= 1 === $info->replace_car_id ? 'selected' : '' ?>>不需要</option>
                                                        <option value="2" <?= 2 === $info->replace_car_id ? 'selected' : '' ?>>京A74110</option>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>方位</td>
                                                <td height="25" class="td_bg">
                                                    <select name="direction_id" id="direction_id">
                                                        <option value="">请选择</option>
                                                        <?php foreach ($direction_items as $item): ?>
                                                            <option value="<?= $item->id ?>" <?= $info->direction_id == $item->id ? 'selected' : '' ?>><?= $item->name ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>范围</td>
                                                <td height="25" class="td_bg">
                                                    <select name="range_id" id="range_id">
                                                        <option value="">请选择</option>
                                                        <?php foreach ($range_items as $item): ?>
                                                            <option value="<?= $item->id ?>" <?= $info->range_id == $item->id ? 'selected' : '' ?>><?= $item->name ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr"><span style="color:#ff0000">*</span>地址</td>
                                                <td colspan="4" height="25" class="td_bg">
                                                    <input name="address" type="text" id="address"
                                                           value="<?= $info->address ?>"
                                                           style="width:80%;"/>
                                                </td>
                                            </tr>
                                        </table>
                                        <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 colspan="7" height="25" class="td_bg" align="left">
                                                    <textarea name="sys_remark" id="sys_remark"
                                                              style="width: 600px;"><?= $info->remark ?></textarea>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="td_bg" colspan="8" align="center">
                                                    <input type="button" class="ACT_btn js-insert-btn" value="提交">
                                                    <input type="button" class="ACT_btn js-update-btn" value="保存">
                                                    <input type="button" class="ACT_btn js-back-btn" value="返回">
                                                </td>
                                            </tr>
                                        </table>
                                    </form>
                                </TD>
                            </TR>
                        </TABLE>
                        <TABLE id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb" class="hide-table">
                            <TR>
                                <TD>
                                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1"
                                           class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td width="10%" align="center" class="bg_tr" nowrap>姓名</td>
                                            <td width="10%" align="center" class="bg_tr" nowrap>操作时间</td>
                                            <td width="70%" align="center" class="bg_tr" nowrap>备注</td>
                                            <td width="10%" align="center" class="bg_tr" nowrap>状态</td>
                                        </tr>
                                        <?php if($log_items): ?>
                                            <?php foreach ($log_items as $item): ?>
                                                <tr>
                                                    <td align="center" class="td_bg" nowrap><?= $item->op_man ?></td>
                                                    <td class="td_bg"
                                                        style="word-break: break-all"><?= date('Y-m-d H:i:s', $item->op_time) ?></td>
                                                    <td class="td_bg" nowrap><?= $item->info ?></td>
                                                    <td class="td_bg"
                                                        style="word-break: break-all"><?= $item->remark ?></td>
                                                </tr>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                        <tr>
                                            <td class="td_bg" colspan="6" align="center">
                                                <input type="button" class="ACT_btn js-back-btn" value="返回">
                                            </td>
                                        </tr>
                                    </table>
                                </TD>
                            </TR>
                        </TABLE>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<!--对话框begin-->
<div id="dialog" style="display: none">
</div>
<!--end-->
<!--遮罩层 begin-->
<div class="mask-layer" style="display: none">
</div>
<!--end-->
<script type="text/javascript" language="javascript">
    //保存按钮
    $(".js-update-btn").click(function () {
        if (confirm('是否确认提交?')) {
            var params = $("#theForm").serialize();
            params = params + '&status=<?=$info->status?>';
            $.post('/business-order/order-save', params, function (data) {
                alert(data.msg);
                if (data.success) {
                    $('#id').val(data.content);
                    window.location.href = '/business-order/order-info?id='+data.content+'&status=<?= $info->status ?>&type=2';
                }
            }, 'json');
        }
    });
    //提交按钮
    $(".js-insert-btn").click(function () {
        var sys_remark = $('#sys_remark').val();
        if (!sys_remark) {
            alert('请先输入提单备注！');
            return false;
        }
        if (confirm('是否确认提交?')) {
            var params = $("#theForm").serialize();
            params = params + '&status=<?= $info->status + 1 ?>';
            $.post('/business-order/order-save', params, function (data) {
                alert(data.msg);
                if (data.success) {
                    $('#id').val(data.content);
                    window.location.href = '/business-order';
                }
            }, 'json');
        }
    });
    //提交维修明细
    $('#add-info-btn').click(function () {
        var id = $('#id').val();
        if (id > 0) {
            art.dialog.open('/fix-car/add-item?fix_id=' + id);
        } else {
            alert('请先保存维修信息');
        }
    });
    //返回按钮
    $('.js-back-btn').click(function () {
        window.location.href = '/business-order/index';
    });

    $('#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');
        }
    });
</script>
