zhuxc 7 years ago
parent
commit
45b15c5747
2 changed files with 33 additions and 17 deletions
  1. 28 15
      www/apps/compmanage/js/controllers.js
  2. 5 2
      www/apps/compmanage/js/factory.js

+ 28 - 15
www/apps/compmanage/js/controllers.js

@@ -1,16 +1,16 @@
-starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDelegate, $rootScope, $ionicHistory, $window, showPopup, global, Comp) {
-    $scope.activeIndex = 0;
+starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDelegate, $rootScope, $ionicHistory, $window,$location, showPopup, global, Comp) {
+    $scope.activeIndex = 3;
     $scope.titleName = ['填写序列号', '选择公司', '用户信息', '导入部门'];
     var compmodal = showPopup.modalTemplate('templates/modal-selectcomp.html', 'slide-in-up', $scope);
 
     global.fetch_user().then(function (res) {
-        if (!global.sn)
-            Comp.sn.get({"comp_id": global.user.compno}, function (data) {
-                global.sn = data.sn;
-                console.warn("sn: " + global.sn);
-            }, function (err) {
-                console.error("获取服务器的SN失败: " + JSON.stringify(err))
-            });
+        // if (!global.sn)
+        //     Comp.sn.get({"comp_id": global.user.compno}, function (data) {
+        //         global.sn = data.sn;
+        //         console.warn("sn: " + global.sn);
+        //     }, function (err) {
+        //         console.error("获取服务器的SN失败: " + JSON.stringify(err))
+        //     });
         $scope.activecomp = {};
     });
 
@@ -23,7 +23,8 @@ starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDe
         $scope.activeIndex = $ionicSlideBoxDelegate.currentIndex();
         if (op == 1) {
             $scope.serialnumber = serialno;
-            Comp.comp().query({"serialno": serialno}, function (data) {
+            global.sn = $scope.serialnumber;
+            Comp.comp('GetComp').query(function (data) {
                 $scope.compdata = data;
                 $scope.activecomp = data[0];
                 $scope.showmodal();
@@ -35,19 +36,31 @@ starter.controller('CompConnectCtrl', function ($scope, $state, $ionicSlideBoxDe
 
     $scope.commit = function (r) {
         $scope.activecomp = _.extend($scope.activecomp, {"cellphone": global.user.cellphone, "imid": global.user.im_usrid, "linkerpassword": global.user.password, "linkerusername": global.user.usrname, "region": 86});
+        global.sn = $scope.serialnumber;
         showPopup.showLoading(1, '正在提交', false);
-        console.log($scope.activecomp);
-        Comp.comp("PostComp/0", $scope.serialnumber).save($scope.activecomp, function (res) {
-            $ionicSlideBoxDelegate.next();
+        Comp.comp("PostComp").save($scope.activecomp, function (data) {
+            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) {
-            console.log(err);
+            alert("erp与linker连接失败:  " + JSON.stringify(err));
         }).$promise.finally(function (f) {
             showPopup.hideLoading();
         })
     };
 
     $scope.importDept = function () {
-
+        showPopup.showLoading(1, '导入中', false);
+        Comp.dept("PostDept").save(function (data) {
+            $window.location.href = "http://" + $location.host() + ":8100/apps/accountMng/index.html#/contacts/-1&Linker test3&78";
+        }, function (err) {
+            alert(JSON.stringify(err))
+        }).$promise.finally(function (f) {
+            showPopup.hideLoading();
+        })
     };
 
     $scope.parse = function () {

+ 5 - 2
www/apps/compmanage/js/factory.js

@@ -4,7 +4,10 @@ starter.factory('Comp', function ($resource, $q, $filter, cfg, formatFilter, glo
     return {
         sn: $resource(formatFilter('{0}erp/comp/', cfg.api)),
         comp: function (actionname) {
-            return $resource(formatFilter('{0}ext_erp/Comp/{1}/', cfg.api, actionname == undefined ? "" : actionname))
+            return $resource(formatFilter('{0}ext_erp/Comp/{1}', cfg.api, actionname == undefined ? "" : actionname))
+        },
+        dept: function (actionname) {
+            return $resource(formatFilter('{0}ext_erp/Dept/{1}', cfg.api, actionname == undefined ? "" : actionname))
         }
     };
 })
@@ -30,7 +33,7 @@ starter.factory('Comp', function ($resource, $q, $filter, cfg, formatFilter, glo
 
                 if (config.url.indexOf("ext_erp") != -1) {//分页时自带了请求路径
                     config.headers['cid'] = JSON.stringify({"linkid": global.user.compno, "langid": "TW", "phone": global.user.cellphone});
-                    config.headers['sn'] = global.sn;
+                    config.headers['sn'] = "0ATTNTP0446-3";
                 }
                 return config;
             }