Selaa lähdekoodia

考核项管理

chenrj-PC\chenrj 9 vuotta sitten
vanhempi
commit
f041e7dbfc

+ 122 - 67
VisualInspection/js/assess_management/assess_item.js

@@ -42,46 +42,45 @@
      getCheckItems();
 
      $("#dept_add").on("click", function() {
-         alert(1);
          var nodedata = check_item_tree.getSelectedNodes();
          edittype = "add"
          loadData(nodedata)
          $('#addModal').modal('show')
      })
 
-    //  $("#dept_edit").on("click", function() {
-    //      //获取选中的节点
-    //      var nodedata = check_item_tree.getSelectedNodes();
-    //      if (nodedata.length < 1) {
-    //          layer.msg('请先选择部门!', {
-    //              time: 2000, //20s后自动关闭
-    //          });
-    //          return;
-    //      }
-    //      edittype = "edit"
-    //      loadData(nodedata)
-    //      $('#addModal').modal('show');
-    //  });
-
-    //  $("#dept_delete").on("click", function() {
-    //      //获取选中的节点
-    //      var nodedata = check_item_tree.getSelectedNodes();
-    //      if (nodedata.length < 1) {
-    //          layer.msg('请先选择部门!', {
-    //              time: 2000, //20s后自动关闭
-    //          });
-    //          return;
-    //      }
-    //      DeptDelete(nodedata[0].id, function(data) {
-    //          layer.msg('删除成功!', {
-    //              time: 2000, //20s后自动关闭
-    //          });
-    //          check_item_tree.removeNode(nodedata[0]);
-    //      }, function(error) {
-
-    //      });
-    //  });
+     $("#dept_edit").on("click", function() {
+         //获取选中的节点
+         var nodedata = check_item_tree.getSelectedNodes();
+         if (nodedata.length < 1) {
+             layer.msg('请先选考核项!', {
+                 time: 2000, //20s后自动关闭
+             });
+             return;
+         }
+         edittype = "edit"
+         loadData(nodedata)
+         $('#addModal').modal('show');
+     });
 
+     $("#dept_delete").on("click", function() {
+         var nodedata = check_item_tree.getSelectedNodes();
+         if (nodedata.length < 1) {
+             layer.msg('请选择考核项!', {
+                 time: 2000, //20s后自动关闭
+             });
+             return;
+         }
+
+         post_common_service("/checkItem/delete", {"id":nodedata[0].id  }, function(data){
+            layer.msg('删除成功!', {
+                 time: 2000, //20s后自动关闭
+             });
+             check_item_tree.removeNode(nodedata[0]);
+             getCheckItems();
+            table_init();
+         }, function(error){ })
+
+     });
 
      $('.datatable').datatable({
          checkable: false,
@@ -91,9 +90,58 @@
              rows: []
          }
      });
+ });
 
+function table_init(){
+    $('.datatable').datatable('load', {
+        cols: cols,
+        rows: []
+    });
+}
 
