@model Com._9pm2.ClientWeb.Models.OrderModel
@{ ViewBag.Title = Model.OrderNo == "" ? "客户新订单" : "修改客户订单";}

<script src="../../Scripts/ordercommon.js?vn=20180813"></script>
<script src="../../Scripts/orderedit.js?vn=20180813"></script>

<style type="text/css">
 

      #popOrderDetail a{
        text-decoration:underline;
    }
     
        @if (!string.IsNullOrEmpty(Model.OrderNo))
    {
       @:.tr-factory{display:none !important;}
    }

    @if(Model.FactoryList.Count==0)
    {
         @:.tr-factory-order{display:none !important;}
    }

     .w360{
        width:360px;
    }


</style>

@if (ViewBag.message == "1")
{
    <div class="info-msg" style="display:block">报价单转换客户订单成功，请检查并完善数据！</div>
}

<div id="divOrder">
    <div class="error-msg"></div>
    <div id="divOrderContent" style="min-height:240px">

        <table id="tableEdit" class="font85 tableEdit" style="width:100%">

            <tr>
                <td class="label">客户</td>
                <td style="width:400px">
                    @Html.DropDownList("CustomerNo", new SelectList(Model.DdlCustomer, "ItemValue", "ItemText"), new { @class = "form-control max-width-180" })
                    <input type="text" placeholder="快速搜索" style="width:100px" class="form-control" id="txtCustomer" />&nbsp;
                    <a href="javascript:void(0)" onclick="newCustomer()">快速创建客户</a>
                </td>
                <td class="label">联系人</td>
                <td colspan="3" class="order-edit-contact">
                    <div>
                        <select id="ContactNo" name="ContactNo" class="form-control select2"></select>
                    </div>
                    <div>
                        &nbsp;
                    </div>
                    <div>
                        @Html.TextBox("Contact", null, new { maxlength = "100", title = "空格分隔，比如：张三 13888888888", @style = "width:180px", @class = "form-control" })&nbsp;
                        <a href="javascript:void(0)" onclick="newContact()">快速创建联系人</a>
                    </div>                   
                </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">
                    @Html.DropDownList("DeliveryType", new SelectList(Model.DdlDeliveryType, "ItemValue", "ItemText"), new { @class = "form-control" })
                    @Html.TextBox("DeliveryAddress", null, new { @class = "form-control", maxlength = "300", style = "width:465px;", placeholder = "请填写送货地址" })
                </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 class="c-fa">外协</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.DropDownList("TaxType", new SelectList(Model.DdlTaxType, "ItemValue", "ItemText"), new { @class = "form-control" })&nbsp;&nbsp;
                    税率 @Html.TextBox("TaxRatio", null, new { maxlength = "10", @class = "text-money tax-ratio" }) %&nbsp;&nbsp;
                    不含税金额 @Html.TextBox("TaxAmount", null, new { maxlength = "10", @readonly = "readonly", @class = "text-money amount" })&nbsp;&nbsp;
                    税金 @Html.TextBox("FeeTax", null, new { maxlength = "10", @readonly = "readonly", @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 class="tr-factory-order">
                <td class="label">关联外协订单</td>
                <td colspan="5">
                    <table class="tableDetail small-control" style="width:100%;max-width:1200px;">
                        <thead>
                            <tr class="title">
                                <th style="width:140px">外协订单号</th>
                                <th>外协商名称</th>
                                <th>详细</th>
                        </thead>
                        <tbody id="tbodyRelation">
                            @foreach (var r in Model.FactoryList)
                            {
                                <tr>
                                    <td>@r.FactoryOrderNo</td>
                                    <td>@r.FactoryName</td>
                                    <td>@Html.Raw(r.OrderName)</td>
                                </tr>
                            }
                        </tbody>
                    </table>

                </td>
            </tr>
            <tr id="tr-factory" style="display:none">
                <td class="label">外协</td>
                <td colspan="5">
                    <div>
                        <div>
                            <div class="btn-group">
                                <button type="button" class="btn btn-default btn-sm" id="btnNewFactoryDetail">新增明细</button>
                                <button type="button" class="btn btn-default btn-sm" id="btnCopyFactoryDetail">复制明细</button>
                                <button type="button" class="btn btn-default btn-sm" id="btnDeleteFactoryDetail">删除明细</button>
                            </div>
                            <button type="button" class="btn btn-default btn-sm" id="btnNewFactory">快速创建外协商</button>
                        </div>
                        <div>
                            <table class="excel-table" id="simpleOrderDetail">
                                <thead>
                                    <tr>
                                        <th></th>
                                        <th style="width:120px">外协商</th>
                                        <th style="width:120px">业务类型</th>
                                        <th>名称</th>
                                        <th>材料</th>
                                        <th style="width:60px">单位</th>
                                        <th>工艺</th>
                                        <th style="width:60px">宽(@Model.WidthUnit)</th>
                                        <th style="width:60px">高(@Model.WidthUnit)</th>
                                        <th style="width:60px">数量</th>
                                        <th style="width:80px">面积(m<sup>2</sup>)</th>
                                        <th style="width:60px">单价</th>
                                        <th style="width:80px">金额</th>
                                        <th>备注</th>
                                    </tr>
                                </thead>
                                <tbody id="simpleOrderTr"></tbody>
                            </table>
                        </div>
                    </div>
                </td>
            </tr>
            <tr id="trWorkFlow" style="display:none">
                <td class="label">流程</td>
                <td colspan="5">
                    @Html.DropDownList("WorkFlowNo", new SelectList(Model.DdlWorkFlow, "ItemValue", "ItemText"), new { @style = "min-width:160px;", @class = "form-control" })
                    <div id="divWorkFlow" style="margin-left:10px; display:none">
                        下一步：<select id="WorkFlowStepNo" class="form-control" name="WorkFlowStepNo" style="width:120px"></select> &nbsp;&nbsp;
                        <div id="divWorkFlowUserId" style="display:inline-block">
                            经办人：<select id="WorkFlowUserId" class="form-control" name="WorkFlowUserId" style="width:120px"></select>
                        </div>
                    </div>
                </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>
        @if (ViewBag.message != "1")
        {
            <button type="button" class="btn btn-default" id="btnCancel">取消</button>
        }

        <button type="button" class="btn btn-primary" id="btnSave">保存</button>
    </div>
</div>

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

    </div>

    <div style="text-align:right;">
        <button class="btn-close" id="btnPriceTipClose" 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 style="width:120px">业务类型</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 type="button" class="btn btn-default" id="btnPriceTipClose" onclick="$('#divPriceHistory').dialog('close');">关闭</button>
    </div>

</div>

<div id="divPriceHistoryFactory" 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 style="width:120px">业务类型</th>
                        <th>详细规格</th>
                        <th style="width:60px">单价</th>
                        <th>备注</th>
                    </tr>
                </thead>
                <tbody id="priceHistoryListFactory"></tbody>
            </table>
        </div>
    </div>

    <div style="text-align:right;">
        <button type="button" class="btn btn-default" id="btnPriceTipClose" onclick="$('#divPriceHistoryFactory').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="hiddenSailPrice" />
                    <input type="hidden" id="hiddenFactoryPrice" />
                </td>
                <td colspan="3">
                    <input type="text" id="OrderName" style="width:100%;" />
                </td>
            </tr>

            <tr>
                <td class="label" title="业务类型不存在？请在“系统配置→订单模板配置”页面添加。">
                    业务类型
                </td>
                <td colspan="3">
                    <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 colspan="3">
                    <table id="tableDetail" class="tableDetail small-control" style="width:100%"></table>
                </td>
            </tr>
            <tr>
                <td class="label" title="材料不存在？请在“库存管理→材料管理”页面添加。">材料</td>
                <td colspan="3">
                    @Html.DropDownList("MaterialId", new SelectList(Model.DdlMaterial, "ItemValue", "ItemText"), new { @class = "form-control select2" })
                    @Html.Hidden("StockNumber")
                </td>
            </tr>
            <tr>
                <td class="label">工艺</td>
                <td id="tdTechnic" class="w360">
                    <div id="divTechnics" class="divTechnics"></div>
                </td>
                <td colspan="2" class="c-fa" style="color:#808080;">
                    订单需要外协加工时，请填写下列信息 &nbsp;&nbsp;
                    <a id="aNewFactory" href="javascript:void(0)">快速创建外协商</a>
                </td>

            </tr>
            <tr>
                <td class="label">单位</td>
                <td>
                    @Html.DropDownList("PriceUnitId", new SelectList(Model.DdlPriceUnit, "ItemValue", "ItemText"), new { @class = "form-control" })
                </td>
                <td class="label c-fa">外协商</td>
                <td class="c-fa">
                    @Html.DropDownList("FactoryNo", new SelectList(Model.DdlFactory, "ItemValue", "ItemText"), new { @class = "select2 FactoryNo" })

                </td>

            </tr>
            <tr>
                <td class="label">数量</td>
                <td>
                    @Html.TextBox("Number", null, new { maxlength = "10", @class = "text-money number" })
                </td>
                <td class="label c-fa">数量</td>
                <td class="c-fa">
                    @Html.TextBox("FactoryNumber", 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);" onclick="OpenPriceTip()">价格提示</a>&nbsp;
                    &nbsp;&nbsp;<a href="javascript:void(0);" onclick="OpenPriceHistory()">历史价格</a>&nbsp;                    
                </td>
                <td class="label c-fa">单价</td>
                <td class="c-fa">
                    @Html.TextBox("FactoryPrice", null, new { maxlength = "10", @class = "text-money price" })
                    &nbsp;&nbsp;<a href="javascript:void(0);" onclick="OpenPriceHistoryFactory()">历史价格</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>
                <td class="label c-fa">金额</td>
                <td class="c-fa">
                    @Html.TextBox("FactoryAmount", null, new { maxlength = "10", @class = "text-money amount" })    &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>
                <td class="label c-fa">备注</td>
                <td class="c-fa">
                    @Html.TextArea("FactoryMemo", 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 type="button" class="btn btn-default" onclick="$('#popOrderDetail').dialog('close');">关闭</button>
        <button type="button" class="btn btn-primary" id="btnSaveDetail" onclick="saveDetail()">保存</button>
    </div>
</div>

<div id="divCustomer" title="快速创建客户" style="display:none">
    <div id="divCustomerContent">
        <table id="tableEdit" class="font85 tableEdit">
            <tr>
                <td class="label">客户名称</td>
                <td>
                    @Html.TextBox("CustomerFullName", 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 type="button" class="btn btn-default" id="btnCancelCustomer">关闭</button>
        <button type="button" class="btn btn-primary" id="btnSaveCustomer">保存</button>

    </div>
</div>

<div id="divContact" title="快速创建联系人" style="display:none">
    <div id="divdivContactContent">

        <table id="tableEdit" class="font85 tableEdit">
            <tr>
                <td class="label" style="height:41px">公司名称</td>
                <td id="tdCustomerName"></td>
            </tr>
            <tr>
                <td class="label">联系人姓名</td>
                <td>
                    @Html.TextBox("ContactName", null, new { maxlength = "100", @style = "" })&nbsp;<span class="redStar">*</span>
                </td>
            </tr>
            <tr>
                <td class="label">电话号码</td>
                <td>
                    @Html.TextBox("Phone", null, new { maxlength = "100", @style = "" })
                </td>
            </tr>
        </table>

    </div>
    <div style="text-align:right;">
        <div class="error-msg"></div>
        <button type="button" class="btn btn-default" onclick="$('#divContact').dialog('close');">关闭</button>
        <button type="button" class="btn btn-primary" onclick="SaveContact()">保存</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>
        <br />

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

<div id="divPopTechnic" title="选择工艺" style="display:none">
    <div id="divPopTechnicContent">
        <div id="divPopTechnicNoData">无可用工艺，请在材料管理添加工艺及价格。</div>
        <div class="divTechnics"></div>

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

@Html.Hidden("OrderDetails", Model.OrderDetailString)
@Html.Hidden("OrderTemplate")
@Html.Hidden("TemplateNo")
@Html.Hidden("Detail")
@Html.Hidden("BackURL")
@Html.Hidden("Approved")
@Html.Hidden("OrderNo")
@Html.Hidden("TemplateId")
@Html.Hidden("WidthUnit")
@Html.Hidden("ShowSimpleFactoryItem")
@Html.Hidden("ShowRightFactoryItem")
@Html.Hidden("EnableWorkFlow")
@Html.Hidden("HideFactory")
<div style="display:none">
    <select id="FactoryCategory"></select>
    <select id="Material"></select>
</div>

