@model Com._9pm2.ClientWeb.Models.FactoryOrderModel
@{ ViewBag.Title = Model.FactoryOrderNo == "" ? "开外协订单" : "修改外协订单";}

<script src="../../Scripts/ordercommon.js?vn=20180813"></script>
<script src="../../Scripts/factoryorderedit.js?vn=20180813"></script>
<style>
    .select2-container--default .select2-selection--single .select2-selection__arrow {
        display: none;
    }
</style>
<div id="divOrder">
    <div class="error-msg"></div>
    <div id="divOrderContent" style="min-height:240px">
        @using (Html.BeginForm("", "", FormMethod.Post, new { id = "form1" }))
        {
            <table id="tableEdit" class="font85 tableEdit" style="width:100%">

                <tr>
                    <td class="label">外协商</td>
                    <td style="width:400px">
                        <div style="width:200px;float:left">
                            @Html.DropDownList("FactoryNo", new SelectList(Model.DdlFactory, "ItemValue", "ItemText"), new { @class = "form-control max-width-180 select2" })
                        </div>
                        <div style="float:left;height:34px;">
                            <a href="javascript:void(0)" style="display:block;line-height:34px;height:34px;vertical-align:middle;margin-left:10px" onclick="newFactory()">快速创建外协商</a>
                        </div>
                    </td>
                    <td class="label">联系人</td>
                    <td colspan="3">
                        @Html.TextBox("Contact", null, new { maxlength = "100", title="空格分隔，比如：张三 13888888888", @style="width:260px", @class = "form-control" })

                    </td>
                </tr>
                <tr>
                    <td class="label">交易日期</td>
                    <td>
                        @Html.TextBox("TransactionDate", Model.TransactionDate.ToString("yyyy-MM-dd"), new { maxlength = "10", @class = "text-date" }) <span class="redStar">*</span>
                    </td>
                    <td class="label">预计完工日期</td>
                    <td colspan="3">
                        @Html.TextBox("ExpectDeliveryDate", Model.ExpectDeliveryDate.HasValue? Model.ExpectDeliveryDate.Value.ToString("yyyy-MM-dd"):"", new { maxlength = "50", @class = "text-date" })
                    </td>
                </tr>

                <tr>
                    <td class="label">明细</td>
                    <td colspan="5">
                        <button onclick="addDetail()" type="button" class="btn btn-default">添加明细项目</button>
                        <table class="tableDetail small-control" style="width:100%;">
                            <thead>
                                <tr class="title">
                                    <th>业务类型</th>
                                    <th>名称</th>
                                    <th>材料</th>
                                    <th style="width:60px">单位</th>
                                    <th>工艺</th>
                                    <th>详细规格</th>
                                    <th>备注</th>
                                    <th style="width:60px">数量</th>
                                    <th style="width:60px">单价</th>
                                    <th style="width:80px">金额</th>
                                    <th style="width:80px"></th>
                                </tr>
                            </thead>
                            <tbody id="tbodyDetail"></tbody>
                        </table>

                    </td>
                </tr>
                <tr>
                    <td class="label">其它费用</td>
                    <td colspan="5">
                        安装费 @Html.TextBox("FeeInstallation", null, new { maxlength = "10", @class = "text-money amount" })&nbsp;&nbsp;
                        送货费 @Html.TextBox("FeeDelivery", null, new { maxlength = "10", @class = "text-money amount" })&nbsp;&nbsp;
                        设计费 @Html.TextBox("FeeDesign", null, new { maxlength = "10", @class = "text-money amount" })&nbsp;&nbsp;
                        其它费用 @Html.TextBox("FeeOther", null, new { maxlength = "10", @class = "text-money amount" })
                    </td>
                </tr>
                <tr>
                    <td class="label">总金额</td>
                    <td colspan="5">
                        @Html.TextBox("MarketAmount", null, new { maxlength = "10", @class = "text-money amount",@readonly="readonly" })&nbsp;<span class="redStar">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="label">折扣金额</td>
                    <td colspan="5">
                        @Html.TextBox("Discount", null, new { maxlength = "10", @class = "text-money amount red-text" })
                    </td>
                </tr>
                <tr>
                    <td class="label">实际金额</td>
                    <td colspan="5">
                        @Html.TextBox("RealAmount", null, new { maxlength = "10", @class = "text-money amount" , @readonly = "readonly" })&nbsp;<span class="redStar">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="label">发票状态</td>
                    <td colspan="5">
                        @Html.CheckBox("IsInvoiced") 已开票
                    </td>
                </tr>

                <tr id="trPrePaid" style="display:none">
                    <td class="label">预付金额</td>
                    <td colspan="5">
                        @Html.TextBox("PrePaid", null, new { maxlength = "10", @class = "text-money amount" })
                        &nbsp;&nbsp;支付方式：@Html.DropDownList("PrePaidPaymentType", new SelectList(Model.DdlPaymentType, "ItemValue", "ItemText"),new { @class="form-control"})
                        &nbsp;&nbsp;备注：<input type="text" class="text-memo" id="PrePaidMemo" />
                    </td>
                </tr>

                <tr>
                    <td class="label">关联客户订单</td>
                    <td colspan="5">
                        <button onclick="addRelation()" type="button" class="btn btn-default">关联客户订单</button>
                        <table class="tableDetail small-control" style="width:100%;max-width:1200px;">
                            <thead>
                                <tr class="title">
                                    <th style="width:140px">客户订单号</th>
                                    <th>客户名</th>
                                    <th>详细规格</th>
                                    <th style="width:80px"></th>
                            </thead>
                            <tbody id="tbodyRelation">
                                @foreach(var r in Model.RelationList)
                                {
                                    <tr id="R_@r.Id">
                                        <td id="@r.OrderNo">@r.OrderNo</td>
                                        <td>@r.CustomerName</td>
                                        <td>@Html.Raw(r.OrderName)</td>
                                        <td>
                                            <a href="javascript:void(0);" style="text-decoration:underline;" onclick="deleteRelation(this)">取消关联</a>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>

                    </td>
                </tr>
                <tr>
                    <td class="label">备注</td>
                    <td colspan="5">
                        @Html.TextArea("Memo", null, new { maxlength = "1000", style = "width:98%;height:80px;", @class = "form-control" })
                    </td>
                </tr>
            </table>
        }
    </div>
    <div style="text-align:right;margin:10px 0">
        <span id="errorMessage" class="error-msg"></span>
        <button class="btn btn-default" type="button" id="btnCancel">取消</button>
        <button class="btn btn-primary" type="button" id="btnSave">保存</button>
    </div>
</div>

<div id="divPriceTip" title="价格表" class="tableEdit" style="display:none">
    <div id="divPriceText" style="margin:20px 0;">

    </div>

    <div style="text-align:right;">
        <button class="btn-close" id="btnPriceTipClose" type="button" onclick="$('#divPriceTip').dialog('close');">关闭</button>
    </div>
</div>

<div id="divPriceHistory" title="外协历史价格" style="display:none">
    <div style="margin:0 0 10px 0;">
        <div class="list">
            <table id="tPriceHistory">
                <thead>
                    <tr class="title">
                        <th style="width:120px">外协商</th>
                        <th style="width:100px">交易日期</th>
                        <th>详细规格</th>
                        <th style="width:60px">单价</th>
                        <th>备注</th>
                    </tr>
                </thead>
                <tbody id="priceHistoryList"></tbody>
            </table>
        </div>
    </div>

    <div style="text-align:right;">
        <button class="btn btn-default" id="btnPriceTipClose" type="button" onclick="$('#divPriceHistory').dialog('close');">关闭</button>
    </div>

</div>

<div id="popOrderDetail" title="明细" style="display: none">
    <div id="popOrderDetailC" class="" style="overflow-y: auto;">
        <div class="error-msg"></div>
        <table class="tableEdit">
            <tr>
                <td class="label">
                    订单名称
                    <input type="hidden" id="hiddenFactoryPrice" />
                </td>
                <td>
                    <input type="text" id="OrderName" style="width:100%;" />
                </td>
            </tr>

            <tr>
                <td class="label" title="业务类型不存在？请在“系统配置→订单模板配置”页面添加。">
                    业务类型
                </td>
                <td>
                    <select id="Category"  class="select2"></select>
                    <input type="hidden" id="ReportCategory" />
                    <input type="hidden" id="Guid" />
                    <input type="hidden" id="Id" />                   
                </td>
            </tr>
            <tr>
                <td class="label">规格</td>
                <td>
                    <table id="tableDetail" class="tableDetail small-control" style="width:100%"></table>
                </td>
            </tr>
            <tr>
                <td class="label" title="材料不存在？请在“库存管理→材料管理”页面添加。">材料</td>
                <td>
                    @Html.DropDownList("MaterialId", new SelectList(new List<Com._9pm2.ClientWeb.Common.SimpleItemList>(), "ItemValue", "ItemText"), new { @class = "form-control select2" })
                </td>
            </tr>
            <tr>
                <td class="label">工艺</td>
                <td>
                    <div id="divTechnics" class="divTechnics"></div>
                </td>
            </tr>
            <tr>
                <td class="label">单位</td>
                <td>
                    @Html.DropDownList("PriceUnitId", new SelectList(Model.DdlPriceUnit, "ItemValue", "ItemText"), new { @class = "form-control" })
                </td>
            </tr>
            <tr>
                <td class="label">数量</td>
                <td>
                    @Html.TextBox("Number", null, new { maxlength = "10", @class = "text-money number" })
                </td>
            </tr>
            <tr>
                <td class="label">单价</td>
                <td>
                    @Html.TextBox("Price", null, new { maxlength = "10", @class = "text-money price" })
                    &nbsp;&nbsp;<a href="javascript:void(0);" style="text-decoration:underline; " onclick="OpenPriceTip()">价格提示</a>&nbsp;
                    <a href="javascript:void(0);" style="text-decoration:underline;" onclick="OpenPriceHistory()">历史价格</a>&nbsp;                    
                </td>
            </tr>
            <tr>
                <td class="label">金额</td>
                <td>
                    @Html.TextBox("Amount", null, new { maxlength = "10", @class = "text-money amount" })&nbsp;<span class="redStar">*</span>    &nbsp;                    
                </td>
            </tr>
            <tr>
                <td class="label">备注</td>
                <td>
                    @Html.TextArea("Memo", null, new { maxlength = "1000", style = "width:100%;height:60px;", @class = "form-control" })
                </td>
            </tr>

        </table>
    </div>
    <div style="text-align: right;">
        <div class="error-msg"></div>
        <button class="btn btn-default" type="button" onclick="$('#popOrderDetail').dialog('close');">关闭</button>
        <button class="btn btn-primary" type="button" id="btnSaveDetail" onclick="saveDetail()">保存</button>
    </div>
</div>

<div id="divFactory" title="快速创建外协商" style="display:none">
    <div id="divdivFactoryContent">

        <table id="tableEdit" class="font85 tableEdit">
            <tr>
                <td class="label">外协商名称</td>
                <td>
                    @Html.TextBox("FactoryName", null, new { maxlength = "100", @style = "width:260px" })&nbsp;<span class="redStar">*</span>
                </td>
            </tr>

        </table>

    </div>
    <div style="text-align:right;">
        <div class="error-msg"></div>
        <button class="btn btn-default" type="button" onclick="$('#divFactory').dialog('close');">关闭</button>
        <button class="btn btn-primary" type="button" id="btnSaveFactory">保存</button>
    </div>
</div>

<div id="divRelation" title="关联客户订单" style="display:none">
    <div id="divRelationContent">

        <div class="nav-tabs-custom ">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#" id="a1">最近10笔订单</a></li>
                <li class=""><a href="#" id="a2">搜索订单</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="tab_1">
                    <table>
                        <thead>
                            <tr class="title">
                                <th style="width:40px">
                                </th>
                                <th style="width:150px">客户订单号</th>
                                <th style="width:130px">客户名称</th>
                                <th>详细</th>

                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var r in Model.RecentOrders)
                            {
                                <tr id="OrderNo">
                                    <td class="td-checkbox">
                                        <input type="checkbox" />
                                    </td>
                                    <td>@r.OrderNo</td>
                                    <td>@r.CustomerName</td>
                                    <td>@Html.Raw(r.OrderName)</td>
                                </tr>
                            }

                        </tbody>
                    </table>
                </div>
                <!-- /.tab-pane -->
                <div class="tab-pane" id="tab_2">
                    <div>
                        <input type="text" style="width:140px" placeholder="客户名或订单号搜索" id="txtKey" />
                        <button class="btn btn-default" id="btnSearch">搜索</button>

                    </div>
                    <table>
                        <thead>
                            <tr class="title">
                                <th style="width:40px">
                                </th>
                                <th style="width:150px">客户订单号</th>
                                <th style="width:130px">客户名称</th>
                                <th>详细</th>

                            </tr>
                        </thead>
                        <tbody id="tbodySearch"></tbody>
                    </table>
                    <div style="display:none" id="chart-no-data">很抱歉，没有满足条件的记录。</div>
                </div>

            </div>
            <!-- /.tab-content -->
        </div>

    </div>
    <div style="text-align:right;">
        <div class="error-msg"></div>
        <button class="btn btn-default" type="button" onclick="$('#divRelation').dialog('close');">关闭</button>
        <button class="btn btn-primary" type="button" id="btnSaveRelation">保存</button>
    </div>
</div>

@Html.Hidden("OrderDetails", Model.OrderDetailString)
@Html.Hidden("OrderTemplate")
@Html.Hidden("TemplateId")
@Html.Hidden("TemplateNo")
@Html.Hidden("Detail")
@Html.Hidden("BackURL")
@Html.Hidden("FactoryOrderNo")
