zhijiezhao há 3 anos atrás
pai
commit
dce9e0085f

+ 17 - 0
src/main/java/com/caimei/modules/consult/service/type/CmConsulttypeService.java

@@ -2,6 +2,7 @@ package com.caimei.modules.consult.service.type;
 
 import java.util.List;
 
+import com.caimei.modules.product.entity.CmBigtype;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -55,4 +56,20 @@ public class CmConsulttypeService extends CrudService<CmConsulttypeDao, CmConsul
 	public void use(CmConsulttype cmConsulttype){
 		dao.update(cmConsulttype);
 	}
+
+	@Transactional(readOnly = false)
+    public void updateSortIndex(String cmConsulttypeIdSortNumber) {
+		if (cmConsulttypeIdSortNumber.contains(",")) {
+			String[] bigTypeIdSortIndexArr = cmConsulttypeIdSortNumber.split(",");
+			for (int i = 0; i < bigTypeIdSortIndexArr.length; i++) {
+				String[] bigTypeIdSortIndex = bigTypeIdSortIndexArr[i].split("_");
+				if (bigTypeIdSortIndex.length == 2) {
+					CmConsulttype cmConsulttype = new CmConsulttype();
+					cmConsulttype.setId(bigTypeIdSortIndex[0]);
+					cmConsulttype.setSortNumber(bigTypeIdSortIndex[1]);
+					dao.update(cmConsulttype);
+				}
+			}
+		}
+	}
 }

+ 17 - 1
src/main/java/com/caimei/modules/consult/web/type/CmConsulttypeController.java

@@ -3,7 +3,7 @@ package com.caimei.modules.consult.web.type;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.shiro.authz.annotation.RequiresPermissions;
+import com.caimei.vo.JsonModel;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.transaction.annotation.Transactional;
@@ -11,6 +11,7 @@ import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
 import com.thinkgem.jeesite.common.config.Global;
@@ -43,6 +44,21 @@ public class CmConsulttypeController extends BaseController {
 		}
 		return entity;
 	}
+
+	@RequestMapping(value = "getType")
+	@ResponseBody
+	public JsonModel getBigType(CmConsulttype cmConsulttype){
+		JsonModel jsonModel = JsonModel.newInstance();
+		return jsonModel.success(cmConsulttype);
+	}
+
+	@RequestMapping(value = "updateSort")
+	@ResponseBody
+	public JsonModel updateSortIndex(String cmConsulttypeIdSortNumber){
+		JsonModel jsonModel = JsonModel.newInstance();
+		cmConsulttypeService.updateSortIndex(cmConsulttypeIdSortNumber);
+		return jsonModel.success("批量更新排序成功");
+	}
 	
 
 	@RequestMapping(value = {"list", ""})

+ 2 - 4
src/main/resources/mappings/modules/consult/type/CmConsulttypeMapper.xml

@@ -35,7 +35,7 @@
 				AND a.className LIKE concat('%',#{className},'%')
 			</if>
 		</where>
-		order by createdTime asc
+		order by sortnumber ASC
 	</select>
 	
 	<select id="findAllList" resultType="CmConsulttype">
@@ -99,9 +99,7 @@
 		<if test="createdTime != null">
 			createdTime = #{createdTime},
 		</if>
-		<if test="delflag != null and delflag != ''">
-		delflag = #{delflag}
-		</if>
+		delflag = 0
 		WHERE id = #{id}
 	</update>
 	

+ 51 - 12
src/main/webapp/WEB-INF/views/modules/consult/type/cmConsulttypeList.jsp

@@ -24,6 +24,40 @@
             $("#searchForm").submit();
             return false;
         }
