You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

257 lines
8.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

var arr = [];
layui.use(['table', 'laytpl', 'form'], function () {
var table = layui.table
, laytpl = layui.laytpl
, form = layui.form;
var tplZcSelectView = zcSelectScript.innerHTML,
viewZcSelectView = document.getElementById('zcSelectView');
// 获取父页传来的项目ID
var projectId = GetQueryString("project_id");
// 获取研究专长
$.ajax({
type: "GET",
dataType: "json",
url: "/dsBase/expert/getExpertZc",
success: function (data) {
laytpl(tplZcSelectView).render(data, function (html) {
viewZcSelectView.innerHTML = html;
});
form.render('select');
}
});
// 获取项目信息
$.ajax({
type: "GET",
dataType: "json",
url: "/dsBase/gtzz/getSubjectInfo",
data: {
subject_id: projectId
},
success: function (data) {
var projectInfoTpl = projectInfoScript.innerHTML,
projectInfoView = document.getElementById('projectInfoView');
laytpl(projectInfoTpl).render(data, function (html) {
projectInfoView.innerHTML = html;
});
}
});
//获取专家
$.ajax({
type: "GET",
dataType: "json",
url: "/dsBase/expert/getSubjectExpert",
data: {
subject_id: projectId,
step_code: '0307'
},
success: function (res) {
for (var i in res.data) {
var _data = { person_id: res.data[i].person_id, person_name: res.data[i].person_name, bureau_name: res.data[i].bureau_name, is_fuzeren: res.data[i].is_master };
arr.push(_data);
}
renderTable();
reloadZhuanJiaView();
}
});
function renderTable() {
table.render({
elem: '#zhuanjiaListTableView'
, url: '/dsBase/expert/getExpertList'
, where: {
zc_id: "-1"
}
, cols: [[
{ align: 'center', field: 'person_name', title: '姓名', width: '15%' }
, { align: 'center', field: 'bureau_name', title: '所属单位', width: '42%' }
, { align: 'center', field: 'zc_name', title: '研究专长', width: '25%' }
, { align: 'center', field: 'age', title: '年龄', width: '10%' }
, { align: 'center', type: 'checkbox', title: '年龄', width: '8%' }
]]
, height: "275"
, parseData: function (res) { //res 即为原始返回的数据
var d = new Date();
var nowYear = d.getFullYear();
for (var i in res.data) {
if (arr.some(item => item.person_id === res.data[i].person_id)) {
res.data[i]["LAY_CHECKED"] = true;
}
res.data[i]["age"] = nowYear - res.data[i]["birthday"].split("-")[0];
}
return {
"code": res.code,
"msg": res.msg,
"count": res.count,
"data": res.data
};
}
, done: function (res) {
// 禁用表头中的全选
$('th[data-field="4"] input[type="checkbox"]').prop('disabled', true);
for (let i in res.data) {
// 给checkbox增加一个ID为取消选中准备
$('td[data-field="4"] input[type="checkbox"]').eq(i).attr('id', 'chk_' + res.data[i]["person_id"]);
}
form.render('checkbox');
}
});
}
var tpl = selectScript.innerHTML,
view = document.getElementById('selectView');
// 重新加载已选专家的列表
function reloadZhuanJiaView() {
laytpl(tpl).render(arr, function (html) {
view.innerHTML = html;
});
}
table.on('checkbox(tableFilter)', function (obj) {
var data = obj.data;
var sel = obj.checked;
var _data = { person_id: data.person_id, person_name: data.person_name, bureau_name: data.bureau_name, is_fuzeren: 0 };
if (sel) {
arr.push(_data);
reloadZhuanJiaView();
} else {
removeAarry(data.person_id);
reloadZhuanJiaView();
}
});
// 表格重载
window.reloadtable = function () {
table.reload('zhuanjiaListTableView', {
where: {
zc_id: $("#zcSelect").val()
, keyword: $("#keyWord").val()
}
});
};
// 点击查询
$("#search").click(function () {
reloadtable();
});
// 确定(保存)
$("#save").click(function () {
if (arr.length < 2) {
layer.msg("专家人数不能少于2人", { icon: 2, time: 1500, shade: [0.1, '#000', true] });
return;
}
if (arr.some(item => item.is_fuzeren === 1)) {
var personIds = "";
var masterId = "";
for (var i = 0; i < arr.length; i++) {
if (arr[i].is_fuzeren === 1) {
masterId = arr[i].person_id;
}
else {
personIds = personIds + arr[i].person_id + ",";
}
}
personIds = personIds.substring(0, personIds.length - 1);
$.ajax({
type: "POST",
dataType: "json",
url: "/dsBase/expert/saveSubjectExpert",
data: {
subject_id: projectId,
step_code: '0307',
person_ids: personIds,
master_id: masterId
},
success: function (data) {
if (data.success) {
layer.msg("设置成功", { icon: 1, time: 1300, shade: [0.1, '#000', true] }, function () {
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
window.parent.parentTableRender('0306');
});
} else {
alert(data.message);
}
}
});
} else {
layer.msg("请设置负责人!", { icon: 2, time: 1500, shade: [0.1, '#000', true] });
}
});
// 取消(关闭)
$("#close").click(function () {
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
});
// 设置负责人
window.setFuzeren = function (person_id) {
arr.some(item => {
if (item.is_fuzeren === 1) {
item.is_fuzeren = 0;
}
});
arr.some(item => {
if (item.person_id === person_id) {
item.is_fuzeren = 1;
}
});
reloadZhuanJiaView();
};
// 移除专家
window.removeZhuanJia = function (person_id) {
removeAarry(person_id);
reloadZhuanJiaView();
// 设置表格中的checkbox为取消选中设置属性要用prop
$("#chk_" + person_id).prop("checked", false);
// 重新加载
form.render('checkbox');
}
// 根据人员ID移除专家数组中的元素
function removeAarry(person_id) {
for (var i = 0; i < arr.length; i++) {
if (arr[i].person_id === person_id) {
index = i;
}
}
arr.splice(index, 1);
}
// 获取参数值
function GetQueryString(name, istop) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (typeof (istop) != "undefined") r = top.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
});