<!DOCTYPE html>
|
<html>
|
<head>
|
<meta charset="utf-8" />
|
<title>用户关联客户导入</title>
|
<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
|
<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
|
<script src="../../../layuiadmin/zgqCustom/zgqCustom.js"></script>
|
<script src="../../../layuiadmin/layui/layui.js"></script>
|
<script src="../../../layuiadmin/Scripts/json2.js"></script>
|
<script src="../../../layuiadmin/Scripts/jquery-1.4.1.js"></script>
|
<script src="../../../layuiadmin/Scripts/webConfig.js"></script>
|
<script src="../../../layuiadmin/PubCustom.js"></script>
|
</head>
|
<body>
|
<div class="layui-fluid" style="padding: 0;">
|
<div class="layui-card" style="padding: 2px;background-color: #efefef;">
|
<div class="layui-card-body" style="padding: 1px;">
|
<form class="layui-form" action="" lay-filter="formData" style="background-color:white;">
|
<div style="padding: 10px; ">
|
<button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="UpLoad" id="UpLoad">文件上传</button>
|
<button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="Confirm" id="Confirm">数据验证</button>
|
<button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnSave_ReWrite" id="btnSave_ReWrite">覆盖导入</button>
|
<button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnSave_Add" id="btnSave_Add">追加导入</button>
|
<button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="Cancel" id="Cancel">退出</button>
|
</div>
|
<div class="layui-tab" lay-filter="tab-POStockInBill">
|
<div class="layui-tab-content">
|
<!--基本信息-->
|
<div class="layui-tab-item layui-show">
|
<div class="layui-form-item" style="padding-top: 10px;">
|
<div class="layui-row">
|
<div class="layui-col-xs4 layui-inline" style="width:100%;">
|
<label class="layui-form-label">导入字段(任选其一):</label>
|
<div class="layui-input-inline">
|
<input type="checkbox" name="checkboxHUserID" id="checkboxHUserID" lay-skin="primary" lay-filter="checkboxHUserID" value="true" title="用户代码">
|
<input type="hidden" value="false" name="HUserID" id="HUserID">
|
</div>
|
<div class="layui-input-inline">
|
<input type="checkbox" name="checkboxHUserName" id="checkboxHUserName" lay-skin="primary" lay-filter="checkboxHUserName" value="true" title="用户名称">
|
<input type="hidden" value="false" name="HUserName" id="HUserName">
|
</div>
|
<!--<div class="layui-input-inline">
|
<input type="checkbox" name="checkboxHCusNumber" id="checkboxHCusNumber" lay-skin="primary" lay-filter="checkboxHCusNumber" value="true" title="客户代码">
|
<input type="hidden" value="false" name="HCusNumber" id="HCusNumber">
|
</div>
|
<div class="layui-input-inline">
|
<input type="checkbox" name="checkboxHCusName" id="checkboxHCusName" lay-skin="primary" lay-filter="checkboxHCusName" value="true" title="客户名称">
|
<input type="hidden" value="false" name="HCusName" id="HCusName">
|
</div>-->
|
</div>
|
<div class="layui-col-xs4 layui-inline" style="width:100%;">
|
<label class="layui-form-label">导入字段(任选其一):</label>
|
<!--<div class="layui-input-inline">
|
<input type="checkbox" name="checkboxHCusNumber" id="checkboxHCusNumber" lay-skin="primary" lay-filter="checkboxHCusNumber" value="true" title="客户代码">
|
<input type="hidden" value="false" name="HCusNumber" id="HCusNumber">
|
</div>
|
<div class="layui-input-inline">
|
<input type="checkbox" name="checkboxHCusName" id="checkboxHCusName" lay-skin="primary" lay-filter="checkboxHCusName" value="true" title="客户名称">
|
<input type="hidden" value="false" name="HCusName" id="HCusName">
|
</div>-->
|
<div class="layui-input-inline">
|
<input type="checkbox" name="checkboxHOrgNumber" id="checkboxHOrgNumber" lay-skin="primary" lay-filter="checkboxHOrgNumber" value="true" title="组织代码">
|
<input type="hidden" value="false" name="HOrgNumber" id="HOrgNumber">
|
</div>
|
<div class="layui-input-inline">
|
<input type="checkbox" name="checkboxHOrgName" id="checkboxHOrgName" lay-skin="primary" lay-filter="checkboxHOrgName" value="true" title="组织名称">
|
<input type="hidden" value="false" name="HOrgName" id="HOrgName">
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
|
<table class="" id="mainTable" lay-filter="mainTable"></table>
|
<script type="text/html" id="toolbarDemo">
|
<div class="layui-btn-container">
|
</div>
|
</script>
|
</form>
|
</div>
|
</div>
|
</div>
|
</body>
|
</html>
|
<script type="text/html" id="barDemo">
|
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
</script>
|
<script>
|
|
layui.config({
|
base: '../../../layuiadmin/' //静态资源所在路径
|
}).extend({
|
index: 'lib/index' //主入口模块
|
}).use(['tree', 'index', 'form', 'table', 'element', 'laypage', 'laydate', 'util', 'upload'], function () {
|
//#region 公用变量
|
var $ = layui.$
|
, admin = layui.admin
|
, layer = layui.layer
|
, table = layui.table
|
, form = layui.form
|
, element = layui.element
|
, laypage = layui.laypage
|
, laydate = layui.laydate
|
, util = layui.util
|
, tree = layui.tree
|
, util = layui.util
|
, upload = layui.upload
|
|
|
var option = [];
|
|
//记录验证标记
|
var confirmBar = 0;
|
//#endregion
|
|
//#region 进入页面即加载
|
//#region 初始化界面
|
set_ClearBill();
|
//#endregion
|
//#endregion
|
|
//#region 触发事件:包括form.on(){}格式的所有点击事件、选择事件等
|
//#region 表头按钮触发事件
|
//#region 覆盖导入 保存数据
|
form.on('submit(btnSave_ReWrite)', function (data) {
|
if (confirmBar == 1) {
|
set_AddNew(data,1);
|
} else {
|
var reConfirmBar = 1;
|
for (var i = 0; i < option.data.length; i++) {
|
if ( (option.data[i].判定结果 != "" && option.data[i].判定结果 != "用户已经关联该客户;") || (option.data[i].客户内码 === null || option.data[i].客户内码 == "") ) {
|
reConfirmBar = 0;
|
break;
|
}
|
}
|
if (reConfirmBar == 1) {
|
set_AddNew(data, 1);
|
} else {
|
layer.msg("保存失败,数据未通过校验,请在修改后重新校验!", { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
|
}
|
}
|
})
|
//#endregion
|
|
//#region 追加导入 保存数据
|
form.on('submit(btnSave_Add)', function (data) {
|
if (confirmBar == 1) {
|
set_AddNew(data, 2);
|
} else {
|
layer.msg("保存失败,数据未通过校验,请在修改后重新校验!", { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
|
}
|
})
|
//#endregion
|
|
//#region 导入 数据验证
|
form.on('submit(Confirm)', function (data) {
|
var HUserID = document.getElementById("checkboxHUserID").checked;
|
var HUserName = document.getElementById("checkboxHUserName").checked;
|
//var HCusNumber = document.getElementById("checkboxHCusNumber").checked;
|
//var HCusName = document.getElementById("checkboxHCusName").checked;
|
var HOrgNumber = document.getElementById("checkboxHOrgNumber").checked;
|
var HOrgName = document.getElementById("checkboxHOrgName").checked;
|
|
if (!((HUserID == true && HUserName == false) || (HUserID == false && HUserName == true))) {
|
layer.msg("请在用户代码和用户名称之间任选一个作为导入字段!");
|
return false;
|
}
|
|
if (!((HOrgNumber == true && HOrgName == false) || (HOrgNumber == false && HOrgName == true))) {
|
layer.msg("请在组织代码和组织名称之间任选一个作为导入字段!");
|
return false;
|
}
|
|
if (AllowLoadData()) {
|
set_confirm(data);
|
}
|
})
|
//#endregion
|
|
//#region 文件上传
|
upload.render({
|
elem: '#UpLoad',
|
url: GetWEBURL() + '/Xt_User/Gy_UserCustomer_ImportByExcel',
|
contentType: 'application/json',
|
exts: 'xls|xlsx', //允许上传的类型
|
//data: {
|
// "WorkBookName": function () {
|
// return $("#WorkBookName").val();
|
// },
|
// "HOrgID": function () {
|
// return sessionStorage["OrganizationID"];
|
// }
|
//},
|
//before: function (data) {
|
// loadIndex = layer.load(2);
|
// this.data = {
|
// "WorkBookName": $("#WorkBookName").val(),
|
// "HOrgID": sessionStorage["OrganizationID"]
|
|
// }
|
//},
|
done: function (data1) {
|
if (data1.count == 1) {
|
option.data = data1.data;
|
table.render(option);
|
} else {
|
layer.alert(data1.code + data1.Message, { icon: 5 });
|
}
|
},
|
error: function (err) {
|
debugger
|
layer.alert('导入出现异常', { icon: 2 });
|
}
|
});
|
//#endregion
|
|
//#region 退出
|
form.on('submit(Cancel)', function () {
|
Pub_Close(1);
|
})
|
//#endregion
|
//#endregion
|
|
//#region 子表触发事件
|
//#region 行内事件
|
table.on('tool(mainTable)', function (obj) {
|
set_GridDelete(obj); //行内删除
|
});
|
//#endregion
|
//#endregion
|
//#endregion
|
|
//#region 此页面所有的方法
|
//#region 初始化界面
|
function set_ClearBill() {
|
//初始化表格
|
set_InitGrid();
|
}
|
//#endregion
|
|
//#region 初始化表格
|
function set_InitGrid() {
|
option = {
|
elem: '#mainTable'
|
, toolbar: '#toolbarDemo'
|
, height: 'full-120'
|
, page: true
|
, cellMinWidth: 90
|
, limit: 50
|
, limits: [50, 500, 5000, 20000]
|
, loading: false
|
, cols: [[
|
{ type: 'checkbox', fixed: 'left' }
|
, { field: '用户代码', title: '用户代码', edit: "true", width: 120 }
|
, { field: '用户名称', title: '用户名称', edit: "true", width: 120 }
|
, { field: '客户内码', title: '客户内码', edit: "true", width: 120, hide: true }
|
, { field: '客户代码', title: '客户代码', edit: "true", width: 120 }
|
, { field: '客户名称', title: '客户名称', edit: "true", width: 120 }
|
, { field: '组织代码', title: '组织代码', edit: "true", width: 120 }
|
, { field: '组织名称', title: '组织名称', edit: "true", width: 120 }
|
, { field: '判定结果', title: '判定结果', edit: "true", width: 240 }
|
, { fixed: 'right', title: '操作', toolbar: '#barDemo' }
|
]]
|
, done: function (res, curr, count) {
|
//循环表数据根据flag状态给行上色
|
$.each(res['data'], function (i, j) {
|
if (j['判定结果'] != '') {
|
Layui_SetDataTableRowColor('table', i + 1, 'red');
|
} else {
|
Layui_SetDataTableRowColor('table', i + 1, 'black');
|
}
|
|
});
|
}
|
};
|
//渲染页面
|
table.render(option);
|
//DisPlay_HideColumn();
|
}
|
//#endregion
|
|
//#region 给table行上色
|
function Layui_SetDataTableRowColor(TabDivId, RowIndex, ColorString) {
|
try {
|
var div = $("[lay-id='mainTable'] tr:eq(" + RowIndex + ")");
|
if (div != null) //找到对象了
|
{
|
// console.log(div);
|
div.css("color", ColorString);
|
|
} else {
|
console.log('没有找到对象');
|
}
|
} catch (e) {
|
console.log(e.message);
|
}
|
}
|
//#endregion
|
|
//#region 导入(数据验证)
|
function set_confirm(data) {
|
var num = [];
|
for (var i = 0; i < option.data.length; i++) {
|
if (option.data[i] != "") {
|
num.push(option.data[i])
|
}
|
}
|
|
//获取导入字段
|
var HUserID = document.getElementById("checkboxHUserID").checked;
|
var HUserName = document.getElementById("checkboxHUserName").checked;
|
//var HCusNumber = document.getElementById("checkboxHCusNumber").checked;
|
//var HCusName = document.getElementById("checkboxHCusName").checked;
|
var HOrgNumber = document.getElementById("checkboxHOrgNumber").checked;
|
var HOrgName = document.getElementById("checkboxHOrgName").checked;
|
var importList = "";
|
if (HUserID == true) {
|
importList += "HUserID;";
|
} else if (HUserName == true) {
|
importList += "HUserName;";
|
}
|
if (HOrgNumber == true) {
|
importList += "HOrgNumber;";
|
} else if (HOrgName == true) {
|
importList += "HOrgName;";
|
}
|
|
//data.field.HOrgID = sessionStorage["OrganizationID"];//组织
|
//var sMainStr = JSON.stringify(data.field);
|
var sSubStr = JSON.stringify(num);
|
var sMainSub = sSubStr + '&和' + sessionStorage["HUserName"] + '&和' + importList;
|
var index = layer.load();
|
|
$.ajax({
|
type: "POST",
|
url: GetWEBURL() + "/Xt_User/Gy_UserCustomer_ImportByExcel_Confirm",
|
async: true,
|
data: { "sMainSub": sMainSub },
|
dataType: "json",
|
success: function (data) {
|
if (data.count == 1) {
|
if (data.Message == "1") {
|
confirmBar = 1;
|
for (var i = 0; i < option.cols[0].length; i++) {
|
option.cols[0][i].edit = "false";
|
}
|
} else {
|
confirmBar = 0;
|
for (var i = 0; i < option.cols[0].length; i++) {
|
option.cols[0][i].edit = "true";
|
}
|
}
|
option.data = data.data;
|
table.render(option);
|
layer.close(index);
|
}
|
else {
|
layer.close(index);
|
layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
|
}
|
},
|
error: function (err) {
|
layer.close(index);
|
layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
|
}
|
});
|
}
|
//#endregion
|
|
//#region 导入(保存)
|
function set_AddNew(data, saveType) {
|
var num = [];
|
for (var i = 0; i < option.data.length; i++) {
|
if (option.data[i] != "") {
|
num.push(option.data[i])
|
}
|
}
|
|
//data.field.HOrgID = sessionStorage["OrganizationID"];//组织
|
//var sMainStr = JSON.stringify(data.field);
|
var sSubStr = JSON.stringify(num);
|
var sMainSub = sSubStr + '&和' + sessionStorage["HUserName"] + '&和' + saveType;
|
var index = layer.load();
|
|
$.ajax({
|
type: "POST",
|
url: GetWEBURL() + "/Xt_User/Gy_UserCustomer_ImportByExcel_Save",
|
async: true,
|
data: { "sMainSub": sMainSub },
|
dataType: "json",
|
success: function (data) {
|
if (data.count == 1) {
|
layer.close(index);
|
layer.msg(data.Message);
|
option.data = null;
|
table.cache["mainTable"] = null;
|
table.render(option);
|
}
|
else {
|
layer.close(index);
|
layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
|
}
|
confirmBar = 0;
|
},
|
error: function (err) {
|
layer.close(index);
|
layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
|
confirmBar = 0;
|
}
|
});
|
}
|
//#endregion
|
|
//#region 数据校验
|
function AllowLoadData() {
|
//获取表格数据
|
var data = table.cache["mainTable"];
|
|
//判断表格是否有数据
|
if (data == null || data == "") {
|
layer.msg("无数据,请先导入数据!");
|
return false;
|
}
|
|
//if (confirmBar == 0) {
|
// layer.msg("数据存在问题,请在修改数据后重新校验!");
|
// return false;
|
//}
|
|
//关键字重复校验
|
var num = [];
|
var temp = "";
|
for (var i = 0; i < data.length; i++) {
|
temp = data[i]["客户代码"] + "," + data[i]["组织代码"];
|
if ($.inArray(temp, num) == -1) {
|
num.push(temp);
|
} else {
|
layer.msg("第" + (i + 1) + "行,客户代码和组织代码存在重复记录!");
|
return false;
|
}
|
}
|
return true;
|
}
|
//#endregion
|
|
//#region 行内删除
|
function set_GridDelete(obj) {
|
var data = obj.data;
|
var rowIndex = $(obj.tr).attr("data-index");
|
if (obj.event === 'del') {
|
layer.confirm('真的删除行吗?', function (index) {
|
console.log("索引为:" + rowIndex);
|
if (rowIndex === '0') {
|
layer.msg('首行无法删除!!!');
|
} else {
|
var oldData = option.data;
|
oldData.splice(obj.tr.data('index'), 1)
|
option.data = oldData;//将数据绑定到data上
|
table.render(option);
|
layer.close(index);
|
}
|
});
|
}
|
}
|
//#endregion
|
//#endregion
|
});
|
|
</script>
|