+
+        //验证输入的排序值是否合法
+        var cmConsulttypeId_sortNumber = '';
+        function confirmSortIndex(index) {
+            var $sortIndex = $("#sortNumber"+index).val();
+            var $bigTypeId = $("#cmConsulttypeId"+index).val();
+            if (!isNaN($sortIndex)) {
+                if($sortIndex % 1 === 0 && $sortIndex >0){
+                    cmConsulttypeId_sortNumber += $bigTypeId+"_"+$sortIndex+",";
+                }else{
+                    alertx("排序只能输入大于0的整数");
+                    $.get("${ctx}/consult/type/cmConsulttype/getType",{'id':$bigTypeId}, function (data) {
+                        $("#sortIndex" + index).val(data.data.sortIndex);
+                    })
+                }
+            }else{
+                alertx("排序只能输入大于0的整数");
+                $.get("${ctx}/consult/type/cmConsulttype/getType",{'id':$bigTypeId},function (data) {
+                    $("#sortIndex" + index).val(data.data.sortIndex);
+                })
+            }
+            alert(cmConsulttypeId_sortNumber);
+        }
+
+        //批量保存排序
+        function updateSortIndex() {
+            $.post("${ctx}/consult/type/cmConsulttype/updateSort",{'cmConsulttypeIdSortNumber':cmConsulttypeId_sortNumber},function(result){
+                $.jBox.tip(result.data, 'info');
+                setTimeout(function () {
+                    $("#searchForm").submit();
+                }, 500);
+            })
+        }
+
     </script>
 </head>
 <body>
@@ -31,13 +65,11 @@
     <li><a href="${ctx}/new/user/agency/regist">已注册用户咨询记录</a></li>
     <li><a href="${ctx}/new/user/visit/unregist">未注册用户咨询记录</a></li>
     <li class="active"><a href="${ctx}/consult/type/cmConsulttype/">咨询类别设置</a></li>
-<%--    <li><a href="${ctx}/consult/type/cmConsulttype/form">咨询类别添加</a></li>--%>
 </ul>
 <form:form id="searchForm" modelAttribute="cmConsulttype" action="${ctx}/consult/type/cmConsulttype/" method="post"
            class="breadcrumb form-search">
     <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
     <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
-    <%--    < class="ul-form">--%>
     <label>类别名称:</label>
     <form:input path="className" class="input-medium" maxlength="20"/>
     <label>状态:</label>
@@ -47,14 +79,11 @@
         <form:option value="2" label="停用"></form:option>
     </form:select>
 
-    &nbsp;&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
-    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+    &nbsp;&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>&nbsp;&nbsp;
+
     <a href="${ctx}/consult/type/cmConsulttype/form"  class="btn btn-primary" style="width: 70px">添加类别</a>
-    &nbsp;&nbsp;&nbsp;&nbsp;
-    &nbsp;&nbsp;&nbsp;&nbsp;
-    <a class="btn btn-primary" style="width: 70px"
-       href="${ctx}/consult/type/cmConsulttype/sort">一键排序</a>
-    &nbsp;&nbsp;&nbsp;&nbsp;
+
+    <input class="btn btn-primary" type="button" value="一键排序" onclick="updateSortIndex()" style="margin-left: 15px"/>
 
     <div class="clearfix"></div>
     </div>
@@ -72,9 +101,14 @@
     </tr>
     </thead>
     <tbody id="sortbody">
-    <c:forEach items="${page.list}" var="cmConsulttype">
+    <c:forEach items="${page.list}" var="cmConsulttype" varStatus="ct">
         <tr>
-            <td>${cmConsulttype.id}</td>
+            <td>
+                <input type="text" id="cmConsulttypeId${ct.index}"
+                       value="${cmConsulttype.id}"
+                       style="width: 50px;display: none">
+                    ${ct.index+1}
+            </td>
             <td>${cmConsulttype.className}</td>
             <td><c:if test="${cmConsulttype.status eq 1}">
                 <div style="color: green">已启用<a style="text-decoration: none" href="${ctx}/consult/type/cmConsulttype/use?id=${cmConsulttype.id}&status=2">&nbsp&nbsp&nbsp 停用</a></div>
@@ -83,7 +117,12 @@
                     <div style="color: red">已停用<a style="text-decoration: none" href="${ctx}/consult/type/cmConsulttype/use?id=${cmConsulttype.id}&status=1">&nbsp&nbsp&nbsp 启用</a></div>
                 </c:if>
             </td>
-            <td>${cmConsulttype.sortNumber}</td>
+            <td>
+                <input type="text" name="sortNumber" id="sortNumber${ct.index}"
+                       onchange="confirmSortIndex(${ct.index})"
+                       value="${cmConsulttype.sortNumber}"
+                       style="width: 50px">
+            </td>
             <td><fmt:formatDate value="${cmConsulttype.createdTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
             <td>
                 <a href="${ctx}/consult/type/cmConsulttype/form?id=${cmConsulttype.id}">编辑</a>