123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657 |
- 'use strict';
- app.controller('newOrderCtrl', ["$scope", "$http", "i18nService", "$rootScope", "$state", "$timeout", "moment", "$interval", "$modal", "$stateParams", "SweetAlert", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_bpm_domain", "api_text", "api_bpm_data", "api_user_data", "api_configure_data", '$parse', "$injector", "$aside", 'toaster', "api_configure_form", "api_cmdb", 'api_bpm', 'api_wechatfile', 'jry_api_bpm', 'api_zsk', function ($scope, $http, i18nService, $rootScope, $state, $timeout, moment, $interval, $modal, $stateParams, SweetAlert, uiGridConstants, uiGridGroupingConstants, Restangular, api_bpm_domain, api_text, api_bpm_data, api_user_data, api_configure_data, $parse, $injector, $aside, toaster, api_configure_form, api_cmdb, api_bpm, api_wechatfile, jry_api_bpm, api_zsk) {
- $scope.langs = i18nService.getAllLangs();
- $scope.lang = 'zh-cn';
- i18nService.setCurrentLang($scope.lang);
- var loginUser = $rootScope.user;
- console.log(loginUser);
- var loginuserGroup = "";
- for (var i = 0; i < $rootScope.user.group.length; i++) {
- if (i == 0) {
- loginuserGroup = $rootScope.user.group[i].id;
- } else {
- loginuserGroup = loginuserGroup + "," + $rootScope.user.group[i].id;
- }
- }
- $scope.transferTime = function (time) {
- return moment(time).format('YYYY-MM-DD HH:mm');
- }
- //事件列表数据存储
- $scope.incidentModel = {
- department: ''
- }
- // 报修科室
- $scope.getDept = function (key) {
- var postData = {
- "idx": 0,
- "sum": 10
- }
- if (key) {
- postData.department = {
- dept: key
- }
- }
- api_user_data.fetchDataList('department', postData).then(function (response) {
- if (response) {
- if (response.status = 200) {
- $scope.department = response.list;
- }
- }
- })
- }
- $scope.getDept();
- //报修科室过滤
- $scope.onChangeDept = function (key) {
- $scope.getDept(key)
- }
- // console.log(items);
- $scope.jry_modelRight = "";
- $scope.jry_modelLeft = "";
- $scope.jry_incidentDescription = "";
- $scope.left_searchData = [];
- $scope.openModels = false
- $scope.right_serch = function () {
- $scope.toGetData.incidentdescribe["describes"] = $scope.jry_modelRight;
- api_zsk.solutionData($scope.toGetData, 'solution').then(function (res1) {
- if (res1.status == 200) {
- $scope.jry_scricData = res1.list;
- for (var i = 0; i < $scope.jry_scricData.length; i++) {
- $scope.jry_scricData[i]["item"] = i + 1
- }
- }
- })
- }
- $scope.left_serch = function () {
- $scope.try_async_load($scope.jry_modelLeft)
- return
- $scope.indexBG = "";
- var fifdata = {
- "idx": 0,
- "sum": 1000,
- "incidentcategory": {
- "category": $scope.jry_modelLeft
- }
- }
- // $scope.toGetData.incidentdescribe["category"]=$scope.jry_modelLeft;
- jry_api_bpm.jry_getFetchDataList(fifdata, "incidentcategory").then(function (response) {
- if (response.status == 200) {
- $scope.left_searchData = response.list;
- console.log($scope.left_searchData)
- }
- })
- }
- $scope.indexBG = "";
- $scope.leftSearchGetData = function (index, data) {
- // console.log(data);
- $scope.indexBG = index;
- $scope.treeId = data.id;
- $scope.toGetData.incidentdescribe["categoryid"] = {
- id: $scope.treeId
- };
- api_zsk.solutionData($scope.toGetData, 'solution').then(function (res) {
- $scope.jry_scricData = res.list;
- for (var i = 0; i < $scope.jry_scricData.length; i++) {
- $scope.jry_scricData[i]["item"] = i + 1
- }
- })
- }
- $scope.toFormData = "";
- // 右侧选项点击
- $scope.getFormItem = function (res) {
- // console.log(res);
- $scope.toFormData = res;
- if ($scope.jry_incidentDescription) {
- var modalInstance = $modal.open({
- templateUrl: 'assets/views/delete.html',
- controller: function ($scope, scope, $modalInstance, api_bpm_data) {
- var rmvList = [];
- $scope.title = '追加故障描述';
- $scope.connect = '是否要追加故障描述?';
- $scope.ok = function () {
- scope.jry_incidentDescription = scope.jry_incidentDescription + scope.toFormData.describes;
- $modalInstance.dismiss('cancel');
- };
- $scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- };
- },
- size: 'sm',
- resolve: {
- scope: function () {
- return $scope;
- }
- }
- });
- } else {
- $scope.jry_incidentDescription = $scope.toFormData.describes;
- }
- }
- //组
- api_user_data.fetchDataList('group', {
- "idx": 0,
- "sum": 1000
- }).then(function (data) {
- $scope.group = data.list;
- });
- /* ----- tree----- */
- var apple_selected, tree, treedata_avm, treedata_geography;
- //$scope.selectedTreeNode = {};ssss
- var i = 0;
- $scope.out = [];
- $scope.outdata = [];
- var systemtype = [];
- $scope.addcate = false;
- $scope.changecate = false;
- var childdata = {};
- $scope.jry_scricData = [];
- $scope.toGetData = {
- "idx": 0,
- "sum": 1000,
- "incidentdescribe": {}
- }
- $scope.treeId = "";
- $scope.my_tree_handler = function (branch) {
- $scope.treeId = branch.id;
- $scope.toGetData.incidentdescribe["categoryid"] = {
- id: $scope.treeId
- };
- api_zsk.solutionData($scope.toGetData, 'solution').then(function (res) {
- $scope.jry_scricData = res.list;
- for (var i = 0; i < $scope.jry_scricData.length; i++) {
- $scope.jry_scricData[i]["item"] = i + 1
- }
- })
- };
- function convertListToTree(data, treeMap) {
- var idToNodeMap = {};
- var root = null;
- var parentNode;
- for (var i = 0; i < data.length; i++) {
- var datum = data[i];
- datum.children = [];
- idToNodeMap[datum.id] = datum;
- if (typeof datum.parent === "undefined") {
- root = datum;
- treeMap[datum.id] = root;
- } else {
- parentNode = idToNodeMap[datum.parent.id];
- 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;
- }
- function transform(nodes) {
- var treeConverter = {
- result: null, //转化后的结果,是根节点,所有节点都是从根节点长出来的
- attributeName: 'id', //节点唯一标识符
- needFind: true, //是否查询节点在result中已经存在,为了优化效率
- transform: function (node) { //转化递归函数,参数:一个待插入节点
- if (node.parent != null) { //该节点有父节点
- var newNode = this.transform(node.parent); //递归进入,返回值为一个节点,用作父节点,该父节点必然存在于result中,这点由下面的算法可以控制
- if (this.needFind) {
- for (var i = 0; i < newNode.children.length; i++) { //查找要插入的node子节点是否在newNode这个父节点中存在
- if (newNode.children[i][this.attributeName] === node[this.attributeName]) {
- return newNode.children[i]; //存在的话直接返回newNode父节点内的该子节点,该子节点必然存在于result中,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
- }
- }
- }
- this.needFind = false; //不存在的话,关闭之后递归的循环判断,因为待插入node节点不存在于result中,故而它的子节点一定不存在于result中,不用再循环判断
- delete node.parent; //删除该节点的parent属性,如果有的话
- node.children = []; //因为确定是要新插入的节点,没有children:[]属性,故给该节点增加children:[]属性
- node.state = {
- "opened": true
- };
- node.typeName = "type";
- node.label =node.category;
- newNode.children.push(node); //将该node节点push进newNode的子节点数组中
- return node; //return该新插入节点,作为递归返回值给上层,用作newNode父节点,node存在于result中故newNode存在于result中
- } else if (node.parent == null) { //该叶节点没有父节点,即为根节点
- delete node.parent; //删除该节点的parent属性,如果有的话
- if (this.result == null) { //根节点不存在
- node.children = []; //给该节点增加children:[]属性
- node.state = {
- "opened": true
- };
- node.typeName = "type";
- node.label =node.category;
- return this.result = node; //该节点赋给result,并return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
- } else {
- node.children = [];
- node.state = {
- "opened": true
- };
- node.typeName = "type";
- node.label =node.category;
- // 顶级去重
- for (var i = 0; i < this.result.children.length; i++) {
- if (this.result.children[i][this.attributeName] === node[this.attributeName]) {
- return this.result.children[i];
- }
- }
- this.result.children.push(node)
- return node // 直接return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
- }
- }
- },
- getWhole: function (nodes, attributeName) { //传入整个叶子节点数组,attributeName作为节点唯一标识符属性,返回整个转化结果
- var _node = {};
- _node.children = [];
- this.result = _node; //重置根节点
- this.attributeName = attributeName == null ? 'id' : attributeName; //唯一标识符默认为“id”
- nodes = JSON.parse(JSON.stringify(nodes)); //复制出一个新的节点对象作为参数,保证不改变原有数据
- nodes.forEach(item => { //循环调用转化方法
- this.needFind = true; //重置开启节点是否已存在判断,保证不插入重复节点
- this.transform(item);
- })
- return this.result; //返回根节点
- }
- }
- var result = treeConverter.getWhole(nodes); //调用
- return result;
- }
- $scope.try_async_load = function (key) {
- $scope.my_data = [];
- $scope.doing_async = true;
- var data = {
- "idx": 0,
- "sum": 1000
- };
- if (key) {
- data.incidentcategory = {
- category: key
- }
- }
- api_bpm_data.fetchDataList('incidentcategory', data).then(function (response) {
- var data = response.list;
- var objects = [];
- // for (var i = 0; i < data.length; i++) {
- // var object = {};
- // object.id = data[i].id;
- // if (angular.isDefined(data[i].parent)) {
- // object.parent = data[i].parent;
- // }
- // if (angular.isDefined(data[i].hasArea)) {
- // object.hasArea = data[i].hasArea;
- // }
- // if (angular.isDefined(data[i].hasSimple)) {
- // object.hasSimple = data[i].hasSimple;
- // }
- // if (angular.isDefined(data[i].group)) {
- // object.group = data[i].group;
- // }
- // object.label = data[i].category;
- // // object.actions = data[i][3]; //权限部分
- // // object.group = "1";
- // // object.user = "2";
- // object.state = {
- // "opened": true
- // };
- // object.typeName = "type";
- // // if()
- // // if (object.actions.indexOf("2") >= 0) { //知识库类型 具有增加权限--系统管理员
- // $scope.showAddSolutionType = true;
- // // }
- // // if (object.actions.indexOf("5") >= 0) { //知识库类型 具有授权权限--系统管理员
- // $scope.showReviewKnowledgeType = true;
- // // }
- // objects.push(object);
- // }
- // $scope.my_data = convertParentToChildList(objects);
- // $scope.tree_data = angular.copy($scope.my_data);
- var li = transform(response.list).children;
- console.log(li)
- $scope.my_data=li
- if ($scope.my_data.length > 0) {
- $scope.doing_async = false;
- }
- console.log($scope.my_data)
- });
- };
- $scope.adddata = {};
- $scope.addparent = false;
- /* -----end submit incidet category----- */
- $scope.try_async_load();
- // 获取故障描述
- // $scope.jry_incidentDescription = scope.$parent.$parent.$parent.model.incident.description;
- // if (scope.$parent.$parent.$parent.model.incident.dept.id) {
- // $scope.deptDatas.deptShow = scope.$parent.$parent.$parent.model.incident.dept.dept;
- // } else {
- // $scope.deptDatas.deptShow = "未知科室";
- // }
- $scope.jry_getUser = function () {
- var data = {
- "idx": 0,
- "sum": 1000,
- "user": {
- "selectType": "pinyin_qs",
- "user": "",
- engineer: 1,
- }
- };
- api_user_data.fetchDataList("user", data).then(function (res) {
- $scope.jry_user = res.list
- })
- }
- $scope.jry_getUser();
- //报修科室
- var getDept = function () {
- var deptData = {
- "idx": 0,
- "sum": 999,
- "department": {
- "department": "",
- "selectType": "pinyin_qs"
- }
- };
- api_user_data.fetchDataList("department", deptData).then(function (data) {
- $scope.jry_deptData = data.list
- })
- }
- getDept()
- // 报修科室模糊搜索
- $scope.jry_deptSearch = function (key, item) {
- console.log(item)
- var deptData = {
- "idx": 0,
- "sum": 999,
- "department": {
- "department": key,
- "selectType": "pinyin_qs"
- }
- };
- api_user_data.fetchDataList("department", deptData).then(function (data) {
- $scope.jry_deptData = data.list
- })
- }
- // 直接处理
- $scope.handleNow = function () {
- }
- // 快速派单
- $scope.sendOrder = function () {
- console.log($scope.incidentModel);
- if (!$scope.incidentModel.department) {
- SweetAlert.swal({
- title: "操作失败",
- text: "请先填写报修科室!",
- type: "error"
- });
- } else if (!$scope.incidentModel.contactsInformation) {
- SweetAlert.swal({
- title: "操作失败",
- text: "请先填写联系电话!",
- type: "error"
- });
- } else if (!$scope.incidentModel.houseNumber) {
- SweetAlert.swal({
- title: "操作失败",
- text: "请先填写故障地点!",
- type: "error"
- });
- } else if (!$scope.incidentModel.description) {
- SweetAlert.swal({
- title: "操作失败",
- text: "请先填写故障描述!",
- type: "error"
- });
- }
- return
- if (!$scope.jry_incidentDescription) {
- SweetAlert.swal({
- title: "操作失败",
- text: "请先填写故障描述!",
- type: "error"
- });
- } else {
- if (scope.$parent.$parent.$parent.model.incident.formKey == "temporaryStorage") {
- api_bpm_domain.complete(scope.$parent.$parent.$parent.model.incident.taskId, $rootScope.user.id, scope.$parent.$parent.$parent.model).then(function (response) {
- if (response) {
- var resData = Restangular.stripRestangular(response);
- SweetAlert.swal({
- title: "提交成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function () {
- $modalInstance.dismiss('cancel');
- $state.go('app.incident.list', {});
- $rootScope.jry_shixian();
- });
- } else {
- SweetAlert.swal({
- title: "系统错误",
- text: "系统错误,请稍后重试!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- }, function () {
- $modalInstance.dismiss('cancel');
- $state.go('app.incident.list', {});
- });
- }
- $scope.ldloading[style.replace('-', '_')] = false;
- });
- } else {
- if (scope.$parent.$parent.$parent.model.openModel) {
- scope.$parent.$parent.$parent.model.incident.callcode = $scope.jry_myPhoneId
- }
- if (scope.$parent.$parent.$parent.model.incident.closecode) {
- delete scope.$parent.$parent.$parent.model.incident.closecode
- }
- if (scope.$parent.$parent.$parent.model.incident.degree) {
- delete scope.$parent.$parent.$parent.model.incident.degree
- }
- if (scope.$parent.$parent.$parent.model.incident.label) {
- delete scope.$parent.$parent.$parent.model.incident.label
- }
- if (scope.$parent.$parent.$parent.model.incident.handleDescription) {
- delete scope.$parent.$parent.$parent.model.incident.handleDescription
- }
- if (scope.$parent.$parent.$parent.model.incident.handlingPersonnelUser) {
- // delete scope.$parent.$parent.$parent.model.incident.handlingPersonnelUser
- }
- scope.$parent.$parent.$parent.model.directClose = false;
- scope.$parent.$parent.$parent.model.incident.isRelation = false;
- // scope.$parent.$parent.$parent.model.incident["handlingPersonnelUser"]=scope.$parent.$parent.$parent.model.incident.acceptUser;
- scope.$parent.$parent.$parent.model["start_code"] = "assignment";
- scope.$parent.$parent.$parent.model["initUser"] = $rootScope.user.id;
- scope.$parent.$parent.$parent.model.incident.description = $scope.jry_incidentDescription;
- scope.$parent.$parent.$parent.model.incident.priority.id = $scope.toFormData.priority.id;
- scope.$parent.$parent.$parent.model.incident.complexity.id = $scope.toFormData.weight.id;
- scope.$parent.$parent.$parent.model.incident.complexity.name = $scope.toFormData.weight.name;
- scope.$parent.$parent.$parent.model.incident.title = $scope.toFormData.categoryid.category;
- scope.$parent.$parent.$parent.model.incident.category = $scope.toFormData.categoryid;
- scope.$parent.$parent.$parent.model.incident["describes"] = {
- id: $scope.toFormData.id
- };
- if ($rootScope.ola_callAccept) {
- scope.$parent.$parent.$parent.model.incident["callID"] = $rootScope.ola_callAccept
- }
- if ($scope.deptDatas.deptShow) {
- if (scope.$parent.$parent.$parent.model.incident.dept.id) {
- } else if ($scope.deptDatas.deptShow.id) {
- scope.$parent.$parent.$parent.model.incident.dept = $scope.deptDatas.deptShow;
- scope.$parent.$parent.$parent.model.incident['faultLocation'] = $scope.deptDatas.deptShow.address
- } else {
- scope.$parent.$parent.$parent.model.incident.dept = $scope.DEP;
- scope.$parent.$parent.$parent.model.incident['faultLocation'] = $scope.DEP.address
- }
- }
- scope.$parent.$parent.$parent.model.incident['receviedCall'] = scope.$parent.$parent.$parent.model.incident.contactsInformation
- console.log(scope.$parent.$parent.$parent.model)
- api_bpm_domain.start("bpm_incident", scope.$parent.$parent.$parent.model).then(function (res) {
- if (res) {
- SweetAlert.swal({
- title: "保存成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function () {
- $modalInstance.dismiss('cancel');
- $state.go('app.incident.list', {});
- $rootScope.jry_shixian();
- });
- } else {
- SweetAlert.swal({
- title: "系统错误",
- text: "系统错误,请稍后重试!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- }, function () {
- $modalInstance.dismiss('cancel');
- $state.go('app.incident.list', {});
- });
- }
- })
- }
- }
- }
- // 暂存
- $scope.temporary = function () {
- // 暂存界面
- if (scope.$parent.$parent.$parent.model.incident.formKey == "temporaryStorage") {
- // 判断是否选择了故障现象
- if ($scope.toFormData) {
- scope.$parent.$parent.$parent.model.incident.priority.id = $scope.toFormData.priority.id;
- scope.$parent.$parent.$parent.model.incident.complexity.id = $scope.toFormData.weight.id;
- scope.$parent.$parent.$parent.model.incident.complexity.name = $scope.toFormData.weight.name;
- scope.$parent.$parent.$parent.model.incident.title = $scope.toFormData.categoryid.category;
- scope.$parent.$parent.$parent.model.incident.category = $scope.toFormData.categoryid;
- scope.$parent.$parent.$parent.model.incident["describes"] = {
- id: $scope.toFormData.id
- };
- }
- // 判断是否填写了故障描述
- if ($scope.jry_incidentDescription) {
- scope.$parent.$parent.$parent.model.incident.description = $scope.jry_incidentDescription;
- }
- var data = {
- incident: scope.$parent.$parent.$parent.model.incident
- }
- api_user_data.jry_updData("incident", data).then(function (response) {
- if (response.status == 200) {
- SweetAlert.swal({
- title: "提交成功!",
- type: "success",
- confirmButtonColor: "#007AFF"
- }, function () {
- $modalInstance.dismiss('cancel');
- $state.go('app.incident.list');
- });
- } else {
- SweetAlert.swal({
- title: "系统错误",
- text: "系统错误,请稍后重试!",
- type: "error",
- confirmButtonColor: "#DD6B55"
- });
- }
- })
- // 新建事件
- } else {
- // 判断是否选择了故障现象
- if ($scope.toFormData) {
- scope.$parent.$parent.$parent.model.incident.priority.id = $scope.toFormData.priority.id;
- scope.$parent.$parent.$parent.model.incident.complexity.id = $scope.toFormData.weight.id;
- scope.$parent.$parent.$parent.model.incident.complexity.name = $scope.toFormData.weight.name;
- scope.$parent.$parent.$parent.model.incident.title = $scope.toFormData.categoryid.category;
- scope.$parent.$parent.$parent.model.incident.category = $scope.toFormData.categoryid;
- scope.$parent.$parent.$parent.model.incident["describes"] = {
- id: $scope.toFormData.id
- };
- }
- // 判断是否填写了故障描述
- if ($scope.jry_incidentDescription) {
- scope.$parent.$parent.$parent.model.incident.description = $scope.jry_incidentDescription;
- }
- scope.$parent.$parent.$parent.model["initUser"] = $rootScope.user.id;
- scope.$parent.$parent.$parent.model.start_code = "temporary";
- api_bpm_domain.start('bpm_incident', scope.$parent.$parent.$parent.model).then(function (response) {
- SweetAlert.swal({
- title: "保存成功!",
- confirmButtonColor: "#007AFF"
- }, function () {
- $modalInstance.dismiss('cancel');
- $state.go("app.incident.list");
- });
- });
- }
- }
- // 取消
- $scope.cancel = function () {
- }
- // $scope.ldloading={};
- // var filterData = {
- // key: 'null',
- // status: 0,
- // pageIndex: 0,
- // pageSum: 10,
- // //treeIds:'[]',
- // userId: loginUser.id
- // }
- $scope.$on('$destroy', function () {
- $interval.cancel($scope.timer)
- });
- }]);
|