wzy
2022-05-19 00c597948cf3e3360b42a747b9bccf60bee4763a
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
<div class="layui-fluid layui-anim febs-anim" id="febs-goods" lay-title="商品列表">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="user-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="名称" name="goodsName" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="add">
                                    新增
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="userTable" lay-data="{id: 'userTable'}"></table>
                    <style type="text/css">
                        .layui-table-cell{
                            text-align:center;
                            height: auto;
                            white-space: nowrap; /*文本不会换行,在同一行显示*/
                            overflow: hidden; /*超出隐藏*/
                            text-overflow: ellipsis; /*省略号显示*/
                        }
                        .layui-table img{
                            max-width:100px
                        }
                    </style>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 表格操作栏 start -->
<script type="text/html" id="user-option">
    <span shiro:lacksPermission="user:view,user:update,user:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <a lay-event="edit" shiro:hasPermission="user:update"><i
            class="layui-icon febs-edit-area febs-blue">&#xe7a5;</i></a>
</script>
<script type="text/html" id="upOrDownSwitch">
    {{# if(d.isSale === 1) { }}
    <input type="checkbox" value={{d.id}} lay-text="上架|下架" checked lay-skin="switch" lay-filter="upOrDownSwitch">
    {{# } else { }}
    <input type="checkbox" value={{d.id}} lay-text="上架|下架" lay-skin="switch" lay-filter="upOrDownSwitch">
    {{# } }}
</script>
<script type="text/html" id="isSkuFormat">
    {{# if(d.isSku === 1) { }}
        <span>是</span>
    {{# } else { }}
        <span>否</span>
    {{# } }}
</script>
<script type="text/html" id="goodsTypeFormat">
    {{# if(d.isNormal == 1) { }}
        <span>普通商品</span>
    {{# } else { }}
        <span>套餐</span>
    {{# } }}
</script>
<style>
    .layui-form-onswitch {
        background-color: #5FB878 !important;
    }
</style>
<!-- 表格操作栏 end -->
<script data-th-inline="none" type="text/javascript">
    // 引入组件并初始化
    layui.use([ 'jquery', 'form', 'table', 'febs'], function () {
        var $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            $view = $('#febs-goods'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            $add = $view.find('#add'),
            sortObject = {field: 'phone', type: null},
            tableIns;
 
        form.render();
 
        // 表格初始化
        initTable();
 
        // 初始化表格操作栏各个按钮功能
        table.on('tool(userTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'downGoods') {
                febs.modal.confirm('下架', '确认下架该商品?', function () {
                    downGoods(data.id);
                });
            }
            if (layEvent === 'upGoods') {
                febs.modal.confirm('上架', '确认上架该商品?', function () {
                    upGoods(data.id);
                });
            }
            if (layEvent === 'delGoods') {
                febs.modal.confirm('删除', '确认删除该商品?', function () {
                    delGoods(data.id);
                });
            }
            if (layEvent === 'detailGoods') {
                febs.modal.open( '商品详情', 'modules/goods/detailGoods/' + data.id, {
                    maxmin: true,
                });
            }
            if (layEvent === 'goodsUpdate') {
                febs.modal.open('编辑', 'modules/goods/goodsUpdateNew/' + data.id, {
                    btn: ['提交', '取消'],
                    area:['100%','100%'],
                    yes: function (index, layero) {
                        $('#febs-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
            if (layEvent === 'seeImgThumb') {
                var t = $view.find('#seeImgThumb'+data.id+'');
                //页面层
                layer.open({
                    type: 1,
                    title: "图片",
                    skin: 'layui-layer-rim', //加上边框
                    area: ['80%', '80%'], //宽高
                    shadeClose: true, //开启遮罩关闭
                    end: function (index, layero) {
                        return false;
                    },
                    content: '<div style="text-align:center"><img src="' + $(t).attr('src') + '" /></div>'
                });
            }
        });
        function downGoods(id) {
            febs.get(ctx + 'admin/goods/downMallGoods/' + id, null, function () {
                febs.alert.success('下架成功');
                $query.click();
            });
        }
        function delGoods(id) {
            febs.get(ctx + 'admin/goods/delMallGoods/' + id, null, function () {
                febs.alert.success('删除成功');
                $query.click();
            });
        }
        function upGoods(id) {
            febs.get(ctx + 'admin/goods/upMallGoods/' + id, null, function () {
                febs.alert.success('上架成功');
                $query.click();
            });
        }
 
        // 查询按钮
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
 
        // 刷新按钮
        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });
 
        $add.on('click', function () {
            febs.modal.open('新增商品', 'modules/goods/goodsAddNew/', {
                btn: ['提交', '取消'],
                area:['100%','100%'],
                yes: function (index, layero) {
                    $('#febs-goods-add').find('#submit').trigger('click');
                },
                btn2: function () {
                    layer.closeAll();
                }
            });
        });
 
        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'userTable',
                url: ctx + 'admin/goods/goodsList?goodsType=1',
                cols: [[
                    {field: 'goodsNo', title: '商品编号', minWidth: 150,align:'left'},
                    {field: 'goodsName', title: '商品名称', minWidth: 150,align:'left'},
                    {field: 'thumb', title: '缩略图',
                        templet: function (d) {
                            return '<a lay-event="seeImgThumb"><img id="seeImgThumb'+d.id+'" src="'+d.thumb+'" alt=""></a>';
                        }, minWidth: 150,align:'center'},
                    {field: 'categaryName', title: '分类', minWidth: 150,align:'left'},
                    {field: 'isSale', title: '是否上架', templet: '#upOrDownSwitch', minWidth: 130,align:'center'},
                    {templet:"#goodsTypeFormat",  title: '商品类型', minWidth: 150,align:'left'},
                    {templet:"#isSkuFormat", title: '是否多规格', minWidth: 150,align:'left'},
                    {field: 'presentPrice', title: '现价', minWidth: 150,align:'left'},
                    {field: 'originalPrice', title: '原价', minWidth: 150,align:'left'},
                    {field: 'stock', title: '商品库存', minWidth: 150,align:'left'},
                    {field: 'skuVolume', title: '商品销量', minWidth: 150,align:'left'},
                    {title: '操作',
                        templet: function (d) {
                            if (d.isSale === 1) {
                                return '';
                                // return '<button class="layui-btn layui-btn-normal layui-btn-xs febs-bg-orange" lay-event="downGoods" shiro:hasPermission="user:update">下架</button>'
                                // + '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detailGoods" shiro:hasPermission="user:update">详情</button>'
                            }else{
                                // '<button class="layui-btn layui-btn-normal layui-btn-xs febs-bg-green" lay-event="upGoods" shiro:hasPermission="user:update">上架</button>'
                                return ''
                                + '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="goodsUpdate" shiro:hasPermission="user:update">编辑</button>'
                                    + '<button class="layui-btn layui-btn-normal layui-btn-xs febs-bg-red" lay-event="delGoods" shiro:hasPermission="user:update">删除</button>'
 
                            }
                        },minWidth: 160,align:'center'}
                ]]
            });
        }
 
        form.on('switch(upOrDownSwitch)', function (data) {
            if (data.elem.checked) {
                upGoods(data.value);
            } else {
                downGoods(data.value);
            }
        })
 
        // 获取查询参数
        function getQueryParams() {
            return {
                goodsName: $searchForm.find('input[name="goodsName"]').val().trim(),
            };
        }
 
    })
</script>