$(document).ready(function() {
var resourceId = GetQueryString("resourceId");
if(resourceId) {
$("#deleteResource").removeClass("disableLi").addClass("deleteResource");
getRecourceMe();
}
var id = $.cookie('orgId');
var temp = [];
var array = [];
var oProfessor=[];
ue = UE.getEditor('editor', {});
/*获取资源信息*/
function getRecourceMe() {
$.ajax({
"url": "/ajax/resource/queryOne",
"type": "GET",
"success": function(data) {
console.log(data);
if(data.success) {
resourceHtml(data.data);
}
},
"data": {
"resourceId": resourceId
},
dataType: "json",
'error': function() {
$.MsgBox.Alert('提示', '服务器连接超时!');
}
});
}
/*处理资源html代码*/
function resourceHtml($da) {
$("#resourceName").val($da.resourceName); //名字
$("#application").val($da.supportedServices); //应用用途
if($da.spec) { //厂商型号
$("#modelNumber").val($da.spec);
}
if($da.parameter) { //性能参数
$("#performancePa").val($da.parameter);
}
if($da.cooperationNotes) { //合作备注
$("#remarkContent").val($da.cooperationNotes);
}
if($da.subject) {
var oSub = $da.subject.split(",");
var oSt = "";
for(var i = 0; i < oSub.length; i++) {
oSt += '
' + oSub[i] + '
'
}
$("#keywordList").html(oSt);
} else {
$("#keywordList").html("");
}
if($da.descp) { //编辑器
ue.ready(function() {
ue.setContent($da.descp);
});
}
if($da.images.length) {
var arr = [];
for(var i = 0; i < $da.images.length; i++) {
var oString = '' +
'' +
'
' +
'
' +
'' +
'' +
'
' +
''
arr[i] = oString;
array[i] = $da.images[i].imageId;
}
$("#fileList dd").eq(2).remove();
if($da.images.length == 1) {
$("#fileList").prepend(arr[0]);
} else if($da.images.length == 2) {
$("#fileList dd").eq(1).remove();
$("#fileList").prepend(arr[1]);
$("#fileList").prepend(arr[0]);
} else if($da.images.length == 3) {
$("#fileList dd").eq(1).remove();
$("#fileList").prepend(arr[2]);
$("#fileList").prepend(arr[1]);
$("#fileList").prepend(arr[0]);
}
}
}
var uploader = WebUploader.create({
auto: true,
fileNumLimit: 3,
swf: '../js/webuploader/Uploader.swf',
server: '../ajax/cachedFileUpload',
fileSingleSizeLimit: 2 * 1024 * 1024,
pick: {
id: "#filePicker",
multiple: false
},
accept: {
title: 'Images',
extensions: 'jpg,jpeg,png',
mimeTypes: 'image/jpg,image/png'
}
});
// 当有文件添加进来的时候
uploader.on('fileQueued', function(file) {
fileId = file.id;
var $len = $("#fileList").find("img").length;
if($len == 0 || $len == 1) {
var oRemove = $("#fileList").find("dd");
oRemove.eq(oRemove.length - 1).remove();
}
var $li = $(
'' +
'' +
'
' +
'
' +
//'' + file.name + '
' +
''
),
$btns = $('' +
'' +
'
').appendTo($li),
$img = $li.find('img');
var $list = $("#fileList");
if($len == 1) {
$list.find("dd").eq(0).after($li)
} else if($len == 2) {
$list.find("dd").eq(1).after($li)
} else {
$list.prepend($li);
}
// 创建缩略图
// 如果为非图片文件,可以不用调用此方法。
// thumbnailWidth x thumbnailHeight 为 100 x 100
uploader.makeThumb(file, function(error, src) {
if(error) {
$img.replaceWith('不能预览');
return;
}
$img.attr('src', src);
}, 1, 1);
/*$li.on('mouseenter', function() {
$btns.stop().animate({
height: 30
});
});
$li.on('mouseleave', function() {
$btns.stop().animate({
height: 0
});
});*/
});
uploader.onError = function(code) {
console.log(code)
$.MsgBox.Alert('提示', '请上传jpg、png格式的图片,大小不超过2M')
};
uploader.on('uploadSuccess', function(file, data) {
uploader.removeFile(fileId);
var cacheImageKey = temp.push(data.data[0].cacheKey);
});
/*删除图片*/
$("#fileList").on("click", ".cancel", function() {
var flag = $(this).attr("flag");
var oNum = $(this).parents("dd").index();
if(flag == 1) {
array.splice(oNum, 1);
} else {
temp.splice(oNum, 1);
}
$(this).parent().parent().remove();
var $len = $("#fileList").find("img").length;
if($len != 2) {
$("#fileList").append("")
}
});
/*资源名称*/
$("#resourceName").bind({
focus: function() {
$("#resourceNamePrompt").show();
},
blur: function() {
$("#resourceNamePrompt").hide();
},
keyup: function() {
if($(this).val().length > 30) {
$(this).val($(this).val().substr(0, 30));
}
}
})
/*关键词*/
$("#keywordName").bind({
focus: function() {
$("#keywordPrompt").show().text('最多可添加5个关键词、每个关键词最多10个字');
$("#keyList").show();
},
blur: function() {
$("#keywordPrompt").hide();
setTimeout(function() {
$("#keyList").show();
}, 200)
},
keyup: function() {
if($(this).val().length > 10) {
$(this).val($(this).val().substr(0, 10));
} else if(0 < $(this).val().length < 10) {
$.ajax({
"url": "/ajax/dataDict/qaHotKey",
"type": "GET",
"success": function(data) {
console.log(data);
if(data.success) {
if(data.data.length==0) {
$("#keyList ul").html("");
} else {
var oSr = "";
for(var i = 0; i < data.data.length; i++) {
oSr += '' + data.data[i].caption + '
'
}
$("#keyList ul").html(oSr);
}
}
},
"data": {
"key": $(this).val()
},
dataType: "json",
'error': function() {
$.MsgBox.Alert('提示', '服务器连接超时!');
}
});
}
}
})
$("#keyList ul").on("click","li",function(){
keyWord($(this).find("p").text());
$("#keyList ul").html("");
})
/*添加关键词*/
$("#addKeyword").click(function() {
keyWord($("#keywordName").val());
})
function keyWord(atl) {
var oKeywordName = atl;
var keywordListLength = $("#keywordList").find("li");
if(oKeywordName.length == 0) {
$("#keywordPrompt").text('关键词输入不能为空');
return;
}
for(var i = 0; i < keywordListLength.length; i++) {
if(oKeywordName == keywordListLength.find("p").eq(i).text()) {
$("#keywordPrompt").text('该关键词已存在');
return;
}
}
var oStr = '' + oKeywordName + '
'
$("#keywordList").append(oStr);
$("#keywordName").val("");
if((keywordListLength.length + 1) == 5) {
$("#keywordHide").hide();
}
}
/*删除关键词*/
$("#keywordList").on("click", ".closeThis", function() {
$(this).parent().remove();
var keywordListLength = $("#keywordList").find("li");
if(keywordListLength.length < 5) {
$("#keywordHide").show();
}
});
/*应用用途*/
$("#application").bind({
focus: function() {
$("#applicationPrompt").show();
},
blur: function() {
$("#applicationPrompt").hide();
},
keyup: function() {
if($(this).val().length > 50) {
$(this).val($(this).val().substr(0, 50));
}
}
})
/*厂商型号*/
$("#modelNumber").bind({
focus: function() {
$("#model").show();
},
blur: function() {
$("#model").hide();
},
keyup: function() {
if($(this).val().length > 50) {
$(this).val($(this).val().substr(0, 50));
}
}
});
function para(sel1, sel2, sel3) {
$(sel1).bind({
focus: function() {
$(sel2).show();
},
blur: function() {
$(sel2).hide();
},
keyup: function(e) {
if($(this).val().length > 200) {
$(this).val($(this).val().substring(0, 200));
e.preventDefault();
}
setTimeout(function() {
$(sel3).text($(sel1).val().length);
}, 1);
}
});
}
/*性能参数*/
para("#performancePa", "#performance", "#entry1");
/*合作备注*/
para('#remarkContent', '#remark', '#entry2');
/*发布*/
$(".goFabu").click(function() {
var oYes = term();
if(oYes == 0) {
return;
}
$.MsgBox.Confirm("提示", "确认发布该资源?", ajsPost);
})
/*预览*/
$("#oPreview").click(function() {
var oYes = term();
if(oYes == 0) {
return;
}
ajsPost("/ajax/resource/orgDraft", 1);
})
/*存草稿*/
$("#oDraft").click(function() {
var oYes = term();
if(oYes == 0) {
return;
}
ajsPost("/ajax/resource/orgDraft", 2);
})
/*删除*/
$("#operateBlocko").on("click", ".deleteResource", function() {
$.MsgBox.Confirm("提示", "确认删除该资源?", deleResource);
})
/*删除函数*/
function deleResource() {
$.ajax({
"url": "/ajax/resource/delete",
"type": "POST",
"success": function(data) {
console.log(data)
if(data.success) {
location.href = "resourceList.html"
}
},
"data": {
"resourceId": resourceId
},
"beforeSend": function() { /*console.log(this.data)*/ },
"contentType": "application/x-www-form-urlencoded",
dataType: "json"
});
}
/*条件是否匹配*/
function term() {
var $len = $("#fileList").find("img").length;
var reName = $("#resourceName").val();
var oIndustry = $("#application").val();
var oLen=$("#expertli").find(".selectAdd").length
if($len == 0) {
$.MsgBox.Alert('提示', '请上传资源图片。');
return 0;
}
if(reName == "") {
$.MsgBox.Alert('提示', '请输入资源名称。');
return 0;
}
if(oIndustry == "") {
$.MsgBox.Alert('提示', '请输入应用用途。');
return 0;
}
if(oLen==0) {
$.MsgBox.Alert('提示', '至少选择一个负责人');
return 0;
}
}
/*发布函数*/
function ajsPost(pa1, pa2) {
var oUrl = "/ajax/resource/orgSave";
if(pa1) {
oUrl = pa1
}
var $data = {};
if(resourceId) {
$data.resourceId = resourceId;
}
$data.orgId = id;
$data.resourceName = $("#resourceName").val(); //资源名字
$data.cooperationNotes = $("#remarkContent").val(); //合作备注
$data.subject = captiureSubInd("keywordList p");
console.log($data.subject);
$data.supportedServices = $("#application").val();
$data.spec = $("#modelNumber").val();
$data.parameter = $("#performancePa").val();
$data.descp = ue.getContent();
$data.fns = temp;
$data.imageIds = array;
$data.professorIds=oProfessor;
//$data.imageIds:资源图片ID NULL 字符串数组
console.log(temp);
$.ajax({
"url": oUrl,
"type": "POST",
"success": function(data) {
console.log(data)
if(data.success) {
if(pa2 == 1) {
resourceId = data.data;
$("#deleteResource").removeClass("disableLi").addClass("deleteResource");
window.open("../resourcePreview.html?resourceId=" + data.data);
//弹出预览
} else if(pa2 == 2) {
$("#deleteResource").removeClass("disableLi").addClass("deleteResource");
resourceId = data.data;
$.MsgBox.Alert('提示', '资源已保存草稿。');
$("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
} else {
$.MsgBox.Alert('提示', '资源发布成功!');
$("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
location.href = "resourceList.html"
}
}
},
"data": $data,
"beforeSend": function() { /*console.log(this.data)*/ },
"contentType": "application/x-www-form-urlencoded",
"traditional": true,
dataType: "json"
});
}
function captiureSubInd(subIndu) {
var industrys = $("#" + subIndu + "");
var industryAll = "";
if(industrys.size() > 0) {
for(var i = 0; i < industrys.size(); i++) {
industryAll += industrys[i].innerText;
industryAll += ',';
};
industryAll = industryAll.substring(0, industryAll.length - 1);
}
return industryAll;
}
function UnauthorizedUser() {
$.ajax({
url: "/ajax/professor/qaOrgAuth",
type: "GET",
timeout: 10000,
dataType: "json",
async:"false",
data: {
"orgId": id,
"orgAuth": 1
},
success: function(data, textState) {
if(data.success) {
console.log(data);
unauthUser(data.data);
}
},
error: function(XMLHttpRequest, textStats, errorThrown) {
$.MsgBox.Alert('提示', '服务器请求失败')
}
})
}
UnauthorizedUser();
function unauthUser($res) {
if(resourceId) {
selUse();
}
var osting=""
for(var i = 0; i < $res.length; i++) {
var img;
var styC="";
var oClass = autho($res[i].authType, $res[i].orgAuth, $res[i].authStatus);
var oTitle="";
if(!resourceId) {
if(i<5) {
styC="selectAdd";
oProfessor.push($res[i].id);
}
}
if($res[i].title) {
oTitle=$res[i].title;
}else{
if($res[i].office) {
oTitle=$res[i].office;
}
}
if($res[i].hasHeadImage) {
img = "/images/head/" + $res[i].id + "_l.jpg";
} else {
img = "../images/default-photo.jpg"
}
var oSt = ''
oSt += ''
oSt += ''
oSt += '
'
oSt += ''+$res[i].name+''
oSt += '
'
oSt += '
'+oTitle+'
'
oSt += '
'
oSt += ''
oSt += ''
osting+=oSt;
}
$("#expertli").html(osting);
}
/*选择用户*/
$("#expertli").on("click","li",function(){
var userL=$("#expertli").find(".selectAdd").length;
var oSel=$(this).find(".selectAdd").length;
var oId=$(this).attr("id");
$("#linkman").text("");
if(oSel == 0) {
if(userL == 5) {
$("#linkman").text("最多可选5个负责人");
return;
}
$(this).find('[flag]').addClass("selectAdd");
oProfessor.push(oId);
} else {
$(this).find('[flag]').removeClass("selectAdd");
for(var i=0;i