123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937 |
- angular.module('push')
- .controller('editConninfoCtrl', function ($scope, $stateParams, $ionicActionSheet, $ionicModal, $timeout, UserService, $ionicSlideBoxDelegate,
- UtilService, ModelService, $ionicScrollDelegate, HandleService, SqliteStorageService, ConfigService) {
- var localinfoid = $stateParams.infoid;//是localinfoid
- $scope.folderlist = angular.copy(ModelService.getLocalFolderList());//分类列表
- $scope.level = 0;
- $scope.checkfolder = "";//被选中的文件夾id
- var copyrecord = {};
- var copyimagelist = [];
- //处理名片(名片下多个人员,则姓名组装-->XXX、XXX、XXX)
- var handleCard = function () {
- angular.forEach($scope.cardlist, function (value, index) {
- if (angular.isDefined(value.personlist) && value.personlist.length > 0) {
- var contactsrt = [];
- angular.forEach(value.personlist, function (val, ind) {
- contactsrt.push(val.contact);
- });
- $scope.cardlist[index].contactsrt = contactsrt.join("、");
- }
- $scope.cardlist[index].type = parseInt(value.type);
- });
- };
- //拼接名片下单位、人员、主题
- var handleConninfoDetailData = function () {
- HandleService.handleConninfoDetailData(tempcardlist, temppersonlist, tempthemelist, tempproductlist, tempiur1list, tempiur2list, tempyearprojectlist).then(function (response) {
- // console.log(response);
- $scope.cardlist = response;
- handleCard();
- }, function () {
- });
- //关闭监听
- overwatch();
- };
- //查找该记录所属本地文件夹
- var queryCheckFolder = function (localclaid) {
- var q_sql = "select * from conninfofolder where localid = '" + localclaid + "'";
- SqliteStorageService.queryData(q_sql).then(function (response) {
- // console.log(response);
- $scope.checkdefolder = response[0];
- $scope.checkfolder = $scope.checkdefolder.localid;
- }, function () {
- });
- angular.forEach($scope.folderlist, function (value, index) {
- if (value.localid == localclaid) {
- $scope.folderlist[index].value = true;
- }
- });
- };
- $scope.isover = 0;//0:本地对接信息开始查询 4:查询结束
- var tempcardlist = [];
- var temppersonlist = [];
- var tempthemelist = [];
- var tempproductlist = [];
- var tempiur1list = [];
- var tempiur2list = [];
- var tempyearprojectlist = [];
- //获取对接信息列表
- var getConninfo = function () {
- var sql = "select * from conninfo where creator = " + UserService.id + " and localid = " + localinfoid;
- SqliteStorageService.queryData(sql).then(function (response) {
- $scope.record = response[0];
- queryCheckFolder($scope.record.localclaid);
- //记录时间格式化
- var str = response[0].conntime;
- if (device.platform != "Android") {
- str = str.replace("-", "/");
- str = str.replace("-", "/");
- }
- $scope.record.date = new Date(str).Format("yyyy年MM月dd日 hh:mm");
- //记录详情格式化(HTML标签转换成文档标记)
- $scope.record.content = UtilService.replaceHTMLTag(response[0].content);
- //--查询图片信息
- var q_pic_sql = "select * from conninfopicture where localinfoid = " + localinfoid;
- SqliteStorageService.queryData(q_pic_sql).then(function (res) {
- // console.log(res);
- $scope.imagelist = res;
- copyimagelist = angular.copy(angular.toJson(res));
- }, function () {
- });
- //--查询名片信息
- var q_com_sql = "select * from conninfounit where localinfoid = " + localinfoid;
- SqliteStorageService.queryData(q_com_sql).then(function (res) {
- tempcardlist = res;
- if (tempcardlist.length > 0) {
- //组装名片localid list
- var cardlocalidstr = "";
- angular.forEach(tempcardlist, 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) {
- temppersonlist = resp;
- $scope.isover++;
- }, function () {
- temppersonlist = [];
- $scope.isover++;
- });
- //--查询主题信息
- var q_the_sql = "select * from conninfotheme where localuid in (" + cardlocalidstr + ")";
- SqliteStorageService.queryData(q_the_sql).then(function (resp) {
- tempthemelist = resp;
- $scope.isover++;
- }, function () {
- tempthemelist = [];
- $scope.isover++;
- });
- //--查询产品信息
- 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.isover++;
- }, function () {
- tempproductlist = [];
- $scope.isover++;
- });
- //--查询产学研经历信息
- 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.isover++;
- }, function () {
- tempiur1list = [];
- $scope.isover++;
- });
- //--查询重大科研项目信息
- 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.isover++;
- }, function () {
- tempiur2list = [];
- $scope.isover++;
- });
- //--查询历年申报项目信息
- 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.cardlist = [];
- }
- }, function () {
- });
- }, function (err) {
- // console.log(err);
- });
- };
- //监听查询是否结束
- var overwatch = $scope.$watch("isover", function (newValue, oldValue, scope) {
- if (newValue == 6) {
- handleConninfoDetailData();
- }
- });
- //编辑:数据是否已操作过
- if (ModelService.getIsFirstOpen() == 1) {
- $scope.record = ModelService.getConninfo();
- $scope.imagelist = ModelService.getImageList();//图片
- $scope.cardlist = ModelService.getCardList();
- handleCard();
- $scope.checkdefolder = ModelService.getEditCheckdeFolder();
- } else {
- getConninfo();
- }
- //分类列表页面
- $scope.search = {searchkey: ""};
- $ionicModal.fromTemplateUrl('templates/modal.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function (modal) {
- $scope.modal = modal;
- });
- //关闭选择文件夹
- $scope.closeModel = function () {
- $scope.modal.hide();
- // angular.forEach($scope.folderlist, function (value, ind) {
- // if (value.value) {
- // $scope.checkdefolder = value;
- // }
- // });
- };
- //选择分类
- $scope.chooseNewUndid = function (folder, index) {
- angular.forEach($scope.folderlist, function (value, ind) {
- $scope.folderlist[ind].value = false;
- });
- $scope.folderlist[index].value = true;
- $scope.checkdefolder = folder;
- $scope.checkfolder = folder.localid;
- ModelService.setEditCheckdeFolder(folder);
- };
- var tempimages = [];
- var uploadImages = function (temprecord) {
- tempimages = [];
- var upimages = [];
- angular.forEach($scope.imagelist, function (data) {
- if (data.photo_name.indexOf("file:") != -1) {
- upimages.push(data.photo_name);
- } else {
- tempimages.push(data);
- }
- });
- if (upimages.length > 0) {
- UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
- // console.log(response);
- angular.forEach(response, function (value, index) {
- if (value.status) {
- tempimages.push({
- id: 0, photo_name: value.userPhoto,
- original_name: value.originalPhoto,
- source_name: value.sourcePhoto,
- source_size: value.source_size
- });
- } else {
- tempimages.push({
- id: 0,
- photo_name: $scope.imagelist[index].photo_name,
- original_name: $scope.imagelist[index].original_name,
- source_name: $scope.imagelist[index].source_name,
- source_size: 0
- });
- }
- });
- $timeout(function () {
- saveInformation(temprecord);
- }, 100);
- }, function () {
- tempimages = angular.copy($scope.imagelist);
- saveInformation(temprecord);
- })
- } else {
- tempimages = angular.copy($scope.imagelist);
- saveInformation(temprecord);
- }
- };
- var checknum = 1;
- $scope.addisover = 0;
- var imagelist = [];
- var saveInformation = function (temprecord) {
- //名片(单位、人员、主题)数据生成
- var insertcardlist = [];//插入名片列表
- var updatecardlist = [];//更新名片列表
- var personlist = [];//人员列表
- var themelist = [];//主题列表
- var productlist = [];//产品列表
- var iur1list = [];//产学研经历列表
- var iur2list = [];//重大科研项目列表
- var yearprojectlist = [];//历年申报项目表
- var dellocaluidstr = "";
- try {
- var conninfodate = UtilService.formatDate();
- //对接信息数据修改
- temprecord.localclaid = $scope.checkdefolder.localid;//本地分类id
- temprecord.claid = $scope.checkdefolder.id;//server分类id
- if (temprecord.synchrotype != 1) {
- temprecord.synchrotype = 2;
- temprecord.updatetime = conninfodate.formattime;//修改时间
- }
- if (!UtilService.isDefined(temprecord.defaultFlag) && temprecord.defaultFlag != 1) {
- temprecord.defaultFlag = 0;
- }
- //图片列表数据生成
- imagelist = tempimages.length > 0 ? tempimages : $scope.imagelist;
- angular.forEach(imagelist, function (value, index) {
- var templocalinfoid = parseInt(temprecord.localid);
- imagelist[index].localid = templocalinfoid + index + "";
- imagelist[index].localinfoid = temprecord.localid;
- imagelist[index].id = 0;
- imagelist[index].infoid = temprecord.id;
- });
- /*------------------------------------------------------------*/
- var tempdatelocalid = conninfodate.timestamp;
- var date = new Date();
- angular.forEach($scope.cardlist, function (value, index) {
- //insert 0:新增名片 其他:名片已插入数据库
- if (value.isinsert == 0) {
- date.setSeconds(date.getSeconds() + index);
- //新增的名片初始化一些数据
- var tempcardobj = angular.copy(value);
- tempcardobj.localid = tempdatelocalid + index + "";
- tempcardobj.localinfoid = temprecord.localid;
- tempcardobj.id = 0;
- tempcardobj.infoid = temprecord.id;
- tempcardobj.synchrotype = 1;
- tempcardobj.creator = UserService.id;
- tempcardobj.creatorcomefrom = ConfigService.comefrom;
- tempcardobj.createtime = date.Format("yyyy-MM-dd hh:mm:ss");
- tempcardobj.updatetime = date.Format("yyyy-MM-dd hh:mm:ss");
- insertcardlist.push(tempcardobj);
- //新增的人员初始化一些数据
- angular.forEach(value.personlist, function (data, ind) {
- var tempperson = data;
- tempperson.localid = tempdatelocalid + ind + "";
- tempperson.localuid = tempcardobj.localid;
- tempperson.id = 0;
- tempperson.uid = 0;
- personlist.push(tempperson);
- });
- //新增的主题初始化一些数据
- angular.forEach(value.themelist, function (data, ind) {
- var temtheme = data;
- temtheme.localid = tempdatelocalid + ind + "";
- temtheme.localuid = tempcardobj.localid;
- temtheme.id = 0;
- temtheme.uid = 0;
- themelist.push(temtheme);
- });
- //新增的产品数据生成
- angular.forEach(value.productlist, function (data, ind) {
- var temproduct = data;
- temproduct.localid = tempdatelocalid + ind + "";
- temproduct.localuid = tempcardobj.localid;
- temproduct.id = 0;
- temproduct.uid = 0;
- temproduct.infoid = temprecord.id;
- productlist.push(temproduct);
- });
- //新增的产学研经历数据生成
- angular.forEach(value.iur1list, function (data, ind) {
- var temiur1 = data;
- temiur1.localid = tempdatelocalid + ind + "";
- temiur1.localuid = tempcardobj.localid;
- temiur1.id = 0;
- temiur1.uid = 0;
- temiur1.infoid = temprecord.id;
- iur1list.push(temiur1);
- });
- //新增的重大科研项数据生成
- angular.forEach(value.iur2list, function (data, ind) {
- var temiur2 = data;
- temiur2.localid = tempdatelocalid + ind + "";
- temiur2.localuid = tempcardobj.localid;
- temiur2.id = 0;
- temiur2.uid = 0;
- temiur2.infoid = temprecord.id;
- iur2list.push(temiur2);
- });
- //新增的重大科研项数据生成
- angular.forEach(value.calendarlist, function (data, ind) {
- var temiur2 = data;
- temiur2.localid = tempdatelocalid + ind + "";
- temiur2.localuid = tempcardobj.localid;
- temiur2.id = 0;
- temiur2.uid = 0;
- temiur2.infoid = temprecord.id;
- yearprojectlist.push(temiur2);
- });
- } else if (value.synchrotype != 0) {
- //组装数据库已存在的名片的localid(用于清空人员、主题,方便后续插入)
- if (dellocaluidstr.length == 0) {
- dellocaluidstr = value.localid;
- } else {
- dellocaluidstr = dellocaluidstr + "," + value.localid;
- }
- //数据库已存在名片,需要修改
- value.updatetime = conninfodate.formattime;
- updatecardlist.push(value);
- //人员列表处理(已存在的不动,新增的初始化数据)
- angular.forEach(value.personlist, function (data, ind) {
- var tempperson = data;
- if (!UtilService.isDefined(tempperson.localid)) {
- tempperson.localid = tempdatelocalid + ind + "";
- tempperson.localuid = value.localid;
- tempperson.id = 0;
- tempperson.uid = 0;
- }
- personlist.push(tempperson);
- });
- //主题列表处理(已存在的不动,新增的初始化数据)
- angular.forEach(value.themelist, function (data, ind) {
- var temtheme = data;
- if (!UtilService.isDefined(temtheme.localid)) {
- temtheme.localid = tempdatelocalid + ind + "";
- temtheme.localuid = value.localid;
- temtheme.id = 0;
- temtheme.uid = 0;
- }
- themelist.push(temtheme);
- });
- //产品数据生成(已存在的不动,新增的初始化数据)
- angular.forEach(value.productlist, function (data, ind) {
- var temproduct = data;
- if (!UtilService.isDefined(data.localid)) {
- temproduct.localid = tempdatelocalid + ind + "";
- temproduct.localuid = value.localid;
- temproduct.id = 0;
- temproduct.uid = 0;
- temproduct.infoid = temprecord.id;
- }
- productlist.push(temproduct);
- });
- //产学研经历数据生成(已存在的不动,新增的初始化数据)
- angular.forEach(value.iur1list, function (data, ind) {
- var temiur1 = data;
- if (!UtilService.isDefined(data.localid)) {
- temiur1.localid = tempdatelocalid + ind + "";
- temiur1.localuid = value.localid;
- temiur1.id = 0;
- temiur1.uid = 0;
- temiur1.infoid = temprecord.id;
- }
- iur1list.push(temiur1);
- });
- //重大科研项数据生成(已存在的不动,新增的初始化数据)
- angular.forEach(value.iur2list, function (data, ind) {
- var temiur2 = data;
- if (!UtilService.isDefined(data.localid)) {
- temiur2.localid = tempdatelocalid + ind + "";
- temiur2.localuid = value.localid;
- temiur2.id = 0;
- temiur2.uid = 0;
- temiur2.infoid = temprecord.id;
- }
- iur2list.push(temiur2);
- });
- //重大科研项数据生成(已存在的不动,新增的初始化数据)
- angular.forEach(value.calendarlist, function (data, ind) {
- var temiur2 = data;
- if (!UtilService.isDefined(data.localid)) {
- temiur2.localid = tempdatelocalid + ind + "";
- temiur2.localuid = value.localid;
- temiur2.id = 0;
- temiur2.uid = 0;
- temiur2.infoid = temprecord.id;
- }
- yearprojectlist.push(temiur2);
- });
- }
- });
- // console.log(temprecord);
- // console.log(imagelist);
- // console.log(insertcardlist);
- // console.log("-----------------------------------");
- // console.log(updatecardlist);
- // console.log(dellocaluidstr);
- // console.log(personlist);
- // console.log(themelist);
- // console.log(productlist);
- // console.log(iur1list);
- // console.log(iur2list);
- console.log(yearprojectlist);
- // console.log("-----------------------------------");
- } catch (e) {
- // console.log(e);
- $scope.hideLoadingToast();
- }
- if (imagelist.length > 0) {
- checknum++;
- }
- if (updatecardlist.length > 0) {
- checknum++;
- }
- if (insertcardlist.length > 0) {
- checknum++;
- }
- 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 (yearprojectlist.length > 0) {
- checknum++;
- }
- //更新记录
- SqliteStorageService.updateSingleData("conninfo", temprecord).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.editstatus = 2;
- $scope.addisover++;
- });
- //更新图片
- var deletesql = "delete from conninfopicture where localinfoid = " + temprecord.localid;
- SqliteStorageService.deleteData(deletesql).then(function () {
- if (imagelist.length > 0) {
- SqliteStorageService.insertBatchData("conninfopicture", imagelist).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- }, function () {
- $scope.hideLoadingToast();
- });
- //更新名片
- if (updatecardlist.length > 0) {
- SqliteStorageService.updateBatchData("conninfounit", updatecardlist).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- //插入新名片
- if (insertcardlist.length > 0) {
- SqliteStorageService.insertBatchData("conninfounit", insertcardlist).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- //删除--插入人员
- var delsql1 = "delete from conninfoperson where localuid in (" + dellocaluidstr + ")";
- SqliteStorageService.deleteData(delsql1).then(function () {
- if (personlist.length > 0) {
- SqliteStorageService.insertBatchData("conninfoperson", personlist).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- }, function () {
- $scope.hideLoadingToast();
- });
- //删除--插入主题
- var delsql2 = "delete from conninfotheme where localuid in (" + dellocaluidstr + ")";
- SqliteStorageService.deleteData(delsql2).then(function () {
- if (themelist.length > 0) {
- SqliteStorageService.insertBatchData("conninfotheme", themelist).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- }, function () {
- $scope.hideLoadingToast();
- });
- //删除--插入产品
- var delsql3 = "delete from conninfoproduct where localuid in (" + dellocaluidstr + ")";
- SqliteStorageService.deleteData(delsql3).then(function () {
- if (productlist.length > 0) {
- SqliteStorageService.insertBatchData("conninfoproduct", productlist).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- }, function () {
- $scope.hideLoadingToast();
- });
- //删除--插入产学研经历
- var delsql4 = "delete from conninfoiur where localuid in (" + dellocaluidstr + ")";
- SqliteStorageService.deleteData(delsql4).then(function () {
- if (iur1list.length > 0) {
- SqliteStorageService.insertBatchData("conninfoiur", iur1list).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- }, function () {
- $scope.hideLoadingToast();
- });
- //删除--插入重大科研项目
- var delsql5 = "delete from conninforesearch where localuid in (" + dellocaluidstr + ")";
- SqliteStorageService.deleteData(delsql5).then(function () {
- if (iur2list.length > 0) {
- SqliteStorageService.insertBatchData("conninforesearch", iur2list).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- }, function () {
- $scope.hideLoadingToast();
- });
- //删除--插入历年申报项目
- var delsql6 = "delete from yearproject where localuid in (" + dellocaluidstr + ")";
- SqliteStorageService.deleteData(delsql6).then(function () {
- if (yearprojectlist.length > 0) {
- SqliteStorageService.insertBatchData("yearproject", yearprojectlist).then(function () {
- $scope.addisover++;
- }, function () {
- $scope.addisover++;
- });
- }
- }, function () {
- $scope.hideLoadingToast();
- });
- };
- $scope.immediateRelease = function () {
- //判断记录标题
- if (!UtilService.isDefined($scope.record.title)) {
- UtilService.showMess("标题不能为空");
- return;
- }
- //记录日期转化为yyyy-MM-dd HH:mm 格式
- 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);
- }
- //记录内容转为HTML标签
- if (UtilService.isDefined(temprecord.content)) {
- temprecord.content = UtilService.replaceEnterTag(temprecord.content);
- }
- $scope.showLoadingToast();
- //检测网络
- if (UtilService.checkNetWork() != "None") {
- //上传图片
- uploadImages(temprecord);
- } else {
- //保存信息
- saveInformation(temprecord);
- }
- };
- //监听是否结束
- var overwatch2 = $scope.$watch("addisover", function (newValue, oldValue, scope) {
- if (newValue == checknum) {
- if ($scope.editstatus == 2) {
- UtilService.showMess("修改记录失败,请重试");
- $scope.hideLoadingToast();
- } else {
- UtilService.showMess("修改记录成功");
- $scope.hideLoadingToast();
- $timeout(function () {
- $scope.goback();
- }, 1000);
- ModelService.resetTempData();
- ConfigService.isedit = 1;
- SqliteStorageService.updateEditFlg(1);
- overwatch2();
- }
- }
- });
- //保存本页面数据
- var saveTempDate = function () {
- var tempstr = $("#appDateTime").val();
- if (UtilService.isDefined(tempstr)) {
- $scope.record.date = tempstr;
- }
- ModelService.setConninfo($scope.record);
- ModelService.setImageList($scope.imagelist);
- ModelService.setCardList($scope.cardlist);
- ModelService.setEditCheckdeFolder($scope.checkdefolder);
- ModelService.setIsFirstOpen(1);
- };
- //切换标志
- $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>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- if (index == 0) {
- getPictures();
- } else if (index == 1) {
- saveTempDate();
- $scope.go('editListCard');
- }
- 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({
- id: 0,
- photo_name: results,
- original_name: results,
- source_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({id: 0, photo_name: value, original_name: value, source_name: results})
- });
- $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 (image, 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 //结束年份
- };
- var optDateTime = $.extend(opt['datetime'], opt['default']);
- $("#appDateTime").mobiscroll(optDateTime).datetime(optDateTime);
- });
- $scope.editBack = function () {
- ModelService.resetTempData();
- $scope.goback();
- };
- //查找分类
- $scope.searchClassification = function () {
- $timeout(function () {
- $(".searchClassification").css("width", "88%");
- $(".category_search_icon").css("left", "5%");
- $(".new_category_search").animate({paddingLeft: "10%"});
- $(".new_category_search").css("text-align", "left");
- $(".searchClassDelete").css("display", "inline-block");
- }, 100);
- };
- //取消查询
- $scope.searchClassDelete = function () {
- $(".searchClassification").css("width", "100%");
- $(".category_search_icon").animate({left: "39%"});
- $(".new_category_search").animate({paddingLeft: "0%"});
- $(".new_category_search").css("text-align", "center");
- $(".searchClassDelete").css("display", "none");
- $scope.search.searchkey = "";
- };
- //点击图片放大
- $scope.bigImage = false; //初始默认大图是隐藏的
- $scope.hideBigImage = function () {
- $timeout(function () {
- $scope.bigImage = false;
- }, 400);
- };
- $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
- $scope.bigImage = true; //显示大图
- // console.log(index);
- $ionicSlideBoxDelegate.update();//重绘,让图片显示出来
- //图片总数量
- setTimeout(function () {
- // console.log(parseInt($ionicSlideBoxDelegate.slidesCount()));
- // console.log(parseInt($ionicSlideBoxDelegate.currentIndex()));
- $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')
- }
- }
- }, 0);
- };
- //显示更多名片部分
- $scope.showMoreCard = function (index) {
- $(".parentWrapCard").eq(index).toggle();
- $(".showCardWrap").eq(index).toggle();
- $(".changeArrowButton").eq(index).toggleClass("upArrow");
- };
- var cardDelect = function (cardindex) {
- if ($scope.cardlist[cardindex].isinsert == 0) {
- $scope.cardlist.splice(cardindex, 1);
- } else {
- $scope.cardlist[cardindex].synchrotype = 4;
- }
- };
- //重新编辑名片
- $scope.editCardContent = function (cardindex) {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">编辑名片</a>'},
- {text: '<a class="action-sheet-push">删除名片</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- if (index == 0) {
- saveTempDate();
- $scope.go("editListCard", {index: cardindex});
- } else {
- cardDelect(cardindex);
- }
- return true;
- }
- });
- };
- //返回上一级目录
- $scope.backUpperFolder = function () {
- ModelService.deleteSelectLevelList($scope.level);
- $scope.level--;
- if ($scope.level == 0) {
- $scope.folderlist = angular.copy(ModelService.getLocalFolderList());
- } else {
- var tempfolder = ModelService.getSelectLevelList()[$scope.level];
- queryLocalFolder(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;
- queryLocalFolder(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;
- }, function () {
- });
- };
- });
|