activityReleaseCtrl.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. /**
  2. * Created by pushkeji on 2018/10/11.
  3. */
  4. angular.module('push')
  5. .controller('activityReleaseCtrl', function ($scope, activitiesModuleService, $timeout, $q, UserService, $ionicPopup, AccountService, $ionicActionSheet, dataToolsService, UtilService, CommonService, ionicDatePicker, $stateParams) {
  6. // taskreleasede 控制器是identifyFormCtrl
  7. /***************** 富文本 ********/
  8. //var editor = KindEditor.create('#editor');
  9. var editor = CKEDITOR.replace('editor');
  10. $scope.activePage = 0;
  11. $scope.pageTitle = ['活动基本信息', '活动详情', '报名表单设置'];
  12. // 获取活动类型下拉列表
  13. var activityType = [];
  14. var user = "";
  15. var allData = $stateParams.data ? JSON.parse($stateParams.data).activityInfo : { id: 0 };
  16. dataToolsService.getTypeEntryListByTypeName('activity_type').then(function (res) {
  17. console.log(res);
  18. if (res.code == 3350) {
  19. angular.forEach(res.data, function (val) {
  20. activityType.push({
  21. text: '<a class="action-sheet-push">' + val.itemkey + '</a>',
  22. itemkey: val.itemvalue,
  23. itemvalue: val.itemkey //名字
  24. })
  25. });
  26. getConfigData().then(function (data) {
  27. for (var i = 0; i < data.length; i++) {
  28. if (data[i].isfixed == 'true') {
  29. data[i].isneed = true;
  30. data[i].disabled = true;
  31. $scope.items.push(data[i]);
  32. } else {
  33. data[i].isneed = false;
  34. data[i].hasChosen = false;
  35. data[i].disabled = false;
  36. $scope.configList.push(data[i]);
  37. }
  38. }
  39. if ($stateParams.data) {
  40. // 编辑
  41. var data = JSON.parse($stateParams.data).activityInfo;
  42. dealWithData(data);
  43. //$("#editor").val(allData.content);
  44. CKEDITOR.instances.editor.setData(allData.content);
  45. //CKEDITOR.instances.editor.setData(data.content);
  46. //editor.text(data.content);
  47. angular.forEach(JSON.parse(data.settingItems), function (vv) {
  48. if (vv.isfixed != 'true') {
  49. $scope.items.push(vv);
  50. for (var j = 0; j < $scope.configList.length; j++) {
  51. if ($scope.configList[j].text == vv.text) {
  52. $scope.configList[j].hasChosen = true;
  53. break;
  54. }
  55. }
  56. }
  57. })
  58. }
  59. })
  60. }
  61. });
  62. var getConfigData = function () {
  63. var deferred = $q.defer();
  64. // 获取报名表单配置选项数据
  65. $scope.configList = [];
  66. $scope.items = [];
  67. activitiesModuleService.getFormConfigurationList().then(function (res) {
  68. console.log(res);
  69. if (res.code == 3350) {
  70. // angular.forEach(res.data,function(val,index){
  71. // if(val.isfixed){
  72. // $scope.items.push(val)
  73. // res.data.splice(index,1);
  74. // }
  75. // })
  76. deferred.resolve(res.data);
  77. }
  78. })
  79. return deferred.promise;
  80. }
  81. var allFormList = [
  82. [
  83. {
  84. title: '活动名称',
  85. placeholder: '请填写活动名称',
  86. content: '',
  87. type: 'input',
  88. needed: true,
  89. saveKey: 'name',
  90. }, {
  91. title: '举办单位',
  92. placeholder: '请填写举办单位',
  93. content: '',
  94. type: 'input',
  95. needed: true,
  96. saveKey: 'orgname',
  97. }, {
  98. title: '活动开始时间',
  99. placeholder: 'yyyy-mm-dd',
  100. content: '',
  101. timeContent: '00:00',
  102. type: 'date',
  103. needed: true,
  104. saveKey: 'begintime',
  105. }, {
  106. title: '活动结束时间',
  107. placeholder: 'yyyy-mm-dd',
  108. content: '',
  109. timeContent: '00:00',
  110. type: 'date',
  111. needed: true,
  112. saveKey: 'endtime',
  113. }, {
  114. title: '报名截止时间',
  115. placeholder: 'yyyy-mm-dd',
  116. content: '',
  117. timeContent: '00:00',
  118. type: 'date',
  119. needed: true,
  120. saveKey: 'dealtime',
  121. }, {
  122. title: '活动人数',
  123. placeholder: '不填默认不限',
  124. content: '',
  125. type: 'input',
  126. needed: false,
  127. saveKey: 'minpeople',
  128. }, {
  129. title: '活动地址',
  130. content: '',
  131. type: 'selectArea',
  132. needed: false,
  133. saveKey: 'addr',
  134. code: 'addr'
  135. }, {
  136. title: '详细地址',
  137. placeholder: '请填写详细地址',
  138. content: '',
  139. type: 'input',
  140. needed: true,
  141. saveKey: 'addrdetail',
  142. },
  143. ],
  144. [
  145. {
  146. title: '活动类别',
  147. placeholder: '请选择活动类别',
  148. content: '',
  149. selectkey: '',
  150. type: 'select',
  151. needed: true,
  152. saveKey: 'type',
  153. key: '',
  154. listItem: activityType
  155. // [
  156. // {
  157. // text: '<a class="action-sheet-push">' + '会议' + '</a>',
  158. // itemkey: 5921,
  159. // itemvalue: '会议' //名字
  160. // },{
  161. // text: '<a class="action-sheet-push">' + '培训' + '</a>',
  162. // itemkey: 5922,
  163. // itemvalue: '培训' //名字
  164. // },{
  165. // text: '<a class="action-sheet-push">' + '产学研活动' + '</a>',
  166. // itemkey: 5923,
  167. // itemvalue: '产学研活动' //名字
  168. // }
  169. // ]
  170. }, {
  171. // title:'活动简介',
  172. // content:'',
  173. // type:'textarea',
  174. // maxlength:500,
  175. // needed:false,
  176. // saveKey:'content',
  177. // code:''
  178. // },{
  179. title: '宣传图片',
  180. content: '[]',
  181. type: 'upload',
  182. needed: false,
  183. imagelist: [],
  184. imageSaveList: [],
  185. imageDeleteList: [],
  186. doctype: 4912,
  187. remarkType: 'add',
  188. rowMargin: true
  189. }, {
  190. title: '附件',
  191. content: '[]',
  192. type: 'upload',
  193. needed: false,
  194. imagelist: [],
  195. imageSaveList: [],
  196. imageDeleteList: [],
  197. doctype: 4900,
  198. remarkType: 'add',
  199. rowMargin: true
  200. },
  201. ],
  202. ]
  203. /*console.log('aaa');
  204. var E,editor;
  205. E=window.wangEditor;
  206. editor=new E('#editor');
  207. editor.customConfig.menus=[
  208. 'head',
  209. 'bold',
  210. 'fontSize',
  211. 'fontName',
  212. 'italic',
  213. 'underline',
  214. 'forceColor',
  215. // 'backColor',
  216. 'link',
  217. // 'list',
  218. 'justify',
  219. 'image',
  220. 'table',
  221. 'video',
  222. 'code',
  223. 'undo'
  224. ]
  225. // editor.customConfig.uploadImgShowBase64=true;
  226. // editor.customConfig.uploadImgMaxSize=10*1024*1024;
  227. editor.create();*/
  228. $scope.getContent = function () {
  229. console.log(editor.txt.html())
  230. }
  231. $scope.getContent2 = function () {
  232. console.log(editor.txt.text())
  233. }
  234. /*******************************************/
  235. // 编辑
  236. // 获取数据处理
  237. var dealWithData = function (temp) {
  238. console.log(temp);
  239. $scope.orgid = temp.orgid ? temp.orgid : 0;
  240. // 处理数据
  241. var arr = [];
  242. $scope.refusereason = temp.refusereason;
  243. if (temp.images != '' && temp.images != null) {
  244. arr = JSON.parse(temp.images);
  245. }
  246. // console.log(temp);
  247. for (var key in temp) {
  248. for (var i = 0; i < allFormList.length; i++) {
  249. for (var k = 0; k < allFormList[i].length; k++) {
  250. if (key == allFormList[i][k].saveKey) {
  251. allFormList[i][k].content = temp[key];
  252. // if(key=='district'&&temp[key]!=''&&$scope.formList[i].type=='selectArea'){
  253. // console.log(temp[key]);
  254. // var tp=JSON.parse(temp[key]);
  255. // var str='';
  256. // angular.forEach(tp,function(val,index){
  257. // str+=val.name+' ';
  258. // })
  259. // $scope.formList[i].content=str;
  260. // }
  261. if (key == 'addr' && temp[key] != '' && allFormList[i][k].type == 'selectArea') {
  262. var tempArry = temp[key].split('/');
  263. for (var j = 0; j < $scope.areaDropDown.length; j++) {
  264. $scope.areaDropDown[j].selectName = tempArry[j];
  265. }
  266. }
  267. if (allFormList[i][k].type == 'select' || allFormList[i][k].type == 'selectDomain' || allFormList[i][k].type == 'affiliatedOrg' || allFormList[i][k].type == 'companyTaskSelect') {
  268. var tparr = allFormList[i][k].listItem.filter(function (vv) {
  269. return vv.itemkey == temp[key];
  270. });
  271. allFormList[i][k].content = tparr.length > 0 ? tparr[0].itemvalue : '';
  272. allFormList[i][k].key = tparr.length > 0 ? tparr[0].itemkey : '';
  273. }
  274. if (allFormList[i][k].type == 'toggle') {
  275. allFormList[i][k].content = temp[key] == 10501 ? '是' : '否';
  276. allFormList[i][k].togglecontent = temp[key] == 10501 ? true : false;
  277. }
  278. if (allFormList[i][k].type == 'date') {
  279. var aa = temp[key].split(' ')
  280. allFormList[i][k].content = aa[0];
  281. var arr = aa[1].split(':');
  282. arr.pop();
  283. allFormList[i][k].timeContent = arr.join(':');
  284. }
  285. }
  286. if (allFormList[i][k].type == 'upload' && arr.length > 0) {
  287. allFormList[i][k].imagelist = arr.filter(function (va, ind) {
  288. return allFormList[i][k].doctype == va.doctype;
  289. });
  290. allFormList[i][k].imageSaveList = arr.filter(function (va, ind) {
  291. return allFormList[i][k].doctype == va.doctype;
  292. });
  293. allFormList[i][k].content = '点击放大查看图片';
  294. }
  295. }
  296. }
  297. }
  298. };
  299. $scope.formList = allFormList[0];
  300. //*************选择区域
  301. $scope.areaDropDown = [
  302. {
  303. title: '省',
  304. code: '0',
  305. showList: false,
  306. list: [],
  307. selectName: ''
  308. }, {
  309. title: '市',
  310. code: '1',
  311. showList: false,
  312. list: [],
  313. selectName: ''
  314. }, {
  315. title: '区',
  316. showList: false,
  317. code: '1',
  318. list: [],
  319. selectName: '',
  320. }
  321. ]
  322. $scope.domainDropDown = [
  323. {
  324. title: '请选择',
  325. code: '0',
  326. showList: false,
  327. list: [],
  328. selectName: '',
  329. }, {
  330. title: '请选择',
  331. code: '1',
  332. showList: false,
  333. list: [],
  334. selectName: '',
  335. }, {
  336. title: '请选择',
  337. showList: false,
  338. code: '1',
  339. list: [],
  340. selectName: '',
  341. }
  342. ]
  343. var getAreaList = function (code, index) {
  344. AccountService.getAreaInfo(code).then(function (res) {
  345. if (res.code == 3350) {
  346. // console.log(res);
  347. // $scope.areaDropDown[index].list=res.data;
  348. $scope.areaDropDown[index].list = [];
  349. angular.forEach(res.data, function (val) {
  350. $scope.areaDropDown[index].list.push({
  351. text: '<a class="action-sheet-push">' + val.areaname + '</a>',
  352. itemkey: val.id,
  353. itemvalue: val.areaname //名字
  354. })
  355. })
  356. } else {
  357. }
  358. })
  359. }
  360. getAreaList(0, 0);
  361. var getDomainList = function (code, index) {
  362. AccountService.getDomainInfo(code, UserService.node).then(function (res) {
  363. if (res.code == 3350) {
  364. // console.log(res);
  365. angular.forEach(res.data, function (val) {
  366. $scope.domainDropDown[index].list.push({
  367. text: '<a class="action-sheet-push">' + val.name + '</a>',
  368. itemkey: val.id,
  369. itemvalue: val.name, //名字,
  370. itemcode: val.code
  371. })
  372. })
  373. } else {
  374. }
  375. })
  376. }
  377. $scope.showAreaList = function (index, outerIndex, arr, key) {
  378. // console.log(arr);
  379. var list = arr[index].list;
  380. $ionicActionSheet.show({
  381. buttons: list,
  382. cancelText: '取消',
  383. buttonClicked: function (indx) {
  384. // 先清除
  385. if (index == 0) {
  386. arr[1].selectName = '';
  387. arr[2].selectName = '';
  388. arr[1].code = '';
  389. arr[2].code = '';
  390. } else if (index == 1) {
  391. arr[2].selectName = '';
  392. arr[2].code = '';
  393. }
  394. if (index < 2) {
  395. arr[index + 1].code = list[indx].itemkey;
  396. if (key == 'area') {
  397. getAreaList(list[indx].itemkey, index + 1);
  398. } else {
  399. getDomainList(list[indx].itemkey, index + 1);
  400. }
  401. }
  402. arr[index].selectName = list[indx].itemvalue;
  403. // var tempArr=[];
  404. // angular.forEach(arr,function(val,index){
  405. // tempArr.push({name:val.selectName,code:val.code});
  406. // })
  407. var tempArr = '';
  408. angular.forEach(arr, function (val, index) {
  409. tempArr += val.selectName + '/';
  410. })
  411. $scope.formList[outerIndex].code = list[indx].itemkey;
  412. if (index == 0) {
  413. $scope.formList[outerIndex].content = tempArr.slice(0, tempArr.length - 3);
  414. } else {
  415. $scope.formList[outerIndex].content = tempArr.slice(0, tempArr.length - 1);
  416. }
  417. // console.log($scope.formList[outerIndex].content);
  418. return true;
  419. }
  420. })
  421. }
  422. $scope.setAreaListCode = function (code, name, index, outerIndex) {
  423. // 先清除
  424. if (index == 0) {
  425. $scope.areaDropDown[1].selectName = '';
  426. $scope.areaDropDown[2].selectName = '';
  427. $scope.areaDropDown[1].code = '1';
  428. $scope.areaDropDown[2].code = '1';
  429. } else if (index == 1) {
  430. $scope.areaDropDown[2].selectName = '';
  431. $scope.areaDropDown[2].code = '1';
  432. }
  433. // 然后再新赋值,准备下一级别数据
  434. $scope.areaDropDown[index].showList = false;
  435. if (index + 1 < $scope.areaDropDown.length) {
  436. $scope.areaDropDown[index + 1].code = code;
  437. getAreaList(code, index + 1);
  438. }
  439. $scope.areaDropDown[index].selectName = name;
  440. var tempArr = [];
  441. angular.forEach($scope.areaDropDown, function (val, index) {
  442. tempArr.push({ name: val.selectName, code: val.code });
  443. })
  444. $scope.formList[outerIndex].content = JSON.stringify(tempArr);
  445. }
  446. // 时间日期
  447. // 日期选择
  448. $scope.validedTime = new Date();
  449. var datePickerObj = {
  450. //选择日期后的回掉
  451. callback: function (val) {
  452. if (typeof (val) === 'undefined') {
  453. } else {
  454. var temp = new Date(val).format("yyyy-MM-dd hh:mm:ss");
  455. $scope.formList[$scope.timeIndex].content = /\d{4}-\d{1,2}-\d{1,2}/g.exec(temp)[0];
  456. datePickerObj.inputDate = new Date(val); //更新日期弹框上的日期
  457. }
  458. },
  459. // disabledDates: [
  460. // new Date(2016, 2, 16),
  461. // new Date(2015, 3, 16),
  462. // new Date(2015, 4, 16),
  463. // new Date(2015, 5, 16),
  464. // new Date('Wednesday, August 12, 2015'),
  465. // new Date("2016-08-16"),
  466. // new Date(1439676000000)
  467. // ],
  468. // from: new Date(2018, 1, 1),
  469. // to: new Date(2050, 10, 30),
  470. // inputDate: new Date(),
  471. // mondayFirst: true,
  472. // disableWeekdays: [], //设置不能选中
  473. // closeOnSelect: false,
  474. // dateFormat: 'yyyy-MM-dd',
  475. // templateType: 'popup',
  476. };
  477. var getArrayList = function (num) {
  478. var arr = [];
  479. for (var i = 0; i < num; i++) {
  480. arr.push(i < 10 ? '0' + i : i);
  481. }
  482. return arr;
  483. }
  484. $scope.showTimePicker = false;
  485. $scope.selectedHour = '00';
  486. $scope.selectedMinute = '00';
  487. $scope.minutes = getArrayList(59);
  488. $scope.hours = getArrayList(24);
  489. $scope.clearTime = function () {
  490. $scope.selectedHour = '00';
  491. $scope.selectedMinute = '00';
  492. }
  493. $scope.getNowTime = function () {
  494. $scope.selectedHour = String(new Date().toTimeString().split(' ')[0].split(':')[0]);
  495. $scope.selectedMinute = String(new Date().toTimeString().split(' ')[0].split(':')[1]);
  496. }
  497. $scope.getTime = function () {
  498. // console.log($scope.selectedHour);
  499. // console.log($scope.selectedMinute);
  500. $scope.formList[$scope.timeIndex].timeContent = $scope.selectedHour + ':' + $scope.selectedMinute;
  501. $scope.selectedHour = '00';
  502. $scope.selectedMinute = '00';
  503. $scope.showTimePicker = false;
  504. }
  505. //打开日期选择框
  506. $scope.openDatePicker = function (type, Index, outerIndex, innerIndex) {
  507. // console.log(1);
  508. $scope.timeIndex = Index;
  509. $scope.type = type;
  510. if (type == 'date') {
  511. ionicDatePicker.openDatePicker(datePickerObj);
  512. } else {
  513. $scope.showTimePicker = true;
  514. }
  515. };
  516. $scope.selectItems = function (index) {
  517. // console.log(index);
  518. if ($scope.formList[index].type == 'select' || $scope.formList[index].type == 'selectDomain' || $scope.formList[index].type == 'affiliatedOrg' || $scope.formList[index].type == 'companyTaskSelect') {
  519. var list = $scope.formList[index].listItem;
  520. $ionicActionSheet.show({
  521. buttons: list,
  522. cancelText: '取消',
  523. buttonClicked: function (indx) {
  524. $scope.formList[index].key = list[indx].itemkey;
  525. $scope.formList[index].content = list[indx].itemvalue;
  526. return true;
  527. }
  528. })
  529. }
  530. }
  531. $scope.goToNextPage = function () {
  532. if ($scope.activePage != 2) {
  533. $scope.activePage++;
  534. if ($scope.activePage == 1) {
  535. document.getElementById("richbox").style.display = '';
  536. // $("#editor").val(allData.content);
  537. CKEDITOR.instances.editor.setData(allData.content);
  538. $("richbox").serialize();
  539. } else {
  540. document.getElementById("richbox").style.display = 'none';
  541. }
  542. $scope.formList = allFormList[$scope.activePage];
  543. }
  544. }
  545. $scope.goToPrePage = function () {
  546. if ($scope.activePage != 0) {
  547. $scope.activePage--;
  548. if ($scope.activePage == 1) {
  549. document.getElementById("richbox").style.display = '';
  550. //$("#editor").val(allData.content);
  551. CKEDITOR.instances.editor.setData(allData.content);
  552. $("richbox").serialize();
  553. } else {
  554. document.getElementById("richbox").style.display = 'none';
  555. }
  556. $scope.formList = allFormList[$scope.activePage];
  557. }
  558. }
  559. $scope.goBackButton = function () {
  560. if ($scope.activePage != 0) {
  561. $scope.activePage--;
  562. if ($scope.activePage == 1) {
  563. document.getElementById("richbox").style.display = '';
  564. //$("#editor").val(allData.content);
  565. CKEDITOR.instances.editor.setData(allData.content);
  566. $("richbox").serialize();
  567. } else {
  568. document.getElementById("richbox").style.display = 'none';
  569. }
  570. $scope.formList = allFormList[$scope.activePage];
  571. } else {
  572. $scope.goback();
  573. }
  574. }
  575. $scope.items = []
  576. $scope.deletItem = function (index) {
  577. for (var i = 0; i < $scope.configList.length; i++) {
  578. if ($scope.configList[i].id == $scope.items[index].id) {
  579. $scope.configList[i].hasChosen = false;
  580. $scope.configList[i].isneed = false;
  581. break;
  582. }
  583. }
  584. $scope.items.splice(index, 1);
  585. }
  586. // $scope.setNeeded=function(index){
  587. // console.log($scope.items[index].isneed);
  588. // if(!$scope.items[index].disabled){
  589. // $scope.items[index].isneed=!$scope.items[index].isneed;
  590. // }
  591. // console.log($scope.items[index]);
  592. // }
  593. $scope.choseList = function (index) {
  594. if ($scope.configList[index].hasChosen) {
  595. if ($scope.app) {
  596. UtilService.showMess('此项已经添加了!');
  597. } else {
  598. CommonService.showMessage('此项已经添加了!', $scope);
  599. }
  600. } else {
  601. $scope.configList[index].showButton = true;
  602. $scope.configList[index].hasChosen = !$scope.configList[index].hasChosen;
  603. $scope.items.push($scope.configList[index]);
  604. }
  605. console.log($scope.configList[index]);
  606. }
  607. $scope.selectTitle = function () {
  608. // var list=[
  609. // {
  610. // text:'姓名',
  611. // saveKey:'orgName',
  612. // isFixed:true,//是否固定选项,不用发布者选择
  613. // },{
  614. // text:'电话',
  615. // saveKey:'phone',
  616. // isFixed:true,
  617. // },{
  618. // text: '所属机构' ,
  619. // saveKey:'orgName',
  620. // isFixed:false,
  621. // },{
  622. // text: '成果',
  623. // saveKey:'',
  624. // isFixed:false,
  625. // type:'configurablePages',
  626. // node:'320412000',//哪个节点的模板用哪个node,如武进 节点
  627. // orgtype:10104,//高校10105
  628. // pageTitle:'新建录入',
  629. // pagecode:1000027,//如武进节点的
  630. // pageid:5
  631. // },{
  632. // text: '需求',
  633. // saveKey:'',
  634. // isFixed:false,
  635. // type:'configurablePages',
  636. // node:'320412000',//哪个节点的模板用哪个node,如武进 节点
  637. // orgtype:10104,//高校10105
  638. // pageTitle:'新建录入',
  639. // pagecode:1000027,//如武进节点的
  640. // pageid:4
  641. // },{
  642. // text: '专利',
  643. // saveKey:'',
  644. // isFixed:false,
  645. // type:'configurablePages',
  646. // node:'320412000',//哪个节点的模板用哪个node,如武进 节点
  647. // orgtype:10104,//高校10105
  648. // pageTitle:'新建录入',
  649. // pagecode:1000027,//如武进节点的
  650. // pageid:7
  651. // }
  652. // ];
  653. $ionicActionSheet.show({
  654. buttons: $scope.configList,
  655. cancelText: '取消',
  656. buttonClicked: function (indx) {
  657. console.log(list[indx]);
  658. $scope.formTitle = list[indx];
  659. return true;
  660. }
  661. })
  662. }
  663. $scope.selectRequired = function () {
  664. var list = [
  665. {
  666. text: '<a class="action-sheet-push">' + '必填' + '</a>',
  667. itemkey: 0,
  668. itemvalue: '必填' //名字
  669. }, {
  670. text: '<a class="action-sheet-push">' + '非必填' + '</a>',
  671. itemkey: 0,
  672. itemvalue: '非必填' //名字
  673. },
  674. ];
  675. $ionicActionSheet.show({
  676. buttons: list,
  677. cancelText: '取消',
  678. buttonClicked: function (indx) {
  679. console.log(list[indx]);
  680. $scope.formRequired = list[indx];
  681. return true;
  682. }
  683. })
  684. }
  685. // 活动发布
  686. // 数据处理
  687. $scope.tempData = {};
  688. submitFormAction = false;
  689. var dealSubmitData = function (arr) {
  690. console.log(arr);
  691. let dl = [];
  692. // 1.先做非空判断
  693. $scope.tempData = $scope.tempData || {};
  694. for (var i = 0; i < arr.length; i++) {
  695. var val = arr[i];
  696. if (val.remarkType == 'manage' && arr[i - 1].type == 'toggle' && (arr[i - 1].content == '10502' || arr[i - 1].content == '否') || val.saveKey == 'minpeople') {
  697. continue;
  698. }
  699. if (val.needed && (val.content === '' || (val.type == 'upload' && val.imagelist.length == 0))) {
  700. if (val.type == 'upload') {
  701. console.log(val);
  702. if ($scope.app) {
  703. UtilService.showMess('请上传' + val.title);
  704. } else {
  705. CommonService.showMessage('请上传' + val.title, $scope);
  706. }
  707. } else {
  708. if ($scope.app) {
  709. UtilService.showMess('请填写' + val.title);
  710. } else {
  711. CommonService.showMessage('请填写' + val.title, $scope);
  712. }
  713. }
  714. submitFormAction = false;
  715. return false;
  716. }
  717. if (val.saveKey === "begintime" && val.type === 'date' && val.needed) {
  718. if (val.content && val.timeContent) {
  719. dl[0] = new Date(`${val.content} ${val.timeContent}`).valueOf();
  720. }
  721. }
  722. if (val.saveKey === "endtime" && val.type === 'date' && val.needed) {
  723. if (val.content && val.timeContent) {
  724. dl[1] = new Date(`${val.content} ${val.timeContent}`).valueOf();
  725. }
  726. }
  727. if (dl.length === 2) {
  728. if (dl[0] > dl[1]) {
  729. if ($scope.app) {
  730. UtilService.showMess('活动开始时间大于活动结束时间');
  731. } else {
  732. CommonService.showMessage('活动开始时间大于活动结束时间', $scope);
  733. }
  734. return false;
  735. } else if (dl[0] === dl[1]) {
  736. if ($scope.app) {
  737. UtilService.showMess('活动持续时间不能为0');
  738. } else {
  739. CommonService.showMessage('活动持续时间不能为0', $scope);
  740. }
  741. return false;
  742. }
  743. }
  744. if (val.type == 'upload' && val.imagelist.length > 1) {
  745. if ($scope.app) {
  746. UtilService.showMess(val.title + '最多上传一张');
  747. } else {
  748. CommonService.showMessage(val.title + '最多上传一张', $scope);
  749. }
  750. return false;
  751. }
  752. }
  753. var tempImages = [];
  754. angular.forEach(arr, function (val, index) {
  755. if (val.type == 'upload') {
  756. // 处理照片
  757. // if(val.imagelist.length>0){
  758. // val.imageSaveList=Object.assign([],val.imagelist);
  759. // }
  760. val.content = '';
  761. var temp = Object.assign([], val.imageSaveList);
  762. angular.forEach(val.imageSaveList, function (v) {
  763. tempImages.push(v);
  764. })
  765. if (val.imageDeleteList.length > 0) {
  766. angular.forEach(val.imageDeleteList, function (value) {
  767. tempImages.push(value);
  768. temp.push(value)
  769. })
  770. }
  771. val.content = JSON.stringify(temp);
  772. } else if (val.type == 'select' || val.type == 'selectDomain' || val.type == 'affiliatedOrg' || val.type == 'companyTaskSelect') {
  773. $scope.tempData[val.saveKey] = val.key;
  774. } else if (val.type == 'selectArea') {
  775. $scope.tempData[val.saveKey] = val.content;
  776. // $scope.tempData.regionsid=val.code;
  777. } else if (val.type == 'toggle') {
  778. if (val.content == '是' || val.content == '否') {
  779. val.content = val.content == '是' ? 10502 : 10501;
  780. }
  781. $scope.tempData[val.saveKey] = val.content;
  782. } else if (val.type == 'date') {
  783. $scope.tempData[val.saveKey] = val.content + " " + val.timeContent + ':00';
  784. } else {
  785. $scope.tempData[val.saveKey] = val.content;
  786. }
  787. })
  788. // console.log(tempImages);
  789. $scope.tempData.images = JSON.stringify(tempImages);
  790. return true;
  791. }
  792. $scope.submitActivities = function () {
  793. var allResult = [];
  794. for (var i = 0; i < allFormList.length; i++) {
  795. // var result=dealSubmitData(allFormList[i]);
  796. allResult = allResult.concat(allFormList[i]);
  797. }
  798. var result = dealSubmitData(allResult);
  799. if (!result) return;
  800. // console.log($scope.tempData);
  801. $scope.tempData.settingItems = JSON.stringify($scope.items);
  802. $scope.tempData.minpeople = $scope.tempData.minpeople || 0;
  803. $scope.tempData.creator = UserService.id;
  804. $scope.tempData.content = CKEDITOR.instances.editor.getData();
  805. $scope.tempData.remark = CKEDITOR.instances.editor.document.getBody().getText();;
  806. $scope.tempData.id = allData.id;
  807. var params = {
  808. data: $scope.tempData,
  809. node: UserService.node,
  810. images: $scope.tempData.images
  811. }
  812. // console.log(params);
  813. // return;
  814. submitFormAction = true;
  815. activitiesModuleService.releaseOrEditActivity(params).then(function (res) {
  816. if (user == "") {
  817. user = res.user;
  818. }
  819. console.log(res);
  820. if (res.code == 3350) {
  821. $scope.go('activitiesHoll');
  822. } else {
  823. $ionicPopup.alert({
  824. title: '提示',
  825. template: res.message
  826. });
  827. }
  828. }).catch(function (res) {
  829. $scope.hideLoadingToast();
  830. $ionicPopup.alert({
  831. title: '提示',
  832. template: "服务器错误"
  833. });
  834. })
  835. }
  836. var listIndex = 1000;
  837. $scope.addImage = function (index) {
  838. listIndex = index;
  839. if ($scope.app) {
  840. var list = [
  841. { text: '<a class="action-sheet-push">拍照</a>' },
  842. { text: '<a class="action-sheet-push">从相册上传</a>' },
  843. ];
  844. var clickfunction = function (indx) {
  845. if (indx == 0) {
  846. $scope.openCamera();
  847. } else {
  848. getPictures();
  849. }
  850. return true;
  851. }
  852. } else {
  853. var list = [
  854. { text: '<a class="action-sheet-push">从相册上传</a>' },
  855. ];
  856. var clickfunction = function (indx) {
  857. if (indx == 0) {
  858. var files = document.getElementById('file');
  859. files.click();
  860. $(files).unbind().on('change', function (e) {
  861. // console.log(e);
  862. if ($scope.formList[listIndex].imagelist.length > 1) {
  863. if ($scope.app) {
  864. UtilService.showMess('只能上传一张照片');
  865. } else {
  866. CommonService.showMessage('只能上传一张照片', $scope);
  867. }
  868. return;
  869. }
  870. $.each(e.target.files, function (i, file) {
  871. var url = null;
  872. if (window.createObjectURL != undefined) { // basic
  873. url = window.createObjectURL(file);
  874. } else if (window.URL != undefined) { // mozilla(firefox)
  875. url = window.URL.createObjectURL(file);
  876. } else if (window.webkitURL != undefined) { // webkit or chrome
  877. url = window.webkitURL.createObjectURL(file);
  878. }
  879. $scope.formList[listIndex].imagelist.push({ photoName: url, originalName: url });
  880. })
  881. $.each(e.target.files, function (i, file) {
  882. var data = new FormData();
  883. data.append('file', file);
  884. CommonService.webUploadImage(data).then(function (res) {
  885. var temp = {
  886. id: 0,
  887. title: "",
  888. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  889. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  890. photoName: res.photoName,
  891. originalName: res.originalName,
  892. sourceName: res.sourceName,
  893. sourceSize: res.sourceSize
  894. }
  895. $scope.formList[listIndex].imageSaveList.push(temp);
  896. // console.log(temp);
  897. // console.log($scope.formList[listIndex]);
  898. })
  899. });
  900. })
  901. }
  902. return true;
  903. }
  904. }
  905. $ionicActionSheet.show({
  906. buttons: list,
  907. cancelText: '取消',
  908. buttonClicked: clickfunction
  909. })
  910. };
  911. $scope.openCamera = function () {
  912. if ($scope.formList[listIndex].imagelist.length >= 9) {
  913. if ($scope.app) {
  914. UtilService.showMess("最多选取9张图片");
  915. } else {
  916. CommonService.showMessage("最多选取9张图片", $scope)
  917. }
  918. return;
  919. }
  920. UtilService.getPicture(1).then(function (results) {
  921. $scope.showLoadingToast();
  922. $scope.formList[listIndex].imagelist.push({ photoName: results, originalName: results })
  923. UtilService.uploadFile([results], 0, "image/jpeg").then(function (response) {
  924. angular.forEach(response, function (value) {
  925. $scope.formList[listIndex].imageSaveList.push({
  926. id: 0,
  927. title: "",
  928. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  929. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  930. photoName: value.photoName,
  931. originalName: value.originalName,
  932. sourceName: value.sourceName,
  933. sourceSize: value.sourceSize
  934. })
  935. })
  936. $scope.hideLoadingToast();
  937. }, function () {
  938. $scope.hideLoadingToast();
  939. if ($scope.app) {
  940. UtilService.showMess("网络不给力,请重试");
  941. } else {
  942. CommonService.showMessage("网络不给力,请重试", $scope)
  943. }
  944. });
  945. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  946. }, function (err) {
  947. });
  948. };
  949. var getPictures = function () {
  950. if (device.platform == "Android") {
  951. verifyStorage();
  952. } else {
  953. getPic();
  954. }
  955. };
  956. var verifyStorage = function () {
  957. window.imagePicker.verifyStorage(
  958. function (results) {
  959. if (results == "1") {
  960. getPic();
  961. }
  962. }, function (error) {
  963. }
  964. );
  965. };
  966. var getPic = function () {
  967. var imagelistLength = $scope.formList[listIndex].imagelist.length;
  968. if (imagelistLength >= 9) {
  969. if ($scope.app) {
  970. UtilService.showMess("最多选取9张图片");
  971. } else {
  972. CommonService.showMessage("最多选取9张图片", $scope)
  973. }
  974. return;
  975. }
  976. UtilService.getPictureList(9 - imagelistLength).then(function (results) {
  977. $scope.showLoadingToast();
  978. angular.forEach(results, function (val, i) {
  979. $scope.formList[listIndex].imagelist.push({ photoName: val, originalName: val });
  980. })
  981. UtilService.uploadFile(results, 0, "image/jpeg").then(function (response) {
  982. angular.forEach(response, function (value) {
  983. if (value.status) {
  984. $scope.formList[listIndex].imageSaveList.push({
  985. id: 0,
  986. title: "",
  987. doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls
  988. isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用
  989. photoName: value.photoName,
  990. originalName: value.originalName,
  991. sourceName: value.sourceName,
  992. sourceSize: value.sourceSize
  993. });
  994. }
  995. })
  996. $scope.hideLoadingToast();
  997. }, function () {
  998. $scope.hideLoadingToast();
  999. if ($scope.app) {
  1000. UtilService.showMess("网络不给力,请重试");
  1001. } else {
  1002. CommonService.showMessage("网络不给力,请重试", $scope)
  1003. }
  1004. });
  1005. $ionicScrollDelegate.$getByHandle("scrollimage").resize();
  1006. }, function (err) {
  1007. });
  1008. };
  1009. //删除图片
  1010. $scope.deletePhoto = function (index, outerIndex) {
  1011. console.log($scope.formList[outerIndex]);
  1012. if ($scope.formList[outerIndex].imageSaveList[index].id != 0) {
  1013. $scope.formList[outerIndex].imageSaveList[index].isenabled = 2;
  1014. $scope.formList[outerIndex].imageDeleteList.push($scope.formList[outerIndex].imageSaveList[index]);
  1015. }
  1016. $scope.formList[outerIndex].imagelist.splice(index, 1);
  1017. $scope.formList[outerIndex].imageSaveList.splice(index, 1);
  1018. // console.log($scope.formList[outerIndex].imagelist);
  1019. // console.log($scope.formList[outerIndex].imageSaveList);
  1020. // console.log($scope.formList[outerIndex].imageDeleteList);
  1021. };
  1022. });