lchao 5 miesięcy temu
rodzic
commit
14eb9b4ab6

+ 28 - 24
qmjszx-admin/src/main/resources/templates/system/mall/add.html

@@ -67,28 +67,12 @@
                 </div>
             </div>
         </div>
-<!--        <div class="col-xs-12">-->
-<!--            <div class="form-group">-->
-<!--                <label class="col-sm-3 control-label is-required">商品库存:</label>-->
-<!--                <div class="col-sm-8">-->
-<!--                    <input name="goodsInventory" class="form-control" type="text" required>-->
-<!--                </div>-->
-<!--            </div>-->
-<!--        </div>-->
-<!--        <div class="col-xs-12">-->
-<!--            <div class="form-group">-->
-<!--                <label class="col-sm-3 control-label is-required">库存成本:</label>-->
-<!--                <div class="col-sm-8">-->
-<!--                    <input name="inventoryCost" class="form-control" type="text" required>-->
-<!--                </div>-->
-<!--            </div>-->
-<!--        </div>-->
         <div class="col-xs-12">
             <div class="form-group">
                 <label class="col-sm-3 control-label">商品状态:</label>
                 <div class="col-sm-8">
-                    <select name="goodsState" class="form-control" th:with="type=${@dict.getType('sys_normal_disable')}">
-                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
+                    <select name="goodsState" class="form-control" th:with="type=${@dict.getType('goods_state')}" disabled>
+                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:attr="selected=${dict.dictValue == '1'}"></option>
                     </select>
                 </div>
             </div>
@@ -99,7 +83,8 @@
                 <div class="col-sm-8">
                     <input type="hidden" name="goodsImg">
                     <div class="file-loading">
-                        <input class="form-control file-upload" id="goodsImg" name="file" type="file">
+<!--                        <input class="form-control file-upload" id="goodsImg" name="file" type="file" multiple accept=".png, .jpg" onchange="validateFiles(this)">-->
+                        <input class="form-control file-upload" id="goodsImg" name="file" type="file" multiple >
                     </div>
                 </div>
             </div>
@@ -138,13 +123,32 @@
 
     $(".file-upload").fileinput({
         uploadUrl: ctx + 'common/upload',
-        maxFileCount: 1,
-        autoReplace: true
+        maxFileCount: 5,
+        allowedFileExtensions:['jpg','png'],
+        maxFileSize: 10240,
+        multiple: true,
     }).on('fileuploaded', function (event, data, previewId, index) {
-        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
+        var inputName = event.currentTarget.id;
+        var existingValue = $("input[name='" + inputName + "']").val();
+        var newValue = data.response.url;
+
+        // 如果已经存在值,则在后面加上逗号分隔的新值
+        if (existingValue) {
+            $("input[name='" + inputName + "']").val(existingValue + ',' + newValue);
+        } else {
+            $("input[name='" + inputName + "']").val(newValue);
+        }
     }).on('fileremoved', function (event, id, index) {
-        $("input[name='" + event.currentTarget.id + "']").val('')
-    })
+        var inputName = event.currentTarget.id;
+        var existingValue = $("input[name='" + inputName + "']").val();
+        var fileUrls = existingValue.split(',');
+
+        // 移除对应的文件路径
+        fileUrls.splice(index, 1);
+
+        // 重新拼接文件路径
+        $("input[name='" + inputName + "']").val(fileUrls.join(','));
+    });
 </script>
 </body>
 </html>

+ 34 - 9
qmjszx-admin/src/main/resources/templates/system/mall/edit.html

@@ -88,7 +88,7 @@
             <div class="form-group">
                 <label class="col-sm-3 control-label">商品状态:</label>
                 <div class="col-sm-8">
-                    <select name="goodsState" class="form-control" th:with="type=${@dict.getType('sys_normal_disable')}">
+                    <select name="goodsState" class="form-control" th:with="type=${@dict.getType('goods_state')}" disabled>
                         <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{goodsState}"></option>
                     </select>
                 </div>
@@ -100,7 +100,7 @@
                 <div class="col-sm-8">
                     <input type="hidden" name="goodsImg" th:field="*{goodsImg}">
                     <div class="file-loading">
-                        <input class="form-control file-upload" id="goodsImg" name="file" type="file">
+                        <input class="form-control file-upload" id="goodsImg" name="file" type="file" multiple>
                     </div>
                 </div>
             </div>
@@ -138,18 +138,43 @@
     }
 
     $(".file-upload").each(function (i) {
-        var val = $("input[name='" + this.id + "']").val()
+        var inputName = this.id;
+        var val = $("input[name='" + inputName + "']").val();
+
+        // 将已上传的图片路径分割成数组
+        var initialPreview = val ? val.split(',') : [];
+
         $(this).fileinput({
             'uploadUrl': ctx + 'common/upload',
             initialPreviewAsData: true,
-            initialPreview: [val],
-            maxFileCount: 1,
-            autoReplace: true
+            initialPreview: initialPreview,
+            maxFileCount: 5,
+            allowedFileExtensions: ['jpg', 'png'],
+            maxFileSize: 10240,
+            multiple: true,
         }).on('fileuploaded', function (event, data, previewId, index) {
-            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
+            var inputName = event.currentTarget.id;
+            var existingValue = $("input[name='" + inputName + "']").val();
+            var newValue = data.response.url;
+
+            // 如果已经存在值,则在后面加上逗号分隔的新值
+            if (existingValue) {
+                $("input[name='" + inputName + "']").val(existingValue + ',' + newValue);
+            } else {
+                $("input[name='" + inputName + "']").val(newValue);
+            }
         }).on('fileremoved', function (event, id, index) {
-            $("input[name='" + event.currentTarget.id + "']").val('')
-        })
+            var inputName = event.currentTarget.id;
+            var existingValue = $("input[name='" + inputName + "']").val();
+            var fileUrls = existingValue.split(',');
+
+            // 移除对应的文件路径
+            fileUrls.splice(index, 1);
+
+            // 重新拼接文件路径
+            $("input[name='" + inputName + "']").val(fileUrls.join(','));
+        });
+
         $(this).fileinput('_initFileActions');
     });
 </script>

