angular.module('push')
.controller('ActivityScheduleCtrl', function ($scope, $stateParams, CommentService, $ionicActionSheet, DockingService, UtilService, $ionicSlideBoxDelegate, $timeout, $ionicScrollDelegate, UserService) {
var today = UtilService.formatDate().formattime3.substring(0,11);
$scope.activityobj = {
isUpdate: 1,//1新增 2编辑
aid: 0,
atitle: "",
connid: $stateParams.infoid,
sourcefrom: 1,// 来源:1-APP 2-WEB
leadername: "",// 团队负责人姓名
leaderuniversity: "",// 所属院校id
leaderuniversityname: "",// 所属院校
leadertel: "",// 联系方式
companyid: "",// 企业id
orgname: "",// 企业名称
orgleadername: "",// 企业负责人姓名
orgleaderduties: "",// 负责人职务
registplace: "",// 所在地区
areaid: "",
orgaddress: "",// 详细地址
orgtel: "",// 企业联系方式
tagname: "",// 对接状态名称
tagid: 0,// 对接状态
tagtime: today,// 对接时间
tagcontent: "",// 需求指导思路
// capital_scale: 0,// 需求预算
// cooperationmodelname: "",// 拟合作模式名称
dockingid : 0,// 对接需求id
docking_content: "",// 对接需求名称
newdocking_content: "",
techrequirementdetail: "",
technical_description: "",// 现场需求简介
imagelist: []
// industry_title: "",// 产学研或科技服务项目名称
// industry_description: ""// 产学研或科技服务项目简介
};
$("#dockingDateTime").attr("value",today);
$scope.showreqdetail = false;
$scope.imagelist = [];
$scope.showmorecompany = false;
$scope.showmorereq = false;
//获取对接状态标签
var reqnamebuttons = [];
//根据记录id获取新建需求反馈所需的初始化信息
var initActivitiesFollowup = function () {
DockingService.initActivitiesFollowup($stateParams.infoid).then(function (response) {
console.log(response);
if (UtilService.isDefined(response.activitymodel)) {
$scope.activityobj.aid = response.activitymodel.id;
$scope.activityobj.atitle = response.activitymodel.title;
}
if (UtilService.isDefined(response.sysUsersInfo)) {
$scope.activityobj.leadername = response.sysUsersInfo.name;
$scope.activityobj.leaderuniversity = response.sysUsersInfo.universityid;
$scope.activityobj.leaderuniversityname = response.sysUsersInfo.universityname;
$scope.$broadcast("recuniversity",response.sysUsersInfo.universityname);
$scope.activityobj.leadertel = UserService.user.user.mobile;
}
if (UtilService.isDefined(response.company)) {
$scope.activityobj.companyid = response.company.companyid;
$scope.activityobj.orgname = response.company.companyname;
$scope.activityobj.orgleadername = response.company.contact;
$scope.activityobj.orgleaderduties = response.company.c_title;
$scope.activityobj.registplace = response.company.district;
$scope.$broadcast("recregistplace",$scope.activityobj.registplace);
$scope.activityobj.areaid = response.company.companyareaid;
$scope.activityobj.orgaddress = response.company.detailaddress;
$scope.activityobj.orgtel = response.company.contactnum;
}
if (UtilService.isDefined(response.reqList) && response.reqList.length>0) {
angular.forEach(response.reqList, function (value, index) {
var temphtml = {
text: '' + value.techrequirementname + '',
reqid: value.id,
reqname: value.techrequirementname
};
reqnamebuttons.push(temphtml);
});
var temphtml2 = {
text: '现场发现需求',
reqid: 0,
reqname: "现场发现需求"
};
reqnamebuttons.push(temphtml2);
}
}, function () {
});
};
initActivitiesFollowup();
//获取对接状态标签
var buttons = [];
var getLabelList = function () {
CommentService.getLabelList().then(function (response) {
angular.forEach(response, function (value, index) {
var temphtml = {
text: '' + value.name + '',
tagid: value.id,
tagname: value.name
};
buttons.push(temphtml);
});
}, function () {
})
};
getLabelList();
//保存活动跟进表
var saveflg = 0;
$scope.saveActivitySchedule = function () {
var tempstr = $("#dockingDateTime").val();
if (UtilService.isDefined(tempstr)) {
$scope.activityobj.tagtime = UtilService.formatTime(tempstr);
}
if (!UtilService.isDefined($scope.activityobj.tagtime)) {
UtilService.showMess("对接时间不能为空");
return;
}
if (!UtilService.isDefined($scope.activityobj.tagname)) {
UtilService.showMess("请选择对接状态");
return;
}
if (!UtilService.isDefined($scope.activityobj.leadername)) {
UtilService.showMess("团队负责人姓名不能为空");
return;
}
if (!UtilService.isDefined($scope.activityobj.leaderuniversityname)) {
UtilService.showMess("所属院校名称不能为空");
return;
}
/*if (!UtilService.isDefined($scope.activityobj.leadertel)) {
UtilService.showMess("负责人联系方式不能为空");
return;
}*/
if (!UtilService.isDefined($scope.activityobj.orgname)) {
UtilService.showMess("对接企业名称不能为空");
return;
}
/*if (!UtilService.isDefined($scope.activityobj.orgleadername)) {
UtilService.showMess("对接企业负责人姓名不能为空");
return;
}
if (!UtilService.isDefined($scope.activityobj.orgleaderduties)) {
UtilService.showMess("对接企业负责人职务不能为空");
return;
}
if (!UtilService.isDefined($scope.activityobj.registplace)) {
UtilService.showMess("对接企业所在地区不能为空");
return;
}
if (!UtilService.isDefined($scope.activityobj.orgaddress)) {
UtilService.showMess("对接企业详细地址不能为空");
return;
}
if (!UtilService.isDefined($scope.activityobj.orgtel)) {
UtilService.showMess("企业联系方式不能为空");
return;
}*/
if ($scope.activityobj.dockingid != 0 && !UtilService.isDefined($scope.activityobj.docking_content)) {
UtilService.showMess("需求名称不能为空");
return;
}
if ($scope.activityobj.dockingid == 0 && !UtilService.isDefined($scope.activityobj.newdocking_content)) {
UtilService.showMess("现场需求名称不能为空");
return;
}
if ($scope.activityobj.dockingid == 0){
$scope.activityobj.docking_content = $scope.activityobj.newdocking_content;
}
if (!UtilService.isDefined($scope.activityobj.tagcontent)) {
UtilService.showMess("需求指导思路不能为空");
return;
}
/*if (!UtilService.isDefined($scope.activityobj.industry_title)) {
UtilService.showMess("项目名称不能为空");
return;
}
if (!UtilService.isDefined($scope.activityobj.industry_description)) {
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({
photo_name: value.userPhoto,
original_name: value.originalPhoto,
source_name: value.sourcePhoto,
source_size: value.source_size
});
}
});
$timeout(function () {
$scope.activityobj.imagelist = angular.toJson(tempimages);
saveInfo();
}, 100);
}, function () {
$scope.hideLoadingToast();
UtilService.showMess("网络不给力,请重试");
saveflg = 0;
})
};
var saveInfo = function () {
console.log($scope.activityobj);
DockingService.saveActivitySchedule($scope.activityobj).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.selectCompany = function () {
$scope.showmorecompany = !$scope.showmorecompany;
};
//选择企业
$scope.checkCompany = function (company) {
$scope.activityobj.orgname = company;
$scope.showmorecompany = false;
};
//展示需求选择列表
$scope.selectReq = function () {
$scope.showmorereq = !$scope.showmorereq;
};
//选择需求
$scope.checkReq = function (req) {
$scope.activityobj.docking_content = req;
$scope.showmorereq = false;
};
//选择对接状态
$scope.showDockingStatus = function () {
$ionicActionSheet.show({
buttons: buttons,
cancelText: '取消',
buttonClicked: function (index) {
$scope.activityobj.tagid = buttons[index].tagid;
$scope.activityobj.tagname = buttons[index].tagname;
return true;
}
});
};
//选择需求名称
$scope.showReqName = function () {
$ionicActionSheet.show({
buttons: reqnamebuttons,
cancelText: '取消',
buttonClicked: function (index) {
$scope.activityobj.dockingid = reqnamebuttons[index].reqid;
$scope.activityobj.docking_content = reqnamebuttons[index].reqname;
if(reqnamebuttons[index].reqid==0){
$scope.showreqdetail = true;
}else {
$scope.showreqdetail = false;
}
return true;
}
});
};
//接收高校选择数据
var reciveuniversity = $scope.$on("university", function (event, data) {
$scope.activityobj.leaderuniversity = data.id;
$scope.activityobj.leaderuniversityname = data.name;
});
//接收城市选择数据
var reciveregplace = $scope.$on("registplace", function (event, data) {
$scope.activityobj.areaid = data.areaid;
$scope.activityobj.registplace = data.registplace;
});
//页面销毁时 回收广播
$scope.$on('$destroy', function () {
reciveregplace();
reciveuniversity();
});
$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: '相册中添加照片'},
{text: '拍照'}
],
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: 'bottom', //显示方式
mode: 'scroller', //日期选择模式
dateFormat: 'yyyy年mm月dd日',
lang: 'zh',
showNow: true,
nowText: "今天",
startYear: currYear - 50, //开始年份
endYear: currYear + 10 //结束年份
};
/*$("#appDateTime").mobiscroll($.extend(opt['date'], opt['default']));*/
var optDateTime = $.extend(opt['datetime'], opt['default']);
$("#dockingDateTime").mobiscroll(optDateTime).date(optDateTime);
});
});