angular.module('push') .controller('wastepaperCtrl', function ($scope, $ionicActionSheet, $ionicPopup, DockingService, UtilService, SqliteStorageService, HandleService, UserService) { if($scope.app){ $scope.setStatusBar(0); } var status = true; var handleConninfoDataByDate = function (templist1, templist2) { HandleService.handleConninfoDataByDate(templist1, templist2, "was").then(function (response) { // console.log("按日期处理本地对接数据完成"); $scope.recordList = response.conninfolist; }, function () { }) }; var tempconninfolist = []; //对接信息列表初始化 var getConninfoList = function () { var sql = "select * from conninfo where status = 1 and creator = " + UserService.id + " order by conntime desc"; SqliteStorageService.queryData(sql).then(function (response) { // console.log(response); tempconninfolist = response; //拼接记录id var infoidlist = ""; angular.forEach(response, function (value) { var tempstr = "'" + value.localid + "'"; infoidlist = infoidlist + tempstr + ","; }); infoidlist = infoidlist.substring(0, infoidlist.length - 1); //--查询图片信息 var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")"; SqliteStorageService.queryData(q_pic_sql).then(function (res) { // console.log(res); handleConninfoDataByDate(response, res); }, function () { }); }, function () { }); }; getConninfoList(); $scope.AllRemove = function () { // 显示记录操作表 $ionicActionSheet.show({ buttons: [ {text: '还原记录'}, {text: '清空记录'} ], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { $(".wastepaperDiv").css("padding-left", "15%"); $("#collect-bottom").css("display", "block"); status = false; } else if (index == 1) { $ionicPopup.show({ template: "

确定永久删除废纸篓所有记录

", title: "清空废纸篓", scope: $scope, buttons: [ {text: "取消"}, { text: '删除', type: "button-positive", onTap: function (e) { deleteAll(); } } ] }) } return true; } }); }; //跳转详情检测 $scope.checkStatus = function (record, rec, index) { if (status) { goRecordDetail(rec) } else { selectRecord(record, rec, index) } }; var goRecordDetail = function (record) { $scope.go("Dockingdetails", {infoid: record.localid}); }; //编辑列表 var selectRecord = function (record, rec, index) { var ii = $scope.recordList.indexOf(record); $scope.recordList[ii].reclist[index].value = !$scope.recordList[ii].reclist[index].value; countInfoidList(); }; var restorelist = []; $scope.selectNum = 0; //组装选中的infoid var countInfoidList = function () { restorelist = []; angular.forEach($scope.recordList, function (record, index) { angular.forEach(record.reclist, function (rec, ind) { if (rec.value) { restorelist.push(rec); } }); }); $scope.selectNum = restorelist.length; }; //批量更新 var updateBatchData = function (tablename, datalist) { SqliteStorageService.updateBatchData(tablename, datalist).then(function () { // console.log("回写成功"); }, function () { }); }; //批量删除 var deleteBatchData = function (tablename, datalist) { SqliteStorageService.deleteBatchData(tablename, datalist).then(function () { // console.log("批量delete成功"); }, function () { }) }; var batchSynchConninfo = function (templist) { DockingService.singleSync(2, templist).then(function (res) { // console.log("还原/删除记录--批量同步成功"); // console.log(res); if (angular.isDefined(res.recordReturnList) && res.recordReturnList.length > 0) { var tempconnlist_del = []; var tempconnlist_up = []; angular.forEach(res.recordReturnList, function (value, index) { var tconn = {}; tconn.localid = value.localid; tconn.id = value.id; if (value.synchrotype == 4) { tempconnlist_del.push(tconn); } else { tconn.synchrotype = 0; tempconnlist_up.push(tconn); } }); deleteBatchData("conninfo", tempconnlist_del); updateBatchData("conninfo", tempconnlist_up); } SqliteStorageService.updateEditFlg(1); }, function () { SqliteStorageService.updateEditFlg(1); }); }; var batchSynchCard = function (templist) { DockingService.singleSync(3, templist).then(function (res) { // console.log("删除名片--名片同步成功"); // console.log(res); if (angular.isDefined(res.cardReturnList) && res.cardReturnList.length > 0) { var tempunitlist_del = []; angular.forEach(res.cardReturnList, function (value, index) { var tunit = {}; tunit.localid = value.localid; tunit.id = value.id; tunit.infoid = value.infoid; tempunitlist_del.push(tunit); }); deleteBatchData("conninfounit", tempunitlist_del); var localuid = ""; angular.forEach(templist, function (data, ind) { localuid = localuid + "'" + data.localid + "'" + ","; }); localuid = localuid.substring(0, localuid.length - 1); var del_per_sql = "delete from conninfoperson where localuid in (" + localuid + ")"; SqliteStorageService.queryData(del_per_sql); var del_the_sql = "delete from conninfotheme where localuid in (" + localuid + ")"; SqliteStorageService.queryData(del_the_sql); } }, function () { }); }; var handleConninfoAndPicture = function (conninfolist, picturelist) { angular.forEach(conninfolist, function (value, index) { //图片拼接 var templist1 = []; angular.forEach(picturelist, function (data, ind) { if (value.localid == data.localinfoid) { templist1.push(data); } }); conninfolist[index].picture = templist1; }); //批量同步记录 batchSynchConninfo(conninfolist); }; //还原 $scope.restore = function () { var templist = []; var infoidlist = ""; angular.forEach(restorelist, function (value, index) { var tempdate = UtilService.formatDate(); var tempobj = angular.copy(value); tempobj.status = 2; tempobj.cloudfolder = ""; tempobj.updatetime = tempdate.formattime; if (UtilService.isDefined(value.id)) { tempobj.synchrotype = 2; } else { tempobj.synchrotype = 1; } templist.push(tempobj); var tempstr = "'" + value.localid + "'"; infoidlist = infoidlist + tempstr + ","; }); infoidlist = infoidlist.substring(0, infoidlist.length - 1); SqliteStorageService.updateBatchData("conninfo", templist).then(function (res) { //--查询图片信息 var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")"; SqliteStorageService.queryData(q_pic_sql).then(function (res) { // console.log("查询图片。。。"); // console.log(res); handleConninfoAndPicture(templist, res); }, function () { SqliteStorageService.updateEditFlg(1); }); UtilService.showMess("还原记录成功"); getConninfoList(); $scope.cancel(); HandleService.changeflg = true; }, function () { SqliteStorageService.updateEditFlg(1); }); }; //取消 $scope.cancel = function () { status = true; $(".wastepaperDiv").css("padding-left", "0%"); $("#collect-bottom").css("display", "none"); }; //清空 var deleteAll = function () { var templist = []; var localinfoidstr = ""; angular.forEach(tempconninfolist, function (value, index) { var tempdate = UtilService.formatDate(); var tempobj = angular.copy(value); tempobj.synchrotype = 4; tempobj.status = 3; tempobj.cloudfolder = ""; tempobj.updatetime = tempdate.formattime; templist.push(tempobj); //组装名片localid list localinfoidstr = localinfoidstr + "'" + value.localid + "'" + ","; }); localinfoidstr = localinfoidstr.substring(0, localinfoidstr.length - 1); SqliteStorageService.updateBatchData("conninfo", templist).then(function (res) { //批量同步记录 batchSynchConninfo(templist); //--查询名片信息 var q_com_sql = "select * from conninfounit where localinfoid in (" + localinfoidstr + ")"; SqliteStorageService.queryData(q_com_sql).then(function (res) { // console.log(res); var tempcardlist = []; var tempdate2 = UtilService.formatDate(); angular.forEach(res, function (data) { var tempobj2 = angular.copy(data); tempobj2.localid = data.localid; tempobj2.synchrotype = 4; tempobj2.updatetime = tempdate2.formattime; tempcardlist.push(tempobj2); }); SqliteStorageService.updateBatchData("conninfounit", tempcardlist).then(function (res) { batchSynchCard(tempcardlist); UtilService.showMess("清空记录成功"); }, function () { }); }); getConninfoList(); HandleService.changeflg = true; SqliteStorageService.updateEditFlg(1); }, function () { }); }; });