123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- angular.module('push')
- .controller('technicalBrokerPublishTrainCtrl', function ($scope, $stateParams, $ionicActionSheet, $ionicPopup, ActivityService, UtilService, $ionicSlideBoxDelegate,
- $timeout, $ionicScrollDelegate, UserService, $ionicModal, TechnicalBrokerPublishTrainService,
- AccountService) {
- var today = UtilService.formatDate().formattime3.substring(0, 20);
- $scope.trainListobj = {
- isUpdate: 1,//1新增 2编辑
- id: 0,
- traintype: 0,
- traintypename: "",
- title: "",
- content: "",
- trainbegintime: "",
- signupenddate: "",
- areaid: 0,
- areaname: "",
- detailaddress: "",
- isactive: 1,// 培训状态:是否有效,0无效,1有效
- sponsors: "",// 传到后台的主办方json stype:类别:1.主办方 2.协办方
- cosponsors: "",// 传到后台的协办方json stype:类别:1.主办方 2.协办方
- delsponsors: "",// 删除的主办方/协办方
- sponsorlist: [],// 取得详情里的主办方
- sponsor: [{
- id: 0,
- sid: 0,
- stype: 2,
- orgtype: 0,
- sponsorname: "",
- introduce: "",
- categorydetail: "",
- logo: ""
- }],// 取得添加主办方的内容
- lecturers: "",// 传到后台的讲师
- dellecturers: "",// 删除的讲师
- images: "",// 传到后台的图片json
- delimages: "",// 删除的图片
- imagelist: []// app端图片插件进行传递的变量
- };
- // $("#trainbegintime").attr("value", today);
- $scope.showreqdetail = false;
- $scope.sponsors = "";
- $scope.delsponsors = "";
- $scope.sponsorlist = [];
- $scope.lecturers = "";
- $scope.dellecturers = "";
- $scope.images = "";
- $scope.delimages = "";
- $scope.imagelist = [];
- $scope.showmorecompany = false;
- $scope.showmorereq = false;
- $scope.companylist = [];
- $scope.sponsorList = [];// 主办方
- $scope.cosponsorList = [{
- id: 0,
- sid: 0,
- stype: 2,
- orgtype: 0,
- sponsorname: "",
- introduce: "",
- categorydetail: "",
- logo: ""
- }];// 协办方
- var delsponsors = [];
- $scope.lecturerList = [{
- id: 0,
- lecturername: ""
- }];
- var dellecturers = [];
- // 获取培训种类列表
- var buttons = [];
- var getTraintypeList = function () {
- TechnicalBrokerPublishTrainService.getTraintypeList().then(function (response) {
- // console.log(response);
- if (UtilService.isDefined(response.traintypeList) && response.traintypeList.length > 0) {
- $scope.trainListobj.traintype = response.traintypeList[0].itemvalue;
- $scope.trainListobj.traintypename = response.traintypeList[0].itemkey;
- angular.forEach(response.traintypeList, function (value, index) {
- var temphtml = {
- text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
- traintype: value.itemvalue,
- traintypename: value.itemkey
- };
- buttons.push(temphtml);
- });
- }
- }, function () {
- })
- };
- getTraintypeList();
- // 获取机构类型列表
- var orgtypebuttons = [];
- var getOrgtypeList = function () {
- TechnicalBrokerPublishTrainService.getOrgtypeList().then(function (response) {
- if (UtilService.isDefined(response.orgtypeList) && response.orgtypeList.length > 0) {
- angular.forEach(response.orgtypeList, function (value, index) {
- var temphtml = {
- text: '<a class="action-sheet-push">' + value.itemkey + '</a>',
- orgtype: value.itemvalue,
- orgtypename: value.itemkey
- };
- orgtypebuttons.push(temphtml);
- });
- // console.log(orgtypebuttons);
- }
- }, function () {
- })
- };
- getOrgtypeList();
- // 获取行业领域列表
- var categorybuttons = [];
- var getCategoryList = function () {
- TechnicalBrokerPublishTrainService.getCategoryList().then(function (response) {
- if (UtilService.isDefined(response.categoryList) && response.categoryList.length > 0) {
- angular.forEach(response.categoryList, function (value, index) {
- var temphtml = {
- text: '<a class="action-sheet-push">' + value.name + '</a>',
- categorydetail: value.code,
- categoryname: value.name
- };
- categorybuttons.push(temphtml);
- });
- }
- }, function () {
- })
- };
- getCategoryList();
- //保存培训信息表
- var saveflg = 0;
- $scope.saveTrainInfo = function () {
- var tempstr = $("#trainbegintime").val();
- if (UtilService.isDefined(tempstr)) {
- $scope.trainListobj.trainbegintime = UtilService.formatTime(tempstr);
- }
- if (!UtilService.isDefined($scope.trainListobj.trainbegintime)) {
- UtilService.showMess("培训时间不能为空");
- return;
- }
- if (!UtilService.isDefined($scope.trainListobj.traintype)) {
- UtilService.showMess("请选择培训类别");
- return;
- }
- if (!UtilService.isDefined($scope.trainListobj.sponsor.orgtype)) {
- UtilService.showMess("请填写主办方信息");
- return;
- }
- if (!UtilService.isDefined($scope.trainListobj.sponsor.sponsorname)) {
- UtilService.showMess("请填写主办方信息");
- return;
- }
- // 若协办方名称为空,当前这条不保存
- if ($scope.cosponsorList.length > 0) {
- angular.forEach($scope.cosponsorList, function (cosponsorList,index,$index) {
- if (!UtilService.isDefined($scope.cosponsorList[index].sponsorname)) {
- $scope.cosponsorList.splice($index, 1);
- }
- });
- }
- if ($scope.lecturerList.length > 0) {
- var lecturerresult = 1;
- angular.forEach($scope.lecturerList, function (lecturerList,index) {
- if (!UtilService.isDefined($scope.lecturerList[index].lecturername)) {
- lecturerresult = 0;
- }
- });
- if(lecturerresult == 0){
- UtilService.showMess("讲师不能为空");
- return;
- }
- }
- var tempstr = $("#signupenddate").val();
- if (UtilService.isDefined(tempstr)) {
- $scope.trainListobj.signupenddate = UtilService.formatTime(tempstr);
- }
- if (!UtilService.isDefined($scope.trainListobj.signupenddate)) {
- UtilService.showMess("培训报名截止时间不能为空");
- return;
- }
- if (!UtilService.isDefined($scope.trainListobj.areaid)) {
- UtilService.showMess("培训所在地区不能为空");
- return;
- }
- if (!UtilService.isDefined($scope.trainListobj.detailaddress)) {
- UtilService.showMess("培训的详细地址不能为空");
- return;
- }
- if ($scope.trainListobj.dockingid != 0 && !UtilService.isDefined($scope.trainListobj.title)) {
- UtilService.showMess("培训标题不能为空");
- return;
- }
- if (!UtilService.isDefined($scope.trainListobj.content)) {
- UtilService.showMess("培训内容不能为空");
- return;
- }
- if (saveflg != 0) {
- return;
- }
- saveflg = 1;
- $scope.showLoadingToast();
- if ($scope.imagelist.length > 0) {
- uploadImages();
- } else {
- saveInfo();
- }
- };
- var tempimages = [];
- var uploadImages = function () {
- tempimages = [];
- var upimages = [];
- angular.forEach($scope.imagelist, function (data) {
- upimages.push(data.photo_name);
- });
- UtilService.uploadFile(upimages, 0, "image/jpeg").then(function (response) {
- // console.log(response);
- angular.forEach(response, function (value) {
- if (value.status) {
- tempimages.push({
- id: 0,
- title: "",
- photo_name: value.userPhoto,
- original_name: value.originalPhoto,
- source_name: value.sourcePhoto,
- source_size: value.source_size
- });
- }
- });
- $timeout(function () {
- saveInfo();
- }, 100);
- }, function () {
- $scope.hideLoadingToast();
- UtilService.showMess("网络不给力,请重试");
- saveflg = 0;
- })
- };
- var saveInfo = function () {
- // console.log($scope.trainListobj);
- $scope.trainListobj.sponsors = angular.toJson($scope.sponsorList);
- $scope.trainListobj.cosponsors = angular.toJson($scope.cosponsorList);
- $scope.trainListobj.delsponsors = delsponsors.join(",");
- $scope.trainListobj.lecturers = angular.toJson($scope.lecturerList);
- $scope.trainListobj.dellecturers = dellecturers.join(",");
- TechnicalBrokerPublishTrainService.saveTrainInfo($scope.trainListobj, tempimages).then(function (response) {
- // console.log(response);
- if (response.isSuccess == 1) {
- UtilService.showMess("添加成功");
- $timeout(function () {
- $scope.goback();
- }, 1500);
- } else {
- UtilService.showMess("网络不给力,请重试");
- }
- $scope.hideLoadingToast();
- saveflg = 0;
- }, function () {
- UtilService.showMess("网络不给力,请重试");
- $scope.hideLoadingToast();
- saveflg = 0;
- })
- };
- //选择机构类型
- $scope.showOrgTypeStatus = function () {
- $ionicActionSheet.show({
- buttons: orgtypebuttons,
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.trainListobj.sponsor.orgtype = orgtypebuttons[index].orgtype;
- $scope.trainListobj.sponsor.orgtypename = orgtypebuttons[index].orgtypename;
- return true;
- }
- });
- };
- // 选择专业领域
- $scope.showStudyStatusshowStudyStatus=function () {
- $ionicActionSheet.show({
- cancelOnStateChange: true,
- cssClass: 'action_s',
- cancelText: '取消',
- buttons: categorybuttons,
- buttonClicked: function (index) {
- $scope.trainListobj.sponsor.categorydetail = categorybuttons[index].categorydetail;
- $scope.trainListobj.sponsor.categoryname = categorybuttons[index].categoryname;
- return true;
- },
- destructiveButtonClicked: function () {
- return true;
- }
- });
- }
- //添加、删除更多协办方
- $scope.AddOrDelCosponsor = function (ind) {
- if (ind == 0) {
- $scope.cosponsorList.push({
- id: 0,
- stype: 2,
- sponsorname: ""
- });
- } else {
- if ($scope.cosponsorList[ind].id != 0) {
- delsponsors.push($scope.cosponsorList[ind].id);
- }
- $scope.cosponsorList.splice(ind, 1);
- }
- };
- //添加、删除更多讲师
- $scope.AddOrDellecturer = function (ind) {
- if (ind == 0) {
- $scope.lecturerList.push({
- id: 0,
- lecturername: ""
- });
- } else {
- if ($scope.lecturerList[ind].id != 0) {
- dellecturers.push($scope.lecturerList[ind].id);
- }
- $scope.lecturerList.splice(ind, 1);
- }
- };
- //选择培训类别
- $scope.showTrainStatus = function () {
- $ionicActionSheet.show({
- buttons: buttons,
- cancelText: '取消',
- buttonClicked: function (index) {
- $scope.trainListobj.traintype = buttons[index].traintype;
- $scope.trainListobj.traintypename = buttons[index].traintypename;
- return true;
- }
- });
- };
- //接收城市选择数据
- var reciveregplace = $scope.$on("registplace", function (event, data) {
- $scope.trainListobj.areaid = data.areaid;
- $scope.trainListobj.areaname = data.registplace;
- });
- //页面销毁时 回收广播
- $scope.$on('$destroy', function () {
- reciveregplace();
- });
- $scope.openCamera = function () {
- if ($scope.imagelist.length >= 9) {
- UtilService.showMess("最多选取9张图片");
- 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) {
- });
- };
- $scope.show = function () {
- $ionicActionSheet.show({
- buttons: [
- {text: '<a class="action-sheet-push">相册中添加照片</a>'},
- {text: '<a class="action-sheet-push">拍照</a>'}
- ],
- cancelText: '取消',
- buttonClicked: function (index) {
- if (index == 0) {
- getPictures();
- } else if (index == 1) {
- $scope.openCamera();
- }
- return true;
- }
- });
- };
- var verifyStorage = function () {
- window.imagePicker.verifyStorage(
- function (results) {
- if (results == "1") {
- getPic();
- }
- }, function (error) {
- }
- );
- };
- var getPic = function () {
- if ($scope.imagelist.length >= 9) {
- UtilService.showMess("最多选取9张图片");
- return;
- }
- UtilService.getPictureList(9 - $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.bigImage = false; //初始默认大图是隐藏的
- $scope.hideBigImage = function () {
- if($scope.app){
- $scope.setStatusBar(0);
- }
- $timeout(function () {
- $scope.bigImage = false;
- }, 400);
- };
- $scope.shouBigImage = function (index) { //传递一个参数(图片的URl)
- if($scope.app){
- $scope.setStatusBar(1);
- }
- $(function () {
- $('div.pinch-zoom').each(function () {
- new RTP.PinchZoom($(this), {});
- });
- });
- $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.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 //结束年份
- };
- var optDateTime = $.extend(opt['datetime'], opt['default']);
- $("#trainbegintime").mobiscroll(optDateTime).datetime(optDateTime);
- });
- //报名截止日期
- $(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']);
- $("#signupenddate").mobiscroll(optDateTime).datetime(optDateTime);
- });
- $scope.isShowAddcosponsor = false;
- $scope.isShowAddlecturer = false;
- //添加协办方
- if ($scope.trainListobj.cosponsor != '') {
- $scope.isShowAddcosponsor = true;
- }
- //添加讲师
- if ($scope.trainListobj.lecturer != '') {
- $scope.isShowAddlecturer = true;
- }
- $ionicModal.fromTemplateUrl('./modules/technicalBroker/views/technicalBrokerAddMainSponsor.html', {
- scope: $scope,
- animation: 'slide-in-up'
- }).then(function (modal) {
- $scope.mainsponsor = modal;
- });
- $scope.showView = function () {
- $scope.mainsponsor.show();
- };
- // 添加主办方保存
- $scope.hideView = function () {
- if (!UtilService.isDefined($scope.trainListobj.sponsor.orgtype)) {
- UtilService.showMess("请选择主办方的机构类型");
- return;
- }
- if (!UtilService.isDefined($scope.trainListobj.sponsor.sponsorname)) {
- UtilService.showMess("请填写主办方名称");
- return;
- }
- $scope.sponsorList = [];// 主办方
- $scope.sponsorList.push({
- id: $scope.trainListobj.sponsor.id,
- sid: $scope.trainListobj.sponsor.sid,
- stype: 1,
- orgtype: $scope.trainListobj.sponsor.orgtype,
- sponsorname: $scope.trainListobj.sponsor.sponsorname,
- introduce: $scope.trainListobj.sponsor.introduce,
- categorydetail: $scope.trainListobj.sponsor.categorydetail,
- logo: $scope.trainListobj.sponsor.logo
- });
- $scope.mainsponsor.hide();
- };
- $scope.saveSponsor = function () {
- $scope.mainsponsor.hide();
- };
- // 编辑头像
- $scope.show_header = function () {
- // 弹出头像选择框
- $ionicActionSheet.show({
- cancelOnStateChange: true,
- cssClass: 'action_s',
- cancelText: '取消',
- buttons: [
- {text: "拍照"},
- {text: "从相册上传"}
- ],
- buttonClicked: function (index) {
- if (index == 0) {
- openCamera(1);
- } else {
- openCamera(0);
- }
- return true;
- },
- destructiveButtonClicked: function () {
- return true;
- }
- });
- };
- var openCamera = function (srcType) {
- var options = {
- // Some common settings are 20, 50, and 100
- quality: 50,
- destinationType: Camera.DestinationType.FILE_URI,
- // In this app, dynamically set the picture source, Camera or photo gallery
- sourceType: srcType,
- encodingType: Camera.EncodingType.JPEG,
- mediaType: Camera.MediaType.PICTURE,
- allowEdit: false,
- correctOrientation: true //Corrects Android orientation quirks
- };
- navigator.camera.getPicture(function (imageData) {
- $scope.imgurl = imageData;
- $scope.showLoadingToast();
- UtilService.uploadFile([imageData], 0, "image/jpeg").then(function (response) {
- // console.log(response);
- $scope.trainListobj.sponsor.logo = response[0].userPhoto;
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- });
- }, function (message) {
- }, options);
- };
- // 切换状态
- $scope.changeToggle = function () {
- $scope.taskListobj.isactive = $scope.taskListobj.actives ? 1 : 0;
- };
- });
|