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
<!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/plugin/jquery-2.1.4.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/systools/MBase.js}"></script>
</head>
<body>
<div class="ibox-content">
    <form class="form-horizontal" id="dataform"
          onsubmit="javascripr:return false;">
 
        <input autocomplete="off"   type="hidden" name="id" th:value="${obj?.id}">
 
        <div class="form-group">
            <label class="col-offset-1 col-sm-2 control-label">入库类型<span
                    class="text-danger">*</span></label>
            <div class="col-sm-3">
                <select class="form-control autoFull" name="instoreType"
                        id="instoreType" data-filed="name" data-value="name"
                        th:data-url="@{/admin/dataDictionary/showDataDictionary}"
                        data-param="{type:'入库类型'}" th:data-def="${obj?.instoreType}"
                        datatype="*" nullmsg="入库类型不能为空">
                    <option value=''>--请选择入库类型--</option>
                </select>
                <div class="Validform_checktip"></div>
            </div>
            <label class="col-sm-2 control-label">创建时间<span
                    class="text-danger">*</span></label>
            <div class="col-sm-3">
                <input autocomplete="off"   type="text" class="form-control datetimepicker"
                       name="instoreDate" readonly="readonly"
                       th:value="${#dates.format(obj==null?(new java.util.Date().getTime()):obj?.instoreDate ,'yyyy-MM-dd HH:mm:ss')}"
                           datatype="*" nullmsg="入库日期不能为空" data-formatter="MGrid.getTime">
                <div class="Validform_checktip"></div>
            </div>
        </div>
 
        <div class="form-group">
            <label class="col-sm-2 control-label">制单人</label>
 
            <div class="col-sm-3" th:if="${obj} eq null" >
                    <input autocomplete="off"   type="text" th:value="${session.userInfo.suName}" name="makingmanName" class="form-control" readonly="readonly">
                <input autocomplete="off"   type="hidden" th:value="${session.userInfo.suId}" name="makingmanId" id="makingmanId">
            </div>
 
            <div class="col-sm-3 " th:if="${obj} ne null " >
                <input autocomplete="off"   type="text" th:value="${obj?.makingmanName}" name="makingmanName" class="form-control " readonly="readonly">
                <input autocomplete="off"   type="hidden" th:value="${obj?.makingmanId}" name="makingmanId"  id="makingmanId">
            </div>
 
        <label class="col-sm-2 control-label" th:if="${obj} ne null">审核人<span
                class="text-danger">*</span></label>
        <div class="col-sm-3" th:if="${obj} ne null">
<!--            <select class="form-control autoFull" name="appmanId" id="appmanId"-->
<!--                    data-filed="suName"-->
<!--                    th:data-url="@{/admin/getShopStaffByRoleName?roleName=仓储主管}"-->
<!--                    th:data-value="suId"-->
<!--                    th:data-def="${obj?.appmanId}"-->
<!--                    datatype="*" nullmsg="审核人不能为空">-->
<!--                <option value=''>&#45;&#45;请选择审核人&#45;&#45;</option>-->
<!--            </select>-->
<!--            <div class="Validform_checktip"></div>-->
 
            <input autocomplete="off"   type="text" th:value="${obj?.appmanName}" name="appmanName" class="form-control " readonly="readonly">
            <input autocomplete="off"   type="hidden" th:value="${obj?.appmanId}" name="appmanId"  id="appmanId">
        </div>
</div>
 
<div class="form-group">
    <label class="col-sm-2 control-label">往来单位<span
            class="text-danger">*</span></label>
    <div class="col-sm-3">
        <select class="form-control autoFull" name="supplierId"
                id="supplierId" data-filed="supplName"
                th:data-url="@{/admin/supplier/all}" th:data-def="${obj?.supplierId}"
                datatype="*" nullmsg="往来单位不能为空">
            <option value=''>--请选择往来单位--</option>
        </select>
        <div class="Validform_checktip"></div>
    </div>
 
 
</div>
 
<div class="form-group">
    <label class="col-sm-2 control-label">备注</label>
    <div class="col-sm-3">
                <textarea type="text" dataType="*1-500" ignore="ignore"
                          class="form-control" name="remark" errormsg="备注不能超过500" th:text="${obj?.remark}"></textarea>
        <div class="Validform_checktip"></div>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">入库仓库<span
            class="text-danger">*</span></label>
    <div class="col-sm-3">
        <select class="form-control autoFull" data-filed="name"
                name="storeId" dataType="*" errormsg="请选择入库仓库"
                th:data-url="@{/admin/warehouse/findSingleShopWarehouse}" th:data-def="${obj?.storeId}">
            <option value="">-- 请选择所属仓库--</option>
        </select>
    </div>
 
    <label class="col-sm-2 control-label">总价</label>
    <div class="col-sm-3">
        <input autocomplete="off"   type="text" class="form-control" id="sumall"
               readonly="readonly" th:value="${obj?.sumall}">
        <div class="Validform_checktip"></div>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 control-label">入库明细 <span
            class="text-danger">*</span></label>
    <div class="col-sm-3">
        <button class="btn btn-success btn-sm" onclick="openPruductList()"
                type="button">添加明细单
        </button>
    </div>
</div>
<div class="form-group">
    <div class="col-sm-8 col-md-offset-2">
        <table class="table table-striped table-hover table-bordered"
               id="mgrid">
            <thead>
            <tr>
                <th>序号</th>
                <th>产品编码</th>
                <th>产品名称</th>
                <th>产品类型</th>
                <th>存货单位</th>
                <th width="120">数量 <span class="text-danger">*</span></th>
                <th width="120">采购单价 <span class="text-danger">*</span></th>
                <th>总金额</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="cpId">
 
            </tbody>
 
        </table>
    </div>
