angular.module('push') .controller('policySettingCtrl', function ($scope, $ionicPopup, $stateParams, $ionicActionSheet, dataToolsService) { $scope.list = $stateParams.list; $scope.value = []; $scope.value.push(1); $scope.addSetting = function () { $scope.value.push(1); } var getSettingList = function () { dataToolsService.getSettingList($scope.list.id).then(function (res) { if(res.code == 3350){ $scope.policySettingList = res.data; angular.forEach($scope.policySettingList, function(val, index){ $scope.orgtypelist.push(val.orgtype); $scope.subsidiestypelist.push(val.subsidy); $scope.subsidiesratelist.push(val.subsidyrate); if(index != $scope.policySettingList.length - 1){ $scope.value.push(1); } }) } }) } getSettingList(); $scope.deleteSetting = function () { $scope.value.splice($scope.value[$scope.value.length - 1], 1); $scope.orgtypelist.splice($scope.orgtypelist[$scope.orgtypelist.length - 1], 1); $scope.subsidiestypelist.splice($scope.subsidiestypelist[$scope.subsidiestypelist.length - 1], 1); $scope.subsidiesratelist.splice($scope.subsidiesratelist[$scope.subsidiesratelist.length - 1], 1); } $scope.orgtypelist = []; $scope.subsidiestypelist = []; $scope.subsidiesratelist = []; $scope.orgtype = [ {itemkey: '高新潜力企业', itemvalue: 0}, {itemkey: '科技型初创企业', itemvalue: 1}, {itemkey: '国家高新技术企业', itemvalue: 2}, {itemkey: '创新引领企业', itemvalue: 3}, {itemkey: '其他企业', itemvalue: 4} ]; $scope.subsidiestype = [ {itemkey: '合同金额', itemvalue: 0}, {itemkey: '当年实际支付金额', itemvalue: 1}, {itemkey: '当年实际支付的除税金额', itemvalue: 2} ]; $scope.selectorgtype = function ($index) { var obtainlist = []; angular.forEach($scope.orgtype, function (val) { obtainlist.push({ text: '' + val.itemkey + '', itemkey: val.itemkey, itemvalue: val.itemvalue }) }) $ionicActionSheet.show({ cancelOnStateChange: true, cssClass: 'action_s', cancelText: '取消', buttons: obtainlist, buttonClicked: function (index) { $scope.orgtypelist[$index] = obtainlist[index].itemkey; return true; } }); } $scope.selectsubsidiestype = function ($index) { var obtainlist = []; angular.forEach($scope.subsidiestype, function (val) { obtainlist.push({ text: '' + val.itemkey + '', itemkey: val.itemkey, itemvalue: val.itemvalue }) }) $ionicActionSheet.show({ cancelOnStateChange: true, cssClass: 'action_s', cancelText: '取消', buttons: obtainlist, buttonClicked: function (index) { $scope.subsidiestypelist[$index] = obtainlist[index].itemkey; return true; } }); } $scope.saveSetting = function () { var orgtypelistlength = $scope.orgtypelist.length; var subsidiestypelistlength = $scope.subsidiestypelist.length; var subsidiesratelistlength = $scope.subsidiesratelist.length; $scope.needInsert = false; if(orgtypelistlength != subsidiestypelistlength || orgtypelistlength != subsidiesratelistlength || subsidiestypelistlength != subsidiesratelistlength){ $scope.needInsert = true; } if(orgtypelistlength == 0 || subsidiestypelistlength == 0 || subsidiesratelistlength == 0){ $scope.needInsert = true; } if($scope.needInsert){ $ionicPopup.alert({ title: '提示', template: '请填写必填项!' }); return; } dataToolsService.saveSetting($scope.list, $scope.orgtypelist, $scope.subsidiestypelist, $scope.subsidiesratelist).then(function (res) { if (res.code == 3350) { $ionicPopup.alert({ title: '提示', template: '保存成功!' }); $scope.go('reward'); } else { $ionicPopup.alert({ title: '提示', template: '保存失败!' }); } }) } });