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
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" xmlns:matrix="http://www.w3.org/1999/xhtml">
<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 class=" container-fluid">
<div class="pd-10">
    <!-- 搜索框部分start -->
    <div class="row form-head">
        <form class="form-inline" id="serchform">
 
            <div class="btn-group search-list " data-for="search-text">
                <button type="button"
                        class="btn btn-default dropdown-toggle searchlist"
                        data-toggle="dropdown">
                    产品名称 <span class="caret "></span>
                </button>
                <ul class="dropdown-menu" role="menu">
                    <li data-field="title"><a>产品名称</a></li>
                    <li data-field="brand"><a>产品品牌 </a></li>
                </ul>
            </div>
            <div class="form-group mr-20 ml-20">
                <input autocomplete="off" id="search-text" name="title" placeholder="输入查询关键词"
                       type="text" class="form-control">
            </div>
 
            <div class="form-group">
                <label class="control-label">是否上架</label>
                <select style="width:200px;" class="form-control select2" size="1"
                        name="status"
                        id="status">
                    <option value="">请选择</option>
                    <option value="1">是</option>
                    <option value="2">否</option>
                </select>
            </div>
            <div class="form-group">
                <label class="control-label">是否为服务</label>
                <select style="width:200px;" class="form-control select2" size="1"
                        name="isService"
                        id="isService">
                    <option value="">请选择</option>
                    <option value="1">是</option>
                    <option value="2">否</option>
                </select>
            </div>
            <div class="form-group">
                <label class="control-label">产品属性</label>
                <select style="width:200px;" class="form-control  col-sm-2select2" size="1" name="attrs"
                        id="parentId">
                </select></div>
            <div class="form-group">
                <label class="control-label">分类</label>
                <select style="width:200px;" class="form-control  select2" size="1" name="categoryId"
                        id="categoryId">
                </select>
            </div>
            <div class="form-group">
                <button onclick="myGrid.serchData(1)" type="button"
                        class="btn btn-info">
                    <i class="fa fa-search "></i> 搜索
                </button>
                <button type="reset" class="btn btn-info ">
                    <i class="fa fa-refresh "></i> 重置
                </button>
            </div>
 
 
        </form>
    </div>
 
    <div class="row">
        <div class="col-sm-12">
            <div id="option-bar">
                <!-- 功能按钮部分 -->
                <div class="row">
                    <button onclick="updateStatus('1')" type="button"
                            class="btn btn-success btn-sm" matrix:btn="shopProduct-upshelf">
                        <i class="fa fa-plus"></i>上架
                    </button>
                    <button onclick="updateStatus('2')" type="button"
                            class="btn btn-success btn-sm" matrix:btn="shopProduct-downshelf">
                        <i class="fa fa-minus-square"></i> 下架
                    </button>
                    <button onclick="myGrid.delItems('id')" type="button"
                            class="btn btn-danger btn-sm" matrix:btn="shopProduct-dels">
                        <i class="fa fa-trash"></i>批量删除
                    </button>
                    <button onclick="openAdd()" type="button"
                            class="btn btn-success btn-sm" matrix:btn="shopProduct-add">
                        <i class="fa fa-plus"></i> 新增
                    </button>
 
                    <button onclick="openEdit()" type="button" class="btn btn-info btn-sm"><i class="fa fa-edit"></i> 编辑
                    </button>
 
                </div>
 
            </div>
            <table id="mgrid">
                <thead>
                <tr>
                    <th data-checkbox="true"></th>
                    <th data-formatter="MGrid.indexfn" data-align="center">序号</th>
                    <th data-field="id" data-align="center">产品ID</th>
                    <th data-field="title" data-align="center">产品名称</th>
                    <th data-field="imgMobile" data-align="center" data-formatter="MGrid.getImage">产品图片</th>
                    <th data-field="attrValues" data-align="center" data-formatter="formatAttr">产品属性</th>
                    <th data-field="price" data-align="center">价格</th>
                    <th data-field="score" data-align="center">积分</th>
                    <th data-field="status" data-align="center" data-formatter="isStatus">是否上架</th>
                    <th data-field="rsVolume" data-align="center">真实销量</th>
 
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
 
 
<script type="text/javascript"
        th:src="@{/js/systools/MJsBase.js}"></script>
