angular.module('push') .controller('chooseShareFolderCtrl', function ($scope, $ionicPopup, $timeout, $stateParams, ModelService, DockingService, SqliteStorageService, HandleService, ConfigService, UserService, UtilService, AuthorityService) { if($scope.app){ $scope.setStatusBar(0); } $scope.search = {searchkey: ""}; var chereslist = angular.fromJson($stateParams.chereslist); var folderid = $stateParams.folderid;//被选择的记录所在文件夹ID var isCloud = $stateParams.isCloud;//区别本地与云 $scope.level = 0; //第一次进入显示一级目录 $scope.folderlist = angular.copy(ModelService.getFolderList()); ModelService.setSelectLevelList([]);//清空已打开目录 $scope.checkfolder = "";//被选中的文件夾id var checkfoldertype = -1;//被选中的文件夾类型 //剔除被选择的记录所在文件夹 var deleteFolderOfConnindo = function () { angular.forEach($scope.folderlist, function (value, index) { if (isCloud == 0) { if (value.localid == folderid) { $scope.folderlist.splice(index, 1); } } else if (isCloud == 1) { if (value.id == folderid) { $scope.folderlist.splice(index, 1); } } }); }; deleteFolderOfConnindo(); //返回上一级目录 $scope.backUpperFolder = function () { ModelService.deleteSelectLevelList($scope.level); $scope.level--; if ($scope.level == 0) { $scope.folderlist = angular.copy(ModelService.getFolderList()); } else { var tempfolder = ModelService.getSelectLevelList()[$scope.level]; if (tempfolder.isCloud == 0) { queryLocalFolder(tempfolder); } else { queryCloudFolder(tempfolder); } $scope.currentfoldername = tempfolder.name; } $scope.checkfolder = ""; }; //打开下一级目录 $scope.openNextFolder = function (folder) { //记录本级目录 var tempobj = { localid: folder.localid, id: folder.id, level: folder.level, isCloud: folder.isCloud, name: folder.name }; ModelService.addSelectLevelList(tempobj); $scope.currentfoldername = folder.name; $scope.folderlist = []; $scope.level = folder.level + 1; if (folder.isCloud == 0) { queryLocalFolder(folder); } else { queryCloudFolder(folder); } $scope.checkfolder = ""; }; //查询本地子文件夹 var queryLocalFolder = function (folder) { var q_sql = "select * from conninfofolder where localparentid = '" + folder.localid + "'"; SqliteStorageService.queryData(q_sql).then(function (response) { // console.log(response); $scope.folderlist = response; deleteFolderOfConnindo(); }, function () { }); }; //查询云子文件夹 var queryCloudFolder = function (folder) { DockingService.newGetConnInfoList(folder.id, folder.level, 1).then(function (response) { // console.log(response); $scope.folderlist = response.connFolderlist; deleteFolderOfConnindo(); }, function () { }) }; //筛选文件夹 $scope.chooseFolder = function (folder, index) { angular.forEach($scope.folderlist, function (value, ind) { $scope.folderlist[ind].value = false; }); if (folder.isCloud == 0) { $scope.checkfolder = folder.localid; checkfoldertype = 0; } if (folder.isCloud == 1) { $scope.checkfolder = folder.id + ""; checkfoldertype = 1; } $scope.folderlist[index].value = true; /*//本地文件夹选择 if (reclib.isCloud == 0) { var localindex = chooselocalfolderidlist.indexOf(reclib.localid); if (localindex == -1) { chooselocalfolderidlist.push(reclib.localid); } else { chooselocalfolderidlist.splice(localindex, 1); } } console.log(chooselocalfolderidlist); //云文件夹选择 if (reclib.isCloud == 1) { var cloudindex = choosecloudfolderidlist.indexOf(reclib.id); if (cloudindex == -1) { choosecloudfolderidlist.push(reclib.id); } else { choosecloudfolderidlist.splice(cloudindex, 1); } } console.log(choosecloudfolderidlist); checklength();*/ }; //检测选中文件夹总数 /*var checklength = function () { if (choosecloudfolderidlist.length > 0 || chooselocalfolderidlist.length > 0) { $scope.blue = "toolReleaseButton_blue"; } else { $scope.blue = ""; } };*/ //复制记录至文件夹 var clickflg = 0; $scope.copyRecordToFolder = function () { //未选中文件夹则不操作 if ($scope.checkfolder.length <= 0) { return; } if (clickflg != 0) { return; } clickflg = 1; //选中记录为本地记录 if (isCloud == 0) { getLocalConinfoDetail(); } //选中记录为云记录 if (isCloud == 1) { getCloudConinfoDetail(); } $timeout(function () { clickflg = 0; }, 2500); }; $scope.queryisover = 0;//0:本地对接信息开始查询 4:查询结束 var conninfo = {}; var picturelist = []; var cardlist = []; var personlist = []; var themelist = []; var tempproductlist = []; var tempiur1list = []; var tempiur2list = []; var tempyearprojectlist = []; //取本地记录信息 var getLocalConinfoDetail = function () { var sql = "select * from conninfo where creator = " + UserService.id + " and localid = " + chereslist[0]; SqliteStorageService.queryData(sql).then(function (response) { // console.log(response); conninfo = response[0]; //--查询图片信息 var q_pic_sql = "select * from conninfopicture where localinfoid = " + chereslist[0]; SqliteStorageService.queryData(q_pic_sql).then(function (res) { // console.log(res); picturelist = res; }, function () { }); //--查询名片信息 var q_com_sql = "select * from conninfounit where localinfoid = " + chereslist[0]; SqliteStorageService.queryData(q_com_sql).then(function (res) { // console.log(res); cardlist = res; if (cardlist.length > 0) { //组装名片localid list var cardlocalidstr = ""; angular.forEach(cardlist, function (data) { var tempstr = "'" + data.localid + "'"; cardlocalidstr = cardlocalidstr + tempstr + ","; }); cardlocalidstr = cardlocalidstr.substring(0, cardlocalidstr.length - 1); //--查询人员信息 var q_per_sql = "select * from conninfoperson where localuid in (" + cardlocalidstr + ")"; SqliteStorageService.queryData(q_per_sql).then(function (resp) { // console.log(resp); personlist = resp; $scope.queryisover++; }, function () { personlist = []; $scope.queryisover++; }); //--查询主题信息 var q_the_sql = "select * from conninfotheme where localuid in (" + cardlocalidstr + ")"; SqliteStorageService.queryData(q_the_sql).then(function (resp) { // console.log(resp); themelist = resp; $scope.queryisover++; }, function () { themelist = []; $scope.queryisover++; }); //--查询产品信息 var q_pro_sql = "select * from conninfoproduct where localuid in (" + cardlocalidstr + ")"; SqliteStorageService.queryData(q_pro_sql).then(function (resp) { // console.log(resp); tempproductlist = resp; $scope.queryisover++; }, function () { tempproductlist = []; $scope.queryisover++; }); //--查询产学研经历信息 var q_iur1_sql = "select * from conninfoiur where localuid in (" + cardlocalidstr + ")"; SqliteStorageService.queryData(q_iur1_sql).then(function (resp) { // console.log(resp); tempiur1list = resp; $scope.queryisover++; }, function () { tempiur1list = []; $scope.queryisover++; }); //--查询重大科研项目信息 var q_iur2_sql = "select * from conninforesearch where localuid in (" + cardlocalidstr + ")"; SqliteStorageService.queryData(q_iur2_sql).then(function (resp) { // console.log(resp); tempiur2list = resp; $scope.queryisover++; }, function () { tempiur2list = []; $scope.queryisover++; }); //--查询历年申报项目信息 var q_project_sql = "select * from yearproject where localuid in (" + cardlocalidstr + ")"; SqliteStorageService.queryData(q_project_sql).then(function (resp) { // console.log(resp); tempyearprojectlist = resp; $scope.isover++; }, function () { tempyearprojectlist = []; $scope.isover++; }); } else { $scope.queryisover = 6; } }, function () { $scope.queryisover = 6; }); }, function (err) { // console.log(err); }); }; //监听本地记录查询是否结束 var overwatch1 = $scope.$watch("queryisover", function (newValue, oldValue, scope) { if (newValue == 6) { HandleService.handleConninfoDetailData(cardlist, personlist, themelist, tempproductlist, tempiur1list, tempiur2list, tempyearprojectlist).then(function (response) { // console.log(response); cardlist = response; //本地有文件夹选中操作--> if (checkfoldertype == 0) { saveConninfoToLocal(); } //云有文件夹选中操作--> if (checkfoldertype == 1) { if (UserService.viplevel == 1) { AuthorityService.isHasEnoughCount(3).then(function (response) { if (response.isHasEnoughCount == 1) { newCreateConninfo(); } else { UtilService.showMess("本月新建记录次数已用完"); $scope.hideLoadingToast(); } }, function () { UtilService.showMess("网络不给力,请重试"); $scope.hideLoadingToast(); }); } else { newCreateConninfo(); } } }, function () { }); } }); //取云记录信息 var getCloudConinfoDetail = function () { DockingService.newGetConnInfoDetails(chereslist[0]).then(function (response) { // console.log(response); conninfo = response; picturelist = response.picture; cardlist = response.unit; // console.log(conninfo); // console.log(picturelist); // console.log(cardlist); //本地有文件夹选中操作--> if (checkfoldertype == 0) { saveConninfoToLocal(); } //云有文件夹选中操作--> if (checkfoldertype == 1) { if (UserService.viplevel == 1) { AuthorityService.isHasEnoughCount(3).then(function (response) { if (response.isHasEnoughCount == 1) { copyConnInfo(); } else { UtilService.showMess("本月新建记录次数已用完"); $scope.hideLoadingToast(); } }, function () { UtilService.showMess("网络不给力,请重试"); $scope.hideLoadingToast(); }); } else { copyConnInfo(); } } }, function () { }); }; var checknum = 1; $scope.addisover = 0; var saveConninfoToLocal = function () { try { var conninfodate = UtilService.formatDate(); var conninfodatelocalid = conninfodate.timestamp; //对接信息数据生成 conninfo.localid = conninfodatelocalid + ""; conninfo.localclaid = $scope.checkfolder; conninfo.id = 0; conninfo.claid = 0; conninfo.creator = UserService.id; conninfo.synchrotype = 1; conninfo.createtime = conninfodate.formattime; conninfo.updatetime = conninfodate.formattime; conninfo.creatorcomefrom = ConfigService.comefrom; //图片列表数据生成 if (picturelist.length > 0) { checknum++; } angular.forEach(picturelist, function (value, index) { picturelist[index].localid = conninfodatelocalid + index + ""; picturelist[index].localinfoid = conninfodatelocalid + ""; picturelist[index].infoid = conninfo.id; picturelist[index].id = 0; }); //名片(单位)数据生成 if (cardlist.length > 0) { checknum++; } var personlist = []; var themelist = []; var productlist = []; var iur1list = []; var iur2list = []; var calendarlist = []; var date = new Date(); angular.forEach(cardlist, function (value, index) { var tempcardlocalid = conninfodatelocalid + index; date.setSeconds(date.getSeconds() + index); cardlist[index].localid = tempcardlocalid + ""; cardlist[index].localinfoid = conninfodatelocalid + ""; cardlist[index].id = 0; cardlist[index].infoid = conninfo.id; cardlist[index].creator = UserService.id; cardlist[index].synchrotype = 1; cardlist[index].creatorcomefrom = ConfigService.comefrom; cardlist[index].createtime = date.Format("yyyy-MM-dd hh:mm:ss"); cardlist[index].updatetime = date.Format("yyyy-MM-dd hh:mm:ss"); //人员数据生成 angular.forEach(value.personlist, function (value1, ind) { var tempperson = value1; tempperson.localid = tempcardlocalid + ind + ""; tempperson.localuid = tempcardlocalid + ""; tempperson.id = 0; tempperson.uid = 0; tempperson.infoid = conninfo.id; personlist.push(tempperson); }); //主题数据生成 angular.forEach(value.themelist, function (value2, ind) { var temtheme = value2; temtheme.localid = tempcardlocalid + ind + ""; temtheme.localuid = tempcardlocalid + ""; temtheme.id = 0; temtheme.uid = 0; temtheme.infoid = conninfo.id; themelist.push(temtheme); }); //产品数据生成 angular.forEach(value.productlist, function (value3, ind) { var temproduct = value3; temproduct.localid = tempcardlocalid + ind + ""; temproduct.localuid = tempcardlocalid + ""; temproduct.id = 0; temproduct.uid = 0; temproduct.infoid = conninfo.id; productlist.push(temproduct); }); //产学研经历数据生成 angular.forEach(value.iur1list, function (value4, ind) { var temiur1 = value4; temiur1.localid = tempcardlocalid + ind + ""; temiur1.localuid = tempcardlocalid + ""; temiur1.id = 0; temiur1.uid = 0; temiur1.infoid = conninfo.id; iur1list.push(temiur1); }); //重大科研项数据生成 angular.forEach(value.iur2list, function (value5, ind) { var temiur2 = value5; temiur2.localid = tempcardlocalid + ind + ""; temiur2.localuid = tempcardlocalid + ""; temiur2.id = 0; temiur2.uid = 0; temiur2.infoid = conninfo.id; iur2list.push(temiur2); }); //历年申报项目数据生成 angular.forEach(value.calendarlist, function (value2, ind) { var tempproject = value2; tempproject.localid = tempcardlocalid + ind + ""; tempproject.localuid = tempcardlocalid + ""; tempproject.id = 0; tempproject.uid = 0; tempproject.infoid = conninfo.id; calendarlist.push(tempproject); }); }); if (personlist.length > 0) { checknum++; } if (themelist.length > 0) { checknum++; } if (productlist.length > 0) { checknum++; } if (iur1list.length > 0) { checknum++; } if (iur2list.length > 0) { checknum++; } if (calendarlist.length > 0) { checknum++; } // console.log("==========================================="); // console.log(conninfo); // console.log(picturelist); // console.log(cardlist); // console.log(personlist); // console.log(themelist); // console.log("==========================================="); } catch (e) { $scope.hideLoadingToast(); } SqliteStorageService.insertSingleData("conninfo", conninfo).then(function () { $scope.addisover++; var tempobj = { localid: $scope.checkfolder, updatetime: conninfodate.formattime }; SqliteStorageService.updateSingleData("conninfofolder", tempobj); }, function () { $scope.hideLoadingToast(); }); if (picturelist.length > 0) { SqliteStorageService.insertBatchData("conninfopicture", picturelist).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } if (cardlist.length > 0) { SqliteStorageService.insertBatchData("conninfounit", cardlist).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } if (personlist.length > 0) { SqliteStorageService.insertBatchData("conninfoperson", personlist).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } if (themelist.length > 0) { SqliteStorageService.insertBatchData("conninfotheme", themelist).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } if (productlist.length > 0) { SqliteStorageService.insertBatchData("conninfoproduct", productlist).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } if (iur1list.length > 0) { SqliteStorageService.insertBatchData("conninfoiur", iur1list).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } if (iur2list.length > 0) { SqliteStorageService.insertBatchData("conninforesearch", iur2list).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } if (calendarlist.length > 0) { SqliteStorageService.insertBatchData("yearproject", calendarlist).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } }; //监听本地记录新增是否结束(云到本地、本地到本地) var overwatch2 = $scope.$watch("addisover", function (newValue, oldValue, scope) { if (newValue == checknum) { UtilService.showMess("复制成功"); $timeout(function () { $scope.goback(); }, 1000); ConfigService.isedit = 1; SqliteStorageService.updateEditFlg(1); } }); //本地到云复制 var newCreateConninfo = function () { conninfo.conntime = conninfo.conntime.substring(0, 16); conninfo.claid = $scope.checkfolder; DockingService.newCreateConninfo(conninfo, picturelist, cardlist).then(function () { UtilService.showMess("复制成功"); if (UserService.viplevel == 1) { $scope.deductUserMemberCount(3); } $timeout(function () { $scope.goback(); }, 1000); }, function () { }) }; //云到云复制 var copyConnInfo = function () { DockingService.copyConnInfo(1, folderid, $scope.checkfolder, chereslist[0]).then(function () { UtilService.showMess("复制成功"); if (UserService.viplevel == 1) { $scope.deductUserMemberCount(3); } $timeout(function () { $scope.goback(); }, 1000); }, function () { }) }; //离开页面关闭监听 $scope.$on('$ionicView.beforeLeave', function () { overwatch1(); overwatch2(); }); });