username@email.com
2024-06-27 3fc58aef2f6f47c4a356df23479e3becca630177
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
<title>货品表</title>
<!--当前位置开始-->
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <script type="text/html" template lay-done="layui.data.updateMainBreadcrumb();">
        </script>
    </div>
</div>
<!--当前位置结束-->
<style>
    /* 重写样式 */
</style>
<script type="text/html" template lay-type="Post" lay-url="{{ layui.setter.apiUrl }}Api/CoreCmsProducts/GetIndex" lay-done="layui.data.done(d);">
    
</script>
 
<script type="text/html" id="LAY-app-Products-toolbar">
    <div class="layui-form coreshop-toolbar-search-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" for="category">商品分类</label>
                <div class="layui-input-inline" style="width: 200px;">                   
                    <div id="sel_category_stortPrducts" class="ew-xmselect-tree"  lay-reqText="请选择商品分类"></div>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="name" placeholder="请输入商品名称" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="barcode" placeholder="请输入商品编码" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="sn" placeholder="请输入货品条码" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="spesDesc" placeholder="请输入货品规格" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="LAY-app-CoreCmsProducts-search"><i class="layui-icon layui-icon-search"></i>筛选</button>
            </div>
 
            <div class="layui-inline layui-inline-6 float-right">
                <div class="layui-form-mid float-right text-right text-red">
                    <i class="layui-icon layui-icon-tips"></i>  库存支持点击数字进行直接编辑
                </div>
            </div>
        </div>
    </div>
</script>
 
<div class="table-body">
    <table id="LAY-app-CoreCmsProducts-tableBox" lay-filter="LAY-app-CoreCmsProducts-tableBox"></table>
</div>
 
<script type="text/html" id="LAY-app-CoreCmsProducts-tableBox-bar">
    <a class="layui-btn layui-btn-xs" lay-event="detail">记录</a>
</script>
 
