controllers.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDelegate, $rootScope, $ionicHistory, $window, $location, formatFilter, 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. $scope.activecomp = {};
  7. });
  8. $scope.lockSlide = function () {
  9. $ionicSlideBoxDelegate.enableSlide(false);
  10. };
  11. $scope.next = function (op, serialno) {
  12. if (op == 1) {
  13. $scope.serialnumber = serialno;
  14. global.sn = $scope.serialnumber;
  15. Comp.comp('GetComp').query(function (data) {
  16. $scope.compdata = data;
  17. $scope.activecomp = data[0];
  18. $ionicSlideBoxDelegate.next();
  19. $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
  20. $scope.showmodal();
  21. }, function (err) {
  22. alert("GetComp失败: " + JSON.stringify(err));
  23. })
  24. } else {
  25. $ionicSlideBoxDelegate.next();
  26. $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
  27. }
  28. };
  29. $scope.commit = function (r) {
  30. $scope.activecomp = _.extend($scope.activecomp, {"cellphone": global.user.cellphone, "imid": global.user.im_usrid, "linkerpassword": "123456", "linkerusername": global.user.usrname, "region": 86});
  31. global.sn = $scope.serialnumber;
  32. showPopup.showLoading(1, '正在提交', false);
  33. Comp.comp("PostComp").save($scope.activecomp, function (data) {
  34. $scope.activecomp = _.extend($scope.activecomp, {"compid": data.linkercompid});
  35. Comp.sn.save({"sn": global.sn, "comp": data.linkercompid}, function (data) {
  36. console.log(data);
  37. $ionicSlideBoxDelegate.next();
  38. }, function (err) {
  39. alert("Linker创建sn失败: " + JSON.stringify(err));
  40. });
  41. }, function (err) {
  42. alert("erp与linker连接失败: " + JSON.stringify(err));
  43. }).$promise.finally(function (f) {
  44. showPopup.hideLoading();
  45. })
  46. };
  47. $scope.importDept = function () {
  48. showPopup.showLoading(1, '导入中', false);
  49. global.user.compno = $scope.activecomp.compid;
  50. Comp.dept("PostDept").save(function (data) {
  51. $window.location.href = formatFilter("http://" + $location.host() + ":8100/apps/accountMng/index.html#/contacts/-1&{0}&{1}", $scope.activecomp.name, $scope.activecomp.compid);
  52. }, function (err) {
  53. alert(JSON.stringify(err))
  54. }).$promise.finally(function (f) {
  55. showPopup.hideLoading();
  56. })
  57. };
  58. $scope.parse = function () {
  59. $window.history.back();
  60. };
  61. $scope.showmodal = function () {
  62. compmodal.then(function (m) {
  63. $rootScope.commons.modal = m;
  64. $rootScope.commons.modal.show();
  65. })
  66. };
  67. $scope.closeModal = function (comp) {
  68. if (comp)
  69. $scope.activecomp = comp;
  70. $rootScope.commons.modal.hide();
  71. };
  72. $scope.back = function () {
  73. if ($scope.activeIndex != 0) {
  74. $ionicSlideBoxDelegate.previous();
  75. $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
  76. } else if ($scope.activeIndex == 0) {
  77. $window.history.back();
  78. }
  79. };
  80. })