358 lines
16 KiB
Plaintext
358 lines
16 KiB
Plaintext
@using WX.CRM.WebHelper
|
||
@{
|
||
ViewBag.Title = "分配员工";
|
||
Layout = "~/Views/Shared/_Index_Layout2.cshtml";
|
||
}
|
||
<style>
|
||
.bodyDiv {
|
||
height: 100%;
|
||
overflow-y: auto;
|
||
}
|
||
</style>
|
||
<div class="mvctool">
|
||
@*<a style="float: left;" class="l-btn l-btn-plain" href="/Res/SalesGroup/SalesGroupDetails?id=@Request.QueryString["id"]">
|
||
自定义分组>>
|
||
</a>*@
|
||
<button class="layui-btn layui-btn-sm layui-btn-primary" id="btnSave">
|
||
<span class="csicon2 icon-save"></span><span class="csicontitle">
|
||
保存
|
||
</span>
|
||
</button>
|
||
</div>
|
||
<table style="width: 100%; border: 1px solid #95b8e7;">
|
||
<tr>
|
||
<td style="vertical-align: top;">
|
||
<div style="display:none;">
|
||
<input type="radio" value="group" name="act" id="group" @if (ViewBag.ActType == "group") { @Html.Raw("checked='checked'") } /><label for="group">按组分配</label>
|
||
<input type="radio" value="user" name="act" id="user" @if (ViewBag.ActType == "user") { @Html.Raw("checked='checked'") } /><label for="user">按员工分配</label>
|
||
<span style="padding-left:50px;"></span>
|
||
<input type="radio" value="rate" name="ratetype" id="rate" /><label for="rate">按比例</label>
|
||
<input type="radio" value="num" name="ratetype" id="num" checked="checked" /><label for="num">按数量</label>
|
||
</div>
|
||
@Html.Raw(ViewBag.gridTable)
|
||
</td>
|
||
<td style="border: 1px solid #95b8e7; width:370px; vertical-align: top; @if (ViewBag.ActType == "group") { @Html.Raw("display:none;") } " id="userTD">
|
||
<div>
|
||
<div id="tb" style="padding:5px;height:auto; visibility:hidden; background-color:#f2f2f2" class="grid_toolbar">
|
||
<span style="padding-right:30%">已选择员工:</span>
|
||
<input type="radio" value="1" name="usertype" id="custom" @if (ViewBag.UserType == 1) { @Html.Raw("checked='checked'") } /><label for="custom">自定义分配</label>
|
||
<input type="radio" value="0" name="usertype" id="auto" @if (ViewBag.UserType == 0) { @Html.Raw("checked='checked'") } /><label for="auto">自动分配</label>
|
||
</div>
|
||
<hr />
|
||
<div id="userDiv"></div>
|
||
@*<hr />
|
||
<div id="unconfDiv"></div>*@
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
<script type="text/javascript">
|
||
$(function () {
|
||
@if (ViewBag.ActType == "user")
|
||
{
|
||
@Html.Raw("UserInit();")
|
||
}
|
||
|
||
$("#tablist tr").click(function () {
|
||
//alert(1);
|
||
$("#tablist .tr_onclick").removeClass("tr_onclick");
|
||
$(this).toggleClass("tr_onclick");
|
||
|
||
var usertype = $('input[name="usertype"]:checked').val();
|
||
var usertypeInputHide = ""
|
||
//if (usertype == 0) {
|
||
// usertypeInputHide = "none;"
|
||
//}
|
||
|
||
var row = $('#tablist').tablegrid('getSelected');
|
||
if (row != null) {
|
||
$("#userDiv ul").hide();
|
||
//$("#unconfDiv ul").hide();
|
||
|
||
//$("#uc" + row.gid).show();
|
||
|
||
if ($("#ug" + row.gid).length > 0) {
|
||
$("#ug" + row.gid).show();
|
||
}
|
||
else {
|
||
$.getJSON("/Res/SalesGroup/GetGroupUser?gid=" + row.gid, function (rep) {
|
||
var html = "<ul id='ug" + row.gid + "' gid=" + row.gid + ">";
|
||
$.each(rep.data, function (i, j) {
|
||
//html += "<li uid='" + j.UserId + "'><span>" + j.UName + "-" + j.Eid + "</span><input type='text' style='width:50px;display:" + usertypeInputHide + ";' /><a href='javascript:void(0)' onclick='Del(this," + row.gid + ")'>删除</a></li>";
|
||
html += "<li style='width:100%;float:left;height:30px;line-height:30px;border-bottom:1px solid #ccc' uid='" + j.UserId + "'><span style='float:left;'>" + j.UName + "-" + j.Eid + "</span><input type='text' style='float:right;width:50px;display:" + usertypeInputHide + ";' value='0' /></li>";
|
||
});
|
||
html += "</ul>";
|
||
$("#userDiv").append(html);
|
||
|
||
//if (usertype == 1) {
|
||
// $("#ug" + row.gid).each(function (i, j) {
|
||
// var num = $(j).children().length;
|
||
// var avg = parseInt(10000 / num) / 100;
|
||
// $(j).children("li").find("input").val(avg);
|
||
// var diff = (10000 - (num * avg * 100));
|
||
// if (diff > 0) {
|
||
// $(j).children("li:first").find("input").val((avg * 100 + diff) / 100);
|
||
// }
|
||
// });
|
||
//}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
|
||
$(":radio[name='usertype']").click(function () {
|
||
//alert(this.value);
|
||
if (this.value == 1) {
|
||
$("#userDiv ul li input[type='text']").show();
|
||
$("#userDiv ul").each(function (i, j) {
|
||
var num = $(j).children().length;
|
||
var avg = parseInt(10000 / num) / 100;
|
||
$(j).children("li").find("input").val(avg);
|
||
var diff = (10000 - (num * avg * 100));
|
||
if (diff > 0) {
|
||
$(j).children("li:first").find("input").val((avg * 100 + diff) / 100);
|
||
}
|
||
});
|
||
}
|
||
else {
|
||
$("#userDiv ul li input[type='text']").hide();
|
||
}
|
||
});
|
||
|
||
//$(":radio[name='act']").click(function () {
|
||
// //var row = $("#tablist tr");
|
||
// if (this.value == "user") {
|
||
// $("#userTD").show();
|
||
|
||
// //$(row).each(function (i, n) {
|
||
// // $(n).children("th:last").show();
|
||
// // $(n).children("td:last").css("color","blue").show();
|
||
// //});
|
||
|
||
// //UserInit();
|
||
|
||
// var usertype = $('input[name="usertype"]:checked').val();
|
||
// var usertypeInputHide = ""
|
||
// if (usertype == 0) {
|
||
// usertypeInputHide = "none;"
|
||
// }
|
||
|
||
// var row = $("#tablist tbody tr");
|
||
// $(row).each(function (i, n) {
|
||
// var rowGid = $(n).children('td').eq(1).text();
|
||
// var r = $(n).find('input[type="text"]').val();
|
||
// if (r != '' && r != null && r != undefined) {
|
||
// $.getJSON("/Res/SalesGroup/GetGroupUser?gid=" + rowGid, function (rep) {
|
||
// var html = "<ul id='ug" + rowGid + "' gid=" + rowGid + " ratio=" + r + " style='display:none'>";
|
||
// $.each(rep.data, function (i, j) {
|
||
// html += "<li style='width:100%;float:left;height:30px;line-height:30px;border-bottom:1px solid #ccc' uid='" + j.UserId + "'><span style='float:left;'>" + j.UName + "-" + j.Eid + "</span><input type='text' style='float:right;width:50px;display:" + usertypeInputHide + ";' /><a href='javascript:void(0)' onclick='Del(this," + rowGid + ")'>删除</a></li>";
|
||
// });
|
||
// html += "</ul>";
|
||
// $("#userDiv").append(html);
|
||
|
||
// if (usertype == 1) {
|
||
// $("#ug" + rowGid).each(function (i, j) {
|
||
// var num = $(j).children().length;
|
||
// var avg = parseInt(10000 / num) / 100;
|
||
// $(j).children("li").find("input").val(avg);
|
||
// var diff = (10000 - (num * avg * 100));
|
||
// if (diff > 0) {
|
||
// $(j).children("li:first").find("input").val((avg * 100 + diff) / 100);
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
// $("#unconfDiv").append("<ul id='uc" + rowGid + "'></ul>");
|
||
// });
|
||
// }
|
||
// });
|
||
// }
|
||
// else if (this.value == "group") {
|
||
// $("#userTD").hide();
|
||
|
||
// $("#userDiv").empty();
|
||
// $("#unconfDiv").empty();
|
||
// }
|
||
//});
|
||
|
||
|
||
|
||
$("#btnSave").click(function () {
|
||
var canSubmit = true;
|
||
var acttype = $('input[name="act"]:checked').val();
|
||
var usertype = $('input[name="usertype"]:checked').val();
|
||
var ratetype = $('input[name="ratetype"]:checked').val();
|
||
//alert(usertype);
|
||
var requestId = "@Request.QueryString["id"]";
|
||
var strategy = "@Request["strategy"]";
|
||
var groups = "";
|
||
var ratio = 0;
|
||
var row = $("#tablist tbody tr");
|
||
//console.log(row);
|
||
$(row).each(function (i, n) {
|
||
var r = $(n).find('input[type="text"]').val();
|
||
if (r != '' && r != null && r != undefined) {
|
||
var gid = $(n).children('td').eq(1).text();
|
||
var gname = $(n).children('td').eq(2).text();
|
||
ratio += parseFloat(r);
|
||
groups += gid + "-" + gname + "-" + r + ",";
|
||
}
|
||
});
|
||
|
||
//if (ratio != 100.00) {
|
||
// $.messager.alert('提示', '分组比例必须是100%!');
|
||
// return;
|
||
//}
|
||
|
||
groups = groups.substr(0, groups.length - 1);
|
||
|
||
//console.log(groups);
|
||
|
||
var users = "";
|
||
if (acttype == "user") {
|
||
$("#userDiv ul").each(function (i, j) {
|
||
var gid = $(j).attr("gid");
|
||
var ratio = $(j).attr("ratio");
|
||
if (ratio != null) {
|
||
var userRatio = 0;
|
||
$(j).children("li").each(function (m, n) {
|
||
if (usertype == 1) {
|
||
var r = $(n).find('input[type="text"]').val();
|
||
if (r != "" && r != null && r != undefined) {
|
||
//userRatio += parseFloat(r * 100);
|
||
userRatio += parseInt(r);
|
||
users += gid + "-" + $(n).attr("uid") + "-" + $(n).find('span').text() + "-" + r + ",";
|
||
}
|
||
else {
|
||
canSubmit = false;
|
||
}
|
||
}
|
||
//else {
|
||
// userRatio = 10000;
|
||
// users += gid + "-" + $(n).attr("uid") + "-" + $(n).find('span').text() + "-0,";
|
||
//}
|
||
});
|
||
|
||
var grateNum = $("#GRate" + gid).val();
|
||
//console.log(grateNum);
|
||
if (grateNum != userRatio) {
|
||
canSubmit = false;
|
||
$.messager.alert('提示', '员工数量设置不正确!');
|
||
return;
|
||
}
|
||
|
||
//if (userRatio / 100 != 100.00) {
|
||
// $.messager.alert('提示', '员工比例必须是100%!');
|
||
// return;
|
||
//}
|
||
}
|
||
});
|
||
|
||
users = users.substr(0, users.length - 1);
|
||
}
|
||
|
||
if (!canSubmit) {
|
||
//$.messager.alert('提示', '分配比例不能为空!');
|
||
return;
|
||
}
|
||
$.r_ajax({
|
||
url: "/Res/SalesGroup/SaveSalesGroupDetial",
|
||
type: "Post",
|
||
data: { id: requestId, userIds: users, groups: groups, usertype: usertype, grouptype: 1, acttype: acttype, ratetype: ratetype, strategy: strategy },
|
||
dataType: "json",
|
||
loading: true,
|
||
success: function (data) {
|
||
if (data.type == 1) {
|
||
window.parent.frameReturnByMes(data.message);
|
||
window.parent.frameReturnByReload(true);
|
||
window.parent.frameReturnByClose()
|
||
}
|
||
else {
|
||
window.parent.frameReturnByMes(data.message);
|
||
}
|
||
}
|
||
});
|
||
});
|
||
});
|
||
|
||
function UserInit() {
|
||
var users = @Html.Raw(ViewBag.Users);
|
||
@*var unconfUser = @Html.Raw(ViewBag.unconfUsers);*@
|
||
|
||
var html = "";
|
||
var html2 = "";
|
||
|
||
var usertype = $('input[name="usertype"]:checked').val();
|
||
var usertypeInputHide = ""
|
||
if (usertype == 0) {
|
||
usertypeInputHide = "none;"
|
||
}
|
||
|
||
var row = $("#tablist tbody tr");
|
||
|
||
$(row).each(function (i, n) {
|
||
var r = $(n).find('input[type="text"]').val();
|
||
var rowGid = $(n).children('td').eq(1).text();
|
||
if (r != '' && r != null && r != undefined) {
|
||
if ($("#ug" + rowGid).length <= 0) {
|
||
html += "<ul id='ug" + rowGid + "' gid=" + rowGid + " ratio=" + r + " style='display:none'>";
|
||
$.each(users, function (i, j) {
|
||
//console.log(j);
|
||
if (j.Gid == rowGid) {
|
||
//html += "<li uid='" + j.UserId + "'><span>" + j.UName + "-" + j.Eid + "</span><input type='text' style='width:50px;display:" + usertypeInputHide + ";' value='" + j.Rate + "' /><a href='javascript:void(0)' onclick='Del(this," + j.Gid + ")'>删除</a></li>";
|
||
html += "<li style='width:100%;float:left;height:30px;line-height:30px;border-bottom:1px solid #ccc' uid='" + j.UserId + "'><span style='float:left;'>" + j.UName + "-" + j.Eid + "</span><input type='text' style='float:right;width:50px;display:" + usertypeInputHide + ";' value='" + j.Rate + "' /></li>";
|
||
}
|
||
});
|
||
html += "</ul>";
|
||
}
|
||
//if ($("#uc" + rowGid).length <= 0) {
|
||
// html2 += "<ul id='uc" + rowGid + "' style='display:none'>";
|
||
// $.each(unconfUser, function (i, j) {
|
||
// if (j.Gid == rowGid) {
|
||
// html2 += "<li uid='" + j.UserId + "'><span>" + j.UName + "-" + j.Eid + "</span><a href='javascript:void(0)' onclick='Add(this," + j.Gid + ")'>添加</a></li>";
|
||
// }
|
||
// });
|
||
// html2 += "</ul>";
|
||
//}
|
||
}
|
||
});
|
||
|
||
$("#userDiv").append(html);
|
||
$("#unconfDiv").append(html2);
|
||
}
|
||
|
||
function setratio(obj, gid) {
|
||
$("#ug" + gid).attr("ratio", $(obj).val());
|
||
}
|
||
|
||
//function Del(obj, gid) {
|
||
// //$("#unconfDiv")
|
||
// var li = $(obj).parent();
|
||
// $(obj).remove();
|
||
// $("<a href='javascript:void(0)' onclick='Add(this," + gid + ")'>添加</a>").appendTo(li);
|
||
// //console.log(li);
|
||
// $("#uc" + gid).append(li).show();
|
||
//}
|
||
|
||
//function Add(obj, gid) {
|
||
// var usertype = $('input[name="usertype"]:checked').val();
|
||
// var li = $(obj).parent();
|
||
// //console.log(li);
|
||
// $(obj).remove();
|
||
// if (usertype == 1) {
|
||
// $("<input type='text' style='width:50px;' value='' /><a href='javascript:void(0)' onclick='Del(this," + gid + ")'>删除</a>").appendTo(li);
|
||
// }
|
||
// else {
|
||
// $("<a href='javascript:void(0)' onclick='Del(this," + gid + ")'>删除</a>").appendTo(li);
|
||
// }
|
||
|
||
// $("#ug" + gid).append(li);
|
||
// //$(li).remove();
|
||
//}
|
||
|
||
document.onkeydown = function () {
|
||
if (event.keyCode == 9) { //如果是其它键,换上相应在ascii 码即可。
|
||
return false;
|
||
}
|
||
}
|
||
</script> |