@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}


<link href="~/Content/css/CommonReport/CommonReport.css" rel="stylesheet" />
<script src="~/Content/js/CommonReport/CommonReport.js"></script>
<link href="~/Content/css/bootstrap/bootstrap-select.css" rel="stylesheet" />
<script src="~/Content/js/bootstrap/bootstrap-select.min.js"></script>
<style>
    * {
        box-sizing: border-box;
    }
</style>
<script>
    var ID = $.request("ID");

    $(function () {
        $("#txtLableCode").attr("disabled", "disabled");
        InitControl();
        InitContro2();
        if (ID != "") {
            GetTXT();
        }
    });

    function GetTXT() {
        if (!!ID) {
            $.ajax({
                url: "/WMS/BasicSettings/GetLabelTXT?ID=" + ID + "&" + Math.random(),
                dataType: "json",
                async: false,
                success: function (data) {
                    debugger;
                    $("#txtLableCode").val(data.rows[0].LableCode);
                    $("#txtLableName").val(data.rows[0].LableName);
                    $("#sel_LableType").val(data.rows[0].LableType).trigger("change");
                    $("#sel_LableSourceID").val(data.rows[0].LableSourceID).trigger("change");
                }
            });
        }
    };


    function InitControl() {
        var $VenCode = $("#sel_LableType");
        $VenCode.select2({
            allowClear: true,
            escapeMarkup: function (m) {
                return m;
            }
        });
        $.ajax({
            url: "/WMS/BasicSettings/GetLableType" + "?" + Math.random(),
            dataType: "json",
            async: false, 
            success: function (data) {
                $.each(data, function (index, item) {
                    $VenCode.append("<option value='" + item.F_ItemCode + "'>&nbsp;" + item.F_ItemName + "</option>");
                });
            }
        });
    }

    function InitContro2() {
        var $VenCode = $("#sel_LableSourceID");
        $VenCode.select2({
            allowClear: true,
            escapeMarkup: function (m) {
                return m;
            }
        });
        $.ajax({
            url: "/WMS/BasicSettings/GetLableSourceID" + "?" + Math.random(),
            dataType: "json",
            async: false,
            success: function (data) {
                $.each(data, function (index, item) {
                    $VenCode.append("<option value='" + item.ID + "'>&nbsp;" + item.SourceName + "</option>");
                });
            }
        });
    }



    function submitForm() {
        var Sys_LableDataSource = [];
       
        var txtLableCode = $("#txtLableCode").val();//编号(新增时是空)
        var txtLableName = $("#txtLableName").val();//名称
        var sel_LableType = $("#sel_LableType").val();//;类型
        var sel_LableSourceID = $("#sel_LableSourceID").val();//标签数据源id
        if (txtLableName == '' || txtLableName == undefined) {
            $.modalAlert("请输入标签名称!");
            return;
        }
        if (sel_LableType == '' || sel_LableType == undefined) {
            $.modalAlert("请选择标签类型");
            return;
        }
        if (sel_LableSourceID == '' && sel_LableSourceID == undefined) {
            $.modalAlert("请选择请选择标签数据源!");
            return;
        }
      
        if (ID=='') {
            $.modalConfirm("确定新建吗?", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/WMS/BasicSettings/CreateLables?txtLableName=" + txtLableName + "&sel_LableType=" + sel_LableType + "&sel_LableSourceID=" + sel_LableSourceID + "&" + Math.random(),
                        param: { Sys_LableDataSource: JSON.stringify(Sys_LableDataSource) },
                        success: function () {
                            $.currentWindow().$("#gridList").trigger("reloadGrid");
                        }
                    })
                }
            });
        } else {
            $.modalConfirm("确定修改吗?", function (r) {
                if (r) {
                    $.submitForm({
                        url: "/WMS/BasicSettings/updateLables?txtLableName=" + txtLableName + "&sel_LableType=" + sel_LableType + "&sel_LableSourceID=" + sel_LableSourceID + "&ID=" + ID + "&" + Math.random(),
                        param: { Sys_LableDataSource: JSON.stringify(Sys_LableDataSource) },
                        success: function () {
                            $.currentWindow().$("#gridList").trigger("reloadGrid");
                        }
                    })
                }
            });
        }

    }








</script>

<form id="form1">
    <div class="widget-body">

        <div style="padding-top: 5px;  ">
            <div class="step-content" id="wizard-steps" style="border-left: none; border-bottom: none; border-right: none;">
                <div class="step-pane active" id="step-1" style="padding-left: 5px; padding-top: 20px; margin-right: 20px;">

                    <table class="form">
                        <tr>
                            <th class="formTitle">标签编号: </th>
                            <td class="formValue" style="overflow:auto" colspan="1">
                                <input class="form-control" name="txtLableCode" id="txtLableCode" style="width: 95%" />
                            </td>
                            <th class="formTitle">标签名称: </th>
                            <td class="formValue" style="overflow:auto" colspan="1">
                                <input class="form-control" name="txtLableName" id="txtLableName" style="width: 95%" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">标签类型: </th>
                            <td class="formValue">
                                <select id="sel_LableType" name="sel_LableType" class="form-control select2" style="width: 230px" placeholder="请选择标签类型..."></select>
                                <input type="hidden" id="hidetext" />
                            </td>
                            <th class="formTitle">标签数据: </th>
                            <td class="formValue">
                                <select id="sel_LableSourceID" name="sel_LableSourceID" class="form-control select2" style="width: 230px" placeholder="请选择标签数据..."></select>
                                <input type="hidden" id="hidetext" />
                            </td>
                        </tr>
                       
                    </table>
                </div>
            </div>
        </div>
    </div>
</form>