/// <reference path="../../includes.ts"/>
/// <reference path="systemPlugin.ts"/>
/// <reference path="systemHelpers.ts"/>
/// <reference path="systemServices.ts"/>
module System{
    export var SystemVerificationController = controller('SystemVerificationController', ['$scope', '$location', '$templateCache', 'Upload', 'NgTableParams', 'ngDialog', 'SystemModel', ($scope, $location, $templateCache, Upload, NgTableParams, ngDialog, SystemModel) => {
		    shareInit($scope);
        $scope.cities =  classifyCity(SystemModel.regionalismInfo);
       
		    $scope.columns = [
            { field: "id", title: '序号', show: false},
            { field: "checkResult", title: "验证结果", show: true},			
            { field: "hasCollect", title: "采集", show: true },
      		  { field: "hasCheckSql", title: "支付信息标准表", show: true },
      		  { field: "hasExecSql", title: "可执行标准表",  show: true },
      		  { field: "city", title: "市",  show: true },
      		  { field: "county", title: "区/县", show: true },
      		  { field: "regionalismCode", title: "行政区划代码", show: true },
      		  { field: "systemCode", title: "信息系统代码",  show: true },
      		  { field: "contactsPerson", title: "联系人",  show: true },
      		  { field: "contactsMethod", title: "联系方式",  show: true },
      		  { field: "databaseType", title: "数据库类型",  show: true}
        ];

        $scope.model = [{
            id: 1,
            checkResult: '是',
            hasCollect: '是',
            hasCheckSql: '是',
            hasExecSql: '是',
            city: '南京市',
            county: '玄武区',
            regionalismCode: '320105',
            systemCode: '2',
            contactsPerson: '文豆豆',
            contactsMethod: '15578203146',
            databaseType: 'oracle'
        },
        {
            id: 2,
            checkResult: '否',
            hasCollect: '是',
            hasCheckSql: '否',
            hasExecSql: '是',
            city: '连云港市',
            county: '浦口区',
            regionalismCode: '320105',
            systemCode: '6',
            contactsPerson: '文豆豆',
            contactsMethod: '15578203147',
            databaseType: 'sqlServer'          
        }];

        console.log($scope.model);

        $scope.filterResult = $scope.model;

          // 表数据
        $scope.tableParams = new NgTableParams({count: 25}, {
           counts: [25, 50, 100],
           dataset: $scope.filterResult
        });  

        $scope.citySelect = (x) =>{           
          if(x != 'all'){
            $scope.countries = classifyCountry(SystemModel.regionalismInfo, x);
            $scope.filterResult = [];
            angular.forEach($scope.model, (item) => {
              if(item.city == x)
                $scope.filterResult.push(item);
            });
            $scope.tableParams.settings({
              dataset: $scope.filterResult
            });        
          }else{          
            $scope.filterResult = $scope.model;
            $scope.tableParams.settings({
              dataset: $scope.filterResult
            }); 
          }
        } 

        $scope.countrySelect = (y) => {         
          if(y != 'all'){
            var result = [];
            angular.forEach($scope.filterResult, (item) => {
              if(item.county == y)
                result.push(item);
            });
            $scope.tableParams.settings({
              dataset: result
            }); 
          }else{
            $scope.tableParams.settings({
              dataset: $scope.filterResult
            });            
          }
        }

        $scope.check = () => {
          console.log($scope.tableParams.data[0]);
        }
	  }]);	
}