controllers.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDelegate, $rootScope, $ionicHistory, $window, showPopup, global, Comp) {
  2. $scope.activeIndex = 0;
  3. $scope.titleName = ['填写序列号', '选择公司', '用户信息', '导入部门'];
  4. var compmodal = showPopup.modalTemplate('templates/modal-selectcomp.html', 'slide-in-up', $scope);
  5. global.fetch_user().then(function (res) {
  6. if (!global.sn)
  7. Comp.sn.get({"comp_id": global.user.compno}, function (data) {
  8. global.sn = data.sn;
  9. console.warn("sn: " + global.sn);
  10. }, function (err) {
  11. console.error("获取服务器的SN失败: " + JSON.stringify(err))
  12. });
  13. $scope.activecomp = {};
  14. });
  15. $scope.lockSlide = function () {
  16. $ionicSlideBoxDelegate.enableSlide(false);
  17. };
  18. $scope.next = function (op, serialno) {
  19. $ionicSlideBoxDelegate.next();
  20. $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
  21. if (op == 1) {
  22. $scope.serialnumber = serialno;
  23. Comp.comp().query({"serialno": serialno}, function (data) {
  24. $scope.compdata = data;
  25. $scope.activecomp = data[0];
  26. $scope.showmodal();
  27. }, function (err) {
  28. console.log(JSON.stringify(err))
  29. })
  30. }
  31. };
  32. $scope.commit = function (r) {
  33. $scope.activecomp = _.extend($scope.activecomp, {"cellphone": global.user.cellphone, "imid": global.user.im_usrid, "linkerpassword": global.user.password, "linkerusername": global.user.usrname, "region": 86});
  34. showPopup.showLoading(1, '正在提交', false);
  35. console.log($scope.activecomp);
  36. Comp.comp("PostComp/0", $scope.serialnumber).save($scope.activecomp, function (res) {
  37. $ionicSlideBoxDelegate.next();
  38. }, function (err) {
  39. console.log(err);
  40. }).$promise.finally(function (f) {
  41. showPopup.hideLoading();
  42. })
  43. };
  44. $scope.importDept = function () {
  45. };
  46. $scope.parse = function () {
  47. $window.history.back();
  48. };
  49. $scope.showmodal = function () {
  50. compmodal.then(function (m) {
  51. $rootScope.commons.modal = m;
  52. $rootScope.commons.modal.show();
  53. })
  54. };
  55. $scope.closeModal = function (comp) {
  56. if (comp)
  57. $scope.activecomp = comp;
  58. $rootScope.commons.modal.hide();
  59. };
  60. $scope.back = function () {
  61. if ($scope.activeIndex != 0) {
  62. $ionicSlideBoxDelegate.previous();
  63. $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
  64. } else if ($scope.activeIndex == 0) {
  65. $window.history.back();
  66. }
  67. };
  68. })