app.controller('hc_flwhCtrl', ["$rootScope", "$scope", "$http", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data","api_cmdb4","api_wechatfile", function($rootScope, $scope, $http, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data,api_cmdb4,api_wechatfile) { $scope.langs = i18nService.getAllLangs(); $scope.lang = 'zh-cn'; $scope.cancles = true; var loginUser = $rootScope.user; var fildata = { "idx": 0, "sum": 1000 }; $scope.choice = false; $scope.backcolor = []; $scope.outarea = []; $scope.outplace = []; $scope.pla = {}; $scope.areaid = {}; $scope.areaname = ""; $scope.areaplace = true; $scope.freshenarea = function() { api_user_data.fetchDataList('area', fildata).then(function(response) { if (response) { if (response.status = 200) { $scope.outarea = response.list; } } }) } $scope.freshenarea(); $scope.freshenplace = function(id) { if (id) { var fildata = { "idx": 0, "sum": 1000, "place": { areaId: id } }; api_user_data.fetchDataList('place', fildata).then(function(response) { if (response) { if (response.status = 200) { $scope.outplace = response.list; } } }) } } $scope.ckickrow = function(data) { $scope.choice = false; $scope.areaid = data.id; $scope.areaname = data.area; $scope.areaplace = true; if (data.id) { $scope.freshenplace(data.id); // var fildata={"idx":0,"sum":1000,"place":{areaId:data.id}}; // api_user_data.fetchDataList('place',fildata).then(function(response){ // if(response){ // if(response.status=200){ // $scope.outplace= response.list; // } // } // }) } else {} } $scope.clickplace = function(pla) { $scope.areaplace = false; $scope.pla = pla } $scope.name_shuzu=[]; $scope.pinpai_shuzu=[]; $scope.guige_shuzu=[]; $scope.name_show=false; $scope.pinpai_show=false; $scope.guige_show=false; //耗材名称编辑 $scope.name_edit=function(){ $scope.name_show=true; } // 名称取消 $scope.name_quxiao=function(){ $scope.name_show=false; } // 耗材名称分类 $scope.refreshDat_name = function () { var dat = { "key":"haocaifenlei", "type":"list" } api_cmdb4.fetchDataList(dat).then(function (data) { $scope.names=data; // console.log($scope.names); }); }; //点击耗材名称,查询品牌型号和规格 $scope.clickname=function(res,index){ $scope.index=index; if(res.id!=''&&res.id!=undefined){ $scope.panduan="修改"; $scope.tit=res.name; $scope.ids=res.id; //品牌型号 var dat={ "key":"pinpai", "parent":res.id } api_cmdb4.fetchDataList(dat).then(function (data) { $scope.xinghaos=data; // console.log($scope.xinghaos) }); //规格 var dat1={ "key":"guige", "parent":res.id } api_cmdb4.fetchDataList(dat1).then(function (data) { $scope.guiges=data; }); }else{ $scope.panduan="新增"; $scope.tit=''; $scope.ids='' } } //名称新增按钮 $scope.add_name=function(){ $scope.names.unshift({name:"添加名称"}); } //型号新增按钮 $scope.add_xinghao=function(){ if($scope.tit==''||$scope.tit==undefined){ SweetAlert.swal({ title: "新增失败", text: "请先选择名称!", type: "error" }); }else{ $scope.xinghaos.unshift({name:"添加型号"}) } } // 规格新增按钮 $scope.add_guige=function(){ if($scope.tit==''||$scope.tit==undefined){ SweetAlert.swal({ title: "新增失败", text: "请先选择名称!", type: "error" }); }else{ $scope.guiges.unshift({name:"添加规格"}) } } //名称编辑完成 $scope.name_wancheng=function(res){ for(var k=0;k<$scope.names.length;k++){ $scope.name_shuzu.push($scope.names[k].name) } if($scope.ids!=''&&$scope.ids!=undefined){ if($scope.name_ipt[res]==''||$scope.name_ipt[res]==undefined){ SweetAlert.swal({ title: "修改失败", text: "修改值不能为空!", type: "error" }); }else{ if($scope.name_shuzu.indexOf($scope.name_ipt[res])!==-1){ SweetAlert.swal({ title: "修改失败", text: "修改值已存在!", type: "error" }); }else{ var dat1={ "id":$scope.ids, "type": "list", "name": $scope.name_ipt[res], "value": "1", } api_cmdb4.upDictionary(dat1).then(function (data) { $scope.name_show=false; $scope.refreshDat_name(); }); $scope.name_shuzu=[]; SweetAlert.swal({ title: "修改成功", confirmButtonColor: "#007AFF", type: "success" }); } } }else{ if($scope.name_ipt[res]==''||$scope.name_ipt[res]==undefined){ SweetAlert.swal({ title: "新增失败", text: "新增值不能为空!", type: "error" }); }else{ if($scope.name_shuzu.indexOf($scope.name_ipt[res])!==-1){ SweetAlert.swal({ title: "新增失败", text: "新增值已存在!", type: "error" }); }else{ var dat={ "key":"haocaifenlei", "name":$scope.name_ipt[res], "type":"list", "value":1 } api_cmdb4.addDictionary(dat).then(function (data) { $scope.name_show=false; $scope.refreshDat_name(); }); $scope.name_shuzu=[]; SweetAlert.swal({ title: "新增成功", confirmButtonColor: "#007AFF", type: "success" }); } } } } // 名称删除 $scope.name_del=function(res){ SweetAlert.swal({ title: "确认删除?", text: "删除的数据不可恢复,请确认继续操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "继续删除", cancelButtonText: "取消操作", closeOnConfirm: false, closeOnCancel: false }, function (isConfirm) { if (isConfirm) { var dat1={ "id":res.id, "deleted":true } api_cmdb4.upDictionary(dat1).then(function (data) { $scope.refreshDat_name(); }); $scope.tit=''; $scope.ids=''; SweetAlert.swal("操作成功!", "数据已经被删除.", "success"); } else { SweetAlert.swal("操作取消", "数据安全", "error"); } }); } //品牌编辑 $scope.pinpai_edit=function(res,index){ $scope.pinpai_index=index; if(res.id!=''&&res.id!=undefined){ $scope.pinpai_panduan="修改"; $scope.pinpai_ids=res.id; }else{ $scope.pinpai_panduan="新增"; $scope.pinpai_ids=''; } $scope.pinpai_show=true; } // 品牌取消 $scope.pinpai_quxiao=function(){ $scope.pinpai_show=false; } //品牌完成 $scope.pinpai_wancheng=function(res){ for(var k=0;k<$scope.xinghaos.length;k++){ $scope.pinpai_shuzu.push($scope.xinghaos[k].name) } if($scope.pinpai_ids!=''&&$scope.pinpai_ids!=undefined){ if($scope.pinpai_ipt[res]==''||$scope.pinpai_ipt[res]==undefined){ SweetAlert.swal({ title: "修改失败", text: "修改值不能为空!", type: "error" }); }else{ if($scope.pinpai_shuzu.indexOf($scope.pinpai_ipt[res])!==-1){ SweetAlert.swal({ title: "修改失败", text: "修改值已存在!", type: "error" }); }else{ var dat1={ "id":$scope.pinpai_ids, "type": "list", "name": $scope.pinpai_ipt[res], "value": "1", } api_cmdb4.upDictionary(dat1).then(function (data) { $scope.pinpai_show=false; //品牌型号 var dat2={ "key":"pinpai", "parent":$scope.ids } api_cmdb4.fetchDataList(dat2).then(function (data) { $scope.xinghaos=data; }); }); $scope.pinpai_shuzu=[]; SweetAlert.swal({ title: "修改成功", confirmButtonColor: "#007AFF", type: "success" }); } } }else{ if($scope.pinpai_ipt[res]==''||$scope.pinpai_ipt[res]==undefined){ SweetAlert.swal({ title: "新增失败", text: "新增值不能为空!", type: "error" }); }else{ if($scope.pinpai_shuzu.indexOf($scope.pinpai_ipt[res])!==-1){ SweetAlert.swal({ title: "新增失败", text: "新增值已存在!", type: "error" }); }else{ var dat={ "key":"pinpai", "name":$scope.pinpai_ipt[res], "type":"list", "value":1, "parent":$scope.ids } api_cmdb4.addDictionary(dat).then(function (data) { $scope.pinpai_show=false; //品牌型号 var dat1={ "key":"pinpai", "parent":$scope.ids } api_cmdb4.fetchDataList(dat1).then(function (data) { $scope.xinghaos=data; }); }); $scope.pinpai_shuzu=[]; SweetAlert.swal({ title: "新增成功", confirmButtonColor: "#007AFF", type: "success" }); } } } } //品牌删除 $scope.pinpai_del=function(res){ SweetAlert.swal({ title: "确认删除?", text: "删除的数据不可恢复,请确认继续操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "继续删除", cancelButtonText: "取消操作", closeOnConfirm: false, closeOnCancel: false }, function (isConfirm) { if (isConfirm) { var dat1={ "id":res.id, "deleted":true } api_cmdb4.upDictionary(dat1).then(function (data) { api_cmdb4.upDictionary(dat1).then(function (data) { $scope.pinpai_show=false; //品牌型号 var dat2={ "key":"pinpai", "parent":$scope.ids } api_cmdb4.fetchDataList(dat2).then(function (data) { $scope.xinghaos=data; }); }); }); SweetAlert.swal("操作成功!", "数据已经被删除.", "success"); } else { SweetAlert.swal("操作取消", "数据安全", "error"); } }); } // 规格编辑 $scope.guige_edit=function(res,index){ $scope.guige_index=index; if(res.id!=''&&res.id!=undefined){ $scope.guige_panduan="修改"; $scope.guige_ids=res.id; }else{ $scope.guige_panduan="新增"; $scope.guige_ids=''; } $scope.guige_show=true; } // 规格取消 $scope.guige_quxiao=function(){ $scope.guige_show=false; } //规格完成 $scope.guige_wancheng=function(res){ for(var k=0;k<$scope.guiges.length;k++){ $scope.guige_shuzu.push($scope.guiges[k].name) } if($scope.guige_ids!=''&&$scope.guige_ids!=undefined){ if($scope.guige_ipt[res]==''||$scope.guige_ipt[res]==undefined){ SweetAlert.swal({ title: "修改失败", text: "修改值不能为空!", type: "error" }); }else{ if($scope.guige_shuzu.indexOf($scope.guige_ipt[res])!==-1){ SweetAlert.swal({ title: "修改失败", text: "修改值已存在!", type: "error" }); }else{ var dat1={ "id":$scope.guige_ids, "type": "list", "name": $scope.guige_ipt[res], "value": "1", } api_cmdb4.upDictionary(dat1).then(function (data) { $scope.guige_show=false; //品牌型号 var dat2={ "key":"guige", "parent":$scope.ids } api_cmdb4.fetchDataList(dat2).then(function (data) { $scope.guiges=data; }); }); $scope.guige_shuzu=[]; SweetAlert.swal({ title: "修改成功", confirmButtonColor: "#007AFF", type: "success" }); } } }else{ if($scope.guige_ipt[res]==''||$scope.guige_ipt[res]==undefined){ SweetAlert.swal({ title: "新增失败", text: "新增值不能为空!", type: "error" }); }else{ if($scope.guige_shuzu.indexOf($scope.guige_ipt[res])!==-1){ SweetAlert.swal({ title: "新增失败", text: "新增值已存在!", type: "error" }); }else{ var dat={ "key":"guige", "name":$scope.guige_ipt[res], "type":"list", "value":1, "parent":$scope.ids } api_cmdb4.addDictionary(dat).then(function (data) { $scope.guige_show=false; //品牌型号 var dat1={ "key":"guige", "parent":$scope.ids } api_cmdb4.fetchDataList(dat1).then(function (data) { $scope.guiges=data; }); }); $scope.guige_shuzu=[]; SweetAlert.swal({ title: "新增成功", confirmButtonColor: "#007AFF", type: "success" }); } } } } //规格删除 $scope.guige_del=function(res){ SweetAlert.swal({ title: "确认删除?", text: "删除的数据不可恢复,请确认继续操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "继续删除", cancelButtonText: "取消操作", closeOnConfirm: false, closeOnCancel: false }, function (isConfirm) { if (isConfirm) { var dat1={ "id":res.id, "deleted":true } api_cmdb4.upDictionary(dat1).then(function (data) { api_cmdb4.upDictionary(dat1).then(function (data) { $scope.guige_show=false; //品牌型号 var dat2={ "key":"guige", "parent":$scope.ids } api_cmdb4.fetchDataList(dat2).then(function (data) { $scope.guiges=data; }); }); }); SweetAlert.swal("操作成功!", "数据已经被删除.", "success"); } else { SweetAlert.swal("操作取消", "数据安全", "error"); } }); } $scope.refreshDat_name(); }]);