wzy
2021-04-01 d388e2788b7ef088d7cd40f901b0acdcec460bc3
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
    content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
    <script type="text/javascript" th:src="@{/js/systools/MBaseVue.js}"></script>
    <link rel="stylesheet" th:href="@{/plugin/element-ui/index.css}">
    <link rel="stylesheet" th:href="@{/plugin/bootstrap-3.3.5/css/bootstrap.min.css}">
    <link th:href="@{/css/styleOne/style.min.css}" rel="stylesheet" type="text/css"/>
 
    <script type="text/javascript" th:src="@{/js/plugin/jquery-2.1.4.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/plugin/jquery.query.js}"></script>
    <script type="text/javascript" th:src="@{/js/systools/MJsBase.js}"></script>
 
    <script type="text/javascript" charset="utf-8"
            th:src="@{/plugin/beditor/ueditor.config.js}"></script>
    <script type="text/javascript" charset="utf-8"
            th:src="@{/plugin/beditor/ueditor.all.js}"></script>
    <script type="text/javascript" th:src="@{/plugin/bootstrap-3.3.5/js/bootstrap.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/systools/AjaxProxyVue.js}"></script>
    <script type="text/javascript" th:src="@{/js/plugin/vue.js}"></script>
    <script type="text/javascript" th:src="@{/plugin/element-ui/index.js}"></script>
    <style>
        .unitbox .el-col {
            margin-left: 5px;
 
        }
 
        .mixSearchBox {
            position: relative;
        }
 
        .mixSearchBox .searchResultTable {
            position: absolute;
            padding: 10px;
            border: 1px solid #e4e7ed;
            border-radius: 4px;
            background-color: #fff;
            box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
            box-sizing: border-box;
            margin: 10px 0;
            z-index: 99999999;
        }
 
        /**e4e7ed*/
 
        .searchResultTable:before, .searchResultTable:after {
            width: 0px;
            height: 0px;
            border-width: 8px;
            border-style: solid;
            border-color: transparent transparent #fff transparent;
            position: absolute;
            content: ' ';
            left: 39px;
            top: -14px;
        }
 
        .searchResultTable:before {
            top: -15px;
            border-color: transparent transparent #e4e7ed transparent;
        }
 
        .searchInput {
            width: 200px;
        }
 
        .measureInput {
            width: 150px;
        }
 
        .tabs {
            margin-bottom: 80px;
        }
 
        .ui-table .el-form-item__content { margin-left: 0 !important; }
    </style>