<script type="text/javascript">
    var myGrid;
 
    $(".select2").select2();
 
    initAttrsSeclect("#parentId");
 
    initCategorySeclect("#categoryId");
 
    $(function () {
        var delUrl = "";
        delUrl = basePath + "/admin/shopProduct/del";
        myGrid = MGrid.initGrid({
            url: basePath + "/admin/shopProduct/showList",
            delUrl: delUrl,
        });
 
    });
 
 
    function formatDate(value, row, index) {
        if (row.buyLimit != null && row.limitCycle != null) {
            return row.buyLimit + "/" + row.limitCycle;
        } else if (row.buyLimit != null && row.limitCycle == null) {
            return row.buyLimit + "/"
        } else if (row.buyLimit == null && row.limitCycle != null) {
            return "/" + row.limitCycle;
        }
 
    }
 
    /**
     * 批量上下架
     */
    function updateStatus(status) {
 
        var ids = myGrid.getSelectItemsIds("id");
        if (ids.length < 1 && '1' == status) {
            layer.msg("请选择您要上架的产品", {
                icon: 5
            });
            return false;
        }
        if (ids.length < 1 && '2' == status) {
            layer.msg("请选择您要下架的产品", {
                icon: 5
            });
            return false;
        }
        var url = basePath + "/admin/shopProduct/updateStatus?ids=" + ids + "&status=" + status;
 
        if ('1' == status) {
            MTools.handleItem(url, "确认要上架这" + ids.split(",").length + "个产品吗?", function () {
                myGrid.serchData(1)
            });
        } else {
            MTools.handleItem(url, "确认要下架这" + ids.split(",").length + "个产品吗?", function () {
                myGrid.serchData(1)
            });
        }
    }
 
    var btns = [];
    btns[0] = "", btns[1] = "";
 
    function buidOperate(value, row, index) {
        var html = "";
        html += btns[0].replace('VALUE', value)
            + btns[1].replace('VALUE', value)
        return html;
    }
 
 
    //打开添加界面
    function openAdd() {
 
        layer.full(layer.open({
            type: 2,
            title: "添加产品",
            area: [MUI.SIZE_L, '400px'],
            maxmin: true,
            content: [basePath + '/admin/shopProduct/editForm']
        }));
 
    }
 
    //打开编辑界面
    function openEdit() {
        var id = myGrid.getSelectItemId();
        layer.full(layer.open({
            type: 2,
            title: "编辑产品",
            area: [MUI.SIZE_L, '400px'],
            maxmin: true,
            content: [basePath + '/admin/shopProduct/editForm?id=' + id]
        }));
    }
 
    function isCanComment(value, row, index) {
        if (value == "1") {
            return "是";
        } else {
            return "否";
        }
    }
 
    function isStatus(value, row, index) {
        if (value == "1") {
            return "是";
        } else {
            return "否";
        }
    }
 
    function isPrescrip(value, row, index) {
        if (value == "1") {
            return "是";
        } else {
            return "否";
        }
    }
 
    //初始化分类下拉选
    function initCategorySeclect(seler, def) {
        $.AjaxProxy().invoke(basePath + "/admin/shopProductAttribute/showSonAttribute?attrCode=cpfl&status=1",
            function (loj) {
                $(seler).createSelectTree(
                    loj.attr("result").rows,
                    {
                        id: "attrId",
                        parent: "parentId",
                        value: "attrName",
                        append: false,
                        defaultValue: def,
                        defaultHtml: '<option value="" selected="selected">请选择产品分类</option>'
                    });
            });
    }
 
    //初始化属性下拉选
    function initAttrsSeclect(seler, def) {
        console.log(1);
        $.AjaxProxy().invoke(basePath + "/admin/shopProductAttribute/showSonAttribute?attrCode=cpfl",
            function (loj) {
                $(seler).createSelectTree(
                    loj.attr("result").rows,
                    {
                        id: "attrId",
                        parent: "parentId",
                        value: "attrName",
                        append: false,
                        defaultValue: def,
                        defaultHtml: '<option value="" selected="selected">请选择产品属性</option>'
                    });
            });
    }
 
    /**
     * 格式化属性
     */
    function formatAttr(value, row, index) {
        var html = "";
        if (value != "") {
            var values = value.split(",");
            for (var i = 0; i < values.length; i++) {
                html += "<span class='label label-warning mr-5'>" + values[i] + "</span>"
            }
        }
        return html;
    }
 
    /**
     * 格式化品种编码
     */
    function getSplitString(str, row, index) {
        // 空白(空格、换行、tab)和逗号分隔的字符串,变成用逗号分隔
        if (str != "" && str != null) {
            var arr = str.split(",");
            var resources = "";
            for (var i = 0; i < arr.length; i++) {
                var arr1 = arr[i].split(/\s+/);
 
                for (var j = 0; j < arr1.length; j++) {
                    if (jQuery.trim(arr1[j]) != "") {
                        resources += jQuery.trim(arr1[j]) + ",";
                    }
                }
            }
            resources = (resources.substring(resources.length - 1) == ',') ? resources.substring(0, resources.length - 1) : resources;
            return resources;
        }
 
    }
 
</script>
 
</body>
</html>