angular.module('push')
.controller('cooperateDetailCtrl', function ($scope, $ionicPopup, UserService, $ionicSlideBoxDelegate, $ionicActionSheet, AccountService, $stateParams, ResourceLibraryService, CommentService, UtilService, $timeout, CommonService,ConfigService,taskModuleService) {
$scope.technicalcontractid = $stateParams.list.technicalcontractid;
$scope.demandreward = $stateParams.list;
$scope.agree = 1;
$scope.checkData = {};
//获取产学研补助审核时的图片
$scope.imageList1 = [];
$scope.imageList2 = [];
$scope.imageList3 = [];
$scope.imageList4 = [];
$scope.imageList5 = [];
$scope.hasAuth = false;
ResourceLibraryService.judgeManager(UserService.id, 10501).then(function (res) {
// console.log(res);
$scope.hasAuth = res.data;
})
AccountService.getTechnicalContractList($scope.technicalcontractid).then(function (res) {
if (res.code == 3350) {
$scope.picturelist = res.data;
console.log($scope.picturelist)
angular.forEach($scope.picturelist, function(val){
if(val.remark == "经技术合同登记的产学研合作合同(技术开发、技术转让、技术咨询、技术服务)"){
$scope.imageList1.push(val)
}
if(val.remark == "发票"){
$scope.imageList2.push(val)
}
if(val.remark == "支付凭证(银行转账凭证)"){
$scope.imageList3.push(val)
}
if(val.remark == "结果凭证(结题报告、进度报告等)"){
$scope.imageList4.push(val)
}
if(val.remark == "法定代表人授权委托书"){
$scope.imageList5.push(val)
}
})
}
})
$scope.agreeClick = function () {
$scope.agree = 1;
}
$scope.rollClick = function () {
$scope.agree = -1;
}
$scope.checkDemandReward = function () {
if ($scope.agree == -1) {
if ($scope.checkData.refusereason == "" || $scope.checkData.refusereason == null) {
$ionicPopup.alert({
title: '确定',
template: '请填写拒绝理由'
});
return;
}else {
submit()
}
}else {
$ionicPopup.confirm({
title: '确定',
template: '
\n' +
' \n' +
' \n' +
'
',
scope: $scope,
buttons: [{
text: '取消',
type: 'button-default',
}, {
text: '确定',
type: 'button-positive',
onTap: function(e) {
if (!$scope.data.rewardmoney) {
CommonService.showMessage("请填写核定补助金额", $scope);
e.preventDefault();
} else {
console.log($scope.data)
submit()
}
}
}]
});
}
}
function submit(){
console.log($scope.checkData.refusereason)
AccountService.submitDemandReward($stateParams.list.id, $scope.agree, $scope.data.rewardmoney,$scope.checkData.refusereason).then(function (res) {
if (res.code == 3350) {
$scope.go('cooperationSubsidyCheck');
}
})
}
//通过technicalcontractid获取TechnicalContract数据
ResourceLibraryService.getTechContractByContractid($scope.technicalcontractid).then(function (res) {
console.log(res)
if (res.code == 3350) {
$scope.data = res.data;
}
})
//重置失败状态,失败原因没有实际作用(仅仅便于调一个接口)
$scope.checkDemandRewardAgain = function (demandreward) {
var by2 = $stateParams.list.by2;
AccountService.submitDemandReward($stateParams.list.id, 0, "1").then(function (res) {
if (res.code == 3350) {
$scope.go("toDeclare", {list: $scope.data, picturelist: $scope.picturelist, by2:by2});
}
})
}
$scope.hasAuth = false;
ResourceLibraryService.judgeManager(UserService.id, 10501).then(function (res) {
// console.log(res);
$scope.hasAuth = res.data;
})
//打开操作表:设置/编辑
$scope.openActionSheet = function (data) {
// isedit:是否可以编辑资源,isset:是否可以设置权限
var buttonlist = [];
buttonlist.push({text: '导出附件zip'});
// buttonlist.push({text: '导出'});
if($scope.demandreward.demandstatus == 1){
buttonlist.push({text: '共享'});
}
if($scope.demandreward.demandstatus == 0){
buttonlist.push({text: '修改'});
}
// else if($scope.demandreward.demandstatus == 8 || $scope.demandreward.demandstatus == 9){
//
// }else {
// }
$ionicActionSheet.show({
buttons: buttonlist,
cancelText: '取消',
buttonClicked: function (index) {
if (buttonlist[index].text == '导出') {
//产学研补助导出功能
taskModuleService.exportCooperationReport(data).then(function (res) {
if (res.code == 3350) {
var file = res.data;
window.open(ConfigService.imgurl + file.sourceName);
return;
} else {
$ionicPopup.alert({
title: '提示',
template: '导出失败!'
})
return;
}
})
return true;
}
if (buttonlist[index].text == '共享') {
taskModuleService.shareCooperationReport($scope.demandreward.id).then(function (res) {
if (res.code == 3350) {
$ionicPopup.alert({
title: '提示',
template: '共享成功!'
})
$scope.go('cooperationSubsidyCheck');
} else {
$ionicPopup.alert({
title: '提示',
template: '共享失败!'
})
return;
}
})
return true;
}
if (buttonlist[index].text == '共享') {
$scope.go("toDeclare", {list: $scope.data, picturelist: $scope.picturelist, by2: 'subsidy'});
}
if (buttonlist[index].text == '导出附件zip') {
var param=[]
console.log($scope.picturelist)
$scope.picturelist.forEach(function (row) {
param.push(ConfigService.imgurl + row.sourceName)
})
$scope.showLoadingToast()
console.log(param)
taskModuleService.usertaskzipsubsidies(param).then(function (res) {
console.log(res)
$scope.hideLoadingToast()
var aEle = document.createElement("a");// 创建a标签
var blob = new Blob([res],{type: "application/zip"});
// aEle.download = item.modelName;// 设置下载文件的文件名
aEle.href = URL.createObjectURL(blob);
aEle.click();// 设置点击事件
})
}
if (buttonlist[index].text == '修改') {
console.log($stateParams.list)
$scope.go("toDeclare", {list: JSON.stringify($stateParams.list)});
}
}
});
};
$scope.bigImage = false; //初始默认大图是隐藏的
$scope.hideBigImage = function () {
if ($scope.app) {
$scope.setStatusBar(0);
}
$scope.bigImage = false;
}
$scope.shouBigImage = function (piclist, index) { //传递一个参数(图片的URl)
window.open(ConfigService.imgurl + piclist[index].sourceName);
return;
};
});