controllers.js 3.3 KB

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