angular.module('push')
.controller('activityFeedBackCtrl', function ($scope, $stateParams, CommentService, $ionicActionSheet, ActivityService, UtilService, $ionicSlideBoxDelegate,
$timeout, $ionicScrollDelegate, UserService, $ionicModal, DockingService) {
var activityid = $stateParams.activityid;
var title = $stateParams.title;
var today = UtilService.formatDate().formattime3.substring(0, 11);
$scope.activityobj = {
isUpdate: 1,//1新增 2编辑
aid: activityid,
atitle: title,
connid: 0,
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,// 需求预算
cooperationmodel: "",// 拟合作模式名称
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;
$scope.companylist = [];
//获取对接状态标签
var reqnamebuttons = [];
//根据记录id获取新建需求反馈所需的初始化信息
var initActivitiesFollowup = function () {
ActivityService.initFollowupInfo(activityid).then(function (response) {
// console.log(response);
// 用户基本信息
if (UtilService.isDefined(response.sysUsersInfo)) {
$scope.activityobj.leadername = response.sysUsersInfo.name;
$scope.activityobj.leaderuniversity = response.sysUsersInfo.universityid;
$scope.activityobj.leaderuniversityname = response.sysUsersInfo.university;
$scope.$broadcast("recuniversity", response.sysUsersInfo.university);
$scope.activityobj.leadertel = UserService.user.user.mobile;
}
// 活动下用户已配对企业列表
if (UtilService.isDefined(response.company) && response.company.length > 0) {
$scope.companylist = response.company;
}
}, 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) {
if (reqlist.length == index) {
$scope.showreqdetail = true;
} else {
$scope.activityobj.dockingid = reqlist[index].id;
$scope.activityobj.docking_content = reqlist[index].techrequirementname;
$scope.activityobj.technical_description = reqlist[index].techrequirementdetail;
$scope.activityobj.cooperationmodel = UtilService.isDefined(reqlist[index].cooperationmodel) ? reqlist[index].cooperationmodel : "";
$scope.activityobj.capital_scale = UtilService.isDefined(reqlist[index].capital_scale) ? reqlist[index].capital_scale : 0;
$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 rate=oldWid/oldHei;
if(oldWid>=screen&&oldHei>=screenH){
var tw=screen;
var th=tw/rate;
if(th=screen&&oldHei<=screenH){
imgObj[n].style.width = screen + 'px';
imgObj[n].style.height = screen/rate + 'px';
imgObj[n].style.marginTop=(screenH-screen/rate)/2+ 'px';
}else if(oldWid<=screen&&oldHei>=screenH){
// var hh=screenH;
// var ww=screenH*rate;
imgObj[n].style.width = screenH*rate + 'px';
imgObj[n].style.height = screenH + 'px';
imgObj[n].style.marginLeft=(screen-screenH*rate)/2+ 'px';
}else{
imgObj[n].style.width = oldWid + 'px';
imgObj[n].style.height = oldHei + 'px';
imgObj[n].style.marginLeft=(screen-oldWid)/2+ 'px';
imgObj[n].style.marginTop=(screenH-oldHei)/2+ 'px';
}
}
}, 500);
};
//删除图片
$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);
});
$ionicModal.fromTemplateUrl('./modules/common/views/selectCompany.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function (modal) {
$scope.selCom = modal;
});
//打开企业列表弹窗
$scope.showCompany = function () {
if (localStorage.wxFlag == "true") {
if (localStorage.isUserFocusXW == 0) {
var title = localStorage.appidStr;
$ionicPopup.alert({
title: '提示',
template: '请先关注微信公众号"' + title + '"!'
});
return;
} else {
if (localStorage.isUserBindWx == 0) {
var wxFlag = JSON.parse(localStorage.params);
if (wxFlag.weChatModel) {
$scope.go('bindPhone', {
params: localStorage.params,
comfrom: 'maincontroller',
url: window.location.href.split('#/')[1]
});
} else {
$scope.go('login');
return;
}
} else {
$scope.go('login');
return;
}
}
} else {
$scope.go('login');
return;
}
};
//关闭企业列表弹窗
$scope.hideModel = function () {
$scope.selCom.hide();
};
//选择企业
$scope.saveCompany = function (com) {
getCompanyInfo(com.companyid);
$scope.activityobj.companyid = com.companyid;// 企业id
$scope.activityobj.orgname = com.companyname;
$scope.selCom.hide();
};
// 获取企业详细信息
var reqlist = [];
var getCompanyInfo = function (companyid) {
ActivityService.initFollowupCompanyInfo(companyid).then(function (response) {
// console.log(response);
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.areaid;
$scope.activityobj.orgaddress = response.company.detailaddress;
$scope.activityobj.orgtel = response.company.contactnum;
}
if (UtilService.isDefined(response.company_techrequirement_lk) && response.company_techrequirement_lk.length > 0) {
angular.forEach(response.company_techrequirement_lk, function (value, index) {
var temphtml = {
text: '' + value.techrequirementname + '',
reqid: value.id,
reqname: value.techrequirementname
};
reqnamebuttons.push(temphtml);
});
reqlist = response.company_techrequirement_lk;
var temphtml2 = {
text: '现场发现需求',
reqid: 0,
reqname: "现场发现需求"
};
reqnamebuttons.push(temphtml2);
}
}, function () {
});
};
});