123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- 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: "<div style='height: 70px;'>" +
- "<input type='text' maxlength='20' ng-model='folder.name' style='border-radius:4px;border:1px solid #e9e9ea;text-indent: 11px;'>" +
- "<span class='pop_subtitle'>20个字以内,支持中英文,数字。</span>" +
- "</div>",
- title: '新建文件夹',
- scope: $scope,
- buttons: [
- {
- text: '取消',
- type: 'button-default',
- onTap: function () {
- $scope.folder.name = "";
- }
- },
- {
- text: '<span class="pop_right_button">创建</span>',
- 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: '<a class="action-sheet-push act_f">添加照片</a>'},
- {text: '<a class="action-sheet-push act_m">添加名片</a>'}
- /*{text: '<a class="action-sheet-push act_s">添加对接主题</a>'},
- {text: '<a class="action-sheet-push act_t">添加参加单位</a>'},
- {text: '<a class="action-sheet-push act_fo">添加人员信息</a>'}*/
- ],
- 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: '<a class="action-sheet-push">从通讯录中添加</a>'},
- {text: '<a class="action-sheet-push">自由编辑</a>'}
- ],
- 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: '<a class="action-sheet-push">同步到高校库</a>'},
- {text: '<a class="action-sheet-push">编辑内容</a>'}
- ],
- 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: '<a class="action-sheet-push">同步到高校库</a>'},
- {text: '<a class="action-sheet-push">编辑内容</a>'}
- ],
- 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<screenH){
- imgObj[n].style.marginTop = (screenH-cc)/2 +'px';
- // console.log("e:"+imgObj[n].style.marginTop);
- }else{
- imgObj[n].style.marginTop = 0+'px';
- // console.log((cc-screenH) +'px')
- }
- }
- }, 10);
- };
- //显示更多名片部分
- $scope.showMoreCard = function (index) {
- $(".parentWrapCard").eq(index).toggle();
- $(".showCardWrap").eq(index).toggle();
- $(".changeArrowButton").eq(index).toggleClass("upArrow");
- /* var cardText = $(".downArrow").eq(index).text();
- if (cardText == '展开') {
- $(".downArrow").eq(index).text("收起");
- } else {
- $(".downArrow").eq(index).text("展开");
- }*/
- };
- var cardDelect = function (cardindex) {
- $scope.cardlist.splice(cardindex, 1);
- };
- //重新编辑名片
- $scope.editCardContent = function (cardindex) {
- $ionicActionSheet.show({
- buttons: [
- /* {text: '<a class="action-sheet-push">同步到高校库</a>'},*/
- {text: '<a class="action-sheet-push">编辑名片</a>'},
- {text: '<a class="action-sheet-push">删除名片</a>'}
- ],
- 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: '<a class="action-sheet-push">云共享设置</a>'}
- ],
- 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;
- }*/
- });
|