var pageCurr;
var pageCount = 0;
var treeCond;
var admin;
var planNeedXmlSelData;
layui.config({
base: baseUrl + "/static/layui/lay/modules/"
}).extend({
steps: 'steps/steps',
cascader: 'cascader/cascader',
}).use(['table','laydate','layer','upload', 'form', 'admin', 'xmSelect', 'steps', 'element', 'cascader', 'tree', 'dropdown'], function(){
var table = layui.table;
var $ = layui.jquery;
var layer = layui.layer;
var layDate = layui.laydate;
var form = layui.form;
admin = layui.admin;
var upload = layui.upload;
var xmSelect = layui.xmSelect;
var steps = layui.steps;
var cascader = layui.cascader;
var tree = layui.tree;
var dropdown = layui.dropdown;
var element = layui.element;
$('#organization').html(localStorage.getItem('nickname') + ' ');
// 部门人员 筛选
dropdown.render({
elem: '#organization'
,content: ['
'].join('')
,style: 'width: 370px; height: 350px; padding: 0 15px; box-shadow: 1px 1px 30px rgb(0 0 0 / 12%);'
,ready: function(){
loadTree();
}
});
// 数据同步
dropdown.render({
elem: '#data-btn'
,align: 'right'
,style: 'border-radius: 5px;'
,className: 'site-dropdown-demo'
,data: [
{
title: '模板下载'
,templet: ' {{d.title}}'
,id: 1
},
{
title: '导入 Excel'
,templet: ' {{d.title}}'
,id: 2
},
{type: '-'}, //分割线
{
title: '导出 Excel'
,templet: ' {{d.title}}'
,id: 3
}
]
,click: async function(item){
switch (item.id) {
case 1:
// 模板下载
layer.load(1, {shade: [0.1,'#fff']});
location.href = baseUrl + "/mould/跟踪项目导入模板.xls";
layer.closeAll('loading');
break
case 2:
// 导入 Excel
$("#importExcel").trigger("click");
break
case 3:
// 导出 Excel
layer.msg("来不及做,等等", {icon: 6});
break
default:
break
}
}
});
// 树形图
var organizationTree;
window.loadTree = function(condition){
var loadIndex = layer.load(2);
$.ajax({
url: baseUrl+"/dept/user/tree/auth",
headers: {'token': localStorage.getItem('token')},
data: {
'condition': condition
},
method: 'POST',
success: function (res) {
layer.close(loadIndex);
if (res.code === 200){
organizationTree = tree.render({
elem: '#organizationTree',
id: 'organizationTree',
onlyIconControl: true,
data: res.data,
click: function (obj) {
treeCond = {
key: obj.data.key,
val: obj.data.id
}
$('#organization').html(obj.data.title + ' ');
$('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
$(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
clearFormVal($('#search-box'));
tableIns.reload({
where: {[obj.data.key]: obj.data.id},
page: {curr: 1}
});
}
});
treeData = res.data;
} else if (res.code === 403){
top.location.href = baseUrl+"/";
} else {
layer.msg(res.msg)
}
}
})
}
// 数据渲染
tableIns = table.render({
elem: '#plan',
headers: {token: localStorage.getItem('token')},
url: baseUrl+'/plan/page/auth',
page: true,
limit: 15,
limits: [15, 30, 50, 100, 200, 500],
// cellMinWidth: 100,
height: 'full-148',
// size: 'sm',
skin: 'line',
cols: [[
{type: 'checkbox'}
,{field: 'id', align: 'center',title: 'ID'}
// ,{field: 'hostId$', align: 'center',title: '所属商户'}
,{field: 'userId$', align: 'left',title: '业务员',hide: false, width: 100, sort:true}
,{field: 'planType$', align: 'left',title: '业务类型', width: 150,hide: false, sort:true}
,{
field: 'name',
align: 'left',
title: '售前规划申请单名称',
width: 220,
style: 'color: #1890ff;cursor:pointer',
event: 'more',
hide: false,
sort:true
}
,{field: 'uuid', align: 'left',title: '规划单号', width: 100,hide: false, sort:true}
,{
field: 'planNeed$',
align: 'left',
title: '所需',
templet:function(d){
return emptyShow(d.planNeed$)
},
hide: false
}
,{field: 'deptId$', align: 'left',title: '所属部门',hide: true}
,{field: 'planner$', align: 'left',title: '规划员',hide: false, width: 100, sort:true}
// ,{field: 'nowHeadman$', align: 'left',title: '规划组长',hide: true}
,{
field: 'orderId$',
align: 'left',
title: '跟踪项目',
width: 220,
style: 'color: #1890ff;cursor:pointer',
event: 'orderMore',
hide: false,
sort:true
}
// ,{
// field: 'cstmrId$',
// align: 'left',
// title: '甲方单位',
// width: 220,
// style: 'color: #1890ff;cursor:pointer',
// event: 'cstmrMore',
// hide: true
// }
,{field: 'appleTime$', align: 'left',title: '申请日期', hide: false, sort:true}
// ,{field: 'beItem$', align: 'center',title: '立项'}
// ,{field: 'planner', align: 'left',title: '规划员', templet:function(d){return emptyShow(d.planner)}}
// ,{field: 'finishTime$', align: 'center',title: '完成时间'}
// ,{field: 'form', align: 'center',title: '表单内容'}
// ,{field: 'change$', align: 'center',title: '更改方案'}
// ,{field: 'changeTime', align: 'center',title: '更改次数'}
// ,{field: 'changeReason', align: 'center',title: '更改方案原因'}
// ,{field: 'planBonus', align: 'center',title: '规格奖金'}
// ,{field: 'planLeaderBonus', align: 'center',title: '规格组长奖金'}
// ,{field: 'files', align: 'center',title: '附件'}
,{field: 'settle$', align: 'center',title: '进度', width: 150, sort:true}
// ,{field: 'settleMsg', align: 'center',title: '审核进度'}
// ,{field: 'comment', align: 'center',title: '评论'}
,{field: 'statusAll$', align: 'center',title: '状态', sort:true, sort:true}
,{field: 'createTime$', align: 'left',title: '添加日期', width: 160, hide: true, sort:true}
,{field: 'updateBy$', align: 'left',title: '修改人', width: 100, sort:true}
,{field: 'updateTime$', align: 'left',title: '修改时间', hide: true, sort:true}
,{field: 'memo', align: 'left',title: '注释', hide: true, sort:true}
,{field: 'center', align: 'left',title: '关联流程', toolbar: '#tbLook', minWidth: 160, hide: false}
,{field: 'assistantHostSign$', align: 'left',title: '主副标记', hide: false}
,{field: 'assistantHostSign', align: 'left',title: '主副标记', hide: true}
,{field: 'hostPlanId', align: 'left',title: '主ID', hide: true}
,{field: 'assistantPlanId', align: 'left',title: '副ID', hide: true}
// ,{field: 'assistantPlanIdSignType', align: 'left',title: '集成货架标志', hide: true}
,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 340}
]],
request: {
pageName: 'curr',
pageSize: 'limit'
},
parseData: function (res) {
return {
'code': res.code,
'msg': res.msg,
'count': res.data.total,
'data': res.data.records
}
},
response: {
statusCode: 200
},
done: function(res, curr, count) {
if (res.code === 403) {
top.location.href = baseUrl+"/";
}
pageCurr=curr;pageCount=count;
limit();
}
});
$("#data-btn-file2").on("click", (e) => {
$("#data-btn-upload").click()
});
var _uploadFile = null
//响应上传
$("#data-btn-upload").on("change",(evt) => {
var files = evt.target.files;
if(files==null || files.length==0){
alert("No files wait for import");
return;
}
var file = files[0]
var tr = $([''
,'' + file.name +' '
,''+ (file.size/1014).toFixed(1) +'kb '
,' '
,''
,'重传 '
,'删除 '
,'下载 '
,' '
,' '].join(''));
//删除
tr.find('.demo-delete').on('click', function(){
tr.remove();
$("#data-btn-upload").val("")
_uploadFile = null
});
$('#data-btn-file3').append(tr)
element.progress('progress-demo-'+ file.lastModified, '0%'); //执行进度条。
element.init();
_uploadFile = file
})
//开始上传
$("#testListAction").on("click", async (e) => {
if (_uploadFile == null) {
return false;
}
var index = layer.load(1, {
shadeClose: false,
title: '上传中..',
shade: [0.5,'#000']
});
var file = _uploadFile
putObject(file,(p) => {
element.progress('progress-demo-'+ file.lastModified, (Math.round(p * 100)) + "%"); //执行进度条。
}).then((result) => {
var filename = result.name
layer.msg('上传成功', {icon: 1});
$("#upload-file-id-" + file.lastModified).html("上传成功")
$("#upload-filename-id-" + file.lastModified).html(filename)
$.ajax({
url: baseUrl+"/plan/insert/file/auth",
headers: {'token': localStorage.getItem('token')},
data: {
'planId': $('.layui-layer-title').text(),
'filename': filename,
'filesize': file.size
},
method: 'POST',
success: function (res) {
if (res.code === 200){
layer.close(index)
console.log(res)
} else if (res.code === 403){
top.location.href = baseUrl+"/";
} else {
layer.msg(res.msg)
}
}
});
}).catch((e) => {
console.log(e)
layer.msg('上传失败', {icon: 2});
$("#upload-file-id-" + file.lastModified).html("上传失败")
})
//清空file
$("#data-btn-upload").val("")
_uploadFile = null
});
// 添加
$("#planAddBtn").click(function () {
let loadIndex = layer.load(2);
$.ajax({
url: baseUrl+"/planType/list/radio/auth",
headers: {'token': localStorage.getItem('token')},
method: 'POST',
success: function (res) {
if (res.code === 200){
admin.open({
type: 1,
area: '300px',
title: '新建售前规划申请单',
content: $('#addDialogPre').html(),
success: function (layero, dIndex) {
let template = Handlebars.compile($('#planTypeTpl').html());
$('#planTypeBox').html(template({list: res.data.map(function (d) {
return {
id: d.id,
name: d.name,
checked: d.checked
}
})})
);
element.init();form.render();
layer.close(loadIndex);
// 确认规划单类型
form.on('submit(planTypeSubmit)', function (data) {
layer.close(dIndex);
let planTypeId = data.field.planType;
let loadIndex0 = layer.load(2);
$.ajax({
url: baseUrl + "/planType/" + planTypeId + "/plan/auth",
headers: {'token': localStorage.getItem('token')},
method: 'GET',
success: function (res0) {
let planType = res0.data.planType;
console.log(planType.html)
if (res0.code === 200) {
admin.open({
type: 1,
area: ["95%", "90%"],
offset: 'auto',
title: '添加售前规划申请单' + ' - ' + planType.name,
content: $('#editDialog').html(),
success: function (layero0, dIndex0) {
$('#customizeBox').html(planType.html)
layer.close(loadIndex0);
let orderSel = loadOrderSel();
let cstmrSel = loadCstmrSel();
let userSel = loadUserSel();
userSel.setValue([
{name: res0.data.nickName, value: Number(res0.data.userId)},
])
let planNeedSel = loadPlanNeedSel();
form.val('detail', {
planTypeName: planType.name,
userXmlSelPhone: res0.data.mobile
});
layDateRender();
form.on('submit(editSubmit)', function (data) {
console.log(data)
data.field.planType = planType.id;
data.field.orderId = orderSel.getValue()[0] ? orderSel.getValue()[0].value : null;
data.field.cstmrId = cstmrSel.getValue()[0] ? cstmrSel.getValue()[0].value : null;
data.field.userId = userSel.getValue()[0] ? userSel.getValue()[0].value : null;
// data.field.planNeed = planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
var planNeedValue= planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
for (var i=1;i'
+ '' + (file.size / 1024).toFixed(1) + 'kb '
// + ' '
+ ''+'已完成'+' '
+ ''
+ '重传 '
// + '删除 '
+ '下载 '
+ ' ';
// 将tr元素添加到目标table中
targetTable.appendChild(tr);
});
}else {
console.log('Failed to get file list error.');
}
},
error: function() {
console.log('Failed to get file list.');
}
});
break;
case "look":
var $a = $(obj.tr).find('a[lay-event="look"]');
var offset = $a.offset();
var top2 = offset.top;
var left = offset.left;
layer.open({
type: 1,
title: false,
area: '2100px',
offset: [top2 + 'px', (left - 1430 + $a.outerWidth()) + 'px'],
shade: .01,
shadeClose: true,
fixed: false,
content: '',
success: function (layero) {
table.render({
elem: '#lookSSXMTable',
headers: {token: localStorage.getItem('token')},
url: baseUrl+'/plan/assistantPlan/view/auth',
where: {
hostPlanId: data.id
},
page: true,
cellMinWidth: 100,
cols: [[
{field: 'id', align: 'center',title: 'ID'}
,{field: 'userId$', align: 'left',title: '业务员',hide: false, width: 100}
,{field: 'planType$', align: 'left',title: '业务类型', width: 150,hide: false}
,{
field: 'name',
align: 'left',
title: '售前规划申请单名称',
width: 220,
style: 'cursor:pointer',
event: 'more',
hide: false
}
,{field: 'uuid', align: 'left',title: '规划单号', width: 100,hide: false}
,{
field: 'planNeed$',
align: 'left',
title: '所需',
templet:function(d){
return emptyShow(d.planNeed$)
},
hide: false
}
,{field: 'deptId$', align: 'left',title: '所属部门',hide: true}
,{field: 'planner$', align: 'left',title: '规划员',hide: false, width: 100}
,{
field: 'orderId$',
align: 'left',
title: '跟踪项目',
width: 220,
style: 'cursor:pointer',
event: 'orderMore',hide: false
}
,{field: 'appleTime$', align: 'left',title: '申请日期', hide: false}
,{field: 'settle$', align: 'center',title: '进度', width: 150}
,{field: 'statusAll$', align: 'center',title: '状态'}
,{field: 'createTime$', align: 'left',title: '添加日期', width: 160, hide: true}
,{field: 'updateBy$', align: 'left',title: '修改人', width: 100}
,{field: 'updateTime$', align: 'left',title: '修改时间', hide: true}
,{field: 'memo', align: 'left',title: '注释', hide: true}
,{field: 'assistantHostSign', align: 'left',title: '主副标记', hide: true}
,{field: 'hostPlanId', align: 'left',title: '主ID', hide: true}
,{field: 'assistantPlanId', align: 'left',title: '副ID', hide: true}
,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 340}
]],
request: {
pageName: 'curr',
pageSize: 'limit'
},
parseData: function (res) {
console.log(res)
return {
'code': res.code,
'msg': res.msg,
'count': res.data.total,
'data': res.data.records
}
},
response: {
statusCode: 200
},
done: function () {
$(layero).find('.layui-table-view').css('margin', '0');
},
size: ''
});
}
});
break;
}
});
// 点击下载按钮时触发文件下载
$('#data-btn-file3').on('click', 'a', function() {
var downloadUrl = $(this).attr('href');
let url = getObjectUrl(downloadUrl)
layer.msg("准备下载中", {icon: 1});
// location.href = url
window.open(url)
return false; // 阻止默认的链接跳转行为
});
function approval(planId, plannerId, dIdx) {
let loadIndex = layer.load(2);
$.ajax({
url: baseUrl+"/plan/approval/auth",
headers: {'token': localStorage.getItem('token')},
data: {
planId: planId,
plannerId: plannerId
},
method: 'POST',
success: function (res) {
if (dIdx) {
layer.close(dIdx);
}
layer.close(loadIndex);
if (res.code === 200){
layer.msg(res.msg, {icon: 1});
tableReload();
} else if (res.code === 403){
top.location.href = baseUrl+"/";
} else {
layer.msg(res.msg, {icon: 2});
}
}
})
}
function approvalEnd(planId, plannerId, dIdx) {
let loadIndex = layer.load(2);
$.ajax({
url: baseUrl+"/plan/approvalEnd/auth",
headers: {'token': localStorage.getItem('token')},
data: {
planId: planId,
plannerId: plannerId
},
method: 'POST',
success: function (res) {
if (dIdx) {
layer.close(dIdx);
}
layer.close(loadIndex);
if (res.code === 200){
layer.msg(res.msg, {icon: 1});
tableReload();
} else if (res.code === 403){
top.location.href = baseUrl+"/";
} else {
layer.msg(res.msg, {icon: 2});
}
}
})
}
/* 弹窗 - 新增、修改 */
function showEditModel(mData) {
let loadIndex = layer.load(2);
$.ajax({
url: baseUrl + "/plan/" + mData.id + "/auth",
headers: {'token': localStorage.getItem('token')},
method: 'GET',
success: function (res) {
layer.close(loadIndex);
if (res.code === 200){
let plan = res.data;
admin.open({
type: 1,
area: ["95%", "90%"],
offset: 'auto',
title: '编辑售前规划申请单 - ' + plan.planType$,
content: $('#editDialog').html(),
success: function (layero, dIndex) {
$('#customizeBox').html(plan.formHtml);
let orderSel = loadOrderSel();
let cstmrSel = loadCstmrSel();
let userSel = loadUserSel();
let planNeedSel = loadPlanNeedSel();
if (plan.orderId) { orderSel.setValue([{name: plan.orderId$, value: plan.orderId}]); }
if (plan.cstmrId) { cstmrSel.setValue([{name: plan.cstmrId$, value: plan.cstmrId}]); }
if (plan.userId) { userSel.setValue([{name: plan.userId$, value: plan.userId}]); }
let split = plan.planNeed.split("-");
if (plan.planNeed) {
var data = []
split.forEach((item,idx) => {
data.push(parseInt(item))
})
planNeedXmlSelData = data
}
layDateRender(plan);
plan['planTypeName'] = plan.planType$;
form.val('detail', plan);
form.on('submit(editSubmit)', function (data) {
data.field.orderId = orderSel.getValue()[0] ? orderSel.getValue()[0].value : null;
data.field.cstmrId = cstmrSel.getValue()[0] ? cstmrSel.getValue()[0].value : null;
data.field.userId = userSel.getValue()[0] ? userSel.getValue()[0].value : null;
// data.field.planNeed = planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
var planNeedValue= planNeedSel.getValue()[0] ? planNeedSel.getValue()[0].value : null;
for (var i=1;i 0) {
let orderId = data.change[0].value;
$.ajax({
url: baseUrl + "/order/" + orderId + "/auth",
headers: {'token': localStorage.getItem('token')},
data: {},
method: 'GET',
success: function (res) {
if (res.code === 200) {
let cstmrSel = loadCstmrSel();
cstmrSel.setValue([{name: res.data.cstmrId$, value: res.data.cstmrId}]);
} else {
layer.msg(res.msg, {icon: 2});
}
}
});
}
}
});
}
window.loadCstmrSel = function () {
return xmSelect.render({
el: '#cstmrXmlSel',
autoRow: true,
filterable: true,
remoteSearch: true,
clickClose: true,
radio: true,
remoteMethod: function (val, cb, show) {
$.ajax({
url: baseUrl + "/cstmr/all/get/kv",
headers: {'token': localStorage.getItem('token')},
data: {
condition: val
},
method: 'POST',
success: function (res) {
if (res.code === 200) {
// cb(res.data)
cb([]);
} else {
cb([]);
layer.msg(res.msg, {icon: 2});
}
}
});
}
});
}
window.loadPlanNeedSel = function () {
var planNeedXmlSel = xmSelect.render({
el: '#planNeedXmlSel',
autoRow: true,
data: []
});
$.ajax({
url: baseUrl + "/planNeed/all/get/kv",
headers: {'token': localStorage.getItem('token')},
data: {
condition: ""
},
method: 'POST',
success: function (res) {
if (res.code === 200) {
planNeedXmlSel.update({
initValue: planNeedXmlSelData,
data: res.data
})
} else {
cb([]);
layer.msg(res.msg, {icon: 2});
}
}
});
return planNeedXmlSel;
}
window.loadUserSel = function () {
return xmSelect.render({
el: '#userXmlSel',
autoRow: true,
filterable: true,
remoteSearch: true,
clickClose: true,
radio: true,
remoteMethod: function (val, cb, show) {
$.ajax({
url: baseUrl + "/user/all/get/kv",
headers: {'token': localStorage.getItem('token')},
data: {
condition: val
},
method: 'POST',
success: function (res) {
if (res.code === 200) {
cb(res.data)
} else {
cb([]);
layer.msg(res.msg, {icon: 2});
}
}
});
}
});
}
});
// 点击事件
$(document).on('click','#data-detail-close', function () {
parent.layer.closeAll();
});
function tableReload() {
if (pageCount === 0) {
let searchData = {};
$.each($('#search-box [name]').serializeArray(), function() {
searchData[this.name] = this.value;
});
if (treeCond) {
searchData[treeCond.key] = treeCond.val;
}
tableIns.reload({
where: searchData,
page: {curr: pageCurr}
});
} else {
$(".layui-laypage-btn")[0].click();
}
}
function upload(obj){
if(!obj.files) {
return;
}
var file = obj.files[0];
admin.confirm('确认同步 [' + file.name +'] 文件吗?', function (index) {
layer.load(1, {shade: [0.1,'#fff']});
var url = baseUrl + "/plan/excel/import/auth";
var form = new FormData();
form.append("file", file);
let xhr = new XMLHttpRequest();
xhr.open("post", url, true);
xhr.setRequestHeader('token', localStorage.getItem('token'));
xhr.onload = uploadComplete;
xhr.onerror = uploadFailed;
xhr.onloadend = function () {
layer.closeAll('loading');
};
// xhr.upload.onprogress = progressFunction;
xhr.upload.onloadstart = function(){
ot = new Date().getTime();
oloaded = 0;
};
xhr.send(form);
}, function(index){
});
}
function uploadComplete(evt) {
let res = JSON.parse(evt.target.responseText);
if(res.code === 200) {
layer.msg(res.msg, {icon: 1});
tableReload();
} else {
alert(res.msg);
// layer.msg(res.msg, {icon: 2});
}
}
function uploadFailed(evt) {
let res = JSON.parse(evt.target.responseText);
alert(res.msg);
// layer.msg(res.msg, {icon: 2});
}