|
|
@@ -333,8 +333,10 @@ $(document).ready(function() {
|
|
|
if ($('.bc-bar .nav li .active').attr('href') === '#htdetail') {
|
|
|
if (node.settle_code || (shenpi_status && node.status !== auditConst.status.uncheck && node.status !== auditConst.status.checkNo)) {
|
|
|
$('#edit_contract_btn').hide();
|
|
|
+ $('#ai_edit_contract_btn').hide();
|
|
|
} else {
|
|
|
$('#edit_contract_btn').show();
|
|
|
+ $('#ai_edit_contract_btn').show();
|
|
|
}
|
|
|
$('#save_contract_btn').hide();
|
|
|
$('#cancel_contract_btn').hide();
|
|
|
@@ -361,6 +363,7 @@ $(document).ready(function() {
|
|
|
}
|
|
|
} else if ($('.bc-bar .nav li .active').attr('href') === '#htpay') {
|
|
|
$('#edit_contract_btn').hide();
|
|
|
+ $('#ai_edit_contract_btn').hide();
|
|
|
$('#save_contract_btn').hide();
|
|
|
$('#cancel_contract_btn').hide();
|
|
|
$('#add_contract_pay_btn').hide();
|
|
|
@@ -389,6 +392,7 @@ $(document).ready(function() {
|
|
|
$('a[href*="#cons-upfile"]').hide();
|
|
|
} else if ($('.bc-bar .nav li .active').attr('href') === '#htfile') {
|
|
|
$('#edit_contract_btn').hide();
|
|
|
+ $('#ai_edit_contract_btn').hide();
|
|
|
$('#save_contract_btn').hide();
|
|
|
$('#cancel_contract_btn').hide();
|
|
|
$('#add_contract_pay_btn').hide();
|
|
|
@@ -396,6 +400,7 @@ $(document).ready(function() {
|
|
|
$('a[href*="#cons-upfile"]').show();
|
|
|
} else if ($('.bc-bar .nav li .active').attr('href') === '#htsupplement') {
|
|
|
$('#edit_contract_btn').hide();
|
|
|
+ $('#ai_edit_contract_btn').hide();
|
|
|
$('#save_contract_btn').hide();
|
|
|
$('#cancel_contract_btn').hide();
|
|
|
$('#add_contract_pay_btn').hide();
|
|
|
@@ -498,6 +503,7 @@ $(document).ready(function() {
|
|
|
contractTreeSpreadObj.changeContractTab(node, true);
|
|
|
} else {
|
|
|
$('#edit_contract_btn').hide();
|
|
|
+ $('#ai_edit_contract_btn').hide();
|
|
|
$('#save_contract_btn').hide();
|
|
|
$('#cancel_contract_btn').hide();
|
|
|
$('a[href*="#cons-upfile"]').hide();
|
|
|
@@ -524,6 +530,7 @@ $(document).ready(function() {
|
|
|
contractTreeSpreadObj.changeContractTab(node, true);
|
|
|
} else {
|
|
|
$('#edit_contract_btn').hide();
|
|
|
+ $('#ai_edit_contract_btn').hide();
|
|
|
$('#save_contract_btn').hide();
|
|
|
$('#cancel_contract_btn').hide();
|
|
|
$('a[href*="#cons-unlock"]').hide();
|
|
|
@@ -676,6 +683,7 @@ $(document).ready(function() {
|
|
|
contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
|
|
|
// contractTreeSpreadObj.setContractPays(result.pays, node);
|
|
|
contractTreeSpreadObj.setContractListHtml('pay', node, result.pays);
|
|
|
+ node.files = result.files;
|
|
|
contractTreeSpreadObj.setContractFiles(result.files, node.id);
|
|
|
// contractTreeSpreadObj.setContractSupplements(result.supplements, node.id);
|
|
|
contractTreeSpreadObj.setContractListHtml('supplement', node, result.supplements);
|
|
|
@@ -689,6 +697,7 @@ $(document).ready(function() {
|
|
|
$('#htfile-table').hide();
|
|
|
$('#htsupplement-table').hide();
|
|
|
$('#edit_contract_btn').hide();
|
|
|
+ $('#ai_edit_contract_btn').hide();
|
|
|
$('#save_contract_btn').hide();
|
|
|
$('#cancel_contract_btn').hide();
|
|
|
$('a[href*="#cons-unlock"]').hide();
|
|
|
@@ -1835,34 +1844,53 @@ $(document).ready(function() {
|
|
|
const node = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
console.log(node);
|
|
|
if (node && node.c_code && (node.uid === user_id || permission_edit_contract) && (!shenpi_status || (shenpi_status && node.status === auditConst.status.uncheck || node.status === auditConst.status.checkNo))) {
|
|
|
- $('#edit_contract_btn').hide();
|
|
|
- $('#save_contract_btn').show();
|
|
|
- $('#cancel_contract_btn').show();
|
|
|
- for (const c of contractDetail) {
|
|
|
- if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
|
|
|
- if (c === 'sign_date') {
|
|
|
- $('#htdetail_' + c).html('<input type="date" class="form-control form-control-sm" value="' + moment(node[c]).format('YYYY-MM-DD') + '">');
|
|
|
- continue;
|
|
|
- } else if (c === 'remark') {
|
|
|
- $('#htdetail_' + c).html('<textarea class="form-control form-control-sm" rows="3">' + node[c] + '</textarea>');
|
|
|
- continue;
|
|
|
- } else if (c === 'tax') {
|
|
|
- $('#htdetail_' + c).html('<input type="number" min="0" max="100" step="1" class="form-control form-control-sm" value="' + (node[c] ? node[c] : '') + '">');
|
|
|
- continue;
|
|
|
- }
|
|
|
- $('#htdetail_' + c).html('<input type="text" class="form-control form-control-sm" value="' + node[c] + '">');
|
|
|
- }
|
|
|
- }
|
|
|
- const attrInfo = node.attribute_json ? JSON.parse(node.attribute_json) : null;
|
|
|
- for (const attr of attributeSet) {
|
|
|
- if (attr.type === 'long_text') {
|
|
|
- $('#htdetail_' + attr.field).html('<textarea class="form-control form-control-sm" rows="3">' + (attrInfo && attrInfo[attr.field] ? attrInfo[attr.field] : '') + '</textarea>');
|
|
|
+ editContract(node);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#ai_edit_contract_btn').on('click', function () {
|
|
|
+ const node = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
+ console.log(node);
|
|
|
+ if (node && node.c_code && (node.uid === user_id || permission_edit_contract) && (!shenpi_status || (shenpi_status && node.status === auditConst.status.uncheck || node.status === auditConst.status.checkNo))) {
|
|
|
+ // files只要pdf,word和图片格式的
|
|
|
+ const files = _.filter(node.files, function (f) {
|
|
|
+ const ext = f.filename.toLowerCase().split('.').splice(-1)[0];
|
|
|
+ return ['pdf', 'doc', 'docx', 'jpg', 'jpeg', 'png', 'webp'].includes(ext);
|
|
|
+ });
|
|
|
+ openAiRecognizeModal({ mode: 'edit', cid: node.id, existingFiles: files });
|
|
|
+ editContract(node);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ function editContract(node) {
|
|
|
+ $('#edit_contract_btn').hide();
|
|
|
+ $('#ai_edit_contract_btn').show();
|
|
|
+ $('#save_contract_btn').show();
|
|
|
+ $('#cancel_contract_btn').show();
|
|
|
+ for (const c of contractDetail) {
|
|
|
+ if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
|
|
|
+ if (c === 'sign_date') {
|
|
|
+ $('#htdetail_' + c).html('<input type="date" class="form-control form-control-sm" value="' + moment(node[c]).format('YYYY-MM-DD') + '">');
|
|
|
+ continue;
|
|
|
+ } else if (c === 'remark') {
|
|
|
+ $('#htdetail_' + c).html('<textarea class="form-control form-control-sm" rows="3">' + node[c] + '</textarea>');
|
|
|
+ continue;
|
|
|
+ } else if (c === 'tax') {
|
|
|
+ $('#htdetail_' + c).html('<input type="number" min="0" max="100" step="1" class="form-control form-control-sm" value="' + (node[c] ? node[c] : '') + '">');
|
|
|
continue;
|
|
|
}
|
|
|
- $('#htdetail_' + attr.field).html('<input type="' + attr.type + '" class="form-control form-control-sm" value="' + (attrInfo && attrInfo[attr.field] ? attrInfo[attr.field] : '') + '">');
|
|
|
+ $('#htdetail_' + c).html('<input type="text" class="form-control form-control-sm" value="' + node[c] + '">');
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ const attrInfo = node.attribute_json ? JSON.parse(node.attribute_json) : null;
|
|
|
+ for (const attr of attributeSet) {
|
|
|
+ if (attr.type === 'long_text') {
|
|
|
+ $('#htdetail_' + attr.field).html('<textarea class="form-control form-control-sm" rows="3">' + (attrInfo && attrInfo[attr.field] ? attrInfo[attr.field] : '') + '</textarea>');
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $('#htdetail_' + attr.field).html('<input type="' + attr.type + '" class="form-control form-control-sm" value="' + (attrInfo && attrInfo[attr.field] ? attrInfo[attr.field] : '') + '">');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
$('#save_contract_btn').on('click', function () {
|
|
|
const node = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
@@ -1943,8 +1971,10 @@ $(document).ready(function() {
|
|
|
// 更新至服务器
|
|
|
postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) {
|
|
|
toastr.success('已编辑成功');
|
|
|
- const refreshNode = contractTree.loadPostData(result);
|
|
|
+ const refreshNode = contractTree.loadPostData({ update: result.contract });
|
|
|
contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
|
|
|
+ node.files = result.files;
|
|
|
+ contractTreeSpreadObj.setContractFiles(result.files, node.id);
|
|
|
const newNode = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
contractTreeSpreadObj.changeContractTab(newNode, true);
|
|
|
});
|
|
|
@@ -1955,6 +1985,7 @@ $(document).ready(function() {
|
|
|
const node = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
if (node && node.c_code && (node.uid === user_id || permission_edit_contract)) {
|
|
|
$('#edit_contract_btn').show();
|
|
|
+ $('#ai_edit_contract_btn').show();
|
|
|
$('#save_contract_btn').hide();
|
|
|
$('#cancel_contract_btn').hide();
|
|
|
for (const c of contractDetail) {
|
|
|
@@ -2001,6 +2032,7 @@ $(document).ready(function() {
|
|
|
})
|
|
|
postDataWithFile(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/file/upload`, formData, function (result) {
|
|
|
contractTreeSpreadObj.setContractFiles(result, node.id);
|
|
|
+ node.files = result;
|
|
|
$('#file-modal').val('');
|
|
|
$('#file-cancel').click()
|
|
|
});
|
|
|
@@ -2014,6 +2046,7 @@ $(document).ready(function() {
|
|
|
deleteAfterHint(function () {
|
|
|
postData(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/file/delete`, { id: fid }, function (result) {
|
|
|
contractTreeSpreadObj.setContractFiles(result, node.id);
|
|
|
+ node.files = result;
|
|
|
});
|
|
|
}, '确认删除该文件?');
|
|
|
});
|
|
|
@@ -2617,17 +2650,22 @@ $(document).ready(function() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ const edit_contract_input_key = ['c_code', 'name', 'tax', 'price', 'party_a', 'party_a_user', 'party_b', 'party_b_user', 'sign_date', 'address', 'entity', 'bank', 'bank_account'];
|
|
|
+ const signDate = $('#cons-add input[name="sign_date"]').datepicker().data('datepicker');
|
|
|
if (permission_add) {
|
|
|
- const signDate = $('#cons-add input[name="sign_date"]').datepicker().data('datepicker');
|
|
|
$('#cons-add').on('show.bs.modal', function () {
|
|
|
- $('#cons-add input[name="code"]').val('');
|
|
|
- $('#cons-add input[name="name"]').val('');
|
|
|
- $('#cons-add input[name="price"]').val('');
|
|
|
- $('#cons-add input[name="party_a"]').val('');
|
|
|
- $('#cons-add input[name="party_b"]').val('');
|
|
|
- $('#cons-add input[name="sign_date"]').val('');
|
|
|
+ for (const key of edit_contract_input_key) {
|
|
|
+ $('#cons-add input[name="' + key + '"]').val('');
|
|
|
+ }
|
|
|
signDate.selectDate('');
|
|
|
$('#cons-add textarea[name="remark"]').val('');
|
|
|
+ // type选回第一个
|
|
|
+ $('#cons-add select[name="type"]').val($('#cons-add select[name="type"] option:first').val());
|
|
|
+ $('#contract-add-cid').val('');
|
|
|
+ $('#contract-add-fid').val('');
|
|
|
+ $('#contract-add-attach').prop('checked', false);
|
|
|
+ $('#ai-file-name').text('');
|
|
|
+ $('#ai-file-panel').hide();
|
|
|
});
|
|
|
|
|
|
$('#add-contract').click(function () {
|
|
|
@@ -2637,17 +2675,17 @@ $(document).ready(function() {
|
|
|
return;
|
|
|
}
|
|
|
console.log(node);
|
|
|
- const data = {
|
|
|
- code: $('#cons-add input[name="code"]').val(),
|
|
|
- name: $('#cons-add input[name="name"]').val(),
|
|
|
- price: $('#cons-add input[name="price"]').val(),
|
|
|
- party_a: $('#cons-add input[name="party_a"]').val(),
|
|
|
- party_b: $('#cons-add input[name="party_b"]').val(),
|
|
|
- sign_date: $('#cons-add input[name="sign_date"]').val() || null,
|
|
|
- remark: $('#cons-add textarea[name="remark"]').val(),
|
|
|
- type: $('#cons-add select[name="type"]').val(),
|
|
|
- }
|
|
|
- if (!data.code) {
|
|
|
+ const data = {};
|
|
|
+ for (const key of edit_contract_input_key) {
|
|
|
+ data[key] = $('#cons-add input[name="'+ key +'"]').val();
|
|
|
+ }
|
|
|
+ const new_cid = $('#contract-add-cid').val();
|
|
|
+ data.cid = new_cid;
|
|
|
+ data.attach = $('#contract-add-attach').prop('checked');
|
|
|
+ data.fid = $('#contract-add-fid').val() ? parseInt($('#contract-add-fid').val()) : 0;
|
|
|
+ data.remark = $('#cons-add textarea[name="remark"]').val();
|
|
|
+ data.type = $('#cons-add select[name="type"]').val();
|
|
|
+ if (!data.c_code) {
|
|
|
toastr.error('请输入合同编号');
|
|
|
return;
|
|
|
}
|
|
|
@@ -3905,6 +3943,293 @@ $(document).ready(function() {
|
|
|
if (stdXmj) stdXmj.spread.refresh();
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ $('#aiFillBtn').on('click', function () {
|
|
|
+ openAiRecognizeModal({ mode: 'create' });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 弹窗状态:mode区分新建/编辑,cid是合同id(编辑时已有,新建时上传成功后才拿到)
|
|
|
+ const aiModalState = {
|
|
|
+ mode: 'create', // 'create' | 'edit'
|
|
|
+ cid: null,
|
|
|
+ existingFiles: [], // 编辑模式下,该合同已有的文件列表 [{ id, filename }, ...]
|
|
|
+ };
|
|
|
+
|
|
|
+ let aiSelectedFile = null; // 用户本次上传选择的新文件
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 打开AI识别弹窗的统一入口
|
|
|
+ * @param {Object} options
|
|
|
+ * mode: 'create' | 'edit'
|
|
|
+ * cid: 编辑模式下传入当前合同id;新建模式不传
|
|
|
+ * existingFiles: 编辑模式下传入该合同已有的文件列表 [{ id, filename }],新建模式不传或传空数组
|
|
|
+ *
|
|
|
+ * 调用示例:
|
|
|
+ * 新建合同弹窗的AI按钮: openAiRecognizeModal({ mode: 'create' })
|
|
|
+ * 编辑合同弹窗的AI按钮: openAiRecognizeModal({ mode: 'edit', cid: contractId, existingFiles: attList })
|
|
|
+ */
|
|
|
+ function openAiRecognizeModal(options) {
|
|
|
+ options = options || {};
|
|
|
+ aiModalState.mode = options.mode || 'create';
|
|
|
+ aiModalState.cid = options.cid || null;
|
|
|
+ aiModalState.existingFiles = options.existingFiles || [];
|
|
|
+
|
|
|
+ resetAiModalUI();
|
|
|
+ renderExistingFilesList();
|
|
|
+ $('#ai-recognize-modal').modal('show');
|
|
|
+ }
|
|
|
+
|
|
|
+ function resetAiModalUI() {
|
|
|
+ // 重置文件上传状态
|
|
|
+ clearUploadedFileUI();
|
|
|
+
|
|
|
+ // 重置单选状态
|
|
|
+ $('input[name="aiFileSource"]').prop('checked', false);
|
|
|
+
|
|
|
+ // 重置勾选项(默认勾选,但实际是否显示由renderExistingFilesList后续逻辑控制)
|
|
|
+ $('#aiAttachToContract').prop('checked', true);
|
|
|
+ $('#aiAttachCheckArea').hide();
|
|
|
+
|
|
|
+ // 重置识别按钮状态
|
|
|
+ $('#aiStartRecognize').prop('disabled', true);
|
|
|
+ resetSubmitBtnUI($('#aiStartRecognize'));
|
|
|
+ }
|
|
|
+
|
|
|
+ function renderExistingFilesList() {
|
|
|
+ const hasExisting = aiModalState.mode === 'edit' && aiModalState.existingFiles.length > 0;
|
|
|
+
|
|
|
+ if (!hasExisting) {
|
|
|
+ $('#aiExistingFilesArea').hide();
|
|
|
+ $('#aiUploadSectionLabel').hide();
|
|
|
+ $('#aiExistingFilesList').empty();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#aiUploadSectionLabel').show();
|
|
|
+ const $list = $('#aiExistingFilesList').empty();
|
|
|
+
|
|
|
+ aiModalState.existingFiles.forEach(function (file) {
|
|
|
+ const radioId = 'aiExistingFile_' + file.id;
|
|
|
+ const $item = $(`
|
|
|
+ <div class="ai-existing-file-item">
|
|
|
+ <div class="form-check">
|
|
|
+ <input type="radio" name="aiFileSource" class="form-check-input" id="${radioId}" value="${file.id}">
|
|
|
+ <label class="form-check-label" for="${radioId}">
|
|
|
+ <i class="fa-solid fa-file-lines"></i> ${file.filename}
|
|
|
+ </label>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ `);
|
|
|
+ $list.append($item);
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#aiExistingFilesArea').show();
|
|
|
+ }
|
|
|
+
|
|
|
+// 选中"已有文件"中的某一项
|
|
|
+ $(document).on('change', 'input[name="aiFileSource"]', function () {
|
|
|
+ const selectedValue = $(this).val();
|
|
|
+
|
|
|
+ if (selectedValue === 'upload') {
|
|
|
+ $('#aiAttachCheckArea').show(); // 新建、编辑场景下,只要是"上传新文件"都显示这个勾选
|
|
|
+ $('#aiStartRecognize').prop('disabled', !aiSelectedFile);
|
|
|
+ } else {
|
|
|
+ // 用户选中了某个已有文件,清空本次上传的新文件状态
|
|
|
+ clearUploadedFileUI();
|
|
|
+ $('#aiAttachCheckArea').hide(); // 已有文件本身已经在合同文件里,不需要"是否添加"这个勾选
|
|
|
+ $('#aiStartRecognize').prop('disabled', false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+// 点击上传区域,触发文件选择
|
|
|
+ $('#aiUploadArea').on('click', function (e) {
|
|
|
+ // file input 冒泡上来的点击,不处理
|
|
|
+ if (e.target.id === 'aiFileInput') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#aiFileInput')[0].click();
|
|
|
+ });
|
|
|
+
|
|
|
+// 拖拽上传
|
|
|
+ $('#aiUploadArea').on('dragover', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ $(this).addClass('dragover');
|
|
|
+ }).on('dragleave', function () {
|
|
|
+ $(this).removeClass('dragover');
|
|
|
+ }).on('drop', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ $(this).removeClass('dragover');
|
|
|
+ const file = e.originalEvent.dataTransfer.files[0];
|
|
|
+ if (file) handleAiFileSelected(file);
|
|
|
+ });
|
|
|
+
|
|
|
+// 选择文件
|
|
|
+ $('#aiFileInput').on('change', function () {
|
|
|
+ const file = this.files[0];
|
|
|
+ if (file) handleAiFileSelected(file);
|
|
|
+ });
|
|
|
+
|
|
|
+ function handleAiFileSelected(file) {
|
|
|
+ aiSelectedFile = file;
|
|
|
+ $('#aiFileName').text(file.name);
|
|
|
+ $('#aiUploadPlaceholder').hide();
|
|
|
+ $('#aiUploadResult').show();
|
|
|
+ $('#aiAttachCheckArea').show(); // 新建场景下,选择文件时也要显示这个勾选框
|
|
|
+
|
|
|
+ // 选中"上传新文件"这个隐藏radio,与已有文件选项互斥
|
|
|
+ $('#aiSourceUpload').prop('checked', true).trigger('change');
|
|
|
+ }
|
|
|
+
|
|
|
+// 移除已选文件
|
|
|
+ $('#aiFileRemove').on('click', function (e) {
|
|
|
+ e.stopPropagation();
|
|
|
+ clearUploadedFileUI();
|
|
|
+ $('#aiStartRecognize').prop('disabled', true);
|
|
|
+ });
|
|
|
+
|
|
|
+ function clearUploadedFileUI() {
|
|
|
+ aiSelectedFile = null;
|
|
|
+ $('#aiFileInput').val('');
|
|
|
+ $('#aiUploadResult').hide();
|
|
|
+ $('#aiUploadPlaceholder').show();
|
|
|
+ }
|
|
|
+
|
|
|
+// 点击「开始识别」
|
|
|
+ $('#aiStartRecognize').on('click', function () {
|
|
|
+ const $btn = $(this);
|
|
|
+ const selectedSource = $('input[name="aiFileSource"]:checked').val();
|
|
|
+ const usingExisting = selectedSource && selectedSource !== 'upload';
|
|
|
+ const usingUpload = selectedSource === 'upload' && aiSelectedFile;
|
|
|
+
|
|
|
+ if (!usingExisting && !usingUpload) return;
|
|
|
+
|
|
|
+ $btn.prop('disabled', true);
|
|
|
+ $('#aiRecognizeBtnText').text('识别中...');
|
|
|
+ $('#aiRecognizeSpinner').show();
|
|
|
+
|
|
|
+ if (usingExisting) {
|
|
|
+ // 使用已有文件 -> 走 editAndAi
|
|
|
+ postData(window.location.pathname + '/ai/edit', { id: aiModalState.cid, fid: selectedSource }, function (res) {
|
|
|
+ handleAiRecognizeSuccess(res);
|
|
|
+ resetSubmitBtnUI($btn);
|
|
|
+ }, function (err) {
|
|
|
+ handleAiRecognizeError(err);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 上传新文件 -> 走 uploadAndAi
|
|
|
+ const formData = new FormData();
|
|
|
+ if (aiSelectedFile === undefined) {
|
|
|
+ toastr.error('未选择上传文件!');
|
|
|
+ resetSubmitBtnUI($btn);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const filesize = aiSelectedFile.size;
|
|
|
+ if (filesize > 50 * 1024 * 1024) {
|
|
|
+ toastr.error('文件大小过大!');
|
|
|
+ resetSubmitBtnUI($btn);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const fileext = aiSelectedFile.name.toLowerCase().split('.').splice(-1)[0];
|
|
|
+ if (['pdf', 'doc', 'docx', 'jpg', 'jpeg', 'png', 'webp'].indexOf(fileext) === -1) {
|
|
|
+ toastr.error('只能上传PDF、Word、图片格式的合同文件!');
|
|
|
+ resetSubmitBtnUI($btn);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (aiModalState.cid) {
|
|
|
+ formData.append('cid', aiModalState.cid);
|
|
|
+ }
|
|
|
+ formData.append('attachToContract', $('#aiAttachToContract').is(':checked') ? '1' : '0');
|
|
|
+ formData.append('size', filesize);
|
|
|
+ formData.append('file', aiSelectedFile);
|
|
|
+ // 新建模式不传uuid,后端会自动生成并在返回结果里带回cid
|
|
|
+ postDataWithFile(window.location.pathname + '/ai/upload', formData, function (res) {
|
|
|
+ handleAiRecognizeSuccess(res);
|
|
|
+ resetSubmitBtnUI($btn);
|
|
|
+ }, function (err) {
|
|
|
+ handleAiRecognizeError(err);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ function resetSubmitBtnUI($btn) {
|
|
|
+ $btn.prop('disabled', false);
|
|
|
+ $('#aiRecognizeBtnText').text('开始识别');
|
|
|
+ $('#aiRecognizeSpinner').hide();
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleAiRecognizeSuccess(res) {
|
|
|
+ const result = res;
|
|
|
+ const data = result.res || {};
|
|
|
+ if (aiModalState.mode === 'create') {
|
|
|
+ for (const key of edit_contract_input_key) {
|
|
|
+ $('#cons-add input[name="' + key + '"]').val(data[key] || '');
|
|
|
+ }
|
|
|
+ signDate.selectDate(data && data.sign_date ? new Date(moment(data.sign_date).format('YYYY-MM-DD')) : '');
|
|
|
+ $('#contract-add-cid').val(result.cid);
|
|
|
+ if (result.file) {
|
|
|
+ $('#contract-add-fid').val(result.file.id || '');
|
|
|
+ $('#contract-add-attach').prop('checked', result.attached || false);
|
|
|
+ $('#ai-file-name').text(result.file.filename); // 例如:合同解析结果.md
|
|
|
+ $('#ai-file-panel').show();
|
|
|
+ } else {
|
|
|
+ $('#contract-add-fid').val('');
|
|
|
+ $('#contract-add-attach').prop('checked', false);
|
|
|
+ $('#ai-file-name').text('');
|
|
|
+ $('#ai-file-panel').hide();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const node = SpreadJsObj.getSelectObject(contractSheet);
|
|
|
+ if (node && node.c_code && (node.uid === user_id || permission_edit_contract) && (!shenpi_status || (shenpi_status && node.status === auditConst.status.uncheck || node.status === auditConst.status.checkNo))) {
|
|
|
+ $('#edit_contract_btn').hide();
|
|
|
+ $('#save_contract_btn').show();
|
|
|
+ $('#cancel_contract_btn').show();
|
|
|
+ for (const c of contractDetail) {
|
|
|
+ if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
|
|
|
+ if (c === 'sign_date') {
|
|
|
+ $('#htdetail_' + c).html('<input type="date" class="form-control form-control-sm" value="' + moment(data[c]).format('YYYY-MM-DD') + '">');
|
|
|
+ continue;
|
|
|
+ } else if (c === 'remark') {
|
|
|
+ $('#htdetail_' + c).html('<textarea class="form-control form-control-sm" rows="3">' + node[c] + '</textarea>');
|
|
|
+ continue;
|
|
|
+ } else if (c === 'tax') {
|
|
|
+ $('#htdetail_' + c).html('<input type="number" min="0" max="100" step="1" class="form-control form-control-sm" value="' + (data[c] ? data[c] : '') + '">');
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $('#htdetail_' + c).html('<input type="text" class="form-control form-control-sm" value="' + data[c] + '">');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const attrInfo = node.attribute_json ? JSON.parse(node.attribute_json) : null;
|
|
|
+ for (const attr of attributeSet) {
|
|
|
+ if (attr.type === 'long_text') {
|
|
|
+ $('#htdetail_' + attr.field).html('<textarea class="form-control form-control-sm" rows="3">' + (attrInfo && attrInfo[attr.field] ? attrInfo[attr.field] : '') + '</textarea>');
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $('#htdetail_' + attr.field).html('<input type="' + attr.type + '" class="form-control form-control-sm" value="' + (attrInfo && attrInfo[attr.field] ? attrInfo[attr.field] : '') + '">');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (result.file) {
|
|
|
+ // 插入到files最前面
|
|
|
+ node.files.unshift(result.file);
|
|
|
+ contractTreeSpreadObj.setContractFiles(node.files, node.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $('#ai-recognize-modal').modal('hide');
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleAiRecognizeError() {
|
|
|
+ toastr.error('识别失败,请重试或手动填写');
|
|
|
+ }
|
|
|
+
|
|
|
+// 弹窗关闭时重置状态(但不清空已回填的表单内容)
|
|
|
+ $('#ai-recognize-modal').on('hidden.bs.modal', function () {
|
|
|
+ clearUploadedFileUI();
|
|
|
+ $('input[name="aiFileSource"]').prop('checked', false);
|
|
|
+ $('#aiAttachCheckArea').hide();
|
|
|
+ $('#aiStartRecognize').prop('disabled', true);
|
|
|
+ resetSubmitBtnUI($('#aiStartRecognize'));
|
|
|
+ });
|
|
|
});
|
|
|
/**
|
|
|
* 校验文件大小、格式
|