</head>
<body>
    <div class="ibox-content" id="app">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="form-horizontal" id="dataform" label-width="120px">
            <div class="form-group">
                <div class="col-sm-4 col-sm-offset-1">
                    <el-form-item label="出库类型" prop="outStoreType">
                        <el-select v-model="ruleForm.outStoreType" placeholder="请选择">
                            <el-option v-for="item in outStoreTypeData"
                                       :key="item.value"
                                       :label="item.value"
                                       :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div class="col-sm-4 col-sm-offset-1">
                    <el-form-item label="出库时间">
                        <el-date-picker disabled v-model="ruleForm.createTime" style="width: 100%" type="datetime" format="yyyy-MM-dd HH:mm:ss"
                                        value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
                        </el-date-picker>
                    </el-form-item>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-4 col-sm-offset-1">
                    <el-form-item label="入库仓库" prop="warehouseData">
                        <el-select v-model="ruleForm.warehouseData" placeholder="请选择">
                            <el-option v-for="item in warehouseList"
                                       :key="item.id"
                                       :label="item.name"
                                       :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </div>
            </div>
            <div class="form-group">
                <!-- 项目绑定产品 -->
                <div class="mixSearchBox col-sm-offset-2">
                    <!-- 搜索框 -->
                    <el-input class="searchInput" @input="searchGoods()" v-model="queryKey"
                              placeholder="搜索添加产品"></el-input>
                    <el-button icon="el-icon-search" type="primary" @click="searchGoods()">搜索</el-button>
                    <div class="searchResultTable" v-show="showSearchTable">
                        <!-- 搜索加载数据表格 -->
                        <el-table
                                v-loading="loading"
                                element-loading-text="拼命加载中"
                                element-loading-spinner="el-icon-loading"
                                element-loading-background="rgba(0, 0, 0, 0.8)"
                                :max-height="400"
                                :data="searchTableData"
                                style="width: 100%">
                            <el-table-column
                                    prop="goods.goodsNo"
                                    label="产品编号"
                                    width="100">
                            </el-table-column>
 
                            <el-table-column
                                    prop="goods.name"
                                    width="280"
                                    label="产品名称">
                            </el-table-column>
 
                            <el-table-column
                                    prop="goods.unit"
                                    label="产品单位">
                            </el-table-column>
                            <el-table-column
                                    prop="storeTotal"
                                    label="库存量">
                            </el-table-column>
                            <el-table-column
                                    prop="goodsPrice"
                                    label="入库单价">
                            </el-table-column>
                            <el-table-column
                                    prop="batch"
                                    label="批次">
                            </el-table-column>
                            <el-table-column
                                    prop="goods.alarmNum"
                                    label="库存预警值">
                            </el-table-column>
                            <el-table-column
                                    prop="storeName"
                                    label="所属仓库">
                            </el-table-column>
                            <el-table-column
                                    prop="goods.goodsSortName"
                                    label="分类">
                            </el-table-column>
                            <el-table-column
                                    prop="address"
                                    label="操作">
                                <template slot-scope="scope">
                                    <el-button type="primary"
                                               size="mini"
                                               @click="handleEdit(scope.$index, scope.row)">选择
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                    <el-row class="mt-20 mb-20 ui-table">
                        <el-col :span="20">
                            <el-table
                                    border
                                    :height="500"
                                    :data="ruleForm.assembleGoods"
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        width="50">
                                </el-table-column>
                                <el-table-column
                                        prop="shoppingGoods.goods.goodsNo"
                                        label="产品编号"
                                        width="100">
                                </el-table-column>
 
                                <el-table-column
                                        prop="shoppingGoods.goods.name"
                                        width="200"
                                        label="产品名称">
                                </el-table-column>
 
                                <el-table-column
                                        prop="shoppingGoods.goods.unit"
                                        label="产品单位">
                                </el-table-column>
                                <el-table-column
                                        prop="shoppingGoods.storeTotal"
                                        label="库存量">
                                </el-table-column>
                                <el-table-column
                                        prop="shoppingGoods.goodsPrice"
                                        label="入库单价">
                                </el-table-column>
                                <el-table-column
                                        prop="shoppingGoods.batch"
                                        label="批次">
                                </el-table-column>
                                <el-table-column
                                        prop="shoppingGoods.goods.alarmNum"
                                        label="库存预警值">
                                </el-table-column>
                                <el-table-column
                                        label="数量">
                                    <template slot-scope="scope">
                                        <el-form-item :prop="'assembleGoods.'+ scope.$index +'.amount'" >
                                            <el-input v-model.number="scope.row.amount"></el-input>
                                        </el-form-item>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        prop="address"
                                        label="操作">
                                    <template slot-scope="scope">
                                        <el-button type="danger"
                                                   size="mini"
                                                   @click="removeItem(scope.$index, scope.row)">删除
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-col>
                    </el-row>
                </div>
                <!-- 项目绑定产品end -->
            </div>
            <div class="form-group ">
                <div class="col-sm-12 text-center">
                    <el-button type="primary" @click="confirmSubmit('ruleForm')">保存</el-button>
                    <el-button type="danger" @click="closeForm">关闭</el-button>
                </div>
            </div>
        </el-form>
    </div>
