/** * Created by pushkeji on 2018/10/11. */ angular.module('push') .controller('activityReleaseCtrl', function ($scope, activitiesModuleService, $timeout, $q, UserService, $ionicPopup, AccountService, $ionicActionSheet, dataToolsService, UtilService, CommonService, ionicDatePicker, $stateParams) { // taskreleasede 控制器是identifyFormCtrl /***************** 富文本 ********/ //var editor = KindEditor.create('#editor'); var editor = CKEDITOR.replace('editor'); $scope.activePage = 0; $scope.pageTitle = ['活动基本信息', '活动详情', '报名表单设置']; // 获取活动类型下拉列表 var activityType = []; var user = ""; var allData = $stateParams.data ? JSON.parse($stateParams.data).activityInfo : { id: 0 }; dataToolsService.getTypeEntryListByTypeName('activity_type').then(function (res) { console.log(res); if (res.code == 3350) { angular.forEach(res.data, function (val) { activityType.push({ text: '' + val.itemkey + '', itemkey: val.itemvalue, itemvalue: val.itemkey //名字 }) }); getConfigData().then(function (data) { for (var i = 0; i < data.length; i++) { if (data[i].isfixed == 'true') { data[i].isneed = true; data[i].disabled = true; $scope.items.push(data[i]); } else { data[i].isneed = false; data[i].hasChosen = false; data[i].disabled = false; $scope.configList.push(data[i]); } } if ($stateParams.data) { // 编辑 var data = JSON.parse($stateParams.data).activityInfo; dealWithData(data); //$("#editor").val(allData.content); CKEDITOR.instances.editor.setData(allData.content); //CKEDITOR.instances.editor.setData(data.content); //editor.text(data.content); angular.forEach(JSON.parse(data.settingItems), function (vv) { if (vv.isfixed != 'true') { $scope.items.push(vv); for (var j = 0; j < $scope.configList.length; j++) { if ($scope.configList[j].text == vv.text) { $scope.configList[j].hasChosen = true; break; } } } }) } }) } }); var getConfigData = function () { var deferred = $q.defer(); // 获取报名表单配置选项数据 $scope.configList = []; $scope.items = []; activitiesModuleService.getFormConfigurationList().then(function (res) { console.log(res); if (res.code == 3350) { // angular.forEach(res.data,function(val,index){ // if(val.isfixed){ // $scope.items.push(val) // res.data.splice(index,1); // } // }) deferred.resolve(res.data); } }) return deferred.promise; } var allFormList = [ [ { title: '活动名称', placeholder: '请填写活动名称', content: '', type: 'input', needed: true, saveKey: 'name', }, { title: '举办单位', placeholder: '请填写举办单位', content: '', type: 'input', needed: true, saveKey: 'orgname', }, { title: '活动开始时间', placeholder: 'yyyy-mm-dd', content: '', timeContent: '00:00', type: 'date', needed: true, saveKey: 'begintime', }, { title: '活动结束时间', placeholder: 'yyyy-mm-dd', content: '', timeContent: '00:00', type: 'date', needed: true, saveKey: 'endtime', }, { title: '报名截止时间', placeholder: 'yyyy-mm-dd', content: '', timeContent: '00:00', type: 'date', needed: true, saveKey: 'dealtime', }, { title: '活动人数', placeholder: '不填默认不限', content: '', type: 'input', needed: false, saveKey: 'minpeople', }, { title: '活动地址', content: '', type: 'selectArea', needed: false, saveKey: 'addr', code: 'addr' }, { title: '详细地址', placeholder: '请填写详细地址', content: '', type: 'input', needed: true, saveKey: 'addrdetail', }, ], [ { title: '活动类别', placeholder: '请选择活动类别', content: '', selectkey: '', type: 'select', needed: true, saveKey: 'type', key: '', listItem: activityType // [ // { // text: '' + '会议' + '', // itemkey: 5921, // itemvalue: '会议' //名字 // },{ // text: '' + '培训' + '', // itemkey: 5922, // itemvalue: '培训' //名字 // },{ // text: '' + '产学研活动' + '', // itemkey: 5923, // itemvalue: '产学研活动' //名字 // } // ] }, { // title:'活动简介', // content:'', // type:'textarea', // maxlength:500, // needed:false, // saveKey:'content', // code:'' // },{ title: '宣传图片', content: '[]', type: 'upload', needed: false, imagelist: [], imageSaveList: [], imageDeleteList: [], doctype: 4912, remarkType: 'add', rowMargin: true }, { title: '附件', content: '[]', type: 'upload', needed: false, imagelist: [], imageSaveList: [], imageDeleteList: [], doctype: 4900, remarkType: 'add', rowMargin: true }, ], ] /*console.log('aaa'); var E,editor; E=window.wangEditor; editor=new E('#editor'); editor.customConfig.menus=[ 'head', 'bold', 'fontSize', 'fontName', 'italic', 'underline', 'forceColor', // 'backColor', 'link', // 'list', 'justify', 'image', 'table', 'video', 'code', 'undo' ] // editor.customConfig.uploadImgShowBase64=true; // editor.customConfig.uploadImgMaxSize=10*1024*1024; editor.create();*/ $scope.getContent = function () { console.log(editor.txt.html()) } $scope.getContent2 = function () { console.log(editor.txt.text()) } /*******************************************/ // 编辑 // 获取数据处理 var dealWithData = function (temp) { console.log(temp); $scope.orgid = temp.orgid ? temp.orgid : 0; // 处理数据 var arr = []; $scope.refusereason = temp.refusereason; if (temp.images != '' && temp.images != null) { arr = JSON.parse(temp.images); } // console.log(temp); for (var key in temp) { for (var i = 0; i < allFormList.length; i++) { for (var k = 0; k < allFormList[i].length; k++) { if (key == allFormList[i][k].saveKey) { allFormList[i][k].content = temp[key]; // if(key=='district'&&temp[key]!=''&&$scope.formList[i].type=='selectArea'){ // console.log(temp[key]); // var tp=JSON.parse(temp[key]); // var str=''; // angular.forEach(tp,function(val,index){ // str+=val.name+' '; // }) // $scope.formList[i].content=str; // } if (key == 'addr' && temp[key] != '' && allFormList[i][k].type == 'selectArea') { var tempArry = temp[key].split('/'); for (var j = 0; j < $scope.areaDropDown.length; j++) { $scope.areaDropDown[j].selectName = tempArry[j]; } } if (allFormList[i][k].type == 'select' || allFormList[i][k].type == 'selectDomain' || allFormList[i][k].type == 'affiliatedOrg' || allFormList[i][k].type == 'companyTaskSelect') { var tparr = allFormList[i][k].listItem.filter(function (vv) { return vv.itemkey == temp[key]; }); allFormList[i][k].content = tparr.length > 0 ? tparr[0].itemvalue : ''; allFormList[i][k].key = tparr.length > 0 ? tparr[0].itemkey : ''; } if (allFormList[i][k].type == 'toggle') { allFormList[i][k].content = temp[key] == 10501 ? '是' : '否'; allFormList[i][k].togglecontent = temp[key] == 10501 ? true : false; } if (allFormList[i][k].type == 'date') { var aa = temp[key].split(' ') allFormList[i][k].content = aa[0]; var arr = aa[1].split(':'); arr.pop(); allFormList[i][k].timeContent = arr.join(':'); } } if (allFormList[i][k].type == 'upload' && arr.length > 0) { allFormList[i][k].imagelist = arr.filter(function (va, ind) { return allFormList[i][k].doctype == va.doctype; }); allFormList[i][k].imageSaveList = arr.filter(function (va, ind) { return allFormList[i][k].doctype == va.doctype; }); allFormList[i][k].content = '点击放大查看图片'; } } } } }; $scope.formList = allFormList[0]; //*************选择区域 $scope.areaDropDown = [ { title: '省', code: '0', showList: false, list: [], selectName: '' }, { title: '市', code: '1', showList: false, list: [], selectName: '' }, { title: '区', showList: false, code: '1', list: [], selectName: '', } ] $scope.domainDropDown = [ { title: '请选择', code: '0', showList: false, list: [], selectName: '', }, { title: '请选择', code: '1', showList: false, list: [], selectName: '', }, { title: '请选择', showList: false, code: '1', list: [], selectName: '', } ] var getAreaList = function (code, index) { AccountService.getAreaInfo(code).then(function (res) { if (res.code == 3350) { // console.log(res); // $scope.areaDropDown[index].list=res.data; $scope.areaDropDown[index].list = []; angular.forEach(res.data, function (val) { $scope.areaDropDown[index].list.push({ text: '' + val.areaname + '', itemkey: val.id, itemvalue: val.areaname //名字 }) }) } else { } }) } getAreaList(0, 0); var getDomainList = function (code, index) { AccountService.getDomainInfo(code, UserService.node).then(function (res) { if (res.code == 3350) { // console.log(res); angular.forEach(res.data, function (val) { $scope.domainDropDown[index].list.push({ text: '' + val.name + '', itemkey: val.id, itemvalue: val.name, //名字, itemcode: val.code }) }) } else { } }) } $scope.showAreaList = function (index, outerIndex, arr, key) { // console.log(arr); var list = arr[index].list; $ionicActionSheet.show({ buttons: list, cancelText: '取消', buttonClicked: function (indx) { // 先清除 if (index == 0) { arr[1].selectName = ''; arr[2].selectName = ''; arr[1].code = ''; arr[2].code = ''; } else if (index == 1) { arr[2].selectName = ''; arr[2].code = ''; } if (index < 2) { arr[index + 1].code = list[indx].itemkey; if (key == 'area') { getAreaList(list[indx].itemkey, index + 1); } else { getDomainList(list[indx].itemkey, index + 1); } } arr[index].selectName = list[indx].itemvalue; // var tempArr=[]; // angular.forEach(arr,function(val,index){ // tempArr.push({name:val.selectName,code:val.code}); // }) var tempArr = ''; angular.forEach(arr, function (val, index) { tempArr += val.selectName + '/'; }) $scope.formList[outerIndex].code = list[indx].itemkey; if (index == 0) { $scope.formList[outerIndex].content = tempArr.slice(0, tempArr.length - 3); } else { $scope.formList[outerIndex].content = tempArr.slice(0, tempArr.length - 1); } // console.log($scope.formList[outerIndex].content); return true; } }) } $scope.setAreaListCode = function (code, name, index, outerIndex) { // 先清除 if (index == 0) { $scope.areaDropDown[1].selectName = ''; $scope.areaDropDown[2].selectName = ''; $scope.areaDropDown[1].code = '1'; $scope.areaDropDown[2].code = '1'; } else if (index == 1) { $scope.areaDropDown[2].selectName = ''; $scope.areaDropDown[2].code = '1'; } // 然后再新赋值,准备下一级别数据 $scope.areaDropDown[index].showList = false; if (index + 1 < $scope.areaDropDown.length) { $scope.areaDropDown[index + 1].code = code; getAreaList(code, index + 1); } $scope.areaDropDown[index].selectName = name; var tempArr = []; angular.forEach($scope.areaDropDown, function (val, index) { tempArr.push({ name: val.selectName, code: val.code }); }) $scope.formList[outerIndex].content = JSON.stringify(tempArr); } // 时间日期 // 日期选择 $scope.validedTime = new Date(); var datePickerObj = { //选择日期后的回掉 callback: function (val) { if (typeof (val) === 'undefined') { } else { var temp = new Date(val).format("yyyy-MM-dd hh:mm:ss"); $scope.formList[$scope.timeIndex].content = /\d{4}-\d{1,2}-\d{1,2}/g.exec(temp)[0]; datePickerObj.inputDate = new Date(val); //更新日期弹框上的日期 } }, // disabledDates: [ // new Date(2016, 2, 16), // new Date(2015, 3, 16), // new Date(2015, 4, 16), // new Date(2015, 5, 16), // new Date('Wednesday, August 12, 2015'), // new Date("2016-08-16"), // new Date(1439676000000) // ], // from: new Date(2018, 1, 1), // to: new Date(2050, 10, 30), // inputDate: new Date(), // mondayFirst: true, // disableWeekdays: [], //设置不能选中 // closeOnSelect: false, // dateFormat: 'yyyy-MM-dd', // templateType: 'popup', }; var getArrayList = function (num) { var arr = []; for (var i = 0; i < num; i++) { arr.push(i < 10 ? '0' + i : i); } return arr; } $scope.showTimePicker = false; $scope.selectedHour = '00'; $scope.selectedMinute = '00'; $scope.minutes = getArrayList(59); $scope.hours = getArrayList(24); $scope.clearTime = function () { $scope.selectedHour = '00'; $scope.selectedMinute = '00'; } $scope.getNowTime = function () { $scope.selectedHour = String(new Date().toTimeString().split(' ')[0].split(':')[0]); $scope.selectedMinute = String(new Date().toTimeString().split(' ')[0].split(':')[1]); } $scope.getTime = function () { // console.log($scope.selectedHour); // console.log($scope.selectedMinute); $scope.formList[$scope.timeIndex].timeContent = $scope.selectedHour + ':' + $scope.selectedMinute; $scope.selectedHour = '00'; $scope.selectedMinute = '00'; $scope.showTimePicker = false; } //打开日期选择框 $scope.openDatePicker = function (type, Index, outerIndex, innerIndex) { // console.log(1); $scope.timeIndex = Index; $scope.type = type; if (type == 'date') { ionicDatePicker.openDatePicker(datePickerObj); } else { $scope.showTimePicker = true; } }; $scope.selectItems = function (index) { // console.log(index); if ($scope.formList[index].type == 'select' || $scope.formList[index].type == 'selectDomain' || $scope.formList[index].type == 'affiliatedOrg' || $scope.formList[index].type == 'companyTaskSelect') { var list = $scope.formList[index].listItem; $ionicActionSheet.show({ buttons: list, cancelText: '取消', buttonClicked: function (indx) { $scope.formList[index].key = list[indx].itemkey; $scope.formList[index].content = list[indx].itemvalue; return true; } }) } } $scope.goToNextPage = function () { if ($scope.activePage != 2) { $scope.activePage++; if ($scope.activePage == 1) { document.getElementById("richbox").style.display = ''; // $("#editor").val(allData.content); CKEDITOR.instances.editor.setData(allData.content); $("richbox").serialize(); } else { document.getElementById("richbox").style.display = 'none'; } $scope.formList = allFormList[$scope.activePage]; } } $scope.goToPrePage = function () { if ($scope.activePage != 0) { $scope.activePage--; if ($scope.activePage == 1) { document.getElementById("richbox").style.display = ''; //$("#editor").val(allData.content); CKEDITOR.instances.editor.setData(allData.content); $("richbox").serialize(); } else { document.getElementById("richbox").style.display = 'none'; } $scope.formList = allFormList[$scope.activePage]; } } $scope.goBackButton = function () { if ($scope.activePage != 0) { $scope.activePage--; if ($scope.activePage == 1) { document.getElementById("richbox").style.display = ''; //$("#editor").val(allData.content); CKEDITOR.instances.editor.setData(allData.content); $("richbox").serialize(); } else { document.getElementById("richbox").style.display = 'none'; } $scope.formList = allFormList[$scope.activePage]; } else { $scope.goback(); } } $scope.items = [] $scope.deletItem = function (index) { for (var i = 0; i < $scope.configList.length; i++) { if ($scope.configList[i].id == $scope.items[index].id) { $scope.configList[i].hasChosen = false; $scope.configList[i].isneed = false; break; } } $scope.items.splice(index, 1); } // $scope.setNeeded=function(index){ // console.log($scope.items[index].isneed); // if(!$scope.items[index].disabled){ // $scope.items[index].isneed=!$scope.items[index].isneed; // } // console.log($scope.items[index]); // } $scope.choseList = function (index) { if ($scope.configList[index].hasChosen) { if ($scope.app) { UtilService.showMess('此项已经添加了!'); } else { CommonService.showMessage('此项已经添加了!', $scope); } } else { $scope.configList[index].showButton = true; $scope.configList[index].hasChosen = !$scope.configList[index].hasChosen; $scope.items.push($scope.configList[index]); } console.log($scope.configList[index]); } $scope.selectTitle = function () { // var list=[ // { // text:'姓名', // saveKey:'orgName', // isFixed:true,//是否固定选项,不用发布者选择 // },{ // text:'电话', // saveKey:'phone', // isFixed:true, // },{ // text: '所属机构' , // saveKey:'orgName', // isFixed:false, // },{ // text: '成果', // saveKey:'', // isFixed:false, // type:'configurablePages', // node:'320412000',//哪个节点的模板用哪个node,如武进 节点 // orgtype:10104,//高校10105 // pageTitle:'新建录入', // pagecode:1000027,//如武进节点的 // pageid:5 // },{ // text: '需求', // saveKey:'', // isFixed:false, // type:'configurablePages', // node:'320412000',//哪个节点的模板用哪个node,如武进 节点 // orgtype:10104,//高校10105 // pageTitle:'新建录入', // pagecode:1000027,//如武进节点的 // pageid:4 // },{ // text: '专利', // saveKey:'', // isFixed:false, // type:'configurablePages', // node:'320412000',//哪个节点的模板用哪个node,如武进 节点 // orgtype:10104,//高校10105 // pageTitle:'新建录入', // pagecode:1000027,//如武进节点的 // pageid:7 // } // ]; $ionicActionSheet.show({ buttons: $scope.configList, cancelText: '取消', buttonClicked: function (indx) { console.log(list[indx]); $scope.formTitle = list[indx]; return true; } }) } $scope.selectRequired = function () { var list = [ { text: '' + '必填' + '', itemkey: 0, itemvalue: '必填' //名字 }, { text: '' + '非必填' + '', itemkey: 0, itemvalue: '非必填' //名字 }, ]; $ionicActionSheet.show({ buttons: list, cancelText: '取消', buttonClicked: function (indx) { console.log(list[indx]); $scope.formRequired = list[indx]; return true; } }) } // 活动发布 // 数据处理 $scope.tempData = {}; submitFormAction = false; var dealSubmitData = function (arr) { console.log(arr); let dl = []; // 1.先做非空判断 $scope.tempData = $scope.tempData || {}; for (var i = 0; i < arr.length; i++) { var val = arr[i]; if (val.remarkType == 'manage' && arr[i - 1].type == 'toggle' && (arr[i - 1].content == '10502' || arr[i - 1].content == '否') || val.saveKey == 'minpeople') { continue; } if (val.needed && (val.content === '' || (val.type == 'upload' && val.imagelist.length == 0))) { if (val.type == 'upload') { console.log(val); if ($scope.app) { UtilService.showMess('请上传' + val.title); } else { CommonService.showMessage('请上传' + val.title, $scope); } } else { if ($scope.app) { UtilService.showMess('请填写' + val.title); } else { CommonService.showMessage('请填写' + val.title, $scope); } } submitFormAction = false; return false; } if (val.saveKey === "begintime" && val.type === 'date' && val.needed) { if (val.content && val.timeContent) { dl[0] = new Date(`${val.content} ${val.timeContent}`).valueOf(); } } if (val.saveKey === "endtime" && val.type === 'date' && val.needed) { if (val.content && val.timeContent) { dl[1] = new Date(`${val.content} ${val.timeContent}`).valueOf(); } } if (dl.length === 2) { if (dl[0] > dl[1]) { if ($scope.app) { UtilService.showMess('活动开始时间大于活动结束时间'); } else { CommonService.showMessage('活动开始时间大于活动结束时间', $scope); } return false; } else if (dl[0] === dl[1]) { if ($scope.app) { UtilService.showMess('活动持续时间不能为0'); } else { CommonService.showMessage('活动持续时间不能为0', $scope); } return false; } } if (val.type == 'upload' && val.imagelist.length > 1) { if ($scope.app) { UtilService.showMess(val.title + '最多上传一张'); } else { CommonService.showMessage(val.title + '最多上传一张', $scope); } return false; } } var tempImages = []; angular.forEach(arr, function (val, index) { if (val.type == 'upload') { // 处理照片 // if(val.imagelist.length>0){ // val.imageSaveList=Object.assign([],val.imagelist); // } val.content = ''; var temp = Object.assign([], val.imageSaveList); angular.forEach(val.imageSaveList, function (v) { tempImages.push(v); }) if (val.imageDeleteList.length > 0) { angular.forEach(val.imageDeleteList, function (value) { tempImages.push(value); temp.push(value) }) } val.content = JSON.stringify(temp); } else if (val.type == 'select' || val.type == 'selectDomain' || val.type == 'affiliatedOrg' || val.type == 'companyTaskSelect') { $scope.tempData[val.saveKey] = val.key; } else if (val.type == 'selectArea') { $scope.tempData[val.saveKey] = val.content; // $scope.tempData.regionsid=val.code; } else if (val.type == 'toggle') { if (val.content == '是' || val.content == '否') { val.content = val.content == '是' ? 10502 : 10501; } $scope.tempData[val.saveKey] = val.content; } else if (val.type == 'date') { $scope.tempData[val.saveKey] = val.content + " " + val.timeContent + ':00'; } else { $scope.tempData[val.saveKey] = val.content; } }) // console.log(tempImages); $scope.tempData.images = JSON.stringify(tempImages); return true; } $scope.submitActivities = function () { var allResult = []; for (var i = 0; i < allFormList.length; i++) { // var result=dealSubmitData(allFormList[i]); allResult = allResult.concat(allFormList[i]); } var result = dealSubmitData(allResult); if (!result) return; // console.log($scope.tempData); $scope.tempData.settingItems = JSON.stringify($scope.items); $scope.tempData.minpeople = $scope.tempData.minpeople || 0; $scope.tempData.creator = UserService.id; $scope.tempData.content = CKEDITOR.instances.editor.getData(); $scope.tempData.remark = CKEDITOR.instances.editor.document.getBody().getText();; $scope.tempData.id = allData.id; var params = { data: $scope.tempData, node: UserService.node, images: $scope.tempData.images } // console.log(params); // return; submitFormAction = true; activitiesModuleService.releaseOrEditActivity(params).then(function (res) { if (user == "") { user = res.user; } console.log(res); if (res.code == 3350) { $scope.go('activitiesHoll'); } else { $ionicPopup.alert({ title: '提示', template: res.message }); } }).catch(function (res) { $scope.hideLoadingToast(); $ionicPopup.alert({ title: '提示', template: "服务器错误" }); }) } var listIndex = 1000; $scope.addImage = function (index) { listIndex = index; if ($scope.app) { var list = [ { text: '拍照' }, { text: '从相册上传' }, ]; var clickfunction = function (indx) { if (indx == 0) { $scope.openCamera(); } else { getPictures(); } return true; } } else { var list = [ { text: '从相册上传' }, ]; var clickfunction = function (indx) { if (indx == 0) { var files = document.getElementById('file'); files.click(); $(files).unbind().on('change', function (e) { // console.log(e); if ($scope.formList[listIndex].imagelist.length > 1) { if ($scope.app) { UtilService.showMess('只能上传一张照片'); } else { CommonService.showMessage('只能上传一张照片', $scope); } return; } $.each(e.target.files, function (i, file) { var url = null; if (window.createObjectURL != undefined) { // basic url = window.createObjectURL(file); } else if (window.URL != undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file); } else if (window.webkitURL != undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file); } $scope.formList[listIndex].imagelist.push({ photoName: url, originalName: url }); }) $.each(e.target.files, function (i, file) { var data = new FormData(); data.append('file', file); CommonService.webUploadImage(data).then(function (res) { var temp = { id: 0, title: "", doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用 photoName: res.photoName, originalName: res.originalName, sourceName: res.sourceName, sourceSize: res.sourceSize } $scope.formList[listIndex].imageSaveList.push(temp); // console.log(temp); // console.log($scope.formList[listIndex]); }) }); }) } return true; } } $ionicActionSheet.show({ buttons: list, cancelText: '取消', buttonClicked: clickfunction }) }; $scope.openCamera = function () { if ($scope.formList[listIndex].imagelist.length >= 9) { if ($scope.app) { UtilService.showMess("最多选取9张图片"); } else { CommonService.showMessage("最多选取9张图片", $scope) } return; } UtilService.getPicture(1).then(function (results) { $scope.showLoadingToast(); $scope.formList[listIndex].imagelist.push({ photoName: results, originalName: results }) UtilService.uploadFile([results], 0, "image/jpeg").then(function (response) { angular.forEach(response, function (value) { $scope.formList[listIndex].imageSaveList.push({ id: 0, title: "", doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用 photoName: value.photoName, originalName: value.originalName, sourceName: value.sourceName, sourceSize: value.sourceSize }) }) $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); if ($scope.app) { UtilService.showMess("网络不给力,请重试"); } else { CommonService.showMessage("网络不给力,请重试", $scope) } }); $ionicScrollDelegate.$getByHandle("scrollimage").resize(); }, function (err) { }); }; var getPictures = function () { if (device.platform == "Android") { verifyStorage(); } else { getPic(); } }; var verifyStorage = function () { window.imagePicker.verifyStorage( function (results) { if (results == "1") { getPic(); } }, function (error) { } ); }; var getPic = function () { var imagelistLength = $scope.formList[listIndex].imagelist.length; if (imagelistLength >= 9) { if ($scope.app) { UtilService.showMess("最多选取9张图片"); } else { CommonService.showMessage("最多选取9张图片", $scope) } return; } UtilService.getPictureList(9 - imagelistLength).then(function (results) { $scope.showLoadingToast(); angular.forEach(results, function (val, i) { $scope.formList[listIndex].imagelist.push({ photoName: val, originalName: val }); }) UtilService.uploadFile(results, 0, "image/jpeg").then(function (response) { angular.forEach(response, function (value) { if (value.status) { $scope.formList[listIndex].imageSaveList.push({ id: 0, title: "", doctype: $scope.formList[listIndex].doctype,//文档类型 1图片,2文件,3pdf,4xls isenabled: 1,//是否可用:0-不可用,1-可用,2-已停用 photoName: value.photoName, originalName: value.originalName, sourceName: value.sourceName, sourceSize: value.sourceSize }); } }) $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); if ($scope.app) { UtilService.showMess("网络不给力,请重试"); } else { CommonService.showMessage("网络不给力,请重试", $scope) } }); $ionicScrollDelegate.$getByHandle("scrollimage").resize(); }, function (err) { }); }; //删除图片 $scope.deletePhoto = function (index, outerIndex) { console.log($scope.formList[outerIndex]); if ($scope.formList[outerIndex].imageSaveList[index].id != 0) { $scope.formList[outerIndex].imageSaveList[index].isenabled = 2; $scope.formList[outerIndex].imageDeleteList.push($scope.formList[outerIndex].imageSaveList[index]); } $scope.formList[outerIndex].imagelist.splice(index, 1); $scope.formList[outerIndex].imageSaveList.splice(index, 1); // console.log($scope.formList[outerIndex].imagelist); // console.log($scope.formList[outerIndex].imageSaveList); // console.log($scope.formList[outerIndex].imageDeleteList); }; });