- });
+// 表格点击修改
+function modify_check_item( id ){
+   post_common_service("/checkItem/getById", {"id":id }, function(data){
+        $(".check_item_group").hide();
+        $("#check_item_name").val(data.name);
+        $("#check_item_score").val(data.score);
+        $("#add_btn").html("修改");
+        $('#addModal').modal('show');
+        $("#add_btn").attr("onclick","addCheckItem_v("+data.id+")");
+    }, function(error){ })
+}
+
+function addCheckItem_v(id){
+    var name = $("#check_item_name").val();
+    var score = $("#check_item_score").val();
+    var data = {
+        "id":id ,
+        "name":name,
+        "score":score 
+    }
+    post_common_service( "checkItem/update",data,function(data){
+        layer.msg('修改成功!', {
+            time: 2000, //20s后自动关闭
+        }, function() {
+            $('#addModal').modal('hide');
+             $("#add_btn").attr("onclick","addCheckItem()");
+            getCheckItems();
+            table_init();
+        })
+    },function(error){})
+
+}
+
+// 表格点击删除
+function delete_check_item(id ){
+    post_common_service("/checkItem/delete", {"id":id }, function(data){
+        layer.msg('删除成功!', {
+                time: 2000, //20s后自动关闭
+            });   
+        getCheckItems();
+        table_init();
+    }, function(error){ })
+} 
 
  function getCheckItems() {
      function zTreeOnRename(event, treeId, treeNode, isCancel) {
@@ -126,7 +174,7 @@
      function getTree(obj,rowObj){
         var userdata = {};
         userdata["checked"] = false;
-        userdata["data"] = [++seq, obj.name, (obj.score!=null?obj.score:""), '<a href="#" data-toggle="modal" data-target="#myModal"><i class="icon icon-edit"></i> 修改</a><a href="#"><i class="icon icon-remove-circle"></i> 删除</a>'];
+        userdata["data"] = [++seq, obj.name, (obj.score!=null?obj.score:""), '<a href="javascript:void(0)" onclick="modify_check_item('+ obj.id +')"  ><i class="icon icon-edit"></i> 修改</a><a href="javascript:void(0)" onclick="delete_check_item('+ obj.id +')" ><i class="icon icon-remove-circle"></i> 删除</a>'];
         rowObj.push(userdata);
 
         if(obj.subCheckItem!=null){
@@ -137,8 +185,6 @@
         return rowObj;
      }
 
-     console.log(1);
-
      function zTreeOnClick(event, treeId, treeNode) {
 
         var rowdata = [];
@@ -147,7 +193,6 @@
 
         for(var i=0;i<z_cache.length;i++){
             var treeObj = getTreeData(z_cache[i],treeNode.id) ;
-            console.log(treeObj)
             if( treeObj != null){
                rowdata = getTree(treeObj,rowdata);
                break ;
@@ -209,6 +254,7 @@
              zdataItem["id"] = m.id;
              zdataItem["value"] = m.id;
              zdataItem["pId"] = null;
+             zdataItem["score"] = m.score ;
              zdataItem["name"] = m.name;
              zdataItem["children"] = addobj(m);
              zdata.push(zdataItem);
@@ -227,6 +273,7 @@
              zdataItem["id"] = m.id;
              zdataItem["value"] = m.id;
              zdataItem["pId"] = data.id;
+             zdataItem["score"] = m.score ;
              zdataItem["icon"] = "";
              zdataItem["name"] = m.name;
              zdataItem["children"] = addobj(m);
@@ -246,68 +293,76 @@ function loadData(nodedata) {
     var pnode = nodedata;
 
     if (edittype == "add") {
-        $("#dept_name").val("")
+        $("#check_item_name").val("") ;
+        $("#check_item_score").val("")
     }
     if (edittype == "edit") {
         selectednodetemp = nodedata[0];
-        $("#dept_name").val(nodedata[0].name)
-        $("#dept_add_btn").html("保存")
+        $("#check_item_name").val(nodedata[0].name);
+        $("#check_item_score").val(nodedata[0].score);
+        $("#add_btn").html("保存")
         if (pnode != null && pnode.length > 0) {
-            pnode = [dept_tree.getNodeByParam("id", pnode[0].pId, null)]
+            pnode = [check_item_tree.getNodeByParam("id", pnode[0].pId, null)]
         }
     }
-
-
-    dept_selectinput = new TreeSelect({
-        element: '#dept_select',
-        data: zdata,
-        valueKey: "id",
-        placeholder: "选择部门",
-        selectvalue: pnode.length > 0 ? pnode[0].id : null
-    });
+    $(".check_item_group").show();
+    if(pnode[0] != null){
+        dept_selectinput = new TreeSelect({
+            element: '#check_item_select',
+            data: zdata,
+            valueKey: "id",
+            placeholder: "选择考核项分类",
+            selectvalue: pnode.length > 0 ? pnode[0].id : null
+        });
+    }else{
+        $(".check_item_group").hide();
+    }
 }
 
 
-function addDept() {
+function addCheckItem() {
     //获取名称
-    var name = $("#dept_name").val();
-    var pid = dept_selectinput.value;
+    var name = $("#check_item_name").val();
+    var score = $("#check_item_score").val();
+
+    var pid =   dept_selectinput!=null?dept_selectinput.value:null ;
+
     var data = {
-        "organname": name,
-        "parentid": pid
+        "name": name,
+        "score":score,
+        "parent_id": pid
     }
 
     if (edittype == "add") {
-        DeptAdd(data, function(datare) {
+        post_common_service( "checkItem/add",data,function(data){
             layer.msg('添加成功!', {
                 time: 2000, //20s后自动关闭
             }, function() {
                 $('#addModal').modal('hide')
-                getDept();
+                getCheckItems();
+                 table_init();
             })
-        }, function(error) {
-
-        })
+        },function(error){})
     }
 
     if (edittype == "edit") {
         data["id"] = selectednodetemp.id;
         if (isSelfOrChild(pid, selectednodetemp)) {
-            layer.msg('不能添加到自身及自身下的子部门!', {
+            layer.msg('不能添加到自身及自身下的子考核项!', {
                 time: 2000, //20s后自动关闭
             })
             return;
         }
-        DeptEdit(data, function(datare) {
+
+         post_common_service( "checkItem/update",data,function(data){
             layer.msg('修改成功!', {
                 time: 2000, //20s后自动关闭
             }, function() {
                 $('#addModal').modal('hide')
-                getDept();
+                getCheckItems();
+                 table_init();
             })
-        }, function(error) {
-
-        });
+        },function(error){})
     }
 }
 

+ 8 - 8
VisualInspection/view/assess_management/assess_item.html

@@ -27,7 +27,7 @@
                     <div class="panel-heading">
                         <span class="title">考核项详情</span>
                         <div class="panel-actions">
-                            <button type="button" class="btn" data-toggle="tooltip" title="添加人员"><i class="icon-plus"></i></button>
+                            <!--<button type="button" class="btn" data-toggle="tooltip" title="添加人员"><i class="icon-plus"></i></button>-->
                         </div>
                     </div>
                     <div class="panel-body no-padding" style="padding:0">
@@ -45,7 +45,7 @@
         <div class="modal-content">
             <div class="modal-header">
                 <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
-                <h4 class="modal-title">添加考核项</h4>
+                <h4 class="modal-title">考核项信息</h4>
             </div>
             <div class="modal-body">
                 <div class="container-fluid ">
@@ -53,26 +53,26 @@
                         <div class="form-group">
                             <label for="exampleInputAccount4" class="col-sm-2">名称:</label>
                             <div class="col-md-6 col-sm-10">
-                                <input type="text" id="dept_name" class="form-control" id="code_flag" placeholder="名称">
+                                <input type="text" id="check_item_name" class="form-control" placeholder="名称">
                             </div>
                         </div>
                         <div class="form-group">
                             <label for="exampleInputAccount4" class="col-sm-2">分数:</label>
                             <div class="col-md-6 col-sm-10">
-                                <input type="text" id="dept_name" class="form-control" id="code_flag" placeholder="分数">
+                                <input type="text" id="check_item_score" class="form-control" placeholder="分数">
                             </div>
                         </div>
-                        <div class="form-group">
-                            <label for="exampleInputPassword4" class="col-sm-2">上级部门:</label>
+                        <div class="form-group check_item_group">
+                            <label for="exampleInputPassword4" class="col-sm-2">分类:</label>
                             <div class="col-md-6 col-sm-10">
-                                <div id="dept_select">分类</div>
+                                <div id="check_item_select"></div>
 
                             </div>
                         </div>
 
                         <div class="form-group">
                             <div class="col-sm-offset-2 col-sm-10">
-                                <button type="button" id="dept_add_btn" class="btn btn-default" onclick="addDept()">添加</button>
+                                <button type="button" id="add_btn" class="btn btn-default" onclick="addCheckItem()">添加</button>
                             </div>
                         </div>
                     </form>

+ 4 - 3
VisualInspection_server/src/main/java/com/xintong/visualinspection/mapper/master/CheckItemMapper.xml

@@ -28,7 +28,7 @@
         WHERE parent_id = #{parent_id}
     </select>
     
-    <insert id="insert" parameterType="com.xintong.visualinspection.dao.master.CheckItemDao" >
+    <insert id="insert" parameterType="com.xintong.visualinspection.bean.CheckItem" >
         INSERT INTO
         check_item
         (name,parent_id,content,score,score_type,type)
@@ -36,7 +36,7 @@
         (#{name}, #{parent_id},#{content},#{score},#{score_type},#{type})
     </insert>
 
-    <update id="update" parameterType="com.xintong.visualinspection.dao.master.CheckItemDao" >
+    <update id="update" parameterType="com.xintong.visualinspection.bean.CheckItem" >
         UPDATE
         check_item
         SET
@@ -45,7 +45,8 @@
         <if test="content != null">content = #{content},</if>
         <if test="score != null">score = #{score},</if>
         <if test="score_type != null">score_type = #{score_type},</if>
-        <if test="type != null">type = #{type}</if>
+        <if test="type != null">type = #{type},</if>
+        id =id 
         WHERE
         id = #{id}
     </update>