zhao
2021-06-11 98186752629a7bd38965418af84db382d90b9c07
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
@{
    Layout = "~/Views/Shared/_LayoutVue.cshtml";
    ViewBag.Title = "库存初始化";
}
 
@section head{
    <style type="text/css">
        .el-message-box__content {
            max-height: 380px;
            overflow: scroll;
        }
    </style>
}
 
<div id="StockInit" v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="正在处理文件,请稍等…">
    <el-card class="box-card">
        <el-upload ref="upload" action="UnscrambleXls"
                   v-bind:on-change="onUploadChange"
                   v-bind:auto-upload="true"
                   v-bind:multiple="false"
                   v-bind:on-progress="onStartProgress"
                   v-bind:on-success="loadFileSuccess"
                   v-bind:on-remove="handleRemove"
                   v-bind:limit="1">
            <el-button slot="trigger" size="min" type="success" style="margin-left: 10px;margin-top:5px;margin-bottom:5px;padding: 7px 15px;font-size: 12px;">选取文件</el-button>
        </el-upload>
    </el-card>
 
    <el-table v-bind:data="tableData" class="tb-edit" style="width: 100%;" v-bind:height="tableHeight" border highlight-current-row size="mini" empty-text="暂无预览数据">
        <el-table-column label="行号" type="index" width="50" align="center" v-bind:index="indexMethod"></el-table-column>
        <el-table-column label="仓库号" prop="CN_S_STOCK_CODE" width="120" align="center"></el-table-column>
        <el-table-column label="货位号" prop="CN_S_LOCATION_CODE" width="150" align="center"></el-table-column>
        <el-table-column label="托盘号" prop="CN_S_TRAY_CODE" width="120" align="center"></el-table-column>
        <el-table-column label="物料编码" prop="CN_S_ITEM_CODE" width="180" align="center"></el-table-column>
        <el-table-column label="数量" prop="CN_F_QUANTITY" width="100" align="center"></el-table-column>
        <el-table-column label="生产批次" prop="CN_S_PRODUCTION_BATCH" width="130" align="center"></el-table-column>
        @*<el-table-column label="到货批次" prop="CN_S_LOT_CODE" width="120" align="center"></el-table-column>*@
        <el-table-column label="物料状态" prop="CN_S_ITEM_STATE" width="100" align="center"></el-table-column>
    </el-table>
    <el-card class="box-card" style="text-align:right">
        <el-row style="padding-right:20px;margin-top:5px;margin-bottom:5px;">
            <el-button size="mini" id="btn_check" type="warning" v-on:click="checkData">数据校验</el-button>
            <el-button size="mini" id="btn_submit" type="primary" v-on:click="submitUpload">确认初始化</el-button>
        </el-row>
    </el-card>
