edit.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. var editBuildingCtrl = function ($scope, $http, $filter, $loading) {
  2. $scope.params = editBuildingModal.params;
  3. $scope.parentLoad = editBuildingModal.parentLoad;
  4. $scope.dataModel = {};
  5. $scope.floorList = [];
  6. $scope.loadData = function () {
  7. $loading.show();
  8. $http({
  9. method: "get",
  10. url: "../../api/build/building/GetBuildingById",
  11. params: {
  12. buildingId: $scope.params.buildingId
  13. }
  14. }).then(function (result) {
  15. $loading.hide();
  16. $scope.dataModel = result.data.Data;
  17. }, function (resp) {
  18. $loading.hide();
  19. $scope.showMsg('错误', '服务器错误');
  20. });
  21. }
  22. $scope.getFloorList = function () {
  23. $http({
  24. method: "get",
  25. url: "../../api/build/building/GetFloorList",
  26. params: {
  27. buildingId: $scope.params.buildingId
  28. }
  29. }).then(function (result) {
  30. $scope.floorList = result.data.Data;
  31. }, function (resp) {
  32. });
  33. };
  34. $scope.add = function () {
  35. $scope.floorList.push({Name:""});
  36. };
  37. $scope.delete = function (index) {
  38. var floor = $scope.floorList[index];
  39. if (floor.BuildingFloorId) {
  40. $http.post('../../api/build/building/DeleteFloor', { buildingFloorId: floor.BuildingFloorId }).then(function (res) {
  41. if (res.data.IsSuccess) {
  42. $scope.floorList.splice(index, 1);
  43. } else {
  44. $scope.showMsg('错误', res.data.Message);
  45. }
  46. });
  47. }
  48. else {
  49. $scope.floorList.splice(index, 1);
  50. }
  51. };
  52. $scope.save = function (isflag) {
  53. if (!isflag) {
  54. $scope.showMsg('提示', '请填写相关信息');
  55. return false;
  56. }
  57. if (isflag) {
  58. $loading.show();
  59. $http({
  60. method: "post",
  61. url: "../../api/build/building/SaveBuilding",
  62. data: {
  63. data: $scope.dataModel,
  64. floorList: $scope.floorList,
  65. }
  66. }).then(function (result) {
  67. $loading.hide();
  68. if (result.data.IsSuccess) {
  69. $scope.showMsg('成功', "操作成功!");
  70. $scope.parentLoad();
  71. $scope.$hide();
  72. } else {
  73. $scope.showMsg('失败', result.data.Message);
  74. }
  75. }, function (resp) {
  76. $loading.hide();
  77. $scope.showMsg('错误', '服务器错误,' + resp.data.message);
  78. })
  79. }
  80. };
  81. $scope.invalidFee = function (index, form1, name) {
  82. if (form1 != undefined) {
  83. name = name + "_" + index;
  84. eval('var i=form1.' + name + '.$invalid');
  85. return i;
  86. }
  87. };
  88. $scope.loadData();
  89. $scope.getFloorList();
  90. };
  91. //定义模态框
  92. var editBuildingModal;