/**
 * 页面表头控制器
 * Created by G on 2018/10/8.
 */
var loginApp = angular.module('loginApp', []);
loginApp.controller('loginController', function ($scope, $q, $http) {

    $scope.catList = [];
    $scope.templateList = [];

    function getJson(url, param, method) {
        if (!method) {
            method = "GET";
        }
        var deferred = $q.defer();
        $http({
            method: method,
            url: url,
            data: param,
        }).success(function (d) {

            deferred.resolve(d);

        });
        return deferred.promise;

    }

    //登录
    /* $http.post("http://localhost:8081/zion/login/thirdParty?amount=twitter&nick=推特昵称&userType=3")

         .success(function(d){

             console.log(d)

         });*/

    $scope.triggleData = function (data) {
        data.isSelected = !data.isSelected;
    };

    //获取所有报关品名
    getJson('/zion/categoryhs/queryAll').then(function (data) {
        $scope.catList = data.data;

    });
    //获取所有运费模板
    getJson('/zion/expressTemplate/queryAll').then(function (data) {
        $scope.templateList = data.data;
    });

    $scope.relateExpCat=function() {
        var selectCat=[];
        var selectTemplate="";
        for(var i=0;i<$scope.catList.length;i++) {
            selectCat.push($scope.catList[i].categoryId);
            /*if(!!$scope.catList[i].isSelected&&!$scope.catList[i].disable) {
                $scope.catList[i].disable=true;
                selectCat.push($scope.catList[i].categoryId);
            }*/
        }
        for(var i=0;i<$scope.templateList.length;i++) {
            if(!!$scope.templateList[i].isSelected&&!$scope.templateList[i].disable) {
                $scope.templateList[i].disable=true;
                selectTemplate=$scope.templateList[i].templateId;
            }
        }

        var param={
            categoryIds:selectCat,
            tempalteId:selectTemplate
        };

        getJson('/zion/expcatrel/buildRelate',param,"POST").then(function (data) {
            if(data.code==1) {
                alert("关联成功");
            } else {
                alert("关联失败");
            }
        });
        //console.log(selectCat);
        //console.log(selectTemplate);
    }

    var handler=function(d) {
        console.log(d);
    }
/*
    var xhr = new XMLHttpRequest();
    var url = 'https://africa.gzdazt.com/zion/login';//?account=1244612031@qq.com&password=123456

    xhr.open('POST', url, true);
    xhr.withCredentials = true;
    xhr.onreadystatechange = handler;
    xhr.send();*/

   /*var dataParam ={
        targetUrl:"https://h5.m.taobao.com/awp/core/detail.htm?spm=a2141.9304519.0.0&id=9679381011&pvid=9e42d83a-82c7-43ac-a89f-199a74d48c2f&scene=3489&scm=1007.13489.98648.tab%3A0_id%3A9679381011_reason%3Ashoal_ranklist_rn%3A9e42d83a-82c7-43ac-a89f-199a74d48c2f"
   };

    $.ajax({
        url: "https://africa.gzdazt.com/zion/spider/item/detail",
        type: "post",
        dataType: "json",
        data: JSON.stringify(dataParam),
        headers: {'Content-Type': 'application/json'},
        success: function (res) {
            console.log(res)
        }
    })*/

    /*$.ajax({
        url:"http://159.138.33.0/zion/spider/item/detail",   //去请求项目二中的url
        data:dataParam,
        method:"GET",
        contentType: "application/json;",
    success:function (data) {
        console.log(data)
    }
    })*/

    /*var xhr = new XMLHttpRequest();
    var url = 'https://africa.gzdazt.com/zion/user/register/identifyCode/960696163@qq.com/xixi';

    xhr.open('GET', url, true);
    xhr.withCredentials = true;
    xhr.onreadystatechange = handler;
    xhr.send();*/


    var dataParam ={
        itemImg: '111',
        itemnum: '111',
        itemprice: '111',
        itemSku: '111',
        itemTitle: '111',
        shopid: '111',
        shopname: '111',
        shopurl: '111'
   };

    $.ajax({
        url: "https://africa.gzdazt.com/zion/item/cart",
        type: "post",
        dataType: "json",
        data: JSON.stringify(dataParam),
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5NjA2OTYxNjNAcXEuY29tIiwiaWF0IjoxNTY4OTYxOTAyLCJleHAiOjE1Njk1NjY3MDJ9.iY4CspfTbRTuapIkKDX1gdXvlEE7Ld7VKy28avoQC4U'
        },
        success: function (res) {
            console.log(res)
        },
        error:function(res) {
            console.log(res)
        }
    })


    /*$http({
        method: "POST",
        url: 'http://159.138.33.0/zion/login',
    }).success(function (d) {
        console.log(d)

    });*/



});
