yujian
2021-05-29 c031329ac49bd4ddf12e309d77c2c6a31b7a2816
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html>
<html class="x-admin-sm">
 
<head>
    <meta charset="UTF-8">
    <title>特价管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../css/theme3049.min.css">
    <script type="text/javascript" src="../../js/vue.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
    <script type="text/javascript" src="../../js/http.js" charset="utf-8"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
 
    <style type="text/css">
        .layui-table-view .layui-table th{
            overflow:hidden;
        }
 
        .layui-table-view .layui-table {
            width: 100%;
        }
    </style>
</head>
 
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">供应商管理</a>
                <a>
                    <cite>账号列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" id="searchForm">
                        <input type="text" name="providerId" id="providerId" style="display: none;"/>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="start"
                                   :value="start">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="end"
                                   :value="end"></div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" id="key" name="key" placeholder="请输入应用名称" :value="key" autocomplete="off"
                                   class="layui-input"></div>
                        <div class="layui-inline layui-show-xs-block">
                            <button type="submit" class="layui-btn">搜索</button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table" id="table_list" lay-filter="app">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
 
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn" onclick="openAddViews()"><i class="layui-icon"></i>添加
        </button>
    </div>
</script>
 
 
<script type="text/html" id="barAction">
    <a class="layui-btn layui-btn-danger layui-btn-xs"  onclick="member_del(this,{{d.LAY_INDEX }},{{d.id}})" >删除</a>
</script>
 
<script>
    function member_del(obj, index, id) {
        layer.confirm('确认要删除吗?', function (index) {
            app.delete(obj, index, id);  //发异步删除数据
        });
    }
</script>
 
 
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|停用" lay-filter="stateBox" {{ d.state== 1 ? 'checked': ''}} >
</script>
 
 
<script>
    var providerId= GetQueryString("pid"); // 上级did
 
    //封装GetQueryString()方法来获取URL后面的value值
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return decodeURI(r[2]);
        return null;
    }
 
    $("#providerId").val(providerId);
 
 
    function openAddViews() {
        xadmin.open('新增链接信息','providerAccount-add.html?pid='+ providerId,500,480);
    }
 
 
    var app = null;
    layui.use('table', function () {
        //搜索表单的vue赋值
        app = new Vue({
            el: "#searchVue",
            data: {
                key: '',
                start: '',
                end: ''
            },
            methods: {
                delete: function (obj, index, id) {
                    var ids = new Array();
                    ids.push(id);
 
                    app.deleteList(ids, function () {
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!', {icon: 1, time: 1000});
                    });
                },
                deleteList: function (ids, success) {
                    ksapp.post("/admin/api/lijin/providerAccount/delete", {ids: JSON.stringify(ids)}, function (e) {
                        if (e.code == 0) {
                            success();
                        } else {
                            layer.msg(e.msg);
                        }
                    }, function (e) {
                    });
                },
                update: function (id, params) {
                    params.id = id;
                    ksapp.post("/admin/api/lijin/providerAccount/modify", params, function (e) {
                        if (e.code == 0) {
                            layer.msg("修改成功");
                        } else
                            layer.msg(e.msg);
                    }, function (e) {
 
                    });
                }
            }
        });
 
        // app.key = ksapp.getQueryParam("appname") != null ? ksapp.getQueryParam("appname") : '';
        // app.start = ksapp.getQueryParam("start");
        // app.end = ksapp.getQueryParam("end");
 
        app.key = $("#key").val();
        // app.start = ksapp.getQueryParam("start");
        // app.end = ksapp.getQueryParam("end");
 
        var table = layui.table;
 
        var url = "/admin/api/lijin/providerAccount/listByPage";
        // var url = "/admin/api/lijin/providerAccount/listByPage?key=" + encodeURIComponent(app.key) + "&startDate=" + app.start + "&endDate=" + app.end;
        // if (providerId != null && providerId != undefined) {
        //     url = url + "&providerId=" + providerId;
        // }
 
        // var data = new FormData("#searchForm");
        // var formData = new FormData($('#searchForm')[0]);
        // var formData = $('#searchForm').serializeArray();
        // Array.push('pageSize', 20);
        // formData.append('pageSize', 20);
        // formData.append('page', 1);
 
        table.render({
            id: 'testReload',
            elem: '#table_list',
            url: url,
            where: {'page': 1, 'pageSize': 20, 'key':app.key }, //如果无需传递额外参数,可不加该参数page=1&pageSize=20
            toolbar: "#toolbar",
            totalRow: true,
            cols: [
                [{type: 'checkbox', title: "ID"},
                    {field: 'id', width: 80, sort: true, title: "ID"},
                    {field: 'state', width: 95, title: "状态", templet: "#switchTpl"},
                    {field: 'accountName',edit: 'text', width: 200, sort: true, title: "账号名称"},
                    {field: 'appKey', edit: 'text', width: 200, title: "APPKey"},
                    {field: 'appSecret', edit: 'text', width: 200, title: "APPSecret"},
                    {field: 'maxMoney', edit: 'text', width: 120, title: "每日最大金额"},
                    {field: 'maxNumber', edit: 'text', width: 120,title: "每日最大商品数"},
                    {field: 'todayConsumeMoney', width: 120, title: "今日已用金额"},
                    {field: 'todayConsumeNumber',  width: 120,title: "今日已用商品数"},
                    {fixed: 'right', width: 150, title: "操作", toolbar: '#barAction'},
                ]
 
            ],
            page: true,
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.pe.totalCount, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
            //,…… //其他参数
        });
 
 
 
        //监听单元格编辑
        table.on('edit(app)',
            function (obj) {
                var value = obj.value, //得到修改后的值
                    data = obj.data, //得到所在行所有键值
                    field = obj.field; //得到字段
                //修改接口
                var params = {id: data.id};
                params[field] = value;
                app.update(data.id, params);
            });
 
        //头工具栏事件
        table.on('toolbar(app)',
            function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'delete':
                        var data = checkStatus.data;
                        if (data == null || data.length == 0) {
                            layer.msg("未选择选项");
                            return;
                        }
                        app.deleteList();
                        break;
                };
            });
 
 
        // var $ = layui.$, active = {
        //     reload: function(){
        //         var dataForm = $('#searchForm').serialize();
        //
        //         //执行重载
        //         table.reload('testReload', {
        //             page: {
        //                 curr: 1 //重新从第 1 页开始
        //             }
        //         });
        //     }
        // };
        // $('.demoTable .layui-btn').on('click', function(){
        //     var type = $(this).data('type');
        //     active[type] ? active[type].call(this) : '';
        // });
 
 
        //监听状态操作
        layui.form.on('switch(stateBox)', function(obj){
            var state = 0;
            if (obj.elem.checked) {
                state = 1;
            }
            var params = {id: this.value, state: state};
            app.update(this.value, params);
        });
 
    });</script>
</html>