'use strict'; var app = angular.module('app', [ 'angularUtils.directives.dirPagination' ]); app.controller("indexCtrl", ["$scope", "$http", "$timeout", function ($scope, $http, $timeout) { var self = this; var s4 = new SM4Util(); self.userId = $.cookie("GlWorkPlatform-userid"); self.userName = $.cookie("GlWorkPlatform-chineseName"); self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken"); self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno"); self.get_type = sp.getUrlName("type"); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } } sp.fitHeight('#treeDivPart', 120); sp.fitHeight('.fp-part-right', 80); //获取树形结构 self.treeData = []; self.getLeftTreeData = function () { var postData = { "tablename": "CODE_YPTYPE", "sql_data": "YPBH", "tablename_data": "SX_BGYPMGR" } $http.post(apiurljs.login + "g2app/richang/getTreeList", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.getMenuBtnList(res.data); self.treeData = res.data; setTimeout(function () { self.nowNodeCode = self.treeData[0].CODE; self.nowNodeName = self.treeData[0].CNAME; self.nowNodeID = self.treeData[0].ID; self.treeData[0].checked = true; self.getData(1); }) }) .error(function (XMLHttpRequest, textStatus, errorThrown) { self.treeData = []; }) } self.getLeftTreeData(); self.getMenuBtnList = function (data) { for (var item of data) { item.checked = false; if (sp.isval(item.C_H_I_L_D_DATA) && item.C_H_I_L_D_DATA.length > 0) { self.getMenuBtnList(item.C_H_I_L_D_DATA); } else { item.C_H_I_L_D_DATA = []; } } } self.nowNodeCode = ""; self.nowNodeName = ""; self.nowNodeID = ""; self.itemCheck = function ($item) { self.treeData.forEach(function (item) { if (item.ID == $item.ID) { $item.checked = !$item.checked; } else { item.checked = false; } if (item.C_H_I_L_D_DATA != "" && item.C_H_I_L_D_DATA != null && item.C_H_I_L_D_DATA != null) { item.C_H_I_L_D_DATA.forEach(function (item2) { if (item2.ID == $item.ID) { $item.checked = !$item.checked; } else { item2.checked = false; } if (item2.C_H_I_L_D_DATA != "" && item2.C_H_I_L_D_DATA != null && item2.C_H_I_L_D_DATA != null) { item2.C_H_I_L_D_DATA.forEach(function (item3) { if (item3.ID == $item.ID) { $item.checked = !$item.checked; } else { item3.checked = false; } if (item3.C_H_I_L_D_DATA != "" && item3.C_H_I_L_D_DATA != null && item3.C_H_I_L_D_DATA != null) { item3.C_H_I_L_D_DATA.forEach(function (item4) { if (item4.ID == $item.ID) { $item.checked = !$item.checked; } else { item4.checked = false; } if (item4.C_H_I_L_D_DATA != "" && item4.C_H_I_L_D_DATA != null && item4.C_H_I_L_D_DATA != null) { item4.C_H_I_L_D_DATA.forEach(function (item5) { if (item5.ID == $item.ID) { $item.checked = !$item.checked; } else { item5.checked = false; } if (item5.C_H_I_L_D_DATA != "" && item5.C_H_I_L_D_DATA != null && item5.C_H_I_L_D_DATA != null) { item5.C_H_I_L_D_DATA.forEach(function (item6) { if (item6.ID == $item.ID) { $item.checked = !$item.checked; } else { item6.checked = false; } if (item6.C_H_I_L_D_DATA != "" && item6.C_H_I_L_D_DATA != null && item6.C_H_I_L_D_DATA != null) { item6.C_H_I_L_D_DATA.forEach(function (item7) { if (item7.ID == $item.ID) { $item.checked = !$item.checked; } else { item7.checked = false; } }) } }) } }) } }) } }) } }) } }) if ($item.checked) { self.nowNodeCode = $item.CODE; self.nowNodeID = $item.ID; self.nowNodeName = $item.CNAME; self.getData(1); } else { self.nowNodeCode = self.treeData[0].CODE; self.nowNodeName = self.treeData[0].CNAME; self.nowNodeID = self.treeData[0].ID; self.treeData[0].checked = true; } } //根据选择的底稿目录获取当前目录下的文件 self.noDataTip = 1; self.rows = []; self.pageno = 1; self.total_count = 0; self.itemsPerPage = 10; self.pageOptions = [10, 15, 20, 25, 30]; self.search = { NAME: "" } self.getData = function (pageno) { self.pageno = pageno; $scope.__default__currentPage = self.pageno; let postData = { "pageno": self.pageno, "pagesize": self.itemsPerPage, "code": self.nowNodeCode, "data_col": "YPBH", "tablename_code": "CODE_YPTYPE", "tablename_data": "SX_BGYPMGR", "order": "id", "sqlwhere": {}, "sqllikewhere": { "YPMC": self.search.YPMC } } $http.post(apiurljs.login + "g2app/richang/queryFormDataBySqlWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (res) { var res = strToJson(s4.decryptData_CBC(res.data)); if (sp.isval(res.data)) { self.noDataTip = 1; self.rows = res.data; self.total_count = res.totalCount; } else { self.rows = []; self.noDataTip = 0; } self.sumTotal(); }).error(function (err) { sp.dialog(JSON.stringify(err)); }); } //删除底稿 self.itemDelete = function ($item) { let postData = { "pageno": 1, "pagesize": 1, "code": $item.CODE, "data_col": "YPBH", "tablename_code": "CODE_YPTYPE", "tablename_data": "SX_BGYPMGR", "order": "id", "sqlwhere": {}, "sqllikewhere": {} } $http.post(apiurljs.login + "g2app/richang/queryFormDataBySqlWithPage", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (res) { var res = strToJson(s4.decryptData_CBC(res.data)); var totalCount = res.totalCount; if (parseInt(totalCount) > 0) { //sp.dialog("当前分类下存在数据,无法删除"); } else { var getDelID = $item.CODE; var dialogHead = "温馨提示×"; var dialogBody = "
删除后不可恢复,您确认要删除吗?
"; var dialogFoot = "
"; $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot); sp.openCenter(".sp-dialog"); ///取消按钮 $('.sp-closeDialog').click(function (event) { sp.closeCenter(".sp-dialog"); event.preventDefault(); event.stopPropagation(); }); //post消息的id $("#delDataTrue").click(function () { var getid = $(this).attr("data-id"); sp.dialoghide(); var data = { "id": $item.ID, "tablename": "CODE_YPTYPE", "parentid": $item.PARENTID, "tablename_data": "SX_BGYPMGR" } //console.log(data); $http.post(apiurljs.login + "g2app/richang/delNode", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { sp.dialog("删除成功"); self.getLeftTreeData(); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) }); } }).error(function (err) { sp.dialog(JSON.stringify(err)); }); } self.selectedItem = { "level": "", "id": "", "layerTitle": "", "add": false, "name": "", "code": "", "child_title": "" } //添加目录树形非一级 self.itemAdd = function ($item) { self.selectedItem.layerTitle = "新增分类"; self.selectedItem.level = $item.LEVELS; self.selectedItem.id = $item.ID; self.selectedItem.add = true; self.selectedItem.name = $item.CNAME; self.selectedItem.code = $item.CODE; self.selectedItem.child_title = ""; sp.layer('#layer_box'); }; //修改目录 self.itemEdit = function ($item) { self.selectedItem.layerTitle = "编辑分类"; self.selectedItem.level = $item.LEVELS; self.selectedItem.id = $item.ID; self.selectedItem.add = false; self.selectedItem.name = $item.CNAME; self.selectedItem.code = $item.CODE; self.selectedItem.child_title = ""; sp.layer('#layer_box'); }; //弹出层-提交按钮事件 self.btnSetTitle = function () { if (!self.selectedItem.add) { if (spngvld.submit("#layer_box")) { let postData = { "id": self.selectedItem.id, "tablename": "CODE_YPTYPE", "setwhere": { "CNAME": self.selectedItem.name } } $http.post(apiurljs.login + "g2app/richang/setColumnsById", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { sp.closeCenter('.sp-layer'); var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.getLeftTreeData(); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } } else { if (spngvld.submit("#layer_box")) { let postData = { "tablename": "CODE_YPTYPE", "code": self.selectedItem.code, "levels": self.selectedItem.level, "cname": self.selectedItem.child_title } $http.post(apiurljs.login + "g2app/richang/TreeAdd", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { sp.closeCenter('.sp-layer'); var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.getLeftTreeData(); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } } } self.search = { YPMC: "", } //弹出筛选框 self.openSearchLayer = function () { sp.layer("#layer_search"); } self.doSearch = function () { sp.closeCenter('.sp-layer'); self.pageno = 1; // 初始化 当前页为 1 self.getData(self.pageno); } //新增数据 self.insertData = []; self.opneInsertLayer = function () { self.insertData = []; self.typeList = []; self.parseTreeJson(self.treeData); sp.layer('#layer_insert'); } self.addItemData = function () { self.insertData.push({ YPBH1: "", YPBH: self.typeList[0].CODE, PP: "", YPMC: "", FL: self.typeList[0].CODE, GG: "", DJ: 0, KC: 0, JDLW: "", BZ: "" }); } self.typeList = []; self.parseTreeJson = function (array) { for (let index = 0; index < array.length; index++) { const element = array[index]; // 1.判断element.children是对象 if (sp.isval(element.C_H_I_L_D_DATA) && element.C_H_I_L_D_DATA.length > 0) { self.parseTreeJson(element.C_H_I_L_D_DATA) } else { // 判断是否为子节点 if (element.LEAF == 1) { self.typeList.push(element); } } } } self.changeItem = function (index, code) { self.insertData[index].YPBH = code; } self.deleteItem = function (index) { self.insertData.splice(index, 1); } self.saveInsertData = function () { if (spngvld.submit("#layer_insert")) { var postData = { "tablename": "SX_BGYPMGR", "data": [] } self.insertData.forEach(function (item) { self.typeList.forEach(function (item2) { if (item.FL == item2.CODE) { item.FL = item2.CNAME; } }) if (item.KC != "" && item.KC != undefined && item.KC != null && item.KC != 0 && item.DJ != "" && item.DJ != undefined && item.DJ != null && item.DJ != 0) { item.JEHJ = item.KC * item.DJ; } else { item.JEHJ = 0; } if (item.KC != "" && item.KC != undefined && item.KC != null) { } else { item.KC = 0; } if (item.DJ != "" && item.DJ != undefined && item.DJ != null) { } else { item.DJ = 0; } }) self.insertData.forEach(function (item) { postData.data.push({ YPBH: item.YPBH, YPBH1: item.YPBH1, PP: item.PP, YPMC: item.YPMC, FL: item.FL, GG: item.GG, DJ: item.DJ, KC: item.KC, JDLW: item.JDLW, BZ: item.BZ, JEHJ: item.JEHJ }); }) $http.post(apiurljs.login + "g2app/dataabase/insertDataList", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { sp.closeCenter('.sp-layer'); var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.getData(1); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } } self.deleteData = function ($item) { var getDelID = $item.ID; var dialogHead = "温馨提示×"; var dialogBody = "
删除后不可恢复,您确认要删除吗?
"; var dialogFoot = "
"; $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot); sp.openCenter(".sp-dialog"); ///取消按钮 $('.sp-closeDialog').click(function (event) { sp.closeCenter(".sp-dialog"); event.preventDefault(); event.stopPropagation(); }); //post消息的id $("#delDataTrue").click(function () { var getid = $(this).attr("data-id"); sp.dialoghide(); var data = {"id": $item.ID, "tablename": "SX_BGYPMGR"} //console.log(data); $http.post(apiurljs.login + "g2app/richang/delDataById", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { sp.dialog("删除成功"); self.getData(1); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) }); } self.sumTotalNum = ""; self.sumTotal = function () { var data = { "tablename_code": "CODE_YPTYPE", "code": self.nowNodeCode, "tablename": "SX_BGYPMGR", "data_col": "YPBH", "hj_col": "KC" } $http.post(apiurljs.login + "g2app/richang/querybangonghj", {data: s4.encryptData_CBC(JSON.stringify(data))}, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.data != null && res.data != undefined && res.data != "") { self.sumTotalNum = res.data; } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } self.itemObj = { YPMC: "", PP: "", GG: "", KC: "", DJ: "", BZ: "", JDLW: "", ID: "" } self.itemDataEdit = function ($item) { self.itemObj.YPMC = $item.YPMC; self.itemObj.PP = $item.PP; self.itemObj.GG = $item.GG; self.itemObj.KC = parseInt($item.KC); self.itemObj.DJ = parseInt($item.DJ); self.itemObj.BZ = $item.BZ; self.itemObj.JDLW = $item.JDLW; self.itemObj.ID = $item.ID; sp.layer('#layer_edit'); }; self.editBtn = function () { if (spngvld.submit("#layer_edit")) { if (self.itemObj.KC != "" && self.itemObj.KC != undefined && self.itemObj.KC != null) { } else { self.itemObj.KC = 0; } if (self.itemObj.DJ != "" && self.itemObj.DJ != undefined && self.itemObj.DJ != null) { } else { self.itemObj.DJ = 0; } let JEHJNum=0; if (self.itemObj.KC != 0 && self.itemObj.DJ != 0) { JEHJNum = self.itemObj.DJ * self.itemObj.KC; } else { JEHJNum = 0; } var postData = { "entity": "SX_BGYPMGR", "data": { YPMC: self.itemObj.YPMC, PP: self.itemObj.PP, GG: self.itemObj.GG, KC: self.itemObj.KC, DJ: self.itemObj.DJ, BZ: self.itemObj.BZ, JDLW: self.itemObj.JDLW, JEHJ: JEHJNum }, "setwhere": " WHERE id=" + self.itemObj.ID + "" } $http.post(apiurljs.login + "g2app/dataabase/UpdataBySql", {data: s4.encryptData_CBC(JSON.stringify(postData))}, postCfg) .success(function (obj) { sp.closeCenter('.sp-layer'); var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.getData(1); } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { }) } else { } } }]) app.directive('treeView', [function () { return { restrict: 'EA', templateUrl: '/treeView.html', scope: { treeData: '=',///声明数据 textField: '@', itemAdd: '&', ///声明新增变量 itemEdit: '&',///声明修改变量 itemCheck: '&',///声明修改变量 itemDelete: '&',///声明修改变量 itemUp: '&', itemDown: '&' }, controller: ['$scope', function ($scope) { $scope.itemExpended = function (item, $event) { item.$$isExpend = !item.$$isExpend; $event.stopPropagation(); }; ///展开折叠图标设置 $scope.getItemIcon = function (item) { var isEnd = $scope.isEnd(item); if (isEnd) { return 'fa fa-paper-plane-o'; } return item.$$isExpend ? 'fa fa-plus-square-o' : 'fa fa-minus-square-o'; }; ///判断是否是最后一级菜单 $scope.isEnd = function (item) { return !item.C_H_I_L_D_DATA || !item.C_H_I_L_D_DATA.length; }; ///事件调用返回 $scope.warpCallback = function (callback, item, $event) { ($scope[callback] || angular.noop)({ $item: item, $event: $event }); }; }] }; }]);