<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/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 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">缺货列表&nbsp;&nbsp;<sup style="color: darkorange"><?= $out_of_stock_list_count ?></sup>
                    </TD>
                    <TD height="30" align="center" class=tab-off id=navcell onclick=switchCell(3) 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">
                                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1"
                                           class="table" style="table-layout: fixed;">
                                        <form id="searchForm">
                                            <tr>
                                                <td class="td_bg">
                                                    车牌号:<input name="car_no" type="text" value="">
                                                    <input type="button" class="act_btn" id="search-btn"
                                                           name="search-btn"
                                                           value="搜索">
                                                    <input type="button" class="act_btn" onclick="itemCreate()" value="采购">

                                                </td>
                                            </tr>
                                        </form>
                                    </table>
                                    <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1"
                                           class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td width="50" align="center" align="center" class="bg_tr" nowrap
                                                width="5%">排序
                                            </td>
                                            <td align="center" align="center" class="bg_tr" nowrap>品牌</td>
                                            <td align="center" align="center" class="bg_tr" nowrap width="10%">车型</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>排量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>年款</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>配件名称</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>数量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>单价</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>采购人</td>
                                            <td align="center" align="center" class="bg_tr" nowrap width="10%">采购时间</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>状态</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>操作</td>
                                        </tr>
                                        <?php if($purchase_items): ?>
                                            <?php foreach($purchase_items as $key=>$item): ?>
                                            <tr>
                                                <td align="center" class="td_bg" nowrap><?= $key + 1 ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->brand->name ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->series->name ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->displacement->name ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->carYear->name ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->name ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->number ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->price ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->getUser->name ?></td>
                                                <td align="center" class="td_bg" nowrap><?= $item->created_at ?></td>
                                                <td align="center" class="td_bg" nowrap>
                                                    <?php if(1 === $item->status): ?>
                                                        <span style="color:red;">采购中</span>
                                                    <?php elseif(2 === $item->status): ?>
                                                        <span style="color: green">已采购,待入库</span>
                                                    <?php elseif(3 === $item->status): ?>
                                                        <span style="color: green">已入库</span>
                                                    <?php endif; ?>
                                                </td>
                                                <td align="center" class="td_bg" nowrap>
                                                    <a href="javascript:void(0)" onclick="view(<?= $item->id ?>)">[详情]</a>
                                                    <?php if(1 === $item->status): ?>
                                                        <a href="javascript:void(0)" onclick="op(<?= $item->id ?>,$(this))">[确认]</a>
                                                    <?php elseif(2 === $item->status || 3 === $item->status): ?>
                                                        <a href="javascript:void(0)" style="color: grey">[确认]</a>
                                                    <?php endif; ?>
                                                </td>
                                            </tr>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                        <!--    <tr>-->
                                        <!--        <td height="25" colspan="12" align="center" class="td_bg">分页位置</td>-->
                                        <!--    </tr>-->
                                    </table>
                                </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="2" cellspacing="1"
                                           class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td width="50" align="center" align="center" class="bg_tr" nowrap
                                                width="5%">排序
                                            </td>
                                            <td align="center" align="center" class="bg_tr" nowrap width="10%">配件名</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>品牌</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>车型</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>排量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>年款</td>
                                        </tr>
                                        <?php if (isset($out_of_stock_list)): ?>
                                            <?php foreach ($out_of_stock_list as $key => $item): ?>
                                                <tr>
                                                    <td align="center" class="td_bg" nowrap><?= $key + 1 ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $item->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $item->brand->name ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $item->series->name ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $item->displacement->name ?></td>
                                                    <td align="left" class="td_bg" nowrap><?= $item->car_year ?></td>
                                                </tr>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                        <!--    <tr>-->
                                        <!--        <td height="25" colspan="12" align="center" class="td_bg">分页位置</td>-->
                                        <!--    </tr>-->
                                    </table>
                                </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="2" cellspacing="1"
                                           class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td align="center" class="bg_tr" nowrap width="5%">排序</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>品牌</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>车型</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>排量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>年份</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>配件名字</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>采购数量</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>操作人</td>
                                            <td align="center" align="center" class="bg_tr" nowrap>操作时间</td>
                                        </tr>
                                        <?php if (isset($store_logs)): ?>
                                            <?php foreach ($store_logs as $key => $store_log): ?>
                                                <tr>
                                                    <td align="center" class="td_bg" nowrap><?= $key + 1 ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->brand->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->series->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->displacement->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->year->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->name ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->number ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->op_man ?></td>
                                                    <td align="center" class="td_bg" nowrap><?= $store_log->op_time ?></td>
                                                </tr>
                                            <?php endforeach; ?>
                                        <?php endif; ?>
                                        <!--    <tr>-->
                                        <!--        <td height="25" colspan="12" align="center" class="td_bg">分页位置</td>-->
                                        <!--    </tr>-->
                                    </table>
                                </TD>
                            </TR>
                        </TABLE>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<script type="text/javascript" language="javascript">
    function itemCreate(){
        window.location.href='/purchase/view';
    }
    //详情
    function view(id){
        if(id < 1) return false;
        window.location.href='/purchase/view?id='+id;
    }
    //确认
    function op(id,obj){
        if(id < 1) return false;
        $.post('/purchase/update',{id:id},function(data){
            alert(data.msg);
            if(data.success){
                obj.parent().prev().html('<span style="color: green">已采购,待入库</span>');
            }
        },'json');
    }
</script>