+ 26 - 21
qmjszx-admin/src/main/resources/templates/system/mall/mall.html

@@ -48,7 +48,6 @@
         var removeFlag = [[${@permission.hasPermi('system:mall:remove')}]];
         var goodsTypeDatas = [[${@dict.getType('goods_type')}]];
         var goodsCurrentPriceDatas = [[${@dict.getType('sys_yes_no')}]];
-        var goodsStateDatas = [[${@dict.getType('sys_normal_disable')}]];
         var prefix = ctx + "system/mall";
 
         $(function() {
@@ -71,10 +70,6 @@
                     field: 'goodsName',
                     title: '商品名称'
                 },
-                // {
-                //     field: 'goodsCode',
-                //     title: '商品条码'
-                // },
                 {
                     field: 'goodsType',
                     title: '商品种类',
@@ -92,11 +87,6 @@
                     title: '商品说明',
                     visible: false
                 },
-                // {
-                //     field: 'goodsUnit',
-                //     title: '计量单位',
-                //     visible: false
-                // },
                 {
                     field: 'goodsCurrentPrice',
                     title: '时价商品',
@@ -113,20 +103,12 @@
                     title: '建议售价',
                     visible: false
                 },
-                // {
-                //     field: 'goodsInventory',
-                //     title: '商品库存'
-                // },
-                // {
-                //     field: 'inventoryCost',
-                //     title: '库存成本',
-                //     visible: false
-                // },
                 {
+                    visible: editFlag == 'hidden' ? false : true,
                     field: 'goodsState',
                     title: '商品状态',
-                    formatter: function(value, row, index) {
-                       return $.table.selectDictLabel(goodsStateDatas, value);
+                    formatter: function (value, row, index) {
+                        return statusTools(row);
                     }
                 },
                 {
@@ -142,6 +124,29 @@
             };
             $.table.init(options);
         });
+
+        /* 商品状态显示 */
+        function statusTools(row) {
+            if (row.goodsState == 2) {
+                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
+            } else {
+                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
+            }
+        }
+
+        /* 用户管理-停用 */
+        function disable(id) {
+            $.modal.confirm("确认要下架商品吗?", function() {
+                $.operate.post(prefix + "/goodsStatus", { "id": id, "goodsState": 2 });
+            })
+        }
+
+        /* 用户管理启用 */
+        function enable(id) {
+            $.modal.confirm("确认要上架商品吗?", function() {
+                $.operate.post(prefix + "/goodsStatus", { "id": id, "goodsState": 1 });
+            })
+        }
     </script>
 </body>
 </html>

+ 14 - 0
qmjszx-business/src/main/java/beilv/shopping/controller/QmjsShoppingMallController.java

@@ -1,6 +1,7 @@
 package beilv.shopping.controller;
 
 import java.util.List;
+
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -87,6 +88,7 @@ public class QmjsShoppingMallController extends BaseController
     @ResponseBody
     public AjaxResult addSave(QmjsShoppingMall qmjsShoppingMall)
     {
+        qmjsShoppingMall.setGoodsState("1");
         return toAjax(qmjsShoppingMallService.insertQmjsShoppingMall(qmjsShoppingMall));
     }
 
@@ -125,4 +127,16 @@ public class QmjsShoppingMallController extends BaseController
     {
         return toAjax(qmjsShoppingMallService.deleteQmjsShoppingMallByIds(ids));
     }
+
+    /**
+     * 商品状态修改
+     */
+    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
+    @RequiresPermissions("system:mall:edit")
+    @PostMapping("/goodsStatus")
+    @ResponseBody
+    public AjaxResult goodsStatus(QmjsShoppingMall qmjsShoppingMall)
+    {
+        return toAjax(qmjsShoppingMallService.goodsStatus(qmjsShoppingMall));
+    }
 }

+ 2 - 0
qmjszx-business/src/main/java/beilv/shopping/service/IQmjsShoppingMallService.java

@@ -60,4 +60,6 @@ public interface IQmjsShoppingMallService
      * @return 结果
      */
     public int deleteQmjsShoppingMallById(Long id);
+
+    int goodsStatus(QmjsShoppingMall qmjsShoppingMall);
 }

+ 10 - 0
qmjszx-business/src/main/java/beilv/shopping/service/impl/QmjsShoppingMallServiceImpl.java

@@ -2,6 +2,7 @@ package beilv.shopping.service.impl;
 
 import java.util.List;
 
+import beilv.common.core.domain.entity.SysUser;
 import beilv.shopping.domain.QmjsShoppingMall;
 import beilv.shopping.mapper.QmjsShoppingMallMapper;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -93,4 +94,13 @@ public class QmjsShoppingMallServiceImpl implements IQmjsShoppingMallService
     {
         return qmjsShoppingMallMapper.deleteQmjsShoppingMallById(id);
     }
+
+    /**
+     * 商城状态修改
+     */
+    @Override
+    public int goodsStatus(QmjsShoppingMall qmjsShoppingMall)
+    {
+        return qmjsShoppingMallMapper.updateQmjsShoppingMall(qmjsShoppingMall);
+    }
 }