<script>
    var indexData;
    var debug = layui.setter.debug;
    layui.data.done = function (d) {
        //开启调试情况下获取接口赋值数据
        if (debug) { console.log(d); }
     
        indexData = d.data.data;
        layui.use(['index', 'table', 'laydate', 'util', 'coredropdown', 'coreHelper','xmSelect'],
            function () {
                var $ = layui.$
                    , admin = layui.admin
                    , table = layui.table
                    , form = layui.form
                    , laydate = layui.laydate
                    , setter = layui.setter
                    , coreHelper = layui.coreHelper
                    , util = layui.util
                    ,xmSelect = layui.xmSelect
                    , view = layui.view;
 
                //重载form
                form.render();
                var searchwhere;
                //监听搜索
                form.on('submit(LAY-app-CoreCmsProducts-search)',
                    function (data) {
                        var field = data.field;
                        searchwhere = field;
                        //执行重载
                        table.reloadData('LAY-app-CoreCmsProducts-tableBox', { where: field });
                    });
                //数据绑定
                table.render({
                    elem: '#LAY-app-CoreCmsProducts-tableBox',
                    url: layui.setter.apiUrl + 'Api/CoreCmsProducts/GetPageList',
                    method: 'POST',
                    toolbar: '#LAY-app-Products-toolbar',
                    defaultToolbar: ['filter', 'print', 'exports'],
                    height: 'full-127',//面包屑142px,搜索框4行172,3行137,2行102,1行67
                    page: true,
                    limit: 30,
                    limits: [10, 15, 20, 25, 30, 50, 100, 200],
                    text: { none: '暂无相关数据' },
                    cols: [
                        [
                            //{ type: "checkbox", fixed: "left" },
                            { field: 'id', title: '序列', width: 60, sort: false },
                            {
                                field: 'images', title: '图片', width: 50, sort: false,
                                templet: function (d) {
                                    if (d.images) {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + d.images + '")><image style="max-width:28px;max-height:28px;" src="' + d.images + '"/></a>';
                                    } else {
                                        return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + setter.noImagePicUrl + '")><image style="max-width:30px;max-height:30px;" src="' + setter.noImagePicUrl + '"/></a>';
                                    }
                                }
                            },
                            { field: 'name', title: '商品名称', sort: false },
                            { field: 'spesDesc', title: '规格值', sort: false },
                            { field: 'barcode', title: '商品条码', sort: false, width: 125 },
                            { field: 'sn', title: '货品编码', sort: false, width: 130 },
                            { field: 'price', title: '销售价', sort: false, width: 60 },
                            { field: 'costprice', title: '成本价', sort: false, width: 60 },
                            { field: 'mktprice', title: '市场价', sort: false, width: 60 },
                            //{ field: 'marketable', title: '是否上架', width: 95, templet: '#switch_marketable', sort: false, unresize: true },
                            { field: 'weight', title: '重量(千克)', sort: false, width: 80 },
                            { field: 'unit', title: '单位', sort: false, width: 60 },
                            { field: 'stock', title: '库存(单击编辑)', sort: false, width: 120, edit: 'text' },
                            {
                                field: 'freezeStock', title: '冻结库存', sort: false, width: 80, templet: function (data) {
                                    if (data.freezeStock > 0) {
                                        return "<button type=\"button\" class=\"layui-btn layui-btn-warm layui-btn-xs\">" + data.freezeStock + "</button>";
                                    } else {
                                        return data.freezeStock;
                                    }
                                }
                            },
                            //{ field: 'isDefalut', title: '是否默认货品', width: 95, templet: '#switch_isDefalut', sort: false, unresize: true },
                            //{ field: 'isDel', title: '是否删除', width: 95, templet: '#switch_isDel', sort: false, unresize: true },
                            { width: 62, align: 'center', title: '操作', fixed: 'right', toolbar: '#LAY-app-CoreCmsProducts-tableBox-bar' }
                        ]
                    ]
                });
                //监听排序事件
                table.on('sort(LAY-app-CoreCmsProducts-tableBox)', function (obj) {
                    table.reloadData('LAY-app-CoreCmsProducts-tableBox', {
                        initSort: obj, //记录初始排序,如果不设的话,将无法标记表头的排序状态。
                        where: { //请求参数(注意:这里面的参数可任意定义,并非下面固定的格式)
                            orderField: obj.field, //排序字段
                            orderDirection: obj.type //排序方式
                        }
                    });
                });
                //监听工具条
                table.on('tool(LAY-app-CoreCmsProducts-tableBox)',
                    function (obj) {
                        if (obj.event === 'detail') {
                            doDetails(obj);
                        }
                    });
                    xmSelect.render({
                    el: '#sel_category_stortPrducts',
                    height: '250px',
                    data: indexData,
                    //initValue: mData ? [mData.parentId] : [],
                    //model: { label: { type: 'text' } },
                    name: 'categoryId',
                    prop: {
                        name: 'title',
                        value: 'id'
                    },                
                    radio: true,
                    clickClose: true,
                    tree: {
                        show: true,
                        indent: 15,
                        strict: false,
                        expandedKeys: true
                    }
                });
 
                //监听单元格编辑
                table.on('edit(LAY-app-CoreCmsProducts-tableBox)', function (obj) {
                    var value = obj.value //得到修改后的值
                        , data = obj.data //得到所在行所有键值
                        , field = obj.field; //得到字段
                    console.log(obj.value);
                    if (!!!obj.value) {
                        layer.msg("不能为空");
                        return false;
                    }
 
                    if(obj.value < 0) {
                        layer.msg('库存不能为负数');
                        table.reloadData('LAY-app-CoreCmsProducts-tableBox');
                        return false;
                    }
 
 
                    if (field == 'stock') {
                        if (coreHelper.isNumber(obj.value)) {
                            layer.confirm('确定要将库存设置为 ' + obj.value + " 吗?", {
                                btn: ['确定', '取消']
                            }, function (index, layero) {
                                coreHelper.Post("Api/CoreCmsProducts/DoSetStock", { id: data.id, data: value }, function (e) {
                                    if (debug) { console.log(e); } //开启调试返回数据
                                    //table.reloadData('LAY-app-CoreCmsProducts-tableBox');
                                    layer.close(index); //再执行关闭
                                    layer.msg(e.msg);
                                });
                            });
                        } else {
                            layer.msg("库存必须为数字");
                            table.reloadData('LAY-app-CoreCmsProducts-tableBox');
                            return false;
                        }
 
                    } else if (field == 'freezeStock') {
                        if (coreHelper.isNumber(obj.value)) {
                            coreHelper.Post("Api/CoreCmsHouseCategory/DoSetFreezeStock", { id: data.id, data: value }, function (e) {
                                if (debug) { console.log(e); } //开启调试返回数据
                                //table.reloadData('LAY-app-CoreCmsProducts-tableBox');
                                layer.msg(e.msg);
                            });
                        } else {
                            layer.msg("冻结库存必须为数字");
                            return false;
                        }
                    }
                });
 
 
 
                //执行预览操作
                function doDetails(obj) {
                    coreHelper.Post("Api/CoreCmsProducts/GetDetails", { id: obj.data.id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '查看记录',
                                area: ['1230px', '90%'],
                                id: 'LAY-popup-CoreCmsProducts-details',
                                success: function (layero, index) {
                                    view(this.id).render('content/stock/products/details', { data: e.data }).done(function () {
                                        form.render();
                                    });
                                    // 禁止弹窗出现滚动条
                                    //$(layero).children('.layui-layer-content').css('overflow', 'visible');
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
 
            });
    };
</script>
 
<!--设置是否上架-->
<script type="text/html" id="switch_marketable">
    <input type="checkbox" name="switch_marketable" lay-skin="switch" lay-text="开启|关闭" disabled="disabled" lay-filter="switch_marketable" {{ d.marketable ? 'checked' : '' }}>
</script>
 
<!--设置是否默认货品-->
<script type="text/html" id="switch_isDefalut">
    <input type="checkbox" name="switch_isDefalut" lay-skin="switch" lay-text="开启|关闭" disabled="disabled" lay-filter="switch_isDefalut" {{ d.isDefalut ? 'checked' : '' }}>
</script>
 
<!--设置是否删除-->
<script type="text/html" id="switch_isDel">
    <input type="checkbox" name="switch_isDel" lay-skin="switch" lay-text="开启|关闭" disabled="disabled" lay-filter="switch_isDel" {{ d.isDel ? 'checked' : '' }}>
</script>