app.controller('hc_flwhCtrl', ["$rootScope", "$scope", "$http", "$state", "$timeout", "$interval", "SweetAlert", "$modal", "FileUploader", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_user_data", "api_wechatfile", function ($rootScope, $scope, $http, $state, $timeout, $interval, SweetAlert, $modal, FileUploader, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_user_data, api_wechatfile) { $scope.langs = i18nService.getAllLangs(); $scope.lang = 'zh-cn'; $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 = { idx: 0, sum: 999, dictionaryTree: { "key": "haocaifenlei", deleted: 0 } } api_user_data.fetchDataList('dictionaryTree', dat).then(function (data) { if(data.status == 200){ $scope.names = data.list; } }); }; //点击耗材名称,查询品牌型号和规格 $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 = { idx: 0, sum: 999, dictionaryTree: { "key": "pinpai", "parent": res.id } } api_user_data.fetchDataList('dictionaryTree', dat).then(function (data) { if(data.status == 200){ $scope.xinghaos = data.list; } }); //规格 var dat1 = { idx: 0, sum: 999, dictionaryTree: { "key": "guige", "parent": res.id } } api_user_data.fetchDataList('dictionaryTree', dat1).then(function (data) { if(data.status == 200){ $scope.guiges = data.list; } }); } 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 = { dictionaryTree: { id: $scope.ids, key: "haocaifenlei", name: $scope.name_ipt[res], value: $scope.name_ipt[res], level: 1, system: 0, deleted: 0 } } api_user_data.addData('dictionaryTree',dat1).then(function (data) { $scope.name_show = false; $scope.name_shuzu = []; SweetAlert.swal({ title: "修改成功", confirmButtonColor: "#007AFF", type: "success" }); $scope.refreshDat_name(); }); } } } 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 = { dictionaryTree: { key: "haocaifenlei", name: $scope.name_ipt[res], value: $scope.name_ipt[res], level: 1, system: 0, deleted: 0 } } api_user_data.addData('dictionaryTree', dat).then(function (data) { $scope.name_show = false; $scope.name_shuzu = []; SweetAlert.swal({ title: "新增成功", confirmButtonColor: "#007AFF", type: "success" }); $scope.refreshDat_name(); }); } } } } // 名称删除 $scope.name_del = function (res) { if(!res.id){ $scope.refreshDat_name(); $scope.tit = ''; $scope.ids = ''; return; } SweetAlert.swal({ title: "确认删除?", text: "删除的数据不可恢复,请确认继续操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "继续删除", cancelButtonText: "取消操作", closeOnConfirm: false, closeOnCancel: false }, function (isConfirm) { if (isConfirm) { var dat1 = [Number(res.id)] api_user_data.rmvData('dictionaryTree',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 = { dictionaryTree: { id: $scope.pinpai_ids, key: "pinpai", name: $scope.pinpai_ipt[res], value: $scope.pinpai_ipt[res], level: 1, system: 0, deleted: 0 } } api_user_data.addData('dictionaryTree',dat1).then(function (data) { $scope.pinpai_show = false; $scope.pinpai_shuzu = []; SweetAlert.swal({ title: "修改成功", confirmButtonColor: "#007AFF", type: "success" }); //品牌型号 var dat2 = { idx: 0, sum: 999, dictionaryTree: { "key": "pinpai", "parent": $scope.ids } } api_user_data.fetchDataList('dictionaryTree', dat2).then(function (data) { if(data.status == 200){ $scope.xinghaos = data.list; } }); }); } } } 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 = { dictionaryTree: { key: "pinpai", name: $scope.pinpai_ipt[res], value: $scope.pinpai_ipt[res], level: 1, system: 0, deleted: 0, parent: $scope.ids } } api_user_data.addData('dictionaryTree', dat).then(function (data) { $scope.pinpai_show = false; $scope.pinpai_shuzu = []; SweetAlert.swal({ title: "新增成功", confirmButtonColor: "#007AFF", type: "success" }); //品牌型号 var dat1 = { idx: 0, sum: 999, dictionaryTree: { "key": "pinpai", "parent": $scope.ids } } api_user_data.fetchDataList('dictionaryTree', dat1).then(function (data) { if(data.status == 200){ $scope.xinghaos = data.list; } }); }); } } } } //品牌删除 $scope.pinpai_del = function (res) { if(!res.id){ $scope.pinpai_show = false; //品牌型号 var dat2 = { idx: 0, sum: 999, dictionaryTree: { "key": "pinpai", "parent": $scope.ids } } api_user_data.fetchDataList('dictionaryTree', dat2).then(function (data) { if(data.status == 200){ $scope.xinghaos = data.list; } }); return; } SweetAlert.swal({ title: "确认删除?", text: "删除的数据不可恢复,请确认继续操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "继续删除", cancelButtonText: "取消操作", closeOnConfirm: false, closeOnCancel: false }, function (isConfirm) { if (isConfirm) { var dat1 = [Number(res.id)] api_user_data.rmvData('dictionaryTree',dat1).then(function (data) { $scope.pinpai_show = false; SweetAlert.swal("操作成功!", "数据已经被删除.", "success"); //品牌型号 var dat2 = { idx: 0, sum: 999, dictionaryTree: { "key": "pinpai", "parent": $scope.ids } } api_user_data.fetchDataList('dictionaryTree', dat2).then(function (data) { if(data.status == 200){ $scope.xinghaos = data.list; } }); }); } 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 = { dictionaryTree: { id: $scope.guige_ids, key: "guige", name: $scope.guige_ipt[res], value: $scope.guige_ipt[res], level: 1, system: 0, deleted: 0 } } api_user_data.addData('dictionaryTree',dat1).then(function (data) { $scope.guige_show = false; $scope.guige_shuzu = []; SweetAlert.swal({ title: "修改成功", confirmButtonColor: "#007AFF", type: "success" }); //品牌型号 var dat2 = { idx: 0, sum: 999, dictionaryTree: { "key": "guige", "parent": $scope.ids } } api_user_data.fetchDataList('dictionaryTree', dat2).then(function (data) { if(data.status == 200){ $scope.guiges = data.list; } }); }); } } } 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 = { dictionaryTree: { key: "guige", name: $scope.guige_ipt[res], value: $scope.guige_ipt[res], level: 1, system: 0, deleted: 0, parent: $scope.ids } } api_user_data.addData('dictionaryTree', dat).then(function (data) { $scope.guige_show = false; $scope.guige_shuzu = []; SweetAlert.swal({ title: "新增成功", confirmButtonColor: "#007AFF", type: "success" }); //品牌型号 var dat1 = { idx: 0, sum: 999, dictionaryTree: { "key": "guige", "parent": $scope.ids } } api_user_data.fetchDataList('dictionaryTree', dat1).then(function (data) { if(data.status == 200){ $scope.guiges = data.list; } }); }); } } } } //规格删除 $scope.guige_del = function (res) { if(!res.id){ $scope.guige_show = false; //品牌型号 var dat2 = { idx: 0, sum: 999, dictionaryTree: { "key": "guige", "parent": $scope.ids } } api_user_data.fetchDataList('dictionaryTree', dat2).then(function (data) { if(data.status == 200){ if(data.status == 200){ $scope.guiges = data.list; } } }); return; } SweetAlert.swal({ title: "确认删除?", text: "删除的数据不可恢复,请确认继续操作!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "继续删除", cancelButtonText: "取消操作", closeOnConfirm: false, closeOnCancel: false }, function (isConfirm) { if (isConfirm) { var dat1 = [Number(res.id)] api_user_data.rmvData('dictionaryTree',dat1).then(function (data) { $scope.guige_show = false; SweetAlert.swal("操作成功!", "数据已经被删除.", "success"); //品牌型号 var dat2 = { idx: 0, sum: 999, dictionaryTree: { "key": "guige", "parent": $scope.ids } } api_user_data.fetchDataList('dictionaryTree', dat2).then(function (data) { if(data.status == 200){ $scope.guiges = data.list; } }); }); } else { SweetAlert.swal("操作取消", "数据安全", "error"); } }); } $scope.refreshDat_name(); }]);