admin
2025-08-08 035edfa382d349ba66240fbfef68c14c7cfc95d1
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>下单任务列表</title>
    <link rel="stylesheet" type="text/css" href="/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="/admin/css/admin.css"/>
    <style>
        .layui-table-cell {
            height: 50px;
            white-space: normal;
            max-height: 50px;
        }
 
 
        #add_task {
            padding: 10px;
        }
    </style>
</head>
 
<body>
<div class="page-content-wrap">
    <form class="layui-form" action="" lay-filter='search'>
        <div class="layui-form-item">
            <div class="layui-inline">
                <input type="text" name="keyword" id="keyword" placeholder="按口令内容搜索" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-inline">
                <input type="text" name="startDate" id="startDate" placeholder="开始日期" autocomplete="off"
                       class="layui-input" readonly>
            </div>
            <div class="layui-inline">
                <input type="text" name="endDate" id="endDate" placeholder="结束日期" autocomplete="off"
                       class="layui-input" readonly>
            </div>
            <div class="layui-inline">
                <select name="status" id="status">
                    <option value="">全部状态</option>
                    <option value="0">未分配</option>
                    <option value="1">分配中</option>
                    <option value="2">已分配</option>
                </select>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="search" id="search"><i
                    class="layui-icon layui-icon-search"></i>搜索
                </button>
                <a href="javascript:void();" class="layui-btn layui-btn-warm" onclick="showCreateTask()"><i
                    class="layui-icon layui-icon-add-circle"></i> 添加任务</a>
            </div>
        </div>
    </form>
    <div>
        <table class="layui-table" lay-even lay-skin="nob" id="table">
 
        </table>
    </div>
</div>
 
<div id="add_task" style="display: none; padding: 20px;">
    <form class="layui-form" action="" lay-filter='add-task'>
        <div class="layui-form-item">
            <label class="layui-form-label">口令内容</label>
            <div class="layui-input-block">
                <textarea type="text" name="keywordContent" rows="5" required lay-verify="required" placeholder="请输入口令内容"
                          autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品来源</label>
            <div class="layui-input-block">
                <select name="productSource" required lay-verify="required">
                    <option value="">请选择商品来源</option>
                    <option value="1">抖音</option>
                    <option value="2">快手</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
                <textarea type="text" name="productName" rows="3" required lay-verify="required" placeholder="请输入商品名称"
                          autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">店铺名称</label>
            <div class="layui-input-block">
                <input type="text" name="shopName" placeholder="请输入店铺名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所需下单数量</label>
            <div class="layui-input-block">
                <input type="number" name="requiredOrderCount" required lay-verify="required|number" min="1"
                       placeholder="请输入所需下单数量" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">收货周期(小时)</label>
            <div class="layui-input-block">
                <input type="number" name="receiveCycleHours" required lay-verify="required|number" min="1"
                       placeholder="请输入收货周期(小时)" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">下单开始时间</label>
            <div class="layui-input-block">
                <input type="text" name="orderStartTime" id="orderStartTime" required lay-verify="required"
                       placeholder="请选择下单开始时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">下单结束时间</label>
            <div class="layui-input-block">
                <input type="text" name="orderEndTime" id="orderEndTime" required lay-verify="required"
                       placeholder="请选择下单结束时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add-task">立即创建</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
 
