policySettingCtrl.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. angular.module('push')
  2. .controller('policySettingCtrl', function ($scope, $ionicPopup, $stateParams, $ionicActionSheet, dataToolsService) {
  3. $scope.list = $stateParams.list;
  4. $scope.value = [];
  5. $scope.value.push(1);
  6. $scope.addSetting = function () {
  7. $scope.value.push(1);
  8. }
  9. var getSettingList = function () {
  10. dataToolsService.getSettingList($scope.list.id).then(function (res) {
  11. if(res.code == 3350){
  12. $scope.policySettingList = res.data;
  13. angular.forEach($scope.policySettingList, function(val, index){
  14. $scope.orgtypelist.push(val.orgtype);
  15. $scope.subsidiestypelist.push(val.subsidy);
  16. $scope.subsidiesratelist.push(val.subsidyrate);
  17. if(index != $scope.policySettingList.length - 1){
  18. $scope.value.push(1);
  19. }
  20. })
  21. }
  22. })
  23. }
  24. getSettingList();
  25. $scope.deleteSetting = function () {
  26. $scope.value.splice($scope.value[$scope.value.length - 1], 1);
  27. $scope.orgtypelist.splice($scope.orgtypelist[$scope.orgtypelist.length - 1], 1);
  28. $scope.subsidiestypelist.splice($scope.subsidiestypelist[$scope.subsidiestypelist.length - 1], 1);
  29. $scope.subsidiesratelist.splice($scope.subsidiesratelist[$scope.subsidiesratelist.length - 1], 1);
  30. }
  31. $scope.orgtypelist = [];
  32. $scope.subsidiestypelist = [];
  33. $scope.subsidiesratelist = [];
  34. $scope.orgtype = [
  35. {itemkey: '高新潜力企业', itemvalue: 0},
  36. {itemkey: '科技型初创企业', itemvalue: 1},
  37. {itemkey: '国家高新技术企业', itemvalue: 2},
  38. {itemkey: '创新引领企业', itemvalue: 3},
  39. {itemkey: '其他企业', itemvalue: 4}
  40. ];
  41. $scope.subsidiestype = [
  42. {itemkey: '合同金额', itemvalue: 0},
  43. {itemkey: '当年实际支付金额', itemvalue: 1},
  44. {itemkey: '当年实际支付的除税金额', itemvalue: 2}
  45. ];
  46. $scope.selectorgtype = function ($index) {
  47. var obtainlist = [];
  48. angular.forEach($scope.orgtype, function (val) {
  49. obtainlist.push({
  50. text: '<a class="action-sheet-push">' + val.itemkey + '</a>',
  51. itemkey: val.itemkey,
  52. itemvalue: val.itemvalue
  53. })
  54. })
  55. $ionicActionSheet.show({
  56. cancelOnStateChange: true,
  57. cssClass: 'action_s',
  58. cancelText: '取消',
  59. buttons: obtainlist,
  60. buttonClicked: function (index) {
  61. $scope.orgtypelist[$index] = obtainlist[index].itemkey;
  62. return true;
  63. }
  64. });
  65. }
  66. $scope.selectsubsidiestype = function ($index) {
  67. var obtainlist = [];
  68. angular.forEach($scope.subsidiestype, function (val) {
  69. obtainlist.push({
  70. text: '<a class="action-sheet-push">' + val.itemkey + '</a>',
  71. itemkey: val.itemkey,
  72. itemvalue: val.itemvalue
  73. })
  74. })
  75. $ionicActionSheet.show({
  76. cancelOnStateChange: true,
  77. cssClass: 'action_s',
  78. cancelText: '取消',
  79. buttons: obtainlist,
  80. buttonClicked: function (index) {
  81. $scope.subsidiestypelist[$index] = obtainlist[index].itemkey;
  82. return true;
  83. }
  84. });
  85. }
  86. $scope.saveSetting = function () {
  87. var orgtypelistlength = $scope.orgtypelist.length;
  88. var subsidiestypelistlength = $scope.subsidiestypelist.length;
  89. var subsidiesratelistlength = $scope.subsidiesratelist.length;
  90. $scope.needInsert = false;
  91. if(orgtypelistlength != subsidiestypelistlength || orgtypelistlength != subsidiesratelistlength || subsidiestypelistlength != subsidiesratelistlength){
  92. $scope.needInsert = true;
  93. }
  94. if(orgtypelistlength == 0 || subsidiestypelistlength == 0 || subsidiesratelistlength == 0){
  95. $scope.needInsert = true;
  96. }
  97. if($scope.needInsert){
  98. $ionicPopup.alert({
  99. title: '提示',
  100. template: '请填写必填项!'
  101. });
  102. return;
  103. }
  104. dataToolsService.saveSetting($scope.list, $scope.orgtypelist, $scope.subsidiestypelist, $scope.subsidiesratelist).then(function (res) {
  105. if (res.code == 3350) {
  106. $ionicPopup.alert({
  107. title: '提示',
  108. template: '保存成功!'
  109. });
  110. $scope.go('reward');
  111. } else {
  112. $ionicPopup.alert({
  113. title: '提示',
  114. template: '保存失败!'
  115. });
  116. }
  117. })
  118. }
  119. });