懒羊羊
2023-11-14 036dcdcec6235d82b008f5c736d27a0d1f90d4a2
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
layui.use(['upload', 'table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var upload = layui.upload;
 
    /**
     * 生产订单管理
     */
    var SalesOrder = {
        tableId: "salesOrderTable"
    };
 
    /**
     * 初始化表格的列
     */
    SalesOrder.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键id'},
            {field: 'salesOrderCode', sort: true, title: '订单编号',width: 160, templet: '#scoreTpl'},
            {field: 'customerNo', sort: true, title: '客户编号',width: 120},
            {field: 'cargoNo', sort: true, title: '货号',width: 120},
            {field: 'productCode', sort: true, title: '产品编号',width: 160},
            {field: 'productName', sort: true, title: '产品名称',width: 160},
            {field: 'planNumber', sort: true, title: '计划数量',width: 120},
            {
                field: 'state', align: "center", title: '状态', templet: function (d) {
                    switch(d.state){
                        case "1" :
                            return "<span style=\"color: #130c0e;\">未开始</span>";
                            break;
                        case "2" :
                            return "<span style=\"color: #00cc33;\">已拆分</span>";
                            break;
                        case "3" :
                            return "<span style=\"color: #ff9933;\">已下发</span>";
                            break;
                        case "4" :
                            return "<span style=\"color: #cc0000;\">已关闭</span>";
                            break;
                        default :
                    }
                }
            },
            {field: 'planStartTime', sort: true, title: '计划开始时间',width: 160},
            {field: 'planEndTime', sort: true, title: '计划结束时间',width: 160},
            {field: 'workshopCode', sort: true, title: '车间编码',width: 120},
            {field: 'lineCode', sort: true, title: '产线编码',width: 120},
            {field: 'deliveryTime', sort: true, title: '交货时间',width: 160},
            {field: 'orderSource', sort: true, title: '订单来源',width: 120},
            {field: 'createUser', sort: true, title: '创建用户',width: 120},
            {field: 'createTime', sort: true, title: '创建时间',width: 160},
            {field: 'updateUser', sort: true, title: '更改用户',width: 120},
            {field: 'updateTime', sort: true, title: '更改时间',width: 160},
            {field: 'remark', sort: true, title: '备注'},
            {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];
    };
 
    /**
     * 点击查询按钮
     */
    SalesOrder.search = function () {
        var queryData = {};
        queryData['salesOrderCode'] = $('#salesOrderCode').val();
        queryData['customerNo'] = $('#customerNo').val();
        queryData['cargoNo'] = $('#cargoNo').val();
        queryData['productCode'] = $('#productCode').val();
        queryData['productName'] = $('#productName').val();
        queryData['workshopCode'] = $('#workshopCode').val();
        queryData['lineCode'] = $('#lineCode').val();
        queryData['state'] = $('#state').val();
        table.reload(SalesOrder.tableId, {
            where: queryData, page: {curr: 1}
        });
    };
 
    //下载模板
    $("#btnTemp").click(function () {
        window.location.href = Feng.ctxPath + "/salesOrder/exportOut"
    });
 
    // 导入excel
    var uploadInst = upload.render({
        elem: '#import'
        ,url: Feng.ctxPath + '/salesOrder/importIn'
        ,accept: 'file'
        ,done: function (res) {
            table.reload(SalesOrder.tableId, {url: Feng.ctxPath + "/salesOrder/list"});
            Feng.success("上传成功")
        }
        ,error: function () {
            Feng.error("上传失败")
        }
    });
 
    $('#split').click(function (){
        var checkRows = table.checkStatus(SalesOrder.tableId);
        console.log(checkRows.data);
        console.log(checkRows);
        console.log(checkRows.data.state);
 
        if (checkRows.data.length !== 1) {
            Feng.error("请选择一条要拆分的订单");
            return;
        }
        if (checkRows.data[0].state === "1") {
            window.location.href = Feng.ctxPath + '/salesOrder/split?id=' + checkRows.data[0].id
        }else {
            Feng.error("已拆分下发订单禁止重复拆分");
            return;
        }
    });
 
    /**
     * 跳转到添加页面
     */
    SalesOrder.jumpAddPage = function () {
        window.location.href = Feng.ctxPath + '/salesOrder/add'
    };
 
    /**
    * 跳转到编辑页面
    *
    * @param data 点击按钮时候的行数据
    */
    SalesOrder.jumpEditPage = function (data) {
        window.location.href = Feng.ctxPath + '/salesOrder/edit?id=' + data.id
    };
 
    SalesOrder.distributeDetails = function (data) {
        layer.open({
            type: 2,
            area: ['1000px', '600px'],
            title: '拆分详情',
            content: Feng.ctxPath + '/salesOrder/distributeDetails',
            success: function (layero, index) {
                window.salesOrderCode = data;
            },
        });
    };
 
    /**
     * 导出excel按钮
     */
    SalesOrder.exportExcel = function () {
        var checkRows = table.checkStatus(SalesOrder.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };
 
    /**
     * 下发订单
     */
    SalesOrder.distribute = function (data) {
        layer.alert(data);
    };
 
    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    SalesOrder.onDeleteItem = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/salesOrder/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(SalesOrder.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", data.id);
            ajax.start();
        };
        Feng.confirm("是否删除?", operation);
    };
 
    // 渲染表格
    var tableResult = table.render({
        elem: '#' + SalesOrder.tableId,
        url: Feng.ctxPath + '/salesOrder/list',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: SalesOrder.initColumn()
    });
 
    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        SalesOrder.search();
    });
 
    // 添加按钮点击事件
    $('#btnAdd').click(function () {
 
    SalesOrder.jumpAddPage();
 
    });
 
    // 导出excel
    $('#btnExp').click(function () {
        SalesOrder.exportExcel();
    });
 
    let salesId = [];
 
    // 绑定下发
    $('#distribute').click(function () {
        var checkRows = table.checkStatus(SalesOrder.tableId);
        console.log(checkRows);
        console.log("checkRows.length=========="+checkRows.data.length)
        if(checkRows.data.length === 1){
            if(checkRows.data[0].state === "3"){
                Feng.error("该工单已下发完毕!");
                return;
            }
        }
        if (checkRows.data.length !== 1) {
            Feng.error("请选择一条要下发的订单");
            return;
        }
        var checkRows = table.checkStatus(SalesOrder.tableId);
        console.log(checkRows.data);
        window.location.href = Feng.ctxPath + '/salesOrder/bindParam?id=' + checkRows.data[0].id
    });
 
    // 工具条点击事件
    table.on('tool(' + SalesOrder.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'edit') {
            SalesOrder.jumpEditPage(data);
        } else if (layEvent === 'delete') {
            SalesOrder.onDeleteItem(data);
        } else if (layEvent === 'clickScore') {
            SalesOrder.distributeDetails(data.salesOrderCode);
        }
    });
});