</body>
<script>
    var vue = new Vue({
        el : "#app",
        data : {
            ruleForm : {
                outStoreType : "",
                warehouseData : "",
                createTime : new Date(),
                assembleGoods : [],
            },
            rules : {
                outStoreType : [
                    { required: true, message: '请选择出库类型', trigger: 'change' }
                ],
                warehouseData : [
                    { required: true, message: '请选择仓库', trigger: 'change' }
                ],
            },
            outStoreTypeData : [],
            warehouseList : [],
            //搜索关键词
            queryKey: '',
            //是否展示搜索表格
            showSearchTable: false,
            //搜索表格数据
            searchTableData: [],
            //表格加载效果
            loading: false,
        },
        created : function() {
            this.getOutStoreType();
            this.getWarehouse();
        },
        methods : {
            initData : function() {},
            getOutStoreType : function () {
                let _this = this;
                AjaxProxy.requst({
                    app: _this,
                    url: basePath + '/admin/customerDictionary/getListByParentCode/CKLX',
                    callback: function (data) {
                        _this.outStoreTypeData = data.rows;
                    }
                });
            },
            getWarehouse : function () {
                let _this = this;
                AjaxProxy.requst({
                    app: _this,
                    url: basePath + '/admin/warehouse/findSingleShopWarehouse',
                    callback: function (data) {
                        _this.warehouseList = data.rows;
                    }
                });
            },
            searchGoods() {
                let _this = this;
 
                if (!_this.ruleForm.warehouseData) {
                    _this.$message.error('请先选择仓库');
                    return;
                }
 
                if (this.queryKey && this.queryKey.trim().length > 0) {
                    this.showSearchTable = true;
                    this.loading = true;
                    AjaxProxy.requst({
                        app: _this,
                        contentType: 'application/x-www-form-urlencoded',
                        data: {name: _this.queryKey, storeId: _this.ruleForm.warehouseData, limit:10000},
                        url: basePath + "/admin/store/showList",
                        callback: function (data) {
                            _this.searchTableData = data.rows;
                            _this.loading = false;
                        }
                    });
                } else {
                    this.showSearchTable = false;
                }
            },
            handleEdit : function(index, row) {
                console.log(row);
                let assembleGoods = this.ruleForm.assembleGoods;
                if (!assembleGoods) {
                    assembleGoods = new Array();
                    this.ruleForm.assembleGoods = assembleGoods;
                }
                //是否已经被选择了
                let selected = false;
                this.ruleForm.assembleGoods.forEach(item => {
                    if (item.shoppingGoods.id == row.id) {
                        selected = true;
                        return;
                    }
                });
                if (!selected) {
                    this.ruleForm.assembleGoods.push({
                        total: 1,
                        assembleGoodId: row.id,
                        shoppingGoods: row
                    });
                }
                this.showSearchTable = false;
            },
 
            removeItem(index, row) {
                this.ruleForm.assembleGoods.splice(index, 1);
            },
            confirmSubmit : function(formName) {
                let _this = this;
                let ruleForm = _this.ruleForm;
 
                var flag = false;
                _this.$refs[formName].validate((valid) => {
                    if (!valid) {
                        console.log('error submit!!');
                        flag = true;
                        return;
                    }
                });
                if (flag) {
                    return;
                }
 
                if (ruleForm.assembleGoods.length <= 0) {
                    _this.$notify({
                        title: '提示',
                        message: '请添加产品',
                        type: 'warning'
                    });
                    return;
                }
 
                this.$confirm('提交后将减少产品库存且无法编辑,是否确认提交?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    _this.dataSubmit(formName);
                }).catch(() => {});
            },
            dataSubmit : function (formName) {
                let _this = this;
                let ruleForm = _this.ruleForm;
 
                var data = {};
                data.type = ruleForm.outStoreType;
                data.time = ruleForm.createTime;
                data.shopId = ruleForm.warehouseData;
                var outStoreItems = [];
                for (var i = 0, length = _this.ruleForm.assembleGoods.length; i < length; i++) {
                    var detail = _this.ruleForm.assembleGoods[i];
                    var outStoreItem = {};
                    outStoreItem.storeId = detail.shoppingGoods.id;
                    outStoreItem.skuId = detail.shoppingGoods.goods.id;
                    outStoreItem.amount = detail.amount;
                    outStoreItems.push(outStoreItem);
                }
                data.outStoreItems = outStoreItems;
                AjaxProxy.requst({
                    app: _this,
                    data: data,
                    url: basePath + "/admin/outstore/addOrModifyJson",
                    callback: function (data) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        parent.myGrid.serchData();
                    }
                });
            },
            closeForm : function() {
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            }
        }
    });
