wangsheng
2021-09-26 fad59c96add549467aeb66a0e1c39950886ce02b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<%@ Page Language="C#"  masterpagefile="~/Main.master" AutoEventWireup="true" CodeFile="GwOpGroup.aspx.cs" Inherits="GwOpGroupPage" %>
 
 
<asp:Content ID="Content1" ContentPlaceHolderID="title" Runat="Server">
通道组管理
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="content" Runat="Server">
    <div class="listCanvas">
        <table class="table table-striped table-bordered table-hover">
            <tr class="header">
                <th>
                通道组名称
                </th>
                <th>
                通道组数据
                </th>
                <th class="col-sm-1">
                    操作
                </th>
            </tr>
            <%=RenderGroupList() %>
        </table>
 
        <button class="action-modal-create btn btn-primary">创建通道组</button>
    </div>
    <div class="modal inmodal fade" id="groupDialog" tabindex="-1" role="dialog" aria-hidden="true">
        <form method="post"  class=" form-horizontal">
        <div class="modal-dialog modal-xs">
            <div class="modal-content ">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">
                        创建/修改通道组 <input type="hidden" name="apid" id="apid" value="0"/></h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="control-label" >
                            通道组名称</label>
                        <div>
                            <input type="text" name="groupName" id="groupName" value="" class="form-control" />
                        </div>
                    </div>
                   <div class="form-group">
                      <table class="table table-striped table-bordered table-hover" id="opList">
                      <thead>
                        <tr><th class="col-md-6">通道</th><th class="col-md-4">权重</th><th  class="col-md-2">操作</th></tr>
                        </thead>
                        <tbody>
                          
                        </tbody>
                        <tfoot>
                              <tr><td colspan="3"><a href="javascript:;" class="btn btn-xs btn-warning action-add-op">添加通道</a> <span>通道权重必须在0-10之间,通道权重为0时,为备份通道</span></td></tr>
                        </tfoot>
                      </table>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-warning" data-dismiss="modal" aria-hidden="true">
                        取消</button>&nbsp;&nbsp;
                    <button class="btn btn-primary action-save-group">
                        保存</button>
                </div>
            </div>
        </div>
        </form>
    </div>
 
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            var opList = <%=RenderOpListJson()%>
 
            $(".action-modal-create").on("click", function () {
                $("#groupDialog").data("id", 0);
                $("#groupDialog .modal-title").text("创建通道组");
                $("#groupDialog #opList tbody").html("");
                $("#groupDialog").modal("show");
            });
            $("#groupDialog").on("click", ".action-remove-op", function () {
                var tr = $(this).parents("tr");
                tr && (tr.remove());
            });
 
            $(".action-add-op").on("click", function () {
                appendOpRow(0,10);
            });
 
            function appendOpRow(opid,weight) {
               var html = [];
               html.push("<tr>");
               html.push("<td><select class='form-control' name='opid'>");
               $.each(opList, function (i) {
                   html.push("<option value='" + this.OpID + "'  "+((this.OpID == opid) ? "selected" : "")+">" +this.OpID+"-"+ this.OpName + "</option>");
               });
               html.push("</select></td>");
               html.push("<td><input type='text' class='form-control' name='weight' value='"+weight+"'></td>");
               html.push("<td><a href='javascript:;' class='btn btn-xs btn-danger action-remove-op'><i class='fa fa-trash'></i></a> </td>");
               html.push("</tr>");
 
               $("#opList tbody").append(html.join(""));
            }
 
            $(".action-save-group").on("click", function (e) {
                e.preventDefault();
                var groupName = $("#groupName").val();
                var groupID = $("#groupDialog").data("id");
                var groupData = [];
                $("#opList tbody tr").each(function (i) {
                    var opid = $(this).find("select[name='opid']").val();
                    var weight = $(this).find("input[name='weight']").val();
                    groupData.push({ opid: opid, weight: weight });
                });
 
                $.post("gwopgroup.ashx", { action: "save", groupID: groupID, groupName: groupName, groupData: $.toJSON(groupData) }, function (r) {
                    mytek.alert(r.Message, r.OK, function () {
                        r.OK && (window.location.reload());
                    });
                }, "json");
            });
            $(".action-delete").on("click",function(e){
                 var id = $(this).data("id");
               
                mytek.confirm("是否需要删除该通道组?", "删除通道组后将无法恢复,并影响相应账号发送,请谨慎操作!", function (b) {
                    if (b) {
                        $.post("gwopgroup.ashx", { action: "delete", groupID: id }, function (r) {
                            mytek.alert(r.Message, r.OK, function () {
                                window.location.reload();
                            });
                        });
                    }
                });
            });
 
            $(".action-modal-edit").on("click", function (e) {
                var id = $(this).data("id");
 
 
                $.get("gwopgroup.ashx", { action: "getGroup", groupid: id }, function (r) {
                    if (r.OK) {
                        $("#groupDialog").data("id", id);
                        $("#groupDialog .modal-title").text("编辑通道组");
                        $("#groupDialog #groupName").val(r.Message.GroupName);
                        $("#groupDialog #opList tbody").html("");
 
                        var data = $.evalJSON(r.Message.GroupData);
                        $.each(data, function (i) { 
                            appendOpRow(this.opid,this.weight);
                        });
 
                        $("#groupDialog").modal("show");
                    } else {
                        mytek.alert(r.Message);
                    }
                });
            });
        });
    </script>
</asp:Content>