angular.module('push') .controller('taskHollCtrl', function ($scope, taskModuleService, $timeout, $q, UserService, ConfigService, $ionicScrollDelegate, CommonService, $ionicPopup, UtilService, $stateParams, $ionicHistory, dataToolsService) { //虚拟搜索框 console.log('taskHoll'); $scope.node = UserService.node; $scope.circleValue = 1; $scope.checkNeedShowFlag = false; $scope.defaultLan = UserService.defaultLan; $scope.isShowSearchButton = true; $scope.keyfilter = { key: '' } $scope.pagenum = 1; $scope.pagesize = 6; $scope.noData = false; $scope.tasktype = 0; $scope.userIsBroker = false; var type = 0; var totalpage = 0; $scope.allData = []; $scope.goWhere = function () { if ($stateParams.comfrom == 'tab.account') { $scope.go('tab.account'); } else { $scope.go('tab.activityIndex'); } }; if ($scope.app) { if (device.platform != "Android") { $scope.isIos = true; } else { $scope.isIos = false; } } taskModuleService.getAllTaskLable(UserService.node).then(function (res) { $scope.labelList = [{ itemvalue: 0, itemkey: '全部', isSelected: true }]; if (res.code == 3350) { angular.forEach(res.data, function (val) { val.isSelected = false; }) $scope.labelList = $scope.labelList.concat(res.data); } }); if ($scope.defaultLan == 'Chinese') { $scope.taskHollList = [ { title: '需求列表', selected: true, type: 0 }, { title: '我报送的', selected: false, type: 1 }, // { title: '我对接的', selected: false, type: 2 }, ] } else { $scope.taskHollList = [ { title: 'Demand List', selected: true, type: 0 }, { title: 'My Submission', selected: false, type: 1 }, { title: 'My Docking', selected: false, type: 2 }, ] } if ($stateParams.comfrom == 'tab.account') { $scope.taskHollList = [ { title: '需求列表', selected: false, type: 0 }, { title: '我发布的', selected: false, type: 1 }, // {title: '我对接的', selected: true, type: 2}, ] } var searchList = function () { $scope.showLoadingToast(); var deferred = $q.defer(); //查询任务列表 taskModuleService.getAllTaskList(UserService.node, type, $scope.tasktype, $scope.keyfilter.key, $scope.pagenum, $scope.pagesize).then(function (res) { // console.log(res); $scope.hideLoadingToast(); deferred.resolve(res.data); totalpage = (res.page == null ? 0 : res.page.totalPage); if ($scope.pagenum >= totalpage) { // 如果没有数据了 用ng-if彻底结束 $scope.showLoadMore = false; } }) return deferred.promise; } $scope.getData = function () { searchList().then(function (data) { console.log(data) $scope.allData = data; $scope.noData = $scope.allData == null || $scope.allData.length == 0; angular.forEach($scope.allData, function (val) { if (val) // 事件按钮 val.action0 = false;//对接录入 5322 val.action1 = false;//对接录入 5322 val.action2 = false;//评价 5323 val.action3 = false;//申请奖励 5324 val.action4 = false;//任务完成 5325 val.actionNum = 0; var tempArr = (val.otherObj && val.otherObj.actions) ? val.otherObj.actions.split(',') : []; // console.log(tempArr); if (tempArr.length > 0) { for (var i = 0; i < tempArr.length; i++) { switch (Number(tempArr[i])) { case 5321: val.action0 = true; val.actionNum++; break; case 5322: val.action1 = true; val.actionNum++; break; // case 5323:val.action2=true;val.actionNum++;break; case 5324: val.action3 = true; $scope.buttonNum++; break; case 5325: val.action4 = true; val.actionNum++; break; } } } val.noSuthority = false; if (val.otherObj && val.otherObj.creator != UserService.id && val.otherObj.taskstatus == 5300 && val.actionNum == 0) { val.noSuthority = true; } }) }); } $scope.getData(); $scope.changeSelected = function (index) { if ((index == 1 || index == 2) && !ConfigService.islogin) { 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; } } else { $scope.index = index; $scope.circleValue = 1; if (index == 0 || index == 2) { $scope.checkNeedShowFlag = false; } else { $scope.checkNeedShowFlag = true; } $scope.pagenum = 1; $scope.showLoadMore = true; angular.forEach($scope.taskHollList, function (val) { val.selected = false; }) $scope.taskHollList[index].selected = true; type = $scope.taskHollList[index].type; $scope.allData = []; $scope.getData(); $ionicScrollDelegate.$getByHandle('privateContent').scrollTop(true); } } $scope.showSearchButtonLeft = function () { // console.log('aaa'); $scope.isShowSearchButton = false; $timeout(function () { $(".showSearchInput").focus(); }, 300) }; $scope.clearSearch = function () { $scope.isShowSearchButton = true; $scope.keyfilter.key = ""; $scope.getData(); } // 下拉刷新 $scope.refreshData = function () { $scope.pagenum = 1; $scope.showLoadMore = true; $scope.getData(); $scope.$broadcast('scroll.refreshComplete'); }; $scope.showLoadMore = true; $scope.loadMore = function () { if ($scope.showLoadMore) { $scope.pagenum++; searchList().then(function (data) { if ($scope.allData.length != 0 && data.length == $scope.allData.length) { for (var i = 0; i < data.length; i++) { for (var j = 0; j < $scope.allData.length; j++) { if (i == j && $scope.allData[j].id != data[i].id) { // $scope.allData = $scope.allData.concat(data); $scope.allData.push(data[i]) // $scope.allData.push.apply($scope.allData,data) break; } } } } else { $scope.allData.push.apply($scope.allData, data) } // $scope.allData.push.apply($scope.allData,data) $scope.$broadcast('scroll.infiniteScrollComplete'); }); } } //判断当前用户是不是技术经纪人 dataToolsService.judgeUserBroker(UserService.id).then(function (res) { if (res.code == 3350) { $scope.userIsBroker = res.data; } }) $scope.releaseTask = function (userIsBroker) { // console.log(1); if (!ConfigService.islogin) { 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; } } else { $scope.go('taskRelease', { userIsBroker: userIsBroker }); } } $scope.goToTaskDetail = function (list) { if (!ConfigService.islogin) { 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; } } else { if (list.source == '330122000') { console.log(list.creator) console.log(UserService.id) if (list.creator == UserService.id) { if (list.otherObj.taskstatus == 5302) { taskModuleService.getTaskReceiver(list.otherObj.id).then(function (res) { for (var i = 0; i < res.data.length; i++) { if (res.data[i] == UserService.id) { list.otherObj.actions = list.otherObj.actions + "," + 5324; break; } } }) } console.log('来自远方的大锅', list) console.log('来自远方的大锅1', { resid: list.unique, node: list.source, title: list.title, restype: list.type, comefrom: 'taskHoll', ifjoin: list.otherObj.ifjoin, actions: list.otherObj.actions, taskstatus: list.otherObj.taskstatus, taskid: list.otherObj.id, opentowho: list.otherObj.opentowho, ispublic: true, }) $scope.go('taskDetail', { resid: list.unique, node: list.source, title: list.title, restype: list.type, comefrom: 'taskHoll', ifjoin: list.otherObj.ifjoin, actions: list.otherObj.actions, taskstatus: list.otherObj.taskstatus, taskid: list.otherObj.id, opentowho: list.otherObj.opentowho, ispublic: true, }); } else { var permissionvalue = list.by6; var splitArr = []; if (permissionvalue == 1 || permissionvalue == 2 || permissionvalue == 3 || permissionvalue == 4 || permissionvalue == 5) { splitArr.push(permissionvalue); } else if (permissionvalue != null) { splitArr = permissionvalue.split(','); } else { splitArr.push(1); } if (splitArr.length == 2) { $scope.showTaskDetail = false; //技术经纪人及高校人员可见 taskModuleService.getUserPermissionCheck(list.unique, list.creator, UserService.id).then(function (res1) { if (!res1.data) {//true可见,false不可见 taskModuleService.checkTaskDetailPermission(2, UserService.id).then(function (res2) { //技术经纪人权限 if (!res2.data) {//true可见,false不可见 taskModuleService.checkTaskDetailPermission(3, UserService.id).then(function (res3) { //高校人员权限 if (!res3.data) {//true可见,false不可见 $ionicPopup.confirm({ title: '确认', template: '仅高校院所专家可见,请先认证高校院所专家', okText: '去认证', cancelText: '取消' }).then(function (result) { if (result) { $scope.go('identifyForm', { pageTitle: '高校认证', code: 4804, action: 'submit' }); } else { $scope.go('taskHoll'); } }) } else { goPermissionTaskDetail(list); $scope.showTaskDetail = true; } if (!res2.data && !$scope.showTaskDetail) { $ionicPopup.confirm({ title: '确认', template: '仅技术经纪人可见,请先认证技术经纪人', okText: '去认证', cancelText: '取消' }).then(function (result) { if (result) { if ($scope.node == '330122000') { $scope.go('identifyFormForTongLu', { pageTitle: '技术经纪人认证', code: 4801, type: 5100, id: UserService.userid }); } if ($scope.node == '320412000') { $scope.go('identifyForm', { pageTitle: '技术经纪人认证', code: 4801, type: 5100, id: UserService.userid }); } } else { $scope.go('taskHoll'); } }) } else { goPermissionTaskDetail(list); } }); } }); } else { goPermissionTaskDetail(list); } }); } else { //单一权限的情况 for (var i = 0; i < splitArr.length; i++) { if (splitArr[i] == 2) { taskModuleService.checkTaskDetailPermission(2, UserService.id).then(function (res) { if (res.code == 3350) { $scope.isVisiableFlag = res.data; if (!$scope.isVisiableFlag) { taskModuleService.getUserPermissionCheck(list.unique, list.creator, UserService.id).then(function (res) { if (res.code == 3350) { $scope.isVisiableFlag = res.data; if (!$scope.isVisiableFlag) {//true可见,false不可见 $ionicPopup.confirm({ title: '确认', template: '仅技术经纪人可见,请先认证技术经纪人', okText: '去认证', cancelText: '取消' }).then(function (result) { if (result) { if ($scope.node == '330122000') { $scope.go('identifyFormForTongLu', { pageTitle: '技术经纪人认证', code: 4801, type: 5100, id: UserService.userid }); } if ($scope.node == '320412000') { $scope.go('identifyForm', { pageTitle: '技术经纪人认证', code: 4801, type: 5100, id: UserService.userid }); } } else { $scope.go('taskHoll'); } }) } else { goPermissionTaskDetail(list); } } }) } else { goPermissionTaskDetail(list); } } }) } else if (splitArr[i] == 3) { taskModuleService.checkTaskDetailPermission(3, UserService.id).then(function (res) { if (res.code == 3350) { $scope.isVisiableFlag = res.data; if (!$scope.isVisiableFlag) { taskModuleService.getUserPermissionCheck(list.unique, list.creator, UserService.id).then(function (res) { if (res.code == 3350) { $scope.isVisiableFlag = res.data; if (!$scope.isVisiableFlag) {//true可见,false不可见 $ionicPopup.confirm({ title: '确认', template: '仅高校院所专家可见,请先认证高校院所专家', okText: '去认证', cancelText: '取消' }).then(function (result) { if (result) { $scope.go('identifyForm', { pageTitle: '高校认证', code: 4804, action: 'submit' }); } else { $scope.go('taskHoll'); } }) } else { goPermissionTaskDetail(list); } } }); } else { goPermissionTaskDetail(list); } } }); } else if (splitArr[i] == 4) { taskModuleService.getUserPermissionCheck(list.unique, list.creator, UserService.id).then(function (res) { if (res.code == 3350) { $scope.isVisiableFlag = res.data; if (list.creator != UserService.id && !$scope.isVisiableFlag) { $ionicPopup.confirm({ title: '提示', template: '此需求已设置权限,若需了解需求详情,去向发布者申请权限', okText: '去申请权限', cancelText: '取消' }).then(function (result) { if (result) { $scope.go("tongluPermissionApply", { resource: list }); } else { $scope.go('taskHoll'); } }) } else { goPermissionTaskDetail(list); } } }) } else { if (splitArr[i] == 1) { if (list.otherObj.taskstatus == 5302) { taskModuleService.getTaskReceiver(list.otherObj.id).then(function (res) { for (var i = 0; i < res.data.length; i++) { if (res.data[i] == UserService.id) { list.otherObj.actions = list.otherObj.actions + "," + 5324; break; } } }) } $scope.go('taskDetail', { resid: list.unique, node: list.source, title: list.title, restype: list.type, comefrom: 'taskHoll', ifjoin: list.otherObj.ifjoin, actions: list.otherObj.actions, taskstatus: list.otherObj.taskstatus, taskid: list.otherObj.id, opentowho: list.otherObj.opentowho, ispublic: true, }); } } } } } } else { if (list.noSuthority) { var alertPopup = $ionicPopup.alert({ title: '提示', template: '自任务发布起一周内仅被邀请用户方可接单,一周后无人接单才会公开接单权限。' }); return; } console.log(list); if (list.otherObj.taskstatus == 5302) { taskModuleService.getTaskReceiver(list.otherObj.id).then(function (res) { for (var i = 0; i < res.data.length; i++) { if (res.data[i] == UserService.id) { list.otherObj.actions = list.otherObj.actions + "," + 5324; break; } } }) } $scope.go('taskDetail', { resid: list.unique, node: list.source, title: list.title, restype: list.type, comefrom: 'taskHoll', ifjoin: list.otherObj.ifjoin, actions: list.otherObj.actions, taskstatus: list.otherObj.taskstatus, taskid: list.otherObj.id, opentowho: list.otherObj.opentowho, ispublic: true, }); } } } var goPermissionTaskDetail = function (list) { if (list.otherObj.taskstatus == 5302) { taskModuleService.getTaskReceiver(list.otherObj.id).then(function (res) { for (var i = 0; i < res.data.length; i++) { if (res.data[i] == UserService.id) { list.otherObj.actions = list.otherObj.actions + "," + 5324; break; } } }) } $scope.go('taskDetail', { resid: list.unique, node: list.source, title: list.title, restype: list.type, comefrom: 'taskHoll', ifjoin: list.otherObj.ifjoin, actions: list.otherObj.actions, taskstatus: list.otherObj.taskstatus, taskid: list.otherObj.id, opentowho: list.otherObj.opentowho }); } $scope.goToTaskDetailForTongLu = function (list, index) { console.log(list) if (!ConfigService.islogin) { 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; } } else { if (list.tonglucheckstatus == -1 || list.tonglucheckstatus == 0 || list.tonglucheckstatus == -2) { $scope.go('techDemandCheck', { id: list.id, checkShow: -1, list: list }); } if (list.tonglucheckstatus == 1) { console.log(list) taskModuleService.getResourceByDemandName(list.projectname, $scope.node).then(function (res) { console.log(res) if (res.code == 3350) { var dataTemp = res.data; $scope.go('taskDetail', { resid: dataTemp.id, node: dataTemp.comefrom, title: dataTemp.title, restype: dataTemp.restype, comefrom: 'taskHoll', index: index, taskid: dataTemp.otherid }); } }) } } } $scope.goToTaskAction = function (list, action, index) { console.log(list); if (!ConfigService.islogin) { 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; } } if (action == 5323) { $scope.go('taskEvaluate', { taskRes: JSON.stringify(list) }) } else if (action == 5322) { // 对接录入 $scope.go('dockingInput', { comfrom: 'dockingInput', taskTitle: list.title, taskid: list.otherObj.id, companyName: list.school, companyid: list.otherObj.companyid, }) } else if (action == 5324) { $scope.go('visitModularForm', { companyid: list.otherObj.companyid, pageTitle: '新建录入', pagecode: 1000027, pageid: 15, restype: 0, node: list.source, title: list.school, }) } else if (action == 5325) { var confirmPopup = $ionicPopup.confirm({ title: '提示信息', template: '是否确定结束任务?', buttons: [ { text: '取消' }, { text: '确定', type: 'button-positive', onTap: function () { return 'ok' } }, ] }); confirmPopup.then(function (res) { if (res == 'ok') { var senddata = { data: { resourceid: list.unique, action: 5325, creator: UserService.id }, node: UserService.node } $scope.showLoadingToast(); console.log(senddata); taskModuleService.saveOrupdatetaskAction(senddata).then(function (res) { console.log(res); $scope.getData(); $scope.hideLoadingToast(); }) } else { return; } }); } else if (action == 5321) { senddata = { data: { resourceid: list.unique, action: 5321, creator: UserService.id }, node: UserService.node } $scope.showLoadingToast(); console.log(senddata); taskModuleService.saveOrupdatetaskAction(senddata).then(function (res) { console.log(res); if (res.code == 3350) { if ($scope.app) { UtilService.showMess("任务申请成功!"); } else { CommonService.showMessage("任务申请成功!", $scope); } $scope.allData[index].action1 = true; $scope.allData[index].action0 = false; $scope.allData[index].action3 = true; $scope.allData[index].otherObj.actions = '5322,5324'; } $scope.hideLoadingToast(); }) } } });