</script>
<script  th:inline="javascript">
    $(".select2").select2({'width':'100%'});
 
    var selectArr=null;
    var totalGoods=[];
    var goodsAttr = '';
    var storeId = 0;
    //初始化操作
    MTools.autoFullSelect();
    // readInitData();
    writeDate();
    var myForm=MForm.initForm({
        beforeSubmit:function(){
            //是否绑定明细
            var bodyTrs=$("#cpId").find("tr");
            if(bodyTrs.length==0){
                layer.msg("请添加消耗的产品",{icon:2});
                return false;
            }
        },
        invokeUrl:basePath+"/admin/outstore/addOrModify",
        afterSubmit:function(){
            parent.myGrid.serchData();
        },
    });
    //时间
    $('.datetimepicker').datetimepicker({
        //format : "yyyy-mm-dd",
        format : "yyyy-mm-dd hh:ii:ss",
 
    });
 
    $("#instoreType").change(function () {
        totalGoods = [];
        $("#cpId").html('');
    });
 
    function submitOutStore() {
        layer.confirm("提交后将减少产品库存且无法编辑,是否确认提交", function() {
            myForm.submit();
        });
    }
 
    function callback(arr) {
        console.log(arr);
        removeDouble(arr);
        writeDate();
    }
 
    function removeDouble(arr) {
        if (totalGoods == null) {
            totalGoods = arr;
        } else {
            //去重
            for (var i = 0; i < arr.length; i++) {
                var isDouble = false;
                for (var j = 0; j < totalGoods.length; j++) {
                    if (arr[i].id == totalGoods[j].id) {
                        isDouble = true;
                        break;
                    }
                }
                //如果不重复
                if (!isDouble) {
                    totalGoods[totalGoods.length] = arr[i];
                }
            }
        }
    }
 
 
    //初始化产品列表
    function openPruductList() {
        //获取所选择 的产品属性,传递给选择页面
        storeId = $("#storeId").val();
 
        if (storeId == '') {
            layer.msg("请选择仓库", {icon: 2});
            return false;
        }
        layer.open({
            type: 2,
            title: "选择产品",
            area: MUI.SIZE_M,
            content: [basePath+'/admin/redirect/hive/store/select-outstore-products-list?storeId='+storeId]
        });
    }
 
    //填写数据到html
    function writeDate(){
        console.log(totalGoods);
        var html="";
        for(var i=0 ; i<totalGoods.length;i++){
            if(!totalGoods[i].sum){
                totalGoods[i].sum="";
            }
            html+='<tr>'
                    +'<td>'+(i+1)+'</td>'
                    +'<td>'+totalGoods[i].goods.goodsNo+'<input autocomplete="off"   type="hidden" name="outStoreItems['+i+'].storeId" value="'+totalGoods[i].id+'"</td>'
                    +'<td>'+totalGoods[i].goods.name+'<input autocomplete="off"   type="hidden" name="outStoreItems['+i+'].skuId" value="'+totalGoods[i].skuId+'"</td>'
                    +'<td>'+totalGoods[i].goods.goodsSortName+'</td>'
                    +'<td>'+totalGoods[i].goods.unit+'</td>'
                    +'<td>'+totalGoods[i].storeTotal+'</td>'
                    +'<td>'+totalGoods[i].goodsPrice+'</td>'
                    +'<td>'+totalGoods[i].batch+'</td>'
                    +'<td><input autocomplete="off"   name="outStoreItems['+i+'].amount" type="text" min="0" class="" style="width:50px" datatype="price" maxlength="10" errormsg="请输入大于0的值" value="">&nbsp;<div class="Validform_checktip"></div></td>'
                    +'<td class="center"><a style="text-decoration: none" class="fa fa-trash" onClick="delSelectItem(this,'+totalGoods[i].id+')" href="javascript:;" title="删除"></a></td>'
                    +'</tr>'
        }
        $("#cpId").html(html);
    }
    function delSelectItem(node, id) {
        //根据列表的id找到元素相应下表的元素
        for (var i = 0; i < totalGoods.length; i++) {
            if (totalGoods[i].id == id) {
                totalGoods.splice(i, 1);
                break;
 
            }
        }
        //移除tr
        $(node).closest('tr').remove();
        $("tbody").find("tr").each(function (i) {
            $(this).find("td").eq(0).html(i + 1);
        });
    }
 
</script>
</body>
</html>