gz_safety_ui/js/aq_settlement/child/payment_form.js

390 lines
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let idParam, objParam, fileList = new Array(), imgListUp = new Array();
let form, laydate, layer, upload, table, util;
let pageNum = 1, tableIns; // 定义分页
let jjDataArr = []; // 清单数据
let delIdArr = [];
let outId = ''; // 出库ID
function setParams(obj) {
objParam = JSON.parse(obj);
$('#supName').val(objParam.supName);
layui.use(['form', 'layer', 'laydate', 'upload', 'table'], function () {
form = layui.form;
layer = layui.layer;
laydate = layui.laydate;
upload = layui.upload;
table = layui.table;
util = layui.util;
laydate.render({
elem: '#fkTime'
});
form.verify();
form.on('submit(formData)', function (data) {
submitApply(data);
});
form.render();
let uploadObj = upload.render({
elem: '#test2',
multiple: true,
dataType: "json",
exts: 'jpg|png|jpeg|doc|docx|pdf|xlsx|xls',
acceptMime: 'image/jpg,image/png,image/jpeg,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
number: 5, //最大上传数量
size: 1024 * 10, //最大文件大小单位k
auto: false, //是否自动上传 默认为true
bindAction: '#hideUpload', //绑定的按钮
choose: function (obj) {
let length = $('.file-iteme').length;
if (length >= 5) {
return layer.msg('最多上传5个附件证明', { icon: 7 });
}
uploadObj.config.elem.next()[0].value = '';
let num = 0;
obj.preview(function (index, file, result) {
num ++;
if(num <= (5-length)){
$('#uploader-list').append(
'<div id="" class="file-iteme">' +
'<div class="handle"><p>x</p></div>' +
handleFileType(index, file, result) +
'</div>'
);
let map = new Map();//将选择的图片索引和图片写成对象存入集合
map.index = index;
map.file = file;
fileList.push(map);
}
});
}
});
});
}
// 设置文件类型
function handleFileType(index, file, result) {
let html = '', img = '';
if(file.ext){
file.ext = file.ext.toLowerCase();
}
if(file.name){
file.name = file.name.toLowerCase();
}
if (file.ext === 'doc' || file.ext === 'docx') {
img = '../../../images/docx.png';
} else if (file.ext === 'xls' || file.ext === 'xlsx') {
img = '../../../images/xlsx.png';
} else if (file.ext === 'pdf') {
img = '../../../images/pdf.png';
} else {
return '<img class="img" style="width: 130px;height: 120px;" data-index=' + index + ' data-name=' + file.name + ' src=' + result + '>';
}
html += '<div class="layout upload-file" data-index=' + index + '>' +
'<img src="' + img + '">' +
'<p style="text-align: center;font-size:12px;">' + file.name + '</p>' +
'</div>';
return html;
}
// 删除文件
$(document).on("click", ".file-iteme .handle", function (event) {
imgListUp.splice(0, imgListUp.length);
let index = $(this).next().attr('data-index');
$.each(fileList, function (inx, ele) {
//对比删除文件索引
//将未删除的存入新集合
if (index != ele.index) {
imgListUp.push(ele);
}
});
$(this).parent().remove();
//将新文件集合替换老集合
fileList.splice(0, fileList.length);
$.each(imgListUp, function (inx, ele) {
fileList.push(ele)
});
});
function saveData2() {
$('#formSubmit').trigger('click')
}
// 提交
function submitApply(data) {
// 校验附件证明是否上传
if (fileList.length === 0) {
return layer.msg('请上传附件证明', { icon: 7 });
}
data.field.supId = objParam.supId;
data.field.contractId = objParam.contractId;
let list = [];
$.each(jjDataArr, function (index, item) {
let obj = { planId: item.planId, outId: item.outId };
list.push(obj);
})
data.field.details = list;
let formData = new FormData();
//遍历最终文件集合
for (let i = 0; i < fileList.length; i++) {
formData.append("file[]", fileList[i].file)
}
formData.append('params', JSON.stringify(data.field));
console.log(data.field);
let loadingMsg = layer.msg('正在提交保存,请稍等...', { icon: 16, shade: 0.01, time: '0' });
let url = dataUrl + 'backstage/supApply/addApplyInfoData';
ajaxRequestByUploadFile(url, formData, function () {
$('.save').addClass("layui-btn-disabled").attr("disabled", true);
$('.cancel').addClass("layui-btn-disabled").attr("disabled", true);
}, function (result) {
layer.close(loadingMsg);
$('.save').removeClass("layui-btn-disabled").attr("disabled", false);
$('.cancel').removeClass("layui-btn-disabled").attr("disabled", false);
if (result.code === 200) {
parent.layer.msg(result.msg, { icon: 1 });
closePage(1);
} else {
layer.msg(result.msg, { icon: 2 });
}
}, function (xhr, status, error) {
layer.close(loadingMsg); // 关闭提示层
layer.msg('服务异常,请稍后重试', { icon: 16, scrollbar: false, time: 2000 });
$('.save').removeClass("layui-btn-disabled").attr("disabled", false);
$('.cancel').removeClass("layui-btn-disabled").attr("disabled", false);
errorFn(xhr, status, error)
}, null);
}
// 选择需求计划单据
function chooseFitType() {
let params = { contractId: objParam.contractId, supId: objParam.supId, outId: outId, jjDataArr: JSON.stringify(jjDataArr) };
openIframeByParamObj("choose_plan_code_list", '选择需要付款的需求计划编号', "./choose_plan_code_list.html", '92%', '95%', params);
}
// 需求计划单据赋值
function addFitDatas(data, outIdArr) {
jjDataArr = JSON.parse(data);
let money = 0;
$.each(jjDataArr, function (index, item) {
money += parseInt(item.money ? item.money : 0);
})
$('#money').val(money);
if (!outId) {
$('#chooseValue').val('选择数据(已选择 ' + outIdArr.length + ' 条)');
$('#no_data_title').css({ 'display': 'none' });
$('#search-info').removeAttr('style');
$('#table-box').removeAttr('style');
outId = outIdArr.join('@');
initTable();
} else {
$('#chooseValue').val('选择数据(已选择 ' + outIdArr.length + ' 条)');
outId = outIdArr.join('@');
reloadTable(1);
}
}
// 查询/重置
function queryTable(type) {
if (type === 1) {
let name = $('#name').val();
let flag = checkValue(name);
if (flag) {
$('#name').val('');
return layer.msg('名称查询包含特殊字符,请重新输入', { icon: 2 });
}
let model = $('#model').val();
let flag2 = checkValue(model);
if (flag2) {
$('#model').val('');
return layer.msg('规格查询包含特殊字符,请重新输入', { icon: 2 });
}
reloadTable(1);
} else if (type === 2) {
$('#name').val('');
$('#model').val('');
layui.form.render();
reloadTable(1);
}
}
// 重载表格
function reloadTable(pageNum) {
table.reload("currentTableId", {
page: {
curr: pageNum ? pageNum : 1,
},
where: {
encryptedData: JSON.stringify({
'name': $('#name').val(),
'model': $('#model').val(),
'contractId': objParam.contractId,
'supId': objParam.supId,
'outId': outId
}),
},
},
);
}
// 初始化表格
function initTable() {
tableIns = table.render({
elem: "#currentTableId",
id: 'currentTableId',
headers: {
authorization: sessionStorage.getItem("gz-token"),
},
url: dataUrl + "backstage/supApply/getPlanApplyDetailsList",
where: {
encryptedData: JSON.stringify({
'name': $('#name').val(),
'model': $('#model').val(),
'contractId': objParam.contractId,
'supId': objParam.supId,
'outId': outId
}),
},
request: {
pageName: 'pageNum',
limitName: 'pageSize'
},
parseData: function (res) { // res 即为原始返回的数据
if (res.code === 401) {
closeWindowOpen();
}
return {
"code": 0, // 解析接口状态
"msg": '获取成功', // 解析提示文本
"count": res.total, // 解析数据长度
"data": res.list // 解析数据列表
};
},
cols: [
[
{
width: '5.9%',
title: "序号",
align: "center",
templet: function (d) {
return d.LAY_NUM;
},
},
{
field: "name",
width: '8%',
title: "名称",
unresize: true,
align: "center",
sort:true,
},
{
field: "model",
width: '10%',
title: "规格",
unresize: true,
align: "center",
sort:true,
},
{
field: "unit",
width: '8%',
title: "单位",
unresize: true,
align: "center",
sort:true,
},
{
field: "price",
width: '10%',
title: "单价(元)",
unresize: true,
align: "center",
sort:true,
},
{
field: "cgNum",
width: '8%',
title: "采购量",
unresize: true,
align: "center",
sort:true,
},
{
field: "ccDay",
width: '10%',
title: "出厂日期",
unresize: true,
align: "center",
sort:true,
},
{
field: "jyDay",
width: '10%',
title: "检验日期",
unresize: true,
align: "center",
sort:true,
},
{
field: "remark",
width: '10%',
title: "备注",
unresize: true,
align: "center",
templet: function (d) {
if (d.remark) {
if (d.remark.length > 60) {
return '<span title="' + d.remark + '">' + d.remark.substring(0, 60) + '...</span>'
} else {
return '<span title="' + d.remark + '">' + d.remark + '</span>'
}
} else {
return '';
}
},
},
{
field: "code",
width: '10%',
title: "需求计划编号",
unresize: true,
align: "center",
templet: function (d) {
let html = "";
html += "<a onclick='openPlanDetail(" + JSON.stringify(d) + ")'>" + d.code + "</a>";
return html;
},
},
{
field: "proName",
width: '10%',
title: "工程名称",
unresize: true,
align: "center",
},
],
],
limits: [10, 15, 20, 25, 50, 100],
limit: 10,
page: true,
done: function (res, curr, count) {
pageNum = tableIns.config.page.curr;
table.resize("currentTableId");
},
});
}
// 需求计划详情
function openPlanDetail(obj) {
console.error(obj);
obj.id = obj.planId;
openIframeByParamObj2("planDetail", "安全工器具需求计划", "../aq_demand_plan/child/apply_plan_detail.html", "92%", "95%", obj);
}
// 关闭页面
function closePage(type) {
let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe层的索引
if (type == 1) {
window.parent.reloadData();
}
parent.layer.close(index); // 再执行关闭
}