starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDelegate, $rootScope, $ionicHistory, $window, $location, formatFilter, showPopup, global, Comp) { $scope.activeIndex = 0; $scope.titleName = ['填写序列号', '选择公司', '用户信息', '导入部门']; var compmodal = showPopup.modalTemplate('templates/modal-selectcomp.html', 'slide-in-up', $scope); global.fetch_user().then(function (res) { $scope.activecomp = {}; }); $scope.lockSlide = function () { $ionicSlideBoxDelegate.enableSlide(false); }; $scope.next = function (op, serialno) { if (op == 1) { $scope.serialnumber = serialno; global.sn = $scope.serialnumber; Comp.comp('GetComp').query(function (data) { $scope.compdata = data; $scope.activecomp = data[0]; $ionicSlideBoxDelegate.next(); $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex(); $scope.showmodal(); }, function (err) { alert("GetComp失败: " + JSON.stringify(err)); }) } else { $ionicSlideBoxDelegate.next(); $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex(); } }; $scope.commit = function (r) { $scope.activecomp = _.extend($scope.activecomp, {"cellphone": global.user.cellphone, "imid": global.user.im_usrid, "linkerpassword": "123456", "linkerusername": global.user.usrname, "region": 86}); global.sn = $scope.serialnumber; showPopup.showLoading(1, '正在提交', false); Comp.comp("PostComp").save($scope.activecomp, function (data) { $scope.activecomp = _.extend($scope.activecomp, {"compid": data.linkercompid}); Comp.sn.save({"sn": global.sn, "comp": data.linkercompid}, function (data) { console.log(data); $ionicSlideBoxDelegate.next(); }, function (err) { alert("Linker创建sn失败: " + JSON.stringify(err)); }); }, function (err) { alert("erp与linker连接失败: " + JSON.stringify(err)); }).$promise.finally(function (f) { showPopup.hideLoading(); }) }; $scope.importDept = function () { showPopup.showLoading(1, '导入中', false); global.user.compno = $scope.activecomp.compid; Comp.dept("PostDept").save(function (data) { $window.location.href = formatFilter("http://" + $location.host() + ":8100/apps/accountMng/index.html#/contacts/-1&{0}&{1}", $scope.activecomp.name, $scope.activecomp.compid); }, function (err) { alert(JSON.stringify(err)) }).$promise.finally(function (f) { showPopup.hideLoading(); }) }; $scope.parse = function () { $window.history.back(); }; $scope.showmodal = function () { compmodal.then(function (m) { $rootScope.commons.modal = m; $rootScope.commons.modal.show(); }) }; $scope.closeModal = function (comp) { if (comp) $scope.activecomp = comp; $rootScope.commons.modal.hide(); }; $scope.back = function () { if ($scope.activeIndex != 0) { $ionicSlideBoxDelegate.previous(); $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex(); } else if ($scope.activeIndex == 0) { $window.history.back(); } }; })