@model Com._9pm2.ClientWeb.Models.MaterialList
@{
    ViewBag.Title = "材料管理";
}
<script src="../../Scripts/stockcommon.js?vn=20180813"></script>
<script src="../../Scripts/material.js?vn=20180813"></script>
<style>
    #CostPrice, #SailPrice, #FactoryPrice {
        width: 100%;
    }

    #technicTable td {
        text-align: center;
    }

    #divTechnicTitle {
        text-align: center;
        font-size: 18px;
        margin: 5px 0 10px 0;
    }
</style>
<form method="post" action="/Warehouse/Material">
    <div class="divSearch">
        <div>
            @Html.DropDownList("sStatus", new SelectList(Model.DdlStatus, "ItemValue", "ItemText"))
            @Html.DropDownList("sCategoryId", new SelectList(Model.DdlCategry, "ItemValue", "ItemText"))
            @Html.TextBox("sKeywords", null, new { maxlength = "50", placeholder = "关键字" })
            <button class="btn btn-default" id="btnSearch">搜索</button>
            <button id="btnNewMaterial" type="button" class="btn btn-default">新增</button>
            <button id="btnImport" type="button" class="btn btn-default">批量导入</button>
            <button class="btn btn-default" type="button" onclick="downExcel()">下载(Excel)</button>   
            
          
        </div>
    </div>
</form>

<div class="error-msg"></div>

<div class="list">
    <table id="tMaterial" class="">
        <thead>
            <tr>
                <th>材料名</th>
                <th>类别</th>
                <th>成本价</th>
                <th>销售价</th>
                <th>外协价</th>
                <th>计价单位</th>    
                <th>开单可用</th>
                <th>登记库存</th>
                <th>关联库存材料</th>
                <th>安全库存</th>
                <th>工艺</th>
                <th>状态</th>
                <th>备注</th>
                <th style="width:120px;">操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.Materials)
            {
                <tr id="@item.Id">
                    <td>@item.Name</td>
                    <td>@item.MaterialCategory.Name</td>
                    <td>@item.CostPrice</td>
                    <td>@item.SailPrice</td>
                    <td>@item.FactoryPrice</td>
                    <td>@item.PriceUnit.Name</td>
                    <td><span>@(item.ForOrder ? "是" : "否")</span></td>
                    <td><span>@(item.ForStock ? "是" : "否")</span></td>
                    <td>@(item.Material2 == null ? "" : item.Material2.Name)</td>
                    <td>@item.SafetyStock</td>
                    <td>@string.Join(",", item.MaterialTechnic.Select(m => m.Technic.Name))</td>
                    <td><span class="status">@(item.IsActive?"已启用":"已停用")</span></td>
                    <td>@item.Memo</td>
                    <td style="text-align:center">

                        <div class="operation-btns">
                            <div>
                                <button id="select">&nbsp;</button>
                            </div>
                            <ul>                                
                                <li><a href="javascript:void(0);" onclick="EditMaterial('@item.Id');">编辑</a></li>                              
                                <li><a href="javascript:void(0);" onclick="DeleteMaterial('@item.Id');">删除</a></li>
                                <li><a href="javascript:void(0);" onclick="EditTechnic('@item.Id','@item.Name');">工艺及价格</a></li>  
                            </ul>
                        </div>
                    </td>
                </tr>            
            }
        </tbody>
    </table>
    @Html.Pager("Material", "Warehouse", Model.RouterDirectory, Model.PagerConfig, "pagerDiv", "pagerDiv", 8, true, false, true, true, false)
</div> 

<div id="divTechnic" title="工艺及价格" style="display:none">
    <div id="divTechnicContent" style="max-height:600px;overflow-y:auto">
        <div id="divTechnicTitle"></div>
        <table id="technicTable">
            <thead>
                <tr>
                    <th style="width:30px"></th>
                    <th>工艺名称</th>
                    <th style="width:100px">成本价格</th>
                    <th style="width:100px">销售价格</th>
                    <th style="width:100px">外协价格</th>
                </tr>
            </thead>
            <tbody id="technics"></tbody>
        </table>

        <div style="display:none" id="chart-no-data">没有可用工艺。请在[材料工艺]页面添加工艺。</div>
        <input type="hidden" id="MaterialId" />
    </div>
    <div style="text-align:right;">

        <div class="error-msg"></div>
        <button type="button" class="btn btn-default" onclick="$('#divTechnic').dialog('close');">取消</button>
        <button type="button" class="btn btn-primary" id="btnSaveTechnic" onclick="SaveTechnic()">保存</button>

    </div>
</div>

@Html.Partial("MaterialEdit")