controllers.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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": global.user.password, "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. Comp.dept("PostDept").save(function (data) {
  50. $window.location.href = formatFilter("http://" + $location.host() + ":8100/apps/accountMng/index.html#/contacts/-1&{0}&{1}", $scope.activecomp.name, $scope.activecomp.compid);
  51. }, function (err) {
  52. alert(JSON.stringify(err))
  53. }).$promise.finally(function (f) {
  54. showPopup.hideLoading();
  55. })
  56. };
  57. $scope.parse = function () {
  58. $window.history.back();
  59. };
  60. $scope.showmodal = function () {
  61. compmodal.then(function (m) {
  62. $rootScope.commons.modal = m;
  63. $rootScope.commons.modal.show();
  64. })
  65. };
  66. $scope.closeModal = function (comp) {
  67. if (comp)
  68. $scope.activecomp = comp;
  69. $rootScope.commons.modal.hide();
  70. };
  71. $scope.back = function () {
  72. if ($scope.activeIndex != 0) {
  73. $ionicSlideBoxDelegate.previous();
  74. $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
  75. } else if ($scope.activeIndex == 0) {
  76. $window.history.back();
  77. }
  78. };
  79. })