123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940 |
- app.controller("inspectionScope", [
- "$rootScope",
- "$scope",
- "$state",
- "$timeout",
- "$interval",
- "SweetAlert",
- "$modal",
- "Restangular",
- "api_bpm_data",
- "api_solution",
- "api_user_data",
- "api_wechatfile",
- "api_sysinfo",
- "api_statistic",
- "api_bpm",
- "jry_api_bpm",
- "api_simple",
- function (
- $rootScope,
- $scope,
- $state,
- $timeout,
- $interval,
- SweetAlert,
- $modal,
- Restangular,
- api_bpm_data,
- api_solution,
- api_user_data,
- api_wechatfile,
- api_sysinfo,
- api_statistic,
- api_bpm,
- jry_api_bpm,
- api_simple
- ) {
- var loginUser = $rootScope.user;
- $scope.stateModel = JSON.parse($state.params.model);
- console.log($scope.stateModel);
- if ($scope.stateModel.model == 1) {
- $scope.modelName = $scope.stateModel.modelName;
- } else {
- $scope.stateModel.model = 0;
- $scope.modelName = $scope.stateModel.title;
- }
- $scope.xinzeng = false;
- $scope.shanchu = false;
- $scope.bianji = false;
- for (var i = 0; i < loginUser.menu.length; i++) {
- if (loginUser.menu[i].link == "shijianshezhi_xinzeng") {
- $scope.xinzeng = true;
- }
- if (loginUser.menu[i].link == "shijianshezhi_shanchu") {
- $scope.shanchu = true;
- }
- if (loginUser.menu[i].link == "shijianshezhi_bianji") {
- $scope.bianji = true;
- }
- }
- $scope.listDataTop = [];
- $scope.listDataBottom = [];
- $scope.leftListIdx = -1;
- $scope.leftListName = "巡检范围";
- $scope.leftListCli = function (idx, data) {
- $scope.leftListIdx = idx;
- $scope.stateModel = data;
- $scope.modelName = data.modelName;
- $scope.copyInspection.tree = [];
- $scope.selectedInspection.isShowZtree = false;
- setTimeout(() => {
- $scope.selectedInspection.isShowZtree = true;
- }, 0);
- };
- // 事件分类开始
- var loginUser = $rootScope.user;
- //组
- api_user_data
- .fetchDataList("group", { idx: 0, sum: 1000 })
- .then(function (data) {
- $scope.group = data.list;
- });
- api_wechatfile
- .getDictionary({ key: "incident_priority", type: "list" })
- .then(function (data) {
- $scope.priority = data;
- });
- /* ----- tree----- */
- var i = 0;
- $scope.out = [];
- $scope.outdata = [];
- $scope.subdata = {};
- $scope.sub1data = {};
- $scope.addcate = false;
- $scope.add1cate = false;
- $scope.changecate = false;
- $scope.filterTree = function (data, id) {
- data = angular.copy(data);
- var newTree = data.filter((x) => x.id !== id);
- newTree.forEach(
- (x) => x.children && (x.children = $scope.filterTree(x.children, id))
- );
- return newTree;
- };
- $scope.userOrGroupType = {}; //当前节点运维组/运维人员
- $scope.dataSave = []; //储存$scope.tree_data
- $scope.group_user = {
- // offlineGroup:{},//线下组
- // onlineUser:{}//线上人
- };
- $scope.selectedInspection = {
- tree: {},
- isShowZtree: true,
- };
- $scope.copyInspection = {
- tree: [],
- };
- $scope.timerZtree = null;
- $scope.timerZtreeCopy = null;
- // 新增
- $scope.addType1 = function (type) {
- console.log();
- // ===============================================
- var modalInstance = $modal.open({
- templateUrl: "assets/views/system/tpl/inspectionchange.html",
- controller: function ($scope, scope, $modalInstance) {
- $scope.add1data = {};
- $scope.thisParent = {}; //当前点击节点的父节点
- $scope.filterTree = function (data, id) {
- data = angular.copy(data);
- var newTree = data.filter((x) => x.id !== id);
- newTree.forEach(
- (x) =>
- x.children && (x.children = $scope.filterTree(x.children, id))
- );
- return newTree;
- };
- $scope.try_async_1load = function () {
- $scope.my_1data = [];
- var data = { idx: 0, sum: 1000, inspectionType: { deleteFlag: 0 } };
- api_bpm_data
- .fetchDataList("inspectionType", data)
- .then(function (response) {
- var data = response.list;
- data = data.filter((v) => !v.parent); //只显示一级
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- var object = {};
- object.id = data[i].id;
- if (angular.isDefined(data[i].user)) {
- object.user = data[i].user || {};
- }
- if (angular.isDefined(data[i].group)) {
- object.group = data[i].group || {};
- }
- if (angular.isDefined(data[i].parent)) {
- object.parent = data[i].parent;
- }
- object.label = data[i].type;
- objects.push(object);
- }
- $scope.my_1data = convertParentToChildList(objects);
- $scope.tree_1data = angular.copy($scope.my_1data);
- // 把选中的巡检范围当作父类回显
- if (scope.selectedInspection.tree.id) {
- // 区分新增和修改
- if (type == "add") {
- $scope.thisParent = data.find(
- (v) => v.id == scope.selectedInspection.tree.id
- );
- if ($scope.thisParent) {
- $scope.thisParent.label = $scope.thisParent.type;
- $scope.thisParent.isExpanded = true;
- $scope.thisParent.selected = true;
- $scope.addparent = true;
- } else {
- $scope.addparent = false;
- }
- } else if (type == "edit") {
- // 编辑
- console.log($scope.my_1data, "原始数据");
- $scope.tree_1data = $scope.my_1data.filter(
- (v) => v.id != scope.selectedInspection.tree.id
- ); //过滤本条
- $scope.thisParent = data.find(
- (v) => v.id == scope.selectedInspection.tree.pId
- );
- if ($scope.thisParent) {
- $scope.thisParent.label = $scope.thisParent.type;
- $scope.thisParent.isExpanded = true;
- $scope.thisParent.selected = true;
- $scope.addparent = true;
- } else {
- $scope.addparent = false;
- }
- $scope.add1data.type = scope.selectedInspection.tree.name;
- $scope.add1data.id = scope.selectedInspection.tree.id;
- }
- } else {
- $scope.addparent = false;
- }
- });
- };
- $scope.try_async_1load();
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
- var root = null; //Initially set our loop to null
- //loop over data
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- //each node will have children, so let's give it a "children" poperty
- datum.children = [];
- //add an entry for this node to the map so that any future children can
- //lookup the parent
- idToNodeMap[datum.id] = datum;
- //Does this node have a parent?
- // console.log("datum="+JSON.stringify(datum))
- if (typeof datum.parent === "undefined") {
- //Doesn't look like it, so this node is the root of the tree
- root = datum;
- treeMap[datum.id] = root;
- } else {
- //This node has a parent, so let's look it up using the id
- parentNode = idToNodeMap[datum.parent.id];
- //We don't need this property, so let's delete it.
- // delete datum.parent;
- //Let's add the current node as a child of the parent node.
- parentNode.children.push(datum);
- }
- }
- return root;
- }
- function convertParentToChildList(data) {
- var treeMap = {};
- var list = [];
- convertListToTree(data, treeMap);
- angular.forEach(treeMap, function (item) {
- list.push(item);
- });
- return list;
- }
- // ------------------------------------------------
- $scope.title = type == "add" ? "巡检范围新增" : "巡检范围修改";
- $scope.cancel = function () {
- $modalInstance.dismiss("cancel");
- };
- $scope.savercode = function (data) {
- if (data && data.type) {
- if ($scope.addparent) {
- data.parent = $scope.add1data.parent;
- } else {
- data.parent = null;
- }
- scope.selectedInspection.tree = {};
- $modalInstance.close(data);
- } else {
- SweetAlert.swal(
- {
- title: "新增失败!",
- text: "请填写必填项!",
- type: "error",
- confirmButtonColor: "#DD6B55",
- },
- function () {}
- );
- }
- };
- },
- resolve: {
- scope: function () {
- return $scope;
- },
- },
- });
- // liaomingming
- modalInstance.result.then(function (selectedItem) {
- console.log($scope);
- if (selectedItem.type) {
- selectedItem.deleteFlag = 0;
- selectedItem.formUiName = "inspection_LinHu_detail";
- selectedItem.formUiEdit = "inspection_LinHu_confirm";
- selectedItem.processKey = "bpm_inspection";
- var filedata = { inspectionType: selectedItem };
- console.log(filedata);
- // return;
- api_bpm_data[type == "add" ? "addData" : "updData"](
- "inspectionType",
- filedata
- ).then(function (response) {
- if (response) {
- if (response.status == 200) {
- $scope.selectedInspection.isShowZtree = false;
- setTimeout(() => {
- $scope.selectedInspection.isShowZtree = true;
- }, 0);
- SweetAlert.swal({
- title: type == "add" ? "增加成功!" : "修改成功!",
- type: "success",
- });
- } else {
- SweetAlert.swal({
- title: type == "add" ? "增加失败!" : "修改失败!",
- type: "error",
- });
- }
- }
- });
- } else {
- SweetAlert.swal(
- {
- title: "新增失败!",
- text: "请填写必填项!",
- type: "error",
- confirmButtonColor: "#DD6B55",
- },
- function () {}
- );
- }
- });
- };
- /* -----start remove incidet category----- */
- // 删除
- $scope.remove1 = function () {
- var modalInstance = $modal.open({
- templateUrl: "assets/views/delete.html",
- controller: function ($scope, scope, $modalInstance, api_bpm_data) {
- $scope.title = "巡检范围删除?";
- $scope.connect = "确定要删除此巡检范围?";
- $scope.ok = function () {
- $modalInstance.close(scope.selectedInspection.tree);
- };
- $scope.cancel = function () {
- $modalInstance.dismiss("cancel");
- };
- },
- size: "sm",
- resolve: {
- scope: function () {
- return $scope;
- },
- },
- });
- modalInstance.result.then(function (selectedItem) {
- if (selectedItem) {
- var rmvList = [];
- rmvList.push(selectedItem.id);
- if (selectedItem.children && selectedItem.children.length > 0) {
- SweetAlert.swal({
- title: "删除失败!",
- text: "请先删除选中的范围的子级",
- type: "error",
- });
- } else {
- api_bpm_data
- .rmvData("inspectionType", rmvList)
- .then(function (response) {
- if (response.data) {
- SweetAlert.swal(
- {
- title: "删除成功!",
- type: "success",
- confirmButtonColor: "#007AFF",
- },
- function () {
- $scope.selectedInspection.isShowZtree = false;
- setTimeout(() => {
- $scope.selectedInspection.isShowZtree = true;
- }, 0);
- }
- );
- } else {
- SweetAlert.swal({
- title: "操作异常!",
- text: "系统异常,请稍后重试,或者联系管理员!",
- type: "error",
- });
- }
- });
- }
- }
- });
- };
- /* -----end remove incidet category----- */
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
- var root = null; //Initially set our loop to null
- //loop over data
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- //each node will have children, so let's give it a "children" poperty
- datum.children = [];
- //add an entry for this node to the map so that any future children can
- //lookup the parent
- idToNodeMap[datum.id] = datum;
- //Does this node have a parent?
- // console.log("datum="+JSON.stringify(datum))
- if (typeof datum.parent === "undefined") {
- //Doesn't look like it, so this node is the root of the tree
- root = datum;
- treeMap[datum.id] = root;
- } else {
- //This node has a parent, so let's look it up using the id
- parentNode = idToNodeMap[datum.parent.id];
- //We don't need this property, so let's delete it.
- // delete datum.parent;
- //Let's add the current node as a child of the parent node.
- parentNode.children.push(datum);
- }
- }
- return root;
- }
- function convertParentToChildList(data) {
- var treeMap = {};
- var list = [];
- convertListToTree(data, treeMap);
- angular.forEach(treeMap, function (item) {
- list.push(item);
- });
- return list;
- }
- $scope.closethis = function (formdata) {
- formdata.category = "";
- formdata.parent.category = "";
- };
- /* -----start submit incidet category----- */
- // 保存设置
- $scope.selectedchangecategory = { value: {} };
- $scope.$watch("selectedchangecategory.value", function (newVal) {
- console.log(newVal);
- if (newVal.user) {
- $scope.group_user["onlineUser"] = newVal.user || undefined;
- } else {
- $scope.group_user["onlineUser"] = undefined;
- }
- if (newVal.group) {
- $scope.group_user["offlineGroup"] = newVal.group || undefined;
- } else {
- $scope.group_user["offlineGroup"] = undefined;
- }
- });
- $scope.editInspection = function (tree, id, newVal, type) {
- tree.forEach((v) => {
- if (v.id == id) {
- v[type] = newVal;
- } else if (v.children) {
- $scope.editInspection(v.children, id, newVal, type);
- }
- });
- };
- $scope.$watch("group_user.offlineGroup", function (newVal) {
- console.log($scope.selectedchangecategory.value);
- console.log($scope.copyInspection.tree);
- console.log(newVal, "group");
- $scope.editInspection(
- $scope.copyInspection.tree,
- $scope.selectedchangecategory.value.id,
- newVal,
- "group"
- );
- if (newVal && newVal.id) {
- $scope.selectedchangecategory.value.group = newVal;
- } else {
- delete $scope.selectedchangecategory.value.group;
- }
- });
- $scope.$watch("group_user.onlineUser", function (newVal) {
- // console.log($scope.selectedchangecategory.value)
- // console.log($scope.copyInspection.tree)
- // console.log(newVal, 'user')
- $scope.editInspection(
- $scope.copyInspection.tree,
- $scope.selectedchangecategory.value.id,
- newVal,
- "user"
- );
- if (newVal && newVal.id) {
- $scope.selectedchangecategory.value.user = newVal;
- } else {
- delete $scope.selectedchangecategory.value.user;
- }
- });
- // 保存设置 liaomingming
- $scope.submit1change = function () {
- console.log($scope.copyInspection.tree);
- console.log($scope.stateModel);
- if ($scope.stateModel.model === 0) {
- // 不设置为模块的时候需要弹窗提示
- var modalInstance = $modal.open({
- templateUrl: "assets/views/system/tpl/inspectionModel.html",
- controller: function ($scope, scope, $modalInstance) {
- $scope.add1data = { model: false };
- $scope.title = "提示";
- $scope.cancel = function () {
- $modalInstance.dismiss("cancel");
- };
- $scope.savercode = function (data) {
- console.log(scope.copyInspection.tree);
- scope.stateModel.model = data.model ? 1 : 0;
- scope.saveCommon(scope);
- $modalInstance.close(data);
- };
- },
- resolve: {
- scope: function () {
- return $scope;
- },
- },
- });
- modalInstance.result.then(function (selectedItem) {});
- return;
- }
- $scope.saveCommon($scope);
- };
- $scope.closeModel = function () {
- $state.go("app.inspection.inspectPlan"); //跳转巡检计划列表
- };
- $scope.TreeToArr = function (tree, arr) {
- tree.forEach((v) => {
- if (v.children) {
- arr.push(v);
- $scope.TreeToArr(v.children, arr);
- } else {
- arr.push(v);
- }
- });
- return arr;
- };
- $scope.saveCommon = function ($scope) {
- if (!$scope.modelName.trim()) {
- SweetAlert.swal({
- title: "策略名称不能为空!",
- type: "error",
- });
- return;
- }
- var arr = $scope.TreeToArr($scope.copyInspection.tree, []);
- $scope.stateModel.modelName = $scope.modelName;
- $scope.stateModel.typeIds = arr.map((v) => v.id).toString();
- arr = arr.map((v) => ({
- inspection: $scope.stateModel,
- inspectionType: v.id,
- parent: v.parent,
- user: v.user,
- group: v.group,
- }));
- // 一条都没选择
- if (arr.length === 0) {
- arr.push({ inspection: $scope.stateModel });
- }
- console.log(arr);
- // return;
- api_simple.addListData("inspectionBind", arr).then(function (response) {
- if (response) {
- if (response.status == 200) {
- $scope.stateModel.status = { id: 120 }; //强制扭转状态为正常
- var filedata = {
- close: "关闭",
- save: "暂存",
- submit: "下一步",
- inspection: $scope.stateModel,
- };
- api_bpm_data
- .addData("inspection", filedata)
- .then(function (response) {
- if (response) {
- if (response.status == 200) {
- SweetAlert.swal(
- {
- title: "保存成功!",
- type: "success",
- },
- function () {
- // $scope.selectedchangecategory.value = {};
- // $scope.copyInspection.tree = [];
- // $scope.changecateObj.changecate = false;
- // $scope.selectedInspection.isShowZtree = false;
- // setTimeout(()=>{
- // $scope.selectedInspection.isShowZtree = true;
- // },0)
- $state.go("app.inspection.inspectPlan"); //跳转巡检计划列表
- }
- );
- } else {
- SweetAlert.swal({
- title: "保存失败!",
- type: "error",
- });
- }
- }
- });
- } else {
- SweetAlert.swal({
- title: "保存失败!",
- type: "error",
- });
- }
- }
- });
- };
- $scope.add1data = {};
- $scope.addparent = false;
- // 事件分类结束
- // 获取组数据
- $scope.getGroupList = function () {
- var postData = {
- idx: 0,
- sum: 1000,
- group: { selectType: "nouser" },
- };
- api_user_data.fetchDataList("group", postData).then((res) => {
- $scope.groupList = res.list;
- });
- };
- $scope.getGroupList();
- // 获取巡检计划数据
- $scope.getGroupList = function (model) {
- var postData = {
- idx: 0,
- sum: 3,
- inspection: { model: model },
- };
- api_user_data.fetchDataList("inspection", postData).then((res) => {
- if (model == 1) {
- $scope.listDataTop = res.list; //巡检范围策略模板
- } else {
- $scope.listDataBottom = res.list; //往期巡检范围策略
- }
- });
- };
- $scope.getGroupList(1);
- $scope.getGroupList();
- // 获取人数据
- $scope.getUserList = function () {
- var postData = {
- idx: 0,
- sum: 1000,
- user: {
- name: "",
- selectType: "pinyin_qs",
- },
- };
- api_user_data.fetchDataList("user", postData).then((res) => {
- $scope.userList = res.list;
- });
- };
- $scope.getUserList();
- $scope.changecateObj = {
- changecate: false,
- };
- // 缓存的绑定数据-http
- $scope.cacheHttp = {
- value: [],
- };
- },
- ]);
- app.directive("zTree", function () {
- // ztree liaomingming
- return {
- restrict: "EA",
- scope: {
- selectInspectionType: "=",
- copyInspectionType: "=",
- stateModel: "=",
- changecate: "=",
- cachehttp: "=",
- },
- controller: function ($scope, $element, api_bpm_data, api_simple) {
- console.log($scope);
- getTreeInfo();
- function getTreeInfo() {
- $scope.treeInfo = [];
- var data = { idx: 0, sum: 1000, inspectionType: { deleteFlag: 0 } };
- $scope.isShowZtree = false;
- api_bpm_data
- .fetchDataList("inspectionType", data)
- .then(function (response) {
- var data = response.list;
- console.log(data);
- var objects = [];
- for (var i = 0; i < data.length; i++) {
- var object = {};
- object.id = data[i].id;
- if (angular.isDefined(data[i].user)) {
- object.user = data[i].user || {};
- }
- if (angular.isDefined(data[i].group)) {
- object.group = data[i].group || {};
- }
- if (angular.isDefined(data[i].parent)) {
- object.parent = data[i].parent;
- object.pId = data[i].parent.id;
- } else {
- object.pId = 0;
- }
- object.name = data[i].type;
- objects.push(object);
- }
- $scope.treeInfo = convertParentToChildList(objects);
- $scope.treeInfo = deleteEmputyChildren($scope.treeInfo);
- console.log($scope.treeInfo);
- // ==================start================
- api_simple
- .fetchDataList("inspectionBind", {
- idx: 0,
- sum: 1000,
- inspectionBind: { inspection: { id: $scope.stateModel.id } },
- })
- .then(function (response) {
- $.fn.zTree.destroy("z-tree");
- $.fn.zTree.init($($element), setting, $scope.treeInfo);
- $scope.isShowZtree = true;
- var result = response.list || [];
- $scope.cachehttp = angular.copy(result);
- result = result.map((v) => v.inspectionType);
- console.log(result);
- result.forEach((v, i) => {
- // 设置路径树节点选中
- // 1、根据id获取树的某个节点:
- var zTree = $.fn.zTree.getZTreeObj("z-tree");
- var node = zTree.getNodeByParam("id", v);
- // 2、设置node节点选中状态:
- zTree.selectNode(node);
- // 3、设置node节点checked选中:
- node.checked = true;
- //注:设置checked属性之后,一定要更新该节点
- zTree.updateNode(node);
- // 展开
- zTree.expandNode(node);
- setTimeout(() => {
- zTreeOnCheck(null, null, node);
- }, 0);
- });
- });
- // ==================end================
- });
- }
- function deleteEmputyChildren(data) {
- data.forEach((v) => {
- if (v.children.length) {
- deleteEmputyChildren(v.children);
- } else {
- delete v.children;
- }
- });
- return data;
- }
- function convertParentToChildList(data) {
- var treeMap = {};
- var list = [];
- convertListToTree(data, treeMap);
- angular.forEach(treeMap, function (item) {
- list.push(item);
- });
- return list;
- }
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
- var root = null; //Initially set our loop to null
- //loop over data
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- //each node will have children, so let's give it a "children" poperty
- datum.children = [];
- //add an entry for this node to the map so that any future children can
- //lookup the parent
- idToNodeMap[datum.id] = datum;
- //Does this node have a parent?
- // console.log("datum="+JSON.stringify(datum))
- // if (typeof datum.parent === "undefined") {
- if (datum.pId === 0) {
- //Doesn't look like it, so this node is the root of the tree
- root = datum;
- treeMap[datum.id] = root;
- } else {
- //This node has a parent, so let's look it up using the id
- // parentNode = idToNodeMap[datum.parent.id];
- parentNode = idToNodeMap[datum.pId];
- //We don't need this property, so let's delete it.
- // delete datum.parent;
- //Let's add the current node as a child of the parent node.
- parentNode.children.push(datum);
- }
- }
- return root;
- }
- var setting = {
- check: {
- enable: true,
- chkStyle: "checkbox",
- chkboxType: { Y: "ps", N: "ps" },
- },
- callback: {
- onClick: onMouseDown,
- onCheck: zTreeOnCheck,
- },
- view: {
- showIcon: false,
- showLine: false,
- },
- };
- // $.fn.zTree.init($($element), setting, $scope.treeInfo);
- //点击菜单项
- function onMouseDown(event, treeId, treeNode) {
- console.log(event, treeId, treeNode);
- $scope.selectInspectionType = treeNode;
- }
- // 点击复选框
- function zTreeOnCheck(event, treeId, treeNode) {
- console.log(event, treeId, treeNode);
- $scope.changecate = false;
- var treeObj = $.fn.zTree.getZTreeObj("z-tree");
- var nodes_arr = treeObj.getCheckedNodes(true);
- var nodes = angular.copy(nodes_arr);
- console.log(nodes);
- var arr = nodes.filter((v) => v.pId === 0);
- arr.forEach((v) => {
- v.children = [];
- });
- arr.forEach((v, i) => {
- nodes.forEach((vv) => {
- if (vv.pId == v.id) {
- arr[i].children.push(vv);
- }
- });
- });
- if ($scope.cachehttp && $scope.cachehttp.length) {
- var result = angular.copy($scope.cachehttp);
- zTreeOnCheckCommon(result, nodes);
- } else {
- api_simple
- .fetchDataList("inspectionBind", {
- idx: 0,
- sum: 1000,
- inspectionBind: { inspection: { id: $scope.stateModel.id } },
- })
- .then(function (response) {
- var result = response.list || [];
- zTreeOnCheckCommon(result, nodes);
- });
- }
- }
- // 点击复选框-common
- function zTreeOnCheckCommon(result, nodes) {
- result = result.map((v) => ({
- id: v.inspectionType,
- name: v.inspectionTypeName,
- group: v.group,
- user: v.user,
- parent: v.parent ? { id: v.parent.inspectionType } : undefined,
- pId: v.parent ? v.parent.inspectionType : 0,
- }));
- for (var i = 0; i < nodes.length; i++) {
- for (var j = 0; j < result.length; j++) {
- if (nodes[i].id == result[j].id) {
- nodes[i] = angular.copy(result[j]);
- }
- }
- }
- var arr = nodes.filter((v) => v.pId === 0);
- arr.forEach((v) => {
- v.children = [];
- });
- arr.forEach((v, i) => {
- nodes.forEach((vv) => {
- if (vv.pId == v.id) {
- arr[i].children.push(vv);
- }
- });
- });
- console.log(arr);
- $scope.copyInspectionType = arr;
- }
- },
- };
- });
- app.directive("zTreeCopy", function () {
- // ztree liaomingming
- return {
- restrict: "EA",
- scope: {
- copyInspectionType: "=",
- changecate: "=",
- selectedchangecategory: "=",
- },
- link: function (scope, element, attrs) {
- scope.$watch("copyInspectionType", function (newVal) {
- console.log(newVal);
- var setting = {
- view: {
- showIcon: false,
- showLine: false,
- },
- callback: {
- onClick: onMouseDown,
- },
- };
- $.fn.zTree.destroy("z-tree-copy");
- var treeObj = $.fn.zTree.init($(element), setting, newVal);
- treeObj.expandAll(true);
- });
- //点击菜单项
- function onMouseDown(event, treeId, treeNode) {
- console.log(event, treeId, treeNode);
- scope.selectedchangecategory = treeNode;
- scope.changecate = true;
- console.log(scope.copyInspectionType);
- }
- },
- controller: function ($scope, $element, api_bpm_data) {},
- };
- });
|