<script src="/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="/admin/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script>
    // 修改任务信息
    function updateTask(id) {
        var layerIndex = layer.open({
            title: "修改下单任务信息",
            type: 2,
            area: ['600px', '600px'],
            shade: 0.3,
            shadeClose: false,
            resize: false,
            content: '/admin/order-task-update.html?id=' + id,
            btn: ['确定', '取消'],
            yes: function (index) {
                //submit方法为弹框内容中的方法
                window["layui-layer-iframe" + index].submit(function (res) {
                    let fdata = {
                        id: id
                    };
                    for (let key in res) {
                        if (key.indexOf(".") >= 0) {
                            let k1 = key.split(".")[0];
                            let k2 = key.split(".")[1];
                            if (k1 in fdata) {
                            } else {
                                fdata[k1] = {};
                            }
                            fdata[k1][k2] = res[key];
                        } else {
                            fdata[key] = res[key]
                        }
                    }
                    for (let key in fdata) {
                        if (typeof (fdata[key]) == 'object') {
                            fdata[key] = JSON.stringify(fdata[key]);
                        }
                    }
                    try {
                        var loadIndex = layer.load(1);
                        $.post("/admin/api/ordertask/js2/update", fdata, function (response) {
                            layer.close(loadIndex);
                            if (response.code == 0) {
                                layer.close(layerIndex);
                                layer.msg("更改成功");
                                // 重新加载表格
                                tableIns.reload();
                            } else {
                                layer.msg(response.msg);
                            }
                        }, 'json').fail(function (jqXHR, textStatus, errorThrown) {
                            layer.close(loadIndex);
                            layer.msg("网络请求失败");
                        });
                    } catch (e) {
                        console.log(e);
                    }
                });
            },
            cancel: function () {
            }
        });
    }
 
    // 删除任务
    function deleteTask(id) {
        layer.confirm('确定要删除这个任务吗?', {
            btn: ['确定', '取消']
        }, function (index) {
            $.post("/admin/api/ordertask/js2/delete", {"id": id}, function (response) {
                if (response.code == 0) {
                    layer.msg("删除成功");
                    // 重新加载表格
                    tableIns.reload();
                } else {
                    layer.msg(response.msg);
                }
            }, 'json').fail(function (jqXHR, textStatus, errorThrown) {
                layer.msg("网络请求失败");
            });
            layer.close(index);
        });
    }
 
    // 分配任务
    function assignTask(id) {
        layer.confirm('确定要分配这个任务吗?', {
            btn: ['确定', '取消']
        }, function (index) {
            $.post("/admin/api/ordertask/js2/assign", {"taskId": id}, function (response) {
                if (response.code == 0) {
                    layer.msg("分配成功");
                    // 重新加载表格
                    tableIns.reload();
                } else {
                    layer.msg(response.msg);
                }
            }, 'json').fail(function (jqXHR, textStatus, errorThrown) {
                layer.msg("网络请求失败");
            });
            layer.close(index);
        });
    }
    
    // 查看已分配设备
    function viewAssignedClients(id) {
        var layerIndex = layer.open({
            title: "已分配设备列表",
            type: 2,
            area: ['1200px', '600px'],
            shade: 0.3,
            shadeClose: false,
            resize: false,
            content: '/admin/order-task-assigned-clients.html?taskId=' + id
        });
    }
 
    function formatDateTime(date, format) {
        var now = date;
        var year = now.getFullYear();
        var month = (now.getMonth() + 1).toString().padStart(2, '0');
        var day = now.getDate().toString().padStart(2, '0');
        var hours = now.getHours().toString().padStart(2, '0');
        var minutes = now.getMinutes().toString().padStart(2, '0');
        var seconds = now.getSeconds().toString().padStart(2, '0');
 
        // 默认格式
        if (!format) {
            return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
        }
 
        // 自定义格式支持
        return format
            .replace('YYYY', year)
            .replace('MM', month)
            .replace('DD', day)
            .replace('HH', hours)
            .replace('mm', minutes)
            .replace('ss', seconds);
    }
 
    function showCreateTask() {
        // 开始与结束时间赋当前时间
        // 创建任务
        $("input[name=orderStartTime]").val(formatDateTime(new Date()));
        $("input[name=orderEndTime]").val(formatDateTime(new Date(new Date().getTime()+1000*60*60*24)));
        var index = layer.open({
            type: 1,
            title: "创建下单任务",
            content: $("#add_task"),
            area: ['600px', '700px'],
            end: function (e) {
                $("#add_task").css("display", "none");
            }
        });
    }
 
    layui.use(['form', 'jquery', 'layer', 'table', 'laydate'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;
 
        // 日期控件初始化
        laydate.render({
            elem: '#startDate',
            theme: '#448aff'
        });
 
        laydate.render({
            elem: '#endDate',
            theme: '#448aff'
        });
 
        laydate.render({
            elem: '#orderStartTime',
            type: 'datetime',
            theme: '#448aff'
        });
 
        laydate.render({
            elem: '#orderEndTime',
            type: 'datetime',
            theme: '#448aff'
        });
 
        let table_option = {
            elem: '#table',
            url: '/admin/api/ordertask/js2/list',
            where: {
                'keyword': $("#keyword").val(),
                'startDate': $("#startDate").val(),
                'endDate': $("#endDate").val(),
                'status': $("#status").val()
            },
            parseData: function(res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.list //解析数据列表
                }
            },
            page: true,
            cols: [[
                {field: 'id', title: '任务ID', width: 80, fixed: 'left'},
                {field: 'keywordContent', title: '口令内容', width: 150},
                {
                    field: 'productSource', title: '商品来源', width: 90, templet: function (d) {
                        if (d.productSource == 1) {
                            return '抖音';
                        } else if (d.productSource == 2) {
                            return '快手';
                        }
                        return '未知';
                    }
                },
                {field: 'productName', title: '商品名称', width: 150},
                {field: 'shopName', title: '店铺名称', width: 120},
                {field: 'requiredOrderCount', title: '需下单数', width: 90},
                {field: 'completedOrderCount', title: '已下单数', width: 90},
                {field: 'receivedOrderCount', title: '已收货数', width: 90},
                {field: 'reviewedOrderCount', title: '已评价数', width: 90},
                {field: 'receiveCycleHours', title: '收货周期(小时)', width: 120},
                {field: 'orderStartTime', title: '下单开始时间', width: 160},
                {field: 'orderEndTime', title: '下单结束时间', width: 160},
                {field: 'createTime', title: '创建时间', width: 160},
                {
                    field: 'status', title: '状态', width: 100, templet: function (d) {
                        if (d.status == 0) {
                            return '<span style="color: #999">未分配</span>';
                        } else if (d.status == 1) {
                            return '<span style="color: #ff9900">分配中</span>';
                        } else if (d.status == 2) {
                            return '<span style="color: #009900">已分配</span>';
                        }
                        return '未知';
                    }
                },
                {
                    field: '', title: '操作', width: 200, align: 'center', fixed:"right", templet: function (d) {
                        let html = '<div>';
                        html += '<a href="javascript:void(0)" onclick="updateTask(' + d.id + ')" class="layui-table-link">修改</a> &nbsp;&nbsp;';
                        html += '<a href="javascript:void(0)" onclick="deleteTask(' + d.id + ')" class="layui-table-link">删除</a> &nbsp;&nbsp;';
                        if (d.status == 0) {
                            html += '<a href="javascript:void(0)" onclick="assignTask(' + d.id + ')" class="layui-table-link">分配</a>';
                        }else{
                            html += '<a href="javascript:void(0)" onclick="viewAssignedClients(' + d.id + ')" class="layui-table-link">已分配设备</a>';
                        }
                        html += '</div>';
                        return html;
                    }
                }
            ]]
        };
 
        //第一个实例
        let tableIns = table.render(table_option);
 
        //监听提交
        form.on('submit(search)', function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });
 
        form.on('submit(add-task)', function (data) {
            $.post("/admin/api/ordertask/js2/add", data.field, function (response) {
                if (response.code == 0) {
                    layer.msg("添加成功");
                    // 关闭弹窗
                    layer.closeAll('page');
                    // 重新加载表格
                    tableIns.reload();
                } else {
                    layer.msg(response.msg);
                }
            }, 'json').fail(function (jqXHR, textStatus, errorThrown) {
                layer.msg("网络请求失败");
            });
 
            return false;
        });
    });
</script>
</body>
 
</html>