<?php if (count($insurances) > 0): ?>
    <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
        <h3 onclick="show('list3')">保险理赔<span id="list3_title">▼</span></h3>
    </div>
    <div id="list3">
        <?php foreach ($insurances as $key => $val): ?>
            <?php if (1 === $key && count($val) > 0): ?>
                <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                       style="table-layout: fixed;">
                    <tr>
                        <td colspan="8" style="text-align: left">更换清单</td>
                    </tr>
                    <tr>
                        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                        <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                        <td width="80" align="center" class="bg_tr" nowrap>保险定价</td>
                        <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                        <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                        <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                        <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                        <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                        <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                        <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                    </tr>
                    <?php foreach ($val as $index => $item): ?>
                        <tr>
                            <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                            <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                            <td align="center" class="td_bg" nowrap><?= $item->insurance_price ?>元</td>
                            <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                            <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                            <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                            <td align="center" class="td_bg"
                                nowrap>
                                <?php if ($item->fix_user): ?>
                                    <?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                                    (<?= $item->fix_user ? \common\models\UserT::findOne($item->fix_user)->group->name : '' ?>
                                    )
                                <?php endif; ?>
                            </td>
                            <td align="center" class="td_bg"
                                nowrap><?= $item->fix_user ? \common\models\FixItemT::findOne($item->id)->userT->name : '' ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                            <td align="center" class="td_bg" nowrap>
                                [<a href="javascript:void(0)"
                                    onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>','<?= $item->car_keep_in_good_id ?>')">详情</a>]
                                [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                                [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="bg_tr" nowrap>备注</td>
                            <td class="td_bg" nowrap colspan="8"><?= $item->fix_remark ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php elseif (2 === $key): ?>
                <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                       style="table-layout: fixed;">
                    <tr>
                        <td colspan="8" style="text-align: left">维修清单</td>
                    </tr>
                    <tr>
                        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                        <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                        <td width="80" align="center" class="bg_tr" nowrap>保险定价</td>
                        <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                        <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                        <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                        <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                        <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                        <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                        <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                    </tr>
                    <?php foreach ($val as $index => $item): ?>
                        <tr>
                            <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                            <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                            <td align="center" class="td_bg" nowrap><?= $item->insurance_price ?>元</td>
                            <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                            <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                            <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                            <td align="center" class="td_bg"
                                nowrap>
                                <?php if ($item->fix_user): ?>
                                    <?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                                    (<?= $item->fix_user ? \common\models\UserT::findOne($item->fix_user)->group->name : '' ?>
                                    )
                                <?php endif; ?>
                            </td>
                            <td align="center" class="td_bg"
                                nowrap><?= $item->fix_user ? \common\models\FixItemT::findOne($item->id)->userT->name : '' ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                            <td align="center" class="td_bg" nowrap>
                                [<a href="javascript:void(0)"
                                    onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>','<?= $item->car_keep_in_good_id ?>')">详情</a>]
                                [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                                [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="bg_tr" nowrap>备注</td>
                            <td class="td_bg" nowrap colspan="8"><?= $item->fix_remark ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php elseif (3 == $key): ?>
                <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                       style="table-layout: fixed;">
                    <tr>
                        <td colspan="8" style="text-align: left">辅料清单</td>
                    </tr>
                    <tr>
                        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                        <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                        <td width="80" align="center" class="bg_tr" nowrap>保险定价</td>
                        <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                        <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                        <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                        <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                        <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                        <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                        <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                    </tr>
                    <?php foreach ($val as $index => $item): ?>
                        <tr>
                            <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                            <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                            <td align="center" class="td_bg" nowrap><?= $item->insurance_price ?>元</td>
                            <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                            <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                            <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                            <td align="center" class="td_bg"
                                nowrap>
                                <?php if ($item->fix_user): ?>
                                    <?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                                    (<?= \common\models\UserT::findOne($item->fix_user)->group->name ?>)
                                <?php endif; ?>
                            </td>
                            <td align="center" class="td_bg"
                                nowrap><?= $item->fix_user ? \common\models\FixItemT::findOne($item->id)->userT->name : '' ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                            <td align="center" class="td_bg" nowrap>
                                [<a href="javascript:void(0)"
                                    onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>','<?= $item->car_keep_in_good_id ?>')">详情</a>]
                                [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                                [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="bg_tr" nowrap>备注</td>
                            <td class="td_bg" nowrap colspan="8"><?= $item->fix_remark ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php elseif (4 == $key): ?>
                <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                       style="table-layout: fixed;">
                    <tr>
                        <td colspan="8" style="text-align: left">待定清单</td>
                    </tr>
                    <tr>
                        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                        <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                        <td width="80" align="center" class="bg_tr" nowrap>保险定价</td>
                        <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                        <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                        <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                        <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                        <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                        <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                        <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                    </tr>
                    <?php foreach ($val as $index => $item): ?>
                        <tr>
                            <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                            <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                            <td align="center" class="td_bg" nowrap><?= $item->insurance_price ?>元</td>
                            <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                            <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                            <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                            <td align="center" class="td_bg"
                                nowrap>
                                <?php if ($item->fix_user): ?>
                                    <?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                                    (<?= \common\models\UserT::findOne($item->fix_user)->group->name ?>)
                                <?php endif; ?>
                            </td>
                            <td align="center" class="td_bg"
                                nowrap><?= $item->fix_user ? \common\models\FixItemT::findOne($item->id)->userT->name : '' ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                            <td align="center" class="td_bg" nowrap>
                                [<a href="javascript:void(0)"
                                    onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>')">详情</a>]
                                [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                                [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="bg_tr" nowrap>备注</td>
                            <td class="td_bg" nowrap colspan="8"><?= $item->fix_remark ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php endif; ?>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
<?php if (count($self_paying) > 0): ?>
    <div style="clear: both"></div>
    <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
        <h3 onclick="show('list4')">自费维修<span id="list4_title">▼</span></h3>
    </div>
    <div id="list4">
        <?php foreach ($self_paying as $key => $val): ?>
            <?php if (1 == $key && count($val) > 0): ?>
                <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                       style="table-layout: fixed;">
                    <tr>
                        <td colspan="8" style="text-align: left">更换清单</td>
                    </tr>
                    <tr>
                        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                        <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                        <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                        <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                        <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                        <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                        <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                        <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                        <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                    </tr>
                    <?php foreach ($val as $index => $item): ?>
                        <tr>
                            <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                            <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                            <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                            <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                            <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                            <td align="center" class="td_bg"
                                nowrap>
                                <?php if ($item->fix_user): ?>
                                    <?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                                    (<?= \common\models\UserT::findOne($item->fix_user)->group->name ?>)
                                <?php endif; ?>
                            </td>
                            <td align="center" class="td_bg"
                                nowrap><?= $item->fix_user ? \common\models\FixItemT::findOne($item->id)->userT->name : '' ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                            <td align="center" class="td_bg" nowrap>
                                [<a href="javascript:void(0)"
                                    onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>')">详情</a>]
                                [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                                [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="bg_tr" nowrap>备注</td>
                            <td class="td_bg" nowrap colspan="7"><?= $item->fix_remark ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php elseif (2 == $key): ?>
                <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                       style="table-layout: fixed;">
                    <tr>
                        <td colspan="8" style="text-align: left">维修清单</td>
                    </tr>
                    <tr>
                        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                        <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                        <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                        <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                        <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                        <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                        <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                        <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                        <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                    </tr>
                    <?php foreach ($val as $index => $item): ?>
                        <tr>
                            <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                            <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                            <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                            <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                            <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                            <td align="center" class="td_bg"
                                nowrap>
                                <?php if ($item->fix_user): ?>
                                    <?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                                    (<?= \common\models\UserT::findOne($item->fix_user)->group->name ?>)
                                <?php endif; ?>
                            </td>
                            <td align="center" class="td_bg"
                                nowrap><?= $item->fix_user ? \common\models\FixItemT::findOne($item->id)->userT->name : '' ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                            <td align="center" class="td_bg" nowrap>
                                [<a href="javascript:void(0)"
                                    onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>')">详情</a>]
                                [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                                [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="bg_tr" nowrap>备注</td>
                            <td class="td_bg" nowrap colspan="7"><?= $item->fix_remark ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php elseif (3 == $key): ?>
                <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                       style="table-layout: fixed;">
                    <tr>
                        <td colspan="8" style="text-align: left">辅料清单</td>
                    </tr>
                    <tr>
                        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                        <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                        <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                        <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                        <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                        <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                        <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                        <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                        <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                    </tr>
                    <?php foreach ($val as $index => $item): ?>
                        <tr>
                            <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                            <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                            <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                            <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                            <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                                (<?= \common\models\UserT::findOne($item->fix_user)->group->name ?>)
                            </td>
                            <td align="center" class="td_bg"
                                nowrap><?= \common\models\FixItemT::findOne($item->id)->userT->name ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                            <td align="center" class="td_bg" nowrap>
                                [<a href="javascript:void(0)"
                                    onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>')">详情</a>]
                                [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                                [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="bg_tr" nowrap>备注</td>
                            <td class="td_bg" nowrap colspan="7"><?= $item->fix_remark ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php elseif (4 == $key): ?>
                <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                       style="table-layout: fixed;">
                    <tr>
                        <td colspan="8" style="text-align: left">待定清单</td>
                    </tr>
                    <tr>
                        <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                        <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                        <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                        <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                        <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                        <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                        <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                        <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                        <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                    </tr>
                    <?php foreach ($val as $index => $item): ?>
                        <tr>
                            <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                            <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                            <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                            <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                            <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                                (<?= \common\models\UserT::findOne($item->fix_user)->group->name ?>)
                            </td>
                            <td align="center" class="td_bg"
                                nowrap><?= \common\models\FixItemT::findOne($item->id)->userT->name ?></td>
                            <td align="center" class="td_bg"
                                nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                            <td align="center" class="td_bg" nowrap>
                                [<a href="javascript:void(0)"
                                    onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>')">详情</a>]
                                [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                                [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="bg_tr" nowrap>备注</td>
                            <td class="td_bg" nowrap colspan="7"><?= $item->fix_remark ?></td>
                        </tr>
                    <?php endforeach; ?>
                </table>
            <?php endif; ?>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
<?php if (count($facial) > 0): ?>
    <div style="clear: both"></div>
    <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
        <h3 onclick="show('list5')">汽车美容<span id="list5_title">▼</span></h3>
    </div>
    <div id="list5">
        <?php foreach ($facial as $key => $val): ?>
            <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
                   style="table-layout: fixed;">
                <tr>
                    <td colspan="8" style="text-align: left">美容装饰</td>
                </tr>
                <tr>
                    <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                    <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                    <td width="50" align="center" class="bg_tr" nowrap>单价</td>
                    <td width="80" align="center" class="bg_tr" nowrap>数量</td>
                    <td width="100" align="center" class="bg_tr" nowrap>结算方式</td>
                    <td width="80" align="center" class="bg_tr" nowrap>维修班组</td>
                    <td width="100" align="center" class="bg_tr" nowrap>维修人</td>
                    <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                    <td width="100" align="center" class="bg_tr" nowrap>操作</td>
                </tr>
                <tr>
                    <td rowspan="2" align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                    <td class="td_bg" style="word-break: break-all"><?= $item->name ?></td>
                    <td align="center" class="td_bg" style="word-break: break-all"><?= $item->price ?>元</td>
                    <td align="center" class="td_bg" nowrap><?= $item->count ?></td>
                    <td class="td_bg" nowrap><?= $item->pay_type == 1 ? '保险理赔' : '自费维修' ?></td>
                    <td align="center" class="td_bg"
                        nowrap>
                        <?php if ($item->fix_user): ?>
                            <?= \common\models\FixItemT::findOne($item->id)->getType2Name() ?>
                            (<?= \common\models\UserT::findOne($item->fix_user)->group->name ?>)
                        <?php endif; ?>
                    </td>

                    <td align="center" class="td_bg"
                        nowrap><?= $item->fix_user ? \common\models\FixItemT::findOne($item->id)->userT->name : '' ?></td>
                    <td align="center" class="td_bg" nowrap><?= 0 == $item->status ? '待维修' : '完工' ?></td>
                    <td align="center" class="td_bg" nowrap>
                        [<a href="javascript:void(0)"
                            onclick="fixCarItemInfo(<?= $item->small_type_id ?>,<?= $item->id ?>,<?= $item->fix_id ?>,'<?= $item->name ?>','<?= $item->insurance_price ?>','<?= $item->price ?>','<?= $item->count ?>','<?= $item->type ?>','<?= $item->fix_user ?>','<?= $item->fix_remark ?>','<?= $item->car_keep_in_good_id ?>')">详情</a>]
                        [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $item->id ?>)">删除</a>]
                        [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $item->id ?>',$(this))">确认</a>]
                    </td>
                </tr>
                <tr>
                    <td align="center" class="bg_tr" nowrap>备注</td>
                    <td class="td_bg" nowrap colspan="7"><?= $item->fix_remark ?></td>
                </tr>
            </table>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
<?php if (count($maintenance) > 0): ?>
    <div style="clear: both"></div>
    <div style="width:98%; margin: 0 auto;color:#1E5494" class="add-title">
        <h3 onclick="show('list6')">汽车保养<span id="list6_title">▼</span></h3>
    </div>
    <div id="list6">
        <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table"
               style="table-layout: fixed;">
            <tr>
                <td colspan="8" style="text-align: left">汽车保养</td>
            </tr>
            <tr>
                <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                <td width="100" align="center" class="bg_tr" nowrap>名称</td>
                <td width="50" align="center" class="bg_tr" nowrap>机油等级</td>
                <td width="80" align="center" class="bg_tr" nowrap>用量</td>
                <td width="100" align="center" class="bg_tr" nowrap>价格</td>
                <td width="80" align="center" class="bg_tr" nowrap>工时费</td>
                <td width="100" align="center" class="bg_tr" nowrap>状态</td>
                <td width="100" align="center" class="bg_tr" nowrap>操作</td>
            </tr>
            <?php foreach ($maintenance as $index => $val): ?>
                <?php $car_keep_in_goods = \common\models\CarKeepInGoodItems::findOne($val->car_keep_in_good_id); ?>
                <tr>
                    <td align="center" class="td_bg" nowrap><?= $index + 1 ?></td>
                    <td class="td_bg" style="word-break: break-all"><?= $val->name ?></td>
                    <td align="center" class="td_bg"
                        style="word-break: break-all"><?= $car_keep_in_goods->level ? $car_keep_in_goods->level : '无' ?></td>
                    <td align="center" class="td_bg"
                        nowrap><?= $car_keep_in_goods->use ? $car_keep_in_goods->use : '无' ?></td>
                    <td class="td_bg" nowrap><?= $car_keep_in_goods->price ?>元</td>
                    <td align="center" class="td_bg"
                        nowrap><?= $car_keep_in_goods->hour ? $car_keep_in_goods->hour : 0 ?></td>
                    <td align="center" class="td_bg" nowrap><?= 0 == $val->status ? '待维修' : '完工' ?></td>
                    <td align="center" class="td_bg" nowrap>
                        [<a href="javascript:void(0)"
                            onclick="fixCarItemInfo(<?= $val->small_type_id ?>,<?= $val->id ?>,<?= $val->fix_id ?>,'<?= $val->name ?>','<?= $val->insurance_price ?>','<?= $val->price ?>','<?= $val->count ?>','<?= $val->type ?>','<?= $val->fix_user ?>','<?= $val->fix_remark ?>','<?= $val->car_keep_in_good_id ?>')">详情</a>]
                        [<a href="javascript:void(0)" onclick="fixItemRemove(<?= $val->id ?>)">删除</a>]
                        [<a href="javascript:void(0)" onclick="fixItemFinish('<?= $val->id ?>',$(this))">确认</a>]
                    </td>
                </tr>
            <?php endforeach; ?>
        </table>
    </div>
<?php endif; ?>
<script>
    var smallTypeId = 0,        //1,更换清单 ; 2,维修清单;3,辅料清单;4,待定清单;5,汽车保养;6,美容装饰
        id = 0,                 //主键id
        fixId = 0,              //fix_id
        name = '',              //name
        insurancePrice = 0,     //保险定价
        price = 0,              //自费单价
        fixUser = 0,            //维修人
        fixRemark = '',         //备注
        count = 0,              //数量
        type = 0,               // 8,钣金 ; 9,底子工;10,喷漆工;11,抛光;12,机电;13,美容装饰;14,洗车;15钣金安装
        carKeepInGoodId = 0;   // 对应 fix_item_t 表 car_keep_in_good_id

    //清单添加对话框
    function fixCarItemInfo(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) {
        smallTypeId = arguments[0],
            id = arguments[1],
            fixId = arguments[2],
            name = arguments[3],
            insurancePrice = arguments[4],
            price = arguments[5],
            count = arguments[6],
            type = arguments[7],
            fixUser = arguments[8],
            fixRemark = arguments[9],
            carKeepInGoodId = arguments[10];

        var dialog = '<form id="dialog-from"><table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">' +
            '<input type="hidden" name="fix_id" value="' + fixId + '">' +
            '<tr class="bg_tr"><td colspan="4"><select id="small_type_id" name="small_type_id" onchange="itemChange($(this).val())">' +
            '<option value="1" ' + (1 == smallTypeId ? 'selected' : '') + '>更换清单</option>' +
            '<option value="2" ' + (2 == smallTypeId ? 'selected' : '') + '>维修清单</option>' +
            '<option value="3" ' + (3 == smallTypeId ? 'selected' : '') + '>辅料清单</option>' +
            '<option value="4" ' + (4 == smallTypeId ? 'selected' : '') + '>待定清单</option>' +
            '<option value="5" ' + (5 == smallTypeId ? 'selected' : '') + '>汽车保养</option>' +
            '<option value="6" ' + (6 == smallTypeId ? 'selected' : '') + '>美容装饰</option>' +
            '</select>&nbsp;&nbsp;&nbsp;&nbsp;</td>' +
            '</tr></table>' +
            '<div id="js-c">' +
            '</div>' +
            '<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table"><tr class="bg_tr"><td align="center" class="td_bg"><input type="button" class="ACT_btn" value="保存" onclick="addItem()"></td></tr></table>'
        '</form>';
        $('#dialog').html($(dialog));
        $('#dialog').show();
        $('#small_type_id').change();
        $('#type').change();
        maskOpen();
    }

    //清单change事件
    function itemChange(val) {
        var appendHtml = '', $parts = '', $len = 0;
        switch (val) {
            //更换清单
            case '1':
            case '3':
            case '4':
                $parts = shops, $len = $parts.length;
                appendHtml += '<table id="tableFix" width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table"><tr class="bg_tr" id="js-l1"><td class="bg_tr">配件名称:</td><td class="td_bg"><input list="part-list" type="text" name="name" id="name" onblur="getPriceByShop($(this))" value="' + ((1 == smallTypeId || 3 == smallTypeId || 4 == smallTypeId) ? name : '') + '"><datalist id="part-list">';
                for (var i = 0; i < $len; i++) {
                    appendHtml += '<option label="' + $parts[i].name + '" value="' + $parts[i].name + '"/>';
                }
                appendHtml += '</datalist></td><td>自费单价:</td><td class="td_bg"><input type="text" id="js-price" name="price" value="' + ((1 == smallTypeId || 3 == smallTypeId || 4 == smallTypeId) ? price : 0) + '">元</td></tr><tr class="bg_tr"><td class="bg_tr">数量:</td><td class="td_bg" colspan="3"><input type="text" name="count" id="count" value="' + ((1 == smallTypeId || 3 == smallTypeId || 4 == smallTypeId) ? count : 0) + '"></td></tr><tr class="bg_tr"><td class="bg_tr">维修班组:</td><td class="td_bg"><select name="type" id="type" onchange="typeChange($(this))">';
                for(var i = 0 ; i < fixCarRole.length ; i ++){
                    appendHtml += '<option value="'+fixCarRole[i].id+'" '+(type == fixCarRole[i].id ? 'selected' : '')+'>'+fixCarRole[i].name+'</option>'
                }

                appendHtml +='</select></td><td>维修人:</td><td class="td_bg"><select name="fix_user" id="fix_user"><option value="">--请选择--</option></select></td></tr></table><table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table"><tr class="bg_tr"><td class="bg_tr">备注:</td><td class="td_bg" colspan="3"><textarea cols="30" rows="2" name="remark">' + ((1 == smallTypeId || 3 == smallTypeId || 4 == smallTypeId) ? fixRemark : '' ) + '</textarea></td></tr></table>';
                break;
            //维修清单
            case '2':
                $parts = parts, $len = $parts.length;
                appendHtml += '<table id="tableFix" width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table"><tr class="bg_tr" id="js-l1"><td class="bg_tr">维修部位:</td><td class="td_bg"><input list="part-list" type="text" name="name" id="name" onblur="getPriceByPart($(this))" value="' + (2 == smallTypeId ? name : '') + '"><datalist id="part-list">';
                for (var i = 0; i < $len; i++) {
                    appendHtml += '<option label="' + $parts[i].name + '" value="' + $parts[i].name + '"/>';
                }
                appendHtml += '</datalist></td><td>自费单价:</td><td class="td_bg"><input type="text" id="js-price" name="price" value="' + (2 == smallTypeId ? price : 0) + '">元</td></tr><tr class="bg_tr"><td>维修班组:</td><td class="td_bg"><select name="type" id="type" onchange="typeChange($(this))">';
                for(var i = 0 ; i < fixCarRole.length ; i ++){
                    appendHtml += '<option value="'+fixCarRole[i].id+'" '+(type == fixCarRole[i].id ? 'selected' : '')+'>'+fixCarRole[i].name+'</option>'
                }
                appendHtml += '</select></td><td>维修人:</td><td class="td_bg"><select name="fix_user" id="fix_user"><option value="">--请选择--</option></select></td></tr></table><table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table"><tr class="bg_tr"><td class="bg_tr">备注:</td><td class="td_bg" colspan="3"><textarea cols="30" rows="2" name="remark">' + (2 == smallTypeId ? fixRemark : '') + '</textarea></td></tr></table>';
                break;
            //保养清单
            case '5':
                var len = keepInGoods.length;
                for (var i = 0; i < len; i++) {
                    appendHtml += '<table id="tableFix" width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table"><tr class="bg_tr"><td class="td_bg"><input type="checkbox" class="js-checkbox" name="name[]" value="' + keepInGoods[i].id + '_' + i + '" ' + (5 == smallTypeId ? (carKeepInGoodId == keepInGoods[i].id ? 'checked' : '') : '') + '>';
                    if (1 == keepInGoods[i]['type']) {
                        appendHtml += '机油' + '&nbsp;机油等级:' + keepInGoods[i]['level'] + '&nbsp;机油用量:' + keepInGoods[i]['use'] + '&nbsp;机油价格:' + keepInGoods[i]['price'] + '元&nbsp;工时费:' + keepInGoods[i]['hour'] + '元';
                    } else if (2 == keepInGoods[i]['type']) {
                        appendHtml += '机油滤芯' + '&nbsp;机油滤芯价格:' + keepInGoods[i]['price'] + '元&nbsp;工时费:' + keepInGoods[i]['hour'] + '元';
                    } else if (3 == keepInGoods[i]['type']) {
                        appendHtml += '空气滤芯' + '&nbsp;空气滤芯价格:' + keepInGoods[i]['price'] + '元&nbsp;工时费:' + keepInGoods[i]['hour'] + '元';
                    } else if (4 == keepInGoods[i]['type']) {
                        appendHtml += '空调滤芯' + '&nbsp;空调滤芯价格:' + keepInGoods[i]['price'] + '元&nbsp;工时费:' + keepInGoods[i]['hour'] + '元';
                    } else if (5 == keepInGoods[i]['type']) {
                        appendHtml += '汽油滤芯' + '&nbsp;汽油滤芯价格:' + keepInGoods[i]['price'] + '元&nbsp;工时费:' + (keepInGoods[i]['hour'] ? keepInGoods[i]['hour'] : 0) + '元';
                    }
                    appendHtml += '</td></tr></table>';
                }
                break;
            case '6':
                $parts = shops, $len = $parts.length;
                appendHtml += '<table id="tableFix" width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table"><tr class="bg_tr" id="js-l1"><td class="bg_tr">项目名称:</td><td class="td_bg"><input list="part-list" type="text" name="name" id="name" onblur="getPriceByShop($(this))" value="'+(6 == smallTypeId ? name : '')+'"><datalist id="part-list">';
                for (var i = 0; i < $len; i++) {
                    appendHtml += '<option label="' + $parts[i].name + '" value="' + $parts[i].name + '"/>';
                }
                appendHtml += '</datalist></td><td>自费单价:</td><td class="td_bg"><input type="text" id="js-price" name="price" value="'+(6 == smallTypeId ? price : 0)+'">元</td></tr><tr class="bg_tr"><td>维修班组:</td><td class="td_bg"><select name="type" id="type" onchange="typeChange($(this))">';
                for(var i = 0 ; i < fixCarRole.length ; i ++){
                    appendHtml += '<option value="'+fixCarRole[i].id+'" '+(type == fixCarRole[i].id ? 'selected' : '')+'>'+fixCarRole[i].name+'</option>'
                }
                appendHtml += '</select></td><td>维修人:</td><td class="td_bg"><select name="fix_user" id="fix_user"><option value="">--请选择--</option></select></td></tr></table><table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table"><tr class="bg_tr"><td class="bg_tr">备注:</td><td class="td_bg" colspan="3"><textarea cols="30" rows="2" name="remark">'+(6 == smallTypeId ? fixRemark : '')+'</textarea></td></tr></table>';
                break;
        }
        $('#js-c').html(appendHtml);
    }

    //根据维修部位、新车购置价查询自费单价
    function getPriceByPart(obj) {
        var val = obj.val();
        if ('' == val || 0 == carPrice) return false;
        $.post('/business-order/get-self-free', {name: val, price: carPrice}, function (data) {
            if (data.success) {
                obj.parents('.bg_tr').find('#js-price').val((data.content ? data.content.price : 0));
            }
        }, 'json');
    }

    //根据配件名，获取自费单价
    function getPriceByShop(obj) {
        var val = obj.val();
        if ('' == val || 0 == carPrice) return false;
        $.post('/business-order/get-price-by-shop', {price: carPrice, name: val}, function (data) {
            if (data.success) {
                obj.parents('.bg_tr').find('#js-price').val((data.content ? data.content : 0));
            }
        }, 'json');
    }

    //清单添加保存
    function addItem() {
        var small_type_id = $('#small_type_id').val();
        if (5 == small_type_id && !$('.js-checkbox:checked').length) { //汽车保养
            alert("请先选择保养类型!");
            return false;
        }

        if (2 == small_type_id) { //维修清单
            if (!$('#name').val()) {
                alert("维修部位不可为空!");
                return false;
            }
        }

        //更换清单、辅料清单、待定清单
        if (1 == small_type_id || 3 == small_type_id || 4 == small_type_id) {
            if (!$('#name').val()) {
                alert("配件名称不可为空!");
                return false;
            }

            if ($('#count').val() <= 0) {
                alert("数量不可为空!");
                return false;
            }
        }

        //美容装饰
        if (6 == small_type_id) {
            if (!$('#name').val()) {
                alert("项目名称不可为空!");
                return false;
            }
        }
        //根据事故类型判断是自费维修、还是保险理赔
        var params = $('#dialog-from').serialize(),
            pay_str = $('#accident_type').val(),
            id = $('#id').val(),
            pay_type = 2;

        if (6 == small_type_id || 5 == small_type_id) { //维修保养只有自费维修
            pay_type = 2;
        } else {
            pay_type = ('自费维修' == pay_str) ? 2 : 1;
        }
        params = params + '&pay_type=' + pay_type;
        $.post('/business-order/driver-save', params, function (data) {
            maskClose();
            alert(data.msg);
            if (data.success) {
                gotoPage('/business-order/ajax-item-list?fix_id=' + id + '&pay_type=' + pay_type + '&role=' + role, 'divBox');
            }
        }, 'json');
    }
    //维修班组 change 事件
    function typeChange(obj){
        var type = obj.val();
        if(type <= 0 ) return false;

        $.post('/business-order/ajax-fix-user',{gid:type},function(data){
            if(data.success && data.content.length > 0){
                var $len = data.content.length , $options;
                for(var i = 0 ; i < $len ; i ++){
                    $options += '<option value="'+data.content[i].id+'">'+data.content[i].name+'</option>';
                }
            }else{
                $options = '<option value="">--请选择--</option>';
            }
            $('#fix_user').html($options);
        })
    }
</script>