</div>
@section scripts{
    <script>
        new Vue({
            el: "#StockInit",
            mixins: [useAutoHeight],
            computed: {
                tableHeight: function () {
                    return this.autoHeight - 130;
                }
            },
            data: {
                fullscreenLoading: false,
                importData: [],
                errorData: [],
                defaults: {
                    fileType: ["xls", "XLS", "xlsx", "XLSX"],
                    fileSize: 1024 * 1024 * 10
                },
                //tableData: [{
                //    CN_S_STOCK_CODE: '',
                //    CN_S_LOCATION_CODE: '',
                //    CN_S_TRAY_CODE: '',
                //    CN_S_ITEM_CODE: '',
                //    CN_F_QUANTITY: '',
                //    CN_S_PRODUCTION_BATCH: '',
                //    CN_S_LOT_CODE: '',
                //    CN_S_ITEM_STATE: ''
                //}]
                tableData: []
            },
            methods: {
                indexMethod: function (index) {
                    return index + 2;
                },
                submitUpload: function () {
                    var $this = this;
                    var validData = [];
 
                    $.each($this.tableData, function (i, n) {
                        if (n.CN_S_ITEM_CODE) {
                            validData.push(n);
                        }
                    });
 
                    if (validData.length == 0) {
                        wms.warning("请先选择文件!");
                        return false;
                    }
                    if ($this.errorData.length != 0) {
                        var htmlStr = "<div style=\"padding-left:30px\">";
                        $.each($this.errorData, function (i, n) {
                            if (n.CN_S_RowIndex != "0")
                                htmlStr = htmlStr + "<font color=\"blue\">第" + n.CN_S_RowIndex + "行存在问题:</font>" + n.CN_S_ErrorContent + "</br>";
                            else
                                htmlStr = htmlStr + "<font color=\"blue\">存在问题:</font>" + n.CN_S_ErrorContent + "</br>";
                        });
                        htmlStr = htmlStr + "</div>";
 
                        wms.customConfirm({
                            title: '验证结果提示',
                            content: htmlStr,
                            confirmText: '关闭',
                            callback: function (action) {
                            }
                        });
                    }
                    else {
                        wms.confirm("确认初始化?", function () {
                            $this.submit();
                        });
                    }
                },
                submit: function () {
 
                    var $this = this;
                    $this.fullscreenLoading = true;
                    ajaxManage({
                        url: "@Url.Action("ImportExcelData")",
                        data: JSON.stringify($this.importData),
                        success: function (data) {
                            $this.fullscreenLoading = false;
                            if (data.Success) {
                                wms.success("初始化成功!");
                                $this.$refs.upload.clearFiles();
                                $this.errorData = [];
                                $this.importData = [];
                                $this.tableData = [];
                            } else {
                                wms.warning(data.Msg);
                            }
                        }
                    });
                },
                checkData: function () {
                    var $this = this;
                    var validData = [];
 
                    $.each($this.tableData, function (i, n) {
                        if (n.CN_S_ITEM_CODE) {
                            validData.push(n);
                        }
                    });
 
                    if (validData.length == 0) {
                        wms.warning("请先选择文件!");
                        return false;
                    }
 
                    if ($this.errorData.length != 0) {
                        var htmlStr = "<div style=\"padding-left:30px\">";
                        $.each($this.errorData, function (i, n) {
                            if (n.CN_S_RowIndex != "0")
                                htmlStr = htmlStr + "<font color=\"blue\">第" + n.CN_S_RowIndex + "行存在问题:</font>" + n.CN_S_ErrorContent + "</br>"
                            else
                                htmlStr = htmlStr + "<font color=\"blue\">存在问题:</font>" + n.CN_S_ErrorContent + "</br>"
                        });
                        htmlStr = htmlStr + "</div>";
 
                        wms.customConfirm({
                            title: '验证结果提示',
                            content: htmlStr,
                            confirmText: '关闭',
                            callback: function (action) {
                            }
                        });
                    }
                    else {
                        wms.customConfirm({
                            title: '初始化提示',
                            confirmText: '确定',
                            content: "数据校验通过,是否直接初始化?",
                            callback: function (action) {
                                if (action == "confirm") {
                                    $this.submit();
                                }
                            }
                        });
                    }
                },
                onUploadChange: function (file) {
                    var _this = this;
                    if ($.inArray(file.name.substring(file.name.lastIndexOf(".") + 1, file.name.length), _this.defaults.fileType) <= -1) {
                        wms.warning("只能上传Excel文件!");
                        this.$refs.upload.clearFiles();
                        return false;
                    }
 
                    if (file.size >= _this.defaults.fileSize) {
                        wms.warning("文件超出10M!");
                        return false;
                    }
                },
                onStartProgress: function (event, file, fileList) {
                    var $this = this;
                    $this.fullscreenLoading = true;
                },
                loadFileSuccess: function (response, file, fileList) {
                    var $this = this;
                    $this.fullscreenLoading = false;
 
                    $this.importData = response.ImportData;
                    $this.errorData = response.ErrorData;
                    console.log(response);
                    $this.tableData = response.ImportData;
                },
                handleRemove: function (file, fileList) {
                    var $this = this;
                    $this.importData = [];
                    $this.errorData = [];
                }
            },
            mounted: function () {
 
            }
        })
    </script>
}