</div>
 
<div class="form-group ">
    <div class="col-sm-12 text-center fixed-button">
        <a href="javascript:;" onclick="myForm.submit()"
           class="btn btn-success radius"><i class="fa fa-check"></i> 保存</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a class="btn btn-danger radius" href="javascript:;"
           onclick="MTools.closeForm()"><i class="fa fa-close"></i> 关闭</a>
    </div>
</div>
</form>
</div>
</body>
 
 
<script type="text/javascript" th:src="@{/js/systools/MJsBase.js}"></script>
 
<script>
    var readInitData=function(){};
 
</script>
<script th:if="${obj} ne null"  th:inline="javascript" >
 
    //初始化产品列表
    readInitData=function() {
        /*<![CDATA[*/
        var projItems=/*[[${obj.instoreDetails}]]*/
        /*]]>*/
        for(var i =0; i<projItems.length; i++){
            var obj = new Object();
            var goods = new Object();
            var projItem=projItems[i];
            debugger
            obj.goodsSortName = projItem.goods.goodsSortName;
            obj.unit = projItem.goods.unit;
            obj.name = projItem.goods.name;
            obj.goodsNo = projItem.goods.goodsNo;
            obj.id = projItem.goods.id;
            obj.purchsePrice = projItem.price;
            obj.sum =projItem.amount;
            obj.totalMoney =projItem.amount;
            obj.totalMoney = obj.totalMoney*projItem.price;
            totalGoods[i] = obj;
        };
    }
 
 
</script>
 
<script th:inline="javascript">
    var goodsAttr = '';
    var totalGoods = [];
    //初始化时间格式
 
 
    $(".datetimepicker").datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        todayBtn: true,
        autoclose: true,
        startView: 2,
        maxView: 3,
        minView: 0
 
    })
    //初始化select
    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/instore/addOrModify",
        afterSubmit: function () {
            parent.myGrid.serchData();
        },
    });
 
 
 
 
    //打开产品界面
    function openPruductList() {
        //获取所选择 的产品属性,传递给选择页面
        goodsAttr = $("#instoreType").val();
        if (goodsAttr == '') {
            layer.msg("请选择入库类型", {icon: 2});
            return false;
        }
        layer.open({
            type: 2,
            title: "选择产品",
            area: MUI.SIZE_M,
            content: [basePath+'/admin/redirect/hive/products/select-products-list?goodsAttr=' + encodeURI(goodsAttr)]
        });
    }
 
    //监听所选择的产品类型,切换类型则要清空原来的产品列表
    $("#instoreType").change(function () {
        totalGoods = [];
        $("#cpId").html('');
    });
 
    //添加产品回调
    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 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);
        });
    }
 
    //填写数据到html
    function writeDate() {
        var html = "";
        for (var i = 0; i < totalGoods.length; i++) {
            if (!totalGoods[i].sum) {
                totalGoods[i].sum = "";
            }
            if (!totalGoods[i].purchsePrice) {
                totalGoods[i].purchsePrice = "";
            }
            if (totalGoods[i].totalMoney == null) {
                totalGoods[i].totalMoney = "0";
            }
            html += '<tr>'
                + '<td>' + (i + 1) + '</td>'
                + '<td>' + totalGoods[i].code + '</td>'
                + '<td>' + totalGoods[i].name + '<input autocomplete="off"   type="hidden" name="instoreDetails[' + i + '].skuId" value="' + totalGoods[i].id + '"></td>'
                + '<td>' + totalGoods[i].goodsSortName + '</td>'
                + '<td>' + totalGoods[i].unit + '</td>'
                + '<td><input autocomplete="off"   id="amount' + i + '" name="instoreDetails[' + i + '].amount" type="text" onblur="calculateTotalPrice(' + i + ')" dataType="n" nullmsg="请填写数量" errormsg="请填写数字" class="form-control moeny" value="' + totalGoods[i].sum + '"><div class="Validform_checktip"></div></td>'
                + '<td><input autocomplete="off"   id="price' + i + '" name="instoreDetails[' + i + '].price" type="text" onblur="calculateTotalPrice(' + i + ')" dataType="price" nullmsg="请填写成本价" errormsg="请填写数字" class="form-control moeny" value="' + totalGoods[i].purchsePrice + '"><div class="Validform_checktip"></div></td>'
                + '<td id="sum' + i + '">' + totalGoods[i].totalMoney + '</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 calculateTotalPrice(i) {
        var totalMoney = Number(0);
        if ($("#cpId").html() == '') {
            layer.alert('请先添加明细单', {icon: 5}, function (index) {
                layer.close(index);
            });
            return false;
        }
        $("#cpId").find("tr").each(function (i) {
 
            var p = Number($(this).find("input").eq(1).val());
            var n = Number($(this).find("input").eq(2).val());
            if (p != '' && n != '') {
                totalMoney = totalMoney+(n*p);
            }
        });
        $("#sumall").val(totalMoney);
        if ($("#amount" + i).val() != '' && $("#price" + i).val() != '') {
            var n = Number($("#amount" + i).val());
            var p = Number($("#price" + i).val());
            $("#sum" + i).text(n*p);
        }
 
    }
 
</script>
</body>
</html>