This commit is contained in:
BianLzhaoMin 2025-02-26 17:56:40 +08:00
parent a17ee9951b
commit d901dd313c
1 changed files with 135 additions and 128 deletions

View File

@ -223,43 +223,39 @@
// $(this).append(fileDom); // $(this).append(fileDom);
} }
}); if (index === cols.length - 1) {
// let lastRow = tableView.find('tr').last(); // 找到最后一行
// let lastCell = lastRow.find('td').last(); // 找到最后一个单元格
// let div = lastCell.find('div')
let div = $(this).find('div')
}); // 创建自定义 DOM 元素
var columsName = ['subName'];//需要合并的列名称 ['business_tenant_name','land','contract_begin','contract_end','history_arrears','period']; let customElement = $('<button>', {
var columsIndex = [1];//需要合并的列索引值 [2,3,5,6,14,15]; class: 'layui-btn layui-btn-sm',
merge(res, columsName, columsIndex); id: 'evaluate-btn',
text: '评价',
type: 'button'
});
let fileList = []
let uploadDom = []
let lastRow = tableView.find('tr').last(); // 找到最后一行 // 将自定义元素插入到最后一个单元格
let lastCell = lastRow.find('td').last(); // 找到最后一个单元格 div.append(customElement);
let div = lastCell.find('div')
// 创建自定义 DOM 元素 customElement.on('click', function (event) {
let customElement = $('<button>', { event.stopPropagation()
class: 'layui-btn layui-btn-sm', event.preventDefault()
id: 'evaluate-btn', let rowIndex = $(this).closest('tr').data('index')
text: '评价', const tableList = JSON.parse(msg)
type: 'button'
});
let fileList = []
let uploadDom = []
// 将自定义元素插入到最后一个单元格
div.append(customElement);
customElement.on('click', function (event) {
event.stopPropagation()
event.preventDefault()
let rowIndex = $(this).closest('tr').data('index')
const tableList = JSON.parse(msg)
// 组装dom // 组装dom
let formHtml = `<div class="dialog-title">${tableList[rowIndex].proName}</div>` let formHtml = `<div class="dialog-title">${tableList[rowIndex].proName}</div>`
let innerHtml = '' let innerHtml = ''
dialogLabelList.forEach((e, index) => { dialogLabelList.forEach((e, index) => {
fileList.push('') fileList.push('')
uploadDom.push('#uploadBtn' + index) uploadDom.push('#uploadBtn' + index)
innerHtml += `<div style="padding:6px 0;display: flex; align-items: center;"> innerHtml += `<div style="padding:6px 0;display: flex; align-items: center;">
<div style="margin-right: 10px;width: 200px";>${e.title}</div> <div style="margin-right: 10px;width: 200px";>${e.title}</div>
<input type="text" data-id="${dialogLabelInfo[index].field}" id="numberInput" name="numberInput" min="0.01" step="0.01" placeholder="请输入大于0的数字" style=";width:180px; padding:1px 5px;" value="${tableList[rowIndex][dialogLabelInfo[index].field]}"> <input type="text" data-id="${dialogLabelInfo[index].field}" id="numberInput" name="numberInput" min="0.01" step="0.01" placeholder="请输入大于0的数字" style=";width:180px; padding:1px 5px;" value="${tableList[rowIndex][dialogLabelInfo[index].field]}">
<button type="button" data-index="${index}" id="uploadBtn${index}" style="color: #4CAF50; border: none; margin-left: 10px; cursor: pointer;"> <button type="button" data-index="${index}" id="uploadBtn${index}" style="color: #4CAF50; border: none; margin-left: 10px; cursor: pointer;">
@ -268,115 +264,126 @@
<div class="upload-success" id="upload-success_${index}" style="display:none"><i data-index="${index}" class="layui-icon" style="font-size: 18px; color: red; cursor: pointer;">&#xe640;</i> </div> <div class="upload-success" id="upload-success_${index}" style="display:none"><i data-index="${index}" class="layui-icon" style="font-size: 18px; color: red; cursor: pointer;">&#xe640;</i> </div>
</div>` </div>`
}) })
formHtml += ` formHtml += `
<div style="padding: 12px;"> <div style="padding: 12px;">
<form id="uploadForm"> <form id="uploadForm">
${innerHtml} ${innerHtml}
</form> </form>
</div>` </div>`
layer.open({ layer.open({
type: 1, type: 1,
area: ['auto', 'auto'], // 宽高 area: ['auto', 'auto'], // 宽高
content: formHtml, content: formHtml,
title: '评分', title: '评分',
btn: ['确定', '取消'], btn: ['确定', '取消'],
success: function (layero, index) { success: function (layero, index) {
// 点击上传按钮的逻辑 // 点击上传按钮的逻辑
layui.use('upload', function () { layui.use('upload', function () {
var upload = layui.upload; var upload = layui.upload;
// 执行上传功能 // 执行上传功能
var uploadInst = upload.render({ var uploadInst = upload.render({
elem: uploadDom.join(','), elem: uploadDom.join(','),
url: ctxPath + '/upload/file', url: ctxPath + '/upload/file',
accept: 'file', accept: 'file',
multiple: false, multiple: false,
done: function (res) { done: function (res) {
// 上传完毕回调 // 上传完毕回调
console.log('文件上传成功'); console.log('文件上传成功');
console.log(res); console.log(res);
var dataIndex = $(this.elem).data('index'); var dataIndex = $(this.elem).data('index');
fileList[dataIndex] = res.obj fileList[dataIndex] = res.obj
// 隐藏当前上传按钮
$(`#uploadBtn${dataIndex}`).hide()
$(`#upload-success_${dataIndex}`).show()
$(`#upload-success_${dataIndex}`).prepend(`<span class="prepend-content">${res.message}</span>`)
// 插入新的 DOM 元素,
// var newDom = $(`<div class="upload-success">${res.message}<i data-index="${dataIndex}" class="layui-icon" style="font-size: 18px; color: red; cursor: pointer;">&#xe640;</i> </div>`);
// $(this.elem).parent().append(newDom);
},
error: function () {
// 请求异常回调
console.log('文件上传失败');
}
})
})
// $('.uploadBtn').on('click', function (event) {
// event.stopPropagation(); // 阻止事件冒泡
// event.preventDefault(); // 阻止默认行为
// console.log('上传附件按钮被点击了');
// });
// 隐藏当前上传按钮
$(`#uploadBtn${dataIndex}`).hide()
$(`#upload-success_${dataIndex}`).show()
$(`#upload-success_${dataIndex}`).prepend(`<span class="prepend-content">${res.message}</span>`)
// 插入新的 DOM 元素,
// var newDom = $(`<div class="upload-success">${res.message}<i data-index="${dataIndex}" class="layui-icon" style="font-size: 18px; color: red; cursor: pointer;">&#xe640;</i> </div>`);
// $(this.elem).parent().append(newDom);
}, },
error: function () { yes: function (index) {
// 请求异常回调 // 点击"确定"按钮时的逻辑
console.log('文件上传失败');
let formData = {};
let fields = dialogLabelInfo.map((e) => e.field)
$('#uploadForm input').each(function () {
let inputValue = $(this).val();
if (parseFloat(inputValue) < 0) {
layer.msg('请输入大于0的数字')
return false
}
let dataId = $(this).data('id') // 获取 data-id
if (dataId && inputValue) {
formData[dataId] = inputValue * 1 // 将 data-id 作为键,输入框的值作为值
}
})
const currentRows = tableList[rowIndex]
Object.assign(currentRows, formData)
currentRows.fileList = fileList
let dataForm = {
templateId: getUrlParam('templateId'),
evaluateId: getUrlParam('id'),
id: getUrlParam('detailsId'),
jsonData: JSON.stringify([currentRows]),
titleFiled: fields.join(','),
}
console.log('提交时的formDat参数', dataForm)
let path = getUrlParam("type") == '0' ? '/outsourcer/saveEvaluateData' : '/outsourcer/updateEvaluateData';
$.ajax({
url: ctxPath + path,
type: 'post',
data: dataForm,
success: function (res) {
if (res.res == '1') {
layer.msg('保存成功');
layer.close(index); // 关闭弹框
initTable()
} else {
layer.msg(res.resMsg);
}
}
})
// 这里可以执行你需要的操作
},
btn2: function (index) {
layer.close(index) // 关闭弹框
return false
} }
}) })
}) });
// $('.uploadBtn').on('click', function (event) {
// event.stopPropagation(); // 阻止事件冒泡
// event.preventDefault(); // 阻止默认行为
// console.log('上传附件按钮被点击了');
// });
},
yes: function (index) {
// 点击"确定"按钮时的逻辑
let formData = {};
let fields = dialogLabelInfo.map((e) => e.field)
$('#uploadForm input').each(function () {
let inputValue = $(this).val();
if (parseFloat(inputValue) < 0) {
layer.msg('请输入大于0的数字')
return false
}
let dataId = $(this).data('id') // 获取 data-id
if (dataId && inputValue) {
formData[dataId] = inputValue * 1 // 将 data-id 作为键,输入框的值作为值
}
})
const currentRows = tableList[rowIndex]
Object.assign(currentRows, formData)
currentRows.fileList = fileList
let dataForm = {
templateId: getUrlParam('templateId'),
evaluateId: getUrlParam('id'),
id: getUrlParam('detailsId'),
jsonData: JSON.stringify([currentRows]),
titleFiled: fields.join(','),
}
console.log('提交时的formDat参数', dataForm)
let path = getUrlParam("type") == '0' ? '/outsourcer/saveEvaluateData' : '/outsourcer/updateEvaluateData';
$.ajax({
url: ctxPath + path,
type: 'post',
data: dataForm,
success: function (res) {
if (res.res == '1') {
layer.msg('保存成功');
layer.close(index); // 关闭弹框
initTable()
} else {
layer.msg(res.resMsg);
}
}
})
// 这里可以执行你需要的操作
},
btn2: function (index) {
layer.close(index) // 关闭弹框
return false
} }
})
});
}); });
var columsName = ['subName'];//需要合并的列名称 ['business_tenant_name','land','contract_begin','contract_end','history_arrears','period'];
var columsIndex = [1];//需要合并的列索引值 [2,3,5,6,14,15];
merge(res, columsName, columsIndex);
$(document).on('click', '.upload-success i', function () { $(document).on('click', '.upload-success i', function () {
var dataIndex = $(this).data('index'); var dataIndex = $(this).data('index');