angular.module('push') .controller('addListCtrl', function ($scope, $ionicHistory, $ionicActionSheet, $ionicModal, $ionicPopup, $timeout, ConfigService, UserService, UtilService, DockingService, ModelService, $ionicScrollDelegate, HandleService, SqliteStorageService, $ionicSlideBoxDelegate) { if($scope.app){ $scope.setStatusBar(0); } $scope.folderlist = ModelService.getLocalFolderList();//分类列表 $scope.checkdefolder = ModelService.getCheckdeFolder();//选中的分类 $scope.search = {searchkey: ""}; var handleFolderData = function (tempfolderlist, tempconninfolist) { HandleService.handleFolderData(tempfolderlist, tempconninfolist).then(function (response) { $scope.folderlist = response.folderlist; angular.forEach($scope.folderlist, function (value, index) { if (value.localid == $scope.checkdefolder.localid) { $scope.checkdefolder = angular.copy(value); ModelService.setCheckdeFolder($scope.checkdefolder); } }); ModelService.setLocalFolderList($scope.folderlist); }, function () { }) }; var getFolderList = function () { var sql = "select * from conninfofolder where userid = " + UserService.id + " and isCloud = 0"; SqliteStorageService.queryData(sql).then(function (response) { var sql = "select * from conninfo where creator = " + UserService.id + " order by conntime desc"; SqliteStorageService.queryData(sql).then(function (response2) { handleFolderData(response, response2); }, function () { }); }, function () { }); }; // getFolderList(); //新增或已有数据 if (angular.isDefined(ModelService.getConninfo().date)) { $scope.record = ModelService.getConninfo(); } else { $scope.record = { date: UtilService.formatDate().formattime3, title: "", flag: 0, content: "" }; } $scope.imagelist = ModelService.getImageList();//图片 $scope.cardlist = ModelService.getCardList(); $ionicModal.fromTemplateUrl('templates/modal.html', { scope: $scope, animation: 'slide-in-up' }).then(function (modal) { $scope.modal = modal; }); // 自定义新建分类弹窗 $scope.showPopup = function () { $ionicPopup.show({ template: "
" + "" + "20个字以内,支持中英文,数字。" + "
", title: '新建文件夹', scope: $scope, buttons: [ { text: '取消', type: 'button-default', onTap: function () { $scope.folder.name = ""; } }, { text: '创建', type: 'button-positive', onTap: function (e) { if (!UtilService.isDefined($scope.folder.name)) { UtilService.showMess("文件夹名称不能为空"); e.preventDefault(); return; } if ($scope.folder.name == "默认文件夹") { UtilService.showMess("默认文件夹已存在"); e.preventDefault(); return; } createFolder(); } } ] }); }; $scope.folder = {name: ""}; //新建分类 var crfoflg = 0; var createFolder = function () { if (crfoflg != 0) { return; } crfoflg = 1; var tempdate = UtilService.formatDate(); var folder = { localid: tempdate.timestamp + "",//本地id id: 0, userid: UserService.id, usercomefrom: ConfigService.comefrom, name: $scope.folder.name, createtime: tempdate.formattime, status: 0, isCloud: 0, synchrotype: 1,// 0:已同步,1:新增,2:修改,3:逻辑删除,4:物理删除 updatetime: tempdate.formattime,//修改时间 counts: 0 }; SqliteStorageService.insertSingleData("conninfofolder", folder).then(function (response) { $scope.folderlist.push(folder); $scope.checkdefolder = folder; $scope.folder.name = ""; $scope.modal.hide(); ModelService.setLocalFolderList($scope.folderlist); ModelService.setCheckdeFolder(folder); SqliteStorageService.updateEditFlg(1); $timeout(function () { crfoflg = 0; }, 1000); }, function () { crfoflg = 0; }); }; //选择分类 $scope.chooseNewUndid = function (folder, index) { ModelService.setCheckdeFolder(folder); $scope.checkdefolder = folder; $scope.modal.hide(); }; var tempimages = []; var uploadImages = function (temprecord) { tempimages = []; var upimages = []; angular.forEach($scope.imagelist, function (data) { upimages.push(data.photo_name); }); UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) { angular.forEach(response, function (value, index) { if (value.status) { tempimages.push({id: 0, photo_name: value.userPhoto, original_name: value.originalPhoto}); } else { tempimages.push({ id: 0, photo_name: $scope.imagelist[index].photo_name, original_name: $scope.imagelist[index].original_name }); } }); $timeout(function () { saveInformation(temprecord); }, 100); }, function () { saveInformation(temprecord); $scope.hideLoadingToast(); UtilService.showMess("网络不给力,请重试"); }) }; var checknum = 1; $scope.addisover = 0; var uptemprecord = {}; var imagelist = []; var saveInformation = function (temprecord) { try { var conninfodate = UtilService.formatDate(); var conninfodatelocalid = conninfodate.timestamp; //对接信息数据生成 temprecord.localid = conninfodatelocalid + ""; temprecord.localclaid = $scope.checkdefolder.localid; temprecord.id = 0; temprecord.claid = $scope.checkdefolder.id; temprecord.creator = UserService.id; temprecord.synchrotype = 1; temprecord.createtime = conninfodate.formattime; temprecord.updatetime = conninfodate.formattime; temprecord.creatorcomefrom = ConfigService.comefrom; temprecord.status = 2; temprecord.defaultFlag = 0; uptemprecord = temprecord; //图片列表数据生成 imagelist = tempimages.length > 0 ? tempimages : $scope.imagelist; if (imagelist.length > 0) { checknum++; } angular.forEach(imagelist, function (value, index) { imagelist[index].localid = conninfodatelocalid + index + ""; imagelist[index].localinfoid = conninfodatelocalid + ""; imagelist[index].id = 0; imagelist[index].infoid = temprecord.id; }); if ($scope.cardlist.length > 0) { checknum++; } //名片(单位、人员、主题)数据生成 var personlist = []; var themelist = []; var date = new Date(); angular.forEach($scope.cardlist, function (value, index) { var tempcardlocalid = conninfodatelocalid + index; date.setSeconds(date.getSeconds() + index); $scope.cardlist[index].localid = tempcardlocalid + ""; $scope.cardlist[index].localinfoid = conninfodatelocalid + ""; $scope.cardlist[index].id = 0; $scope.cardlist[index].infoid = temprecord.id; $scope.cardlist[index].creator = UserService.id; $scope.cardlist[index].synchrotype = 1; $scope.cardlist[index].creatorcomefrom = ConfigService.comefrom; $scope.cardlist[index].createtime = date.Format("yyyy-MM-dd hh:mm:ss"); $scope.cardlist[index].updatetime = date.Format("yyyy-MM-dd hh:mm:ss"); angular.forEach(value.personlist, function (value, ind) { var tempperson = value; tempperson.localid = tempcardlocalid + ind + ""; tempperson.localuid = tempcardlocalid + ""; tempperson.id = 0; tempperson.uid = 0; personlist.push(tempperson); }); angular.forEach(value.themelist, function (value, ind) { var temtheme = value; temtheme.localid = tempcardlocalid + ind + ""; temtheme.localuid = tempcardlocalid + ""; temtheme.id = 0; temtheme.uid = 0; themelist.push(temtheme); }); }); if (personlist.length > 0) { checknum++; } if (themelist.length > 0) { checknum++; } } catch (e) { $scope.hideLoadingToast(); } SqliteStorageService.insertSingleData("conninfo", temprecord).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); if (imagelist.length > 0) { SqliteStorageService.insertBatchData("conninfopicture", imagelist).then(function () { $scope.addisover++; }, function () { $scope.hideLoadingToast(); }); } if ($scope.cardlist.length > 0) { SqliteStorageService.insertBatchData("conninfounit", $scope.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(); }); } }; //公共批量更新 var updateBatchData = function (tablename, datalist) { SqliteStorageService.updateBatchData(tablename, datalist).then(function () { }, function () { }); }; //共享对接记录至云文件夹 var shareConninfoToCloudFolder = function (claid) { //同步记录 uptemprecord.claid = claid; if (ModelService.sharecloudflg) { uptemprecord.cloudfolder = ModelService.getShareCloudIdList().join(","); } else { uptemprecord.cloudfolder = ""; } uptemprecord.picture = imagelist; DockingService.singleSync(2, [uptemprecord]).then(function (res) { if (angular.isDefined(res.recordReturnList) && res.recordReturnList.length > 0) { var tconninfo = {}; tconninfo.localid = res.recordReturnList[0].localid; tconninfo.id = res.recordReturnList[0].id; tconninfo.claid = res.recordReturnList[0].claid; tconninfo.synchrotype = 0; //同步名片 if ($scope.cardlist.length > 0) { angular.forEach($scope.cardlist, function (value, index) { $scope.cardlist[index].infoid = res.recordReturnList[0].id; }); DockingService.singleSync(3, $scope.cardlist).then(function (res) { // console.log("新建记录--名片同步成功"); // console.log(res); if (angular.isDefined(res.cardReturnList) && res.cardReturnList.length > 0) { var tempunitlist = []; angular.forEach(res.cardReturnList, function (value, index) { var tunit = {}; tunit.localid = value.localid; tunit.id = value.id; tunit.infoid = value.infoid; tunit.synchrotype = 0; tempunitlist.push(tunit); }); updateBatchData("conninfounit", tempunitlist); } }, function () { showSuccess(); }); } updateBatchData("conninfo", [tconninfo]); } }, function () { showSuccess(); }); $timeout(function () { ModelService.resetTempData(); ModelService.sharecloudflg = false; showSuccess(); }, 2000); }; //显示创建记录成功 var showSuccess = function () { UtilService.showMess("新建记录成功"); $scope.hideLoadingToast(); $timeout(function () { $scope.goback(); }, 1000); ModelService.resetTempData(); SqliteStorageService.updateEditFlg(1); overwatch(); }; //监听是否结束 var overwatch = $scope.$watch("addisover", function (newValue, oldValue, scope) { if (newValue == checknum) { HandleService.changeflg = true; if (UtilService.checkNetWork() != "None") { if (uptemprecord.claid == 0) { // console.log($scope.checkdefolder); DockingService.createFolder($scope.checkdefolder).then(function (resc) { // console.log(resc); // console.log("分类上传至Server成功"); var folder = {}; folder.localid = $scope.checkdefolder.localid; folder.id = resc.conn.id; folder.synchrotype = 0; SqliteStorageService.updateSingleData("conninfofolder", folder).then(function () { // console.log("更新本地分类id成功"); }, function () { }); shareConninfoToCloudFolder(resc.conn.id); }, function () { showSuccess(); }) } else { shareConninfoToCloudFolder(uptemprecord.claid); } } else { showSuccess(); } } }); $scope.immediateRelease = function () { if (!UtilService.isDefined($scope.record.title)) { UtilService.showMess("标题不能为空"); return; } var temprecord = angular.copy($scope.record); var tempstr = $("#appDateTime").val(); if (UtilService.isDefined(tempstr)) { temprecord.conntime = UtilService.formatTime(tempstr); } else { temprecord.conntime = UtilService.formatTime($scope.record.date); } if (UtilService.isDefined(temprecord.content)) { temprecord.content = UtilService.replaceEnterTag(temprecord.content); } $scope.showLoadingToast(); if (UtilService.checkNetWork() != "None") { uploadImages(temprecord); } else { saveInformation(temprecord); } }; var saveTempDate = function () { ModelService.setConninfo($scope.record); ModelService.setImageList($scope.imagelist); ModelService.setCardList($scope.cardlist); }; //是否标志 $scope.checkFlag = function () { $scope.record.flag = $scope.record.flag == 1 ? 0 : 1; }; $scope.show = function () { $ionicActionSheet.show({ buttons: [ {text: '添加照片'}, {text: '添加名片'} /*{text: '添加对接主题'}, {text: '添加参加单位'}, {text: '添加人员信息'}*/ ], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { getPictures(); } else if (index == 1) { saveTempDate(); $scope.go('addListCard'); } /* else if (index == 2) { saveTempDate(); $scope.go('DockingTheme'); } else if (index == 3) { saveTempDate(); $scope.go('ParticipatingUnits'); } else if (index == 4) { $ionicActionSheet.show({ buttons: [ {text: '从通讯录中添加'}, {text: '自由编辑'} ], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { getContact(); } else if (index == 1) { var tempdate = UtilService.formatDate(); $scope.members.push({localid: tempdate.timestamp, contact: "", type: 0, phone: ""}); } return true; } }); }*/ return true; } }); }; $scope.openCamera = function () { if ($scope.imagelist.length >= 18) { UtilService.showMess("最多选取18张图片"); return; } UtilService.getPicture(1).then(function (results) { // console.log(results); $scope.imagelist.push({photo_name: results, original_name: results}); $scope.totalImglength = 600 * $scope.imagelist.length; $ionicScrollDelegate.$getByHandle("scrollimage").resize(); }, function (err) { }); }; var verifyStorage = function () { window.imagePicker.verifyStorage( function (results) { if (results == "1") { getPic(); } }, function (error) { } ); }; var getPic = function () { if ($scope.imagelist.length >= 18) { UtilService.showMess("最多选取18张图片"); return; } UtilService.getPictureList(18 - $scope.imagelist.length).then(function (results) { // console.log(results); angular.forEach(results, function (value, index) { $scope.imagelist.push({photo_name: value, original_name: value}) }); $scope.totalImglength = 600 * $scope.imagelist.length; $ionicScrollDelegate.$getByHandle("scrollimage").resize(); }, function (err) { }); }; var getPictures = function () { if (device.platform == "Android") { verifyStorage(); } else { getPic(); } }; //删除图片 $scope.deletePhoto = function (index) { $scope.imagelist.splice(index, 1); }; //时间选择器 $(function () { var currYear = (new Date()).getFullYear(); var opt = {}; opt.date = {preset: 'date'}; opt.datetime = {preset: 'datetime'}; opt.time = {preset: 'time'}; opt.default = { theme: 'android-ics light', //皮肤样式 display: 'modal', //显示方式 mode: 'scroller', //日期选择模式 dateFormat: 'yyyy年mm月dd日', lang: 'zh', showNow: true, nowText: "今天", startYear: currYear - 50, //开始年份 endYear: currYear + 10 //结束年份 }; /*$("#appDateTime").mobiscroll($.extend(opt['date'], opt['default']));*/ var optDateTime = $.extend(opt['datetime'], opt['default']); $("#appDateTime").mobiscroll(optDateTime).datetime(optDateTime); }); $scope.addListBack = function () { ModelService.resetTempData(); ModelService.sharecloudflg = false; $scope.goback(); }; //重新编辑参与主题结果 $scope.editThemeContent = function (theme, listindex) { $ionicActionSheet.show({ buttons: [ {text: '同步到高校库'}, {text: '编辑内容'} ], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { $scope.go("buildResourceInit"); } if (index == 1) { $scope.go("DockingTheme", {theme: theme, index: listindex}); } } }); }; //重新编辑参与单位结果 $scope.editUnitContent = function (company, listindex) { $ionicActionSheet.show({ buttons: [ {text: '同步到高校库'}, {text: '编辑内容'} ], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { $scope.go("buildResourceInit"); } if (index == 1) { $scope.go("ParticipatingUnits", {company: company, index: listindex}); } } }); }; //点击图片放大 $scope.bigImage = false; //初始默认大图是隐藏的 $scope.hideBigImage = function () { $timeout(function (){ $scope.bigImage = false; },400); }; $scope.shouBigImage = function (index) { //传递一个参数(图片的URl) $scope.bigImage = true;//显示大图 $ionicSlideBoxDelegate.update();//重绘,让图片显示出来 //图片总数量 setTimeout(function () { $ionicSlideBoxDelegate.$getByHandle('slide_detail').slide(index, -10); //获取图片 var imgObj = document.getElementsByClassName('bigimage'); var n; for (n = 0; n < imgObj.length; n++) { // 获取图片的原始高度和宽度 var oldWid = imgObj[n].naturalWidth; var oldHei = imgObj[n].naturalHeight; var screen = document.body.offsetWidth; var screenH =window.innerHeight; // console.log(oldWid / oldHei); // console.log(screen); var cc = screen / (oldWid / oldHei); imgObj[n].style.height = cc + 'px'; if(cc同步到高校库'},*/ {text: '编辑名片'}, {text: '删除名片'} ], cancelText: '取消', buttonClicked: function (index) { /*if (index == 0) { $scope.go("buildResourceInit"); }*/ if (index == 0) { saveTempDate(); $scope.go("addListCard", {index: cardindex}); } else { cardDelect(cardDelect); } return true; } }); }; //对接记录设置 $scope.editCloudSare = function () { $ionicActionSheet.show({ buttons: [ {text: '云共享设置'} ], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { if (UtilService.checkNetWork() == "None") { UtilService.showMess("当前网络已关闭,请打开网络后操作此功能"); return true; } saveTempDate(); $scope.go("CloudShareSet"); } return true; } }); }; //键盘操作 /* $scope.closeKeyboard=function () { $(".addList_bottom_first").toggleClass("keyBoardHide"); $scope.isOpen =true; }*/ });