@{

    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<style type="text/css">
    table tr td:first-child
    {
        text-align: right;
        width: 30%;
    }
</style>
<div class="wrapper wrapper-content" style="width: inherit;">
    <div class="ibox float-e-margins" style="width: inherit;">
        <div>
            <div style="text-align: center" id="lab">
                @Html.Raw(ViewBag.label1)
            </div>
        </div>
        <table class="table table-bordered table-striped table-hover">
            <tr>
                <td>代理商编号</td>
                <td>
                    <input type="text" id="usercode" style="width: 400px">
                </td>
            </tr>
            <tr>
                <td>公司名称</td>
                <td>
                    <input type="text" id="userfullname" style="width: 400px">
                </td>
            </tr>
            <tr>
                <td>联系人</td>
                <td>
                    <input type="text" id="person" style="width: 400px">
                </td>
            </tr>
            <tr>
                <td>联系电话</td>
                <td>
                    <input type="text" id="persontel" style="width: 400px">
                </td>
            </tr>
            <tr>
                <td>用户数</td>
                <td>
                    <input type="text" id="zcnum" style="width: 400px">
                </td>
            </tr>
            <tr>
                <td>类型</td>
                <td>
                    <select name="zctype" id="zctype" style="width: 200px">
                        @{if (ViewBag.IsAdd == true)
                            {
                            <option value="0001000001">增加</option>}
                        }
                        @{if (ViewBag.IsAll == true)
                            {
                            <option value="0001000001">增加</option>
                            <option value="0001000003">调整</option>
                            }
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td>付费方式</td>
                <td>
                    <select name="regtype" id="regtype" style="width: 200px">
                        @{
                            if (ViewBag.IsYearOrBuyout == true && ViewBag.IsFzLimit)
                            {
                            <option value="0000200006">年费</option>
                            <option value="0000200005">买断</option>
                            }
                            else if (ViewBag.IsYearOrBuyout == true && !ViewBag.IsFzLimit)
                            {
                            <option value="0000200002">年费</option>
                            <option value="0000200001">买断</option>
                            }
                        }

                    </select>
                </td>
            </tr>
            <tr>
                <td>省份</td>
                <td>
                    <div>
                        <select name="Province" id="Province" style="width: 160px; float: left">
                            <option>—请选择—</option>
                        </select>
                        <select name="City" id="City" style="width: 160px;">
                            <option>—请选择—</option>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td>管家婆版本</td>
                
                @{
                    if (ViewBag.WLTVERSION != "WLTGY")
                    {
                        <td>
                            &nbsp;&nbsp;
                            <input type="radio" value="TYHH" name="radios" id="banbenhh" checked="checked" />辉煌系列
                            <input type="radio" value="TYFX" name="radios" id="banbenfx" /> 分销系列
                            <input type="radio" value="TYCM" name="radios" id="banbencm" /> 财贸系列
                            <input type="radio" value="HYSP" name="radios" id="banbensp" /> 食品系列
                            <input type="radio" value="HYQF" name="radios" id="banbenqf" /> 千方系列

                        </td>
                    }
                    else
                    {
                        <td>
                            &nbsp;&nbsp;
                            <input type="radio" value="HYFZ" name="radios" id="banbenfz" checked="checked" />服装系列
                        </td>
                    }
                }
            </tr>
            <tr>
                <td></td>
                <td>
                    @{if (ViewBag.btnSave == true)
                      {
                        <button id="btnSave" class="btn btn-default">提交</button>
                      }
                    }
                    @{if (ViewBag.btnActivation == true)
                      {
                        <button id="btnActivation" class="btn btn-default">激活</button>
                      }
                    }
                </td>
            </tr>
        </table>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $.ajax({
            url: "../DealerEdition/GetProvincelist",
            type: "post",
            datatype: "Json",
            async: false,
            success: function (data) {
                $.each(data, function (i, item) {
                    $("<option></option>").val(item["PID"]).text(item["ProvinceName"]).appendTo($("#Province"));
                })
            }
        });
        DataBind();
        $("#Province").change(function () {
            GetCity();
        });

        $("#btnSave").click(function () {
            //是否拍照
            var chkObjs = null;
            var obj = document.getElementsByName("radios")
            for (var i = 0; i < obj.length; i++) { //遍历Radio
                if (obj[i].checked) {
                    chkObjs = obj[i].value;
                }
            }
            $.ajax({
                url: "../Register/SaveRegSoftware",
                dataType: "text",
                data: {
                    usercode: $("#usercode").val(),
                    userfullname: $("#userfullname").val(),
                    person: $("#person").val(),
                    persontel: $("#persontel").val(),
                    zcnum: $("#zcnum").val(),
                    zctype: $("#zctype").val(), //注册类型
                    regtype: $("#regtype").val(), //付费方式
                    province: $("#Province").val(),
                    city: $("#City").val(),
                    chkObjs: chkObjs
                },
                type: "post",
                success: function (data) {
                    //新增或修改成功后刷新table
                    parent.layer.msg(data, { icon: 1, time: 2000 });
                    parent.$('#RegisteTable').bootstrapTable("refresh");
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                },
                error: function (data) {
                    layer.msg(data, { icon: 2, time: 2000 });
                }
            })
        })
        ////激活按钮
        $("#btnActivation").click(function () {

            //是否拍照
            var chkObjs = null;
            var obj = document.getElementsByName("radios")
            for (var i = 0; i < obj.length; i++) { //遍历Radio
                if (obj[i].checked) {
                    chkObjs = obj[i].value;
                }
            }
            $.ajax({
                url: "../Register/jihuosavedata",
                dataType: "text",
                data: {
                    usercode: $("#usercode").val(),
                    userfullname: $("#userfullname").val(),
                    person: $("#person").val(),
                    persontel: $("#persontel").val(),
                    zcnum: $("#zcnum").val(),
                    zctype: $("#zctype").val(), //注册类型
                    regtype: $("#regtype").val(), //付费方式
                    province: $("#Province").val(),
                    city: $("#City").val(),
                    chkObjs: chkObjs
                },
                type: "post",
                success: function (data) {
                    //新增或修改成功后刷新table
                    parent.layer.msg(data, { icon: 1, time: 2000 });
                    parent.$('#RegisteTable').bootstrapTable("refresh");
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                },
                error: function (data) {
                    layer.msg(data, { icon: 2, time: 2000 });
                }
            })
        })
    });
    function GetCity() {
        $("#City").empty();
        $.ajax({
            url: "../DealerEdition/GetCitylist",
            data: {
                pid: $("#Province").val()
            },
            type: "post",
            datatype: "Json",
            async: false,
            success: function (data) {
                $.each(data, function (i, item) {
                    $("<option></option>").val(item["Value"]).text(item["Text"]).appendTo($("#City"));
                })
            }
        });
    }
    function DataBind() {
        $.ajax({
            url: "../Register/GetRegister",
            type: "post",
            datatype: "Json",
            success: function (data) {
                if (data != null && data != undefined) {
                    data = JSON.parse(data.substring(1, data.length - 1));
                    $("#usercode").val(data["cusercode"]);
                    $("#userfullname").val(data["company"]);
                    $("#person").val(data["person"]);
                    $("#persontel").val(data["tel"]);
                    $("#zcnum").val(data["usercount"]);
                    $("#zctype").val(data["registertype"]); //注册类型
                    $("#regtype").val(data["payfor"]); //付费方式
                    $("#Province").val(data["sheng"]);
                    $("input[name='radios'][value='" + data["banben"] + "']").attr("checked", true);
                    GetCity();
                    $("#City").val(data["shi"]);

                }
            }
        })
    }
</script>
