$(function () { autoFlashHeight(); handleFileList(fileList); $('#file-ok').click(function () { const files = Array.from($('#file-modal')[0].files) const valiData = files.map(v => { const ext = v.name.substring(v.name.lastIndexOf('.') + 1) return { size: v.size, ext } }); if (validateFiles(valiData)) { if (files.length) { const formData = new FormData(); files.forEach(file => { formData.append('name', file.name); formData.append('size', file.size); formData.append('file', file); }) postDataWithFile(preUrl + '/file/upload', formData, function (result) { handleFileList(result); $('#file-cancel').click(); }); } } }) function handleFileList(files = []) { $('#file-content').empty(); // const { uncheck, checkNo } = auditConst.status const newFiles = files.map(file => { let showDel = false; if (file.uid === cur_uid) { if (financialPay.status === auditConst.status.checked) { showDel = false } else { showDel = true } } return {...file, showDel} }) let html = financialPay.filePermission ? `上传附件` : ''; newFiles.forEach((file, idx) => { if (file.showDel) { html += `${idx + 1}${file.filename}${file.username}${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}` } else { html += `${idx + 1}${file.filename}${file.username}${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}` } }) $('#file-content').append(html); } $('#file-content').on('click', 'a', function () { if ($(this).hasClass('file-del')) { const id = $(this).data('id'); postData(preUrl + '/file/delete', {id}, (result) => { handleFileList(result); }) } }); // 回车提交 $('#pay-table input').on('keypress', function () { if(window.event.keyCode === 13) { $(this).blur(); } }); $('#pay-table input').blur(function () { const val_name = $(this).data('name'); let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null; switch(val_name) { default: if(val && val.length > 255) { toastr.error('超出字段范围,请缩减'); $(this).val(financialPay[val_name]); return false; } break; } updatePayMsg(val_name, val, $(this)); }); $('#pay-table textarea').blur(function () { const val_name = $(this).data('name'); let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null; updatePayMsg(val_name, val, $(this)); }); $('#pay-table select').change(function () { const val_name = $(this).attr('data-name'); let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null; updatePayMsg(val_name, val, $(this)); }); function updatePayMsg(val_name, val, _self) { if(financialPay[val_name] !== val) { postData(preUrl + '/save', { type: 'pay_save', name: val_name, val}, function (result) { financialPay[val_name] = val; _self.val(financialPay[val_name]); }, function () { _self.val(financialPay[val_name]); }) } else { $(this).val(financialPay[val_name]); } } const payContractSpread = SpreadJsObj.createNewSpread($('#pay-contract-spread')[0]); const payContractSpreadSheet = payContractSpread.getActiveSheet(); const payContractSpreadSetting = { cols: [ {title: '合同编号', colSpan: '1', rowSpan: '2', field: 'c_code', hAlign: 0, width: 110, formatter: '@', readOnly: true, backColor2: 'backColor.fromContract'}, {title: '合同名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 130, formatter: '@', readOnly: true, backColor2: 'backColor.fromContract'}, {title: '合同金额', colSpan: '1', rowSpan: '2', field: 'total_price', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'}, {title: '收款单位', colSpan: '1', rowSpan: '2', field: 'entity', hAlign: 1, width: 130, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-0'}, {title: '收款单位账号', colSpan: '1', rowSpan: '2', field: 'bank_account', hAlign: 1, formatter: '@', width: 130, readOnly: 'readOnly.isEdit', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-0'}, {title: '收款单位开户行', colSpan: '1', rowSpan: '2', field: 'bank', hAlign: 1, formatter: '@', width: 130, readOnly: 'readOnly.isEdit', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-0'}, {title: '小额支出', colSpan: '1', rowSpan: '2', field: 'small_expenses', cellType: 'checkbox', hAlign: 1, width: 60, readOnly: 'readOnly.isEdit2'}, {title: '支付金额', colSpan: '1', rowSpan: '2', field: 'pay_price', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit2'}, {title: '累计支付', colSpan: '1', rowSpan: '2', field: 'accumulate_pay_price', getValue: 'getValue.accumulate_pay_price', hAlign: 2, width: 80, type: 'Number', readOnly: true }, {title: '结算金额', colSpan: '1', rowSpan: '2', field: 'settle_price', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit2'}, {title: '累计结算', colSpan: '1', rowSpan: '2', field: 'accumulate_settle_price', getValue: 'getValue.accumulate_settle_price', hAlign: 2, width: 80, type: 'Number', readOnly: true }, {title: '未结算', colSpan: '1', rowSpan: '2', field: 'not_pay_price', getValue: 'getValue.not_pay_price', hAlign: 2, width: 80, type: 'Number', readOnly: true }, {title: '支付方式', colSpan: '1', rowSpan: '2', field: 'pay_type', hAlign: 2, width: 80, cellType: 'unit', comboItems: payTypeList }, {title: '发票', colSpan: '1', rowSpan: '2', field: 'bill', hAlign: 1, cellType: 'checkbox', width: 60, readOnly: 'readOnly.isEdit2' }, {title: '附件', colSpan: '1', rowSpan: '2', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn', normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: 'getValue.attachment' }, ], emptyRows: 0, headRows: 2, headRowHeight: [25, 25], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', // readOnly: readOnly, localCache: { key: 'pay-contract-spread', colWidth: true, } }; payContractSpreadSetting.imageClick = function (data) { makeAttTable(data); $('#pay-contract-file').modal('show'); }; const payContractCol = { getValue: { attachment: function (data) { return data.files ? data.files.length : 0; }, accumulate_pay_price: function (data) { return !data.cid ? data.pay_price : data.accumulate_pay_price; }, accumulate_settle_price: function (data) { return !data.cid ? data.settle_price : data.accumulate_settle_price; }, not_pay_price: function (data) { return ZhCalc.sub(data.total_price || 0, data.accumulate_settle_price || 0); }, }, readOnly: { isEdit: function (data) { return data.c_code || readOnly; }, isEdit2: function (data) { return readOnly; }, }, backColor: { fromContract: function (data) { if (!data.cid) { return '#f8f9fa'; } }, } } const payContractSpreadObj = { deletePress: function (sheet) { return; }, valueChanged: function (e, info) { // 防止ctrl+z撤销数据 SpreadJsObj.reLoadRowData(info.sheet, info.row); }, }; if (!readOnly) { payContractSpreadObj.add = function () { postData(preUrl + '/save', { type: 'contract_white_add' }, function (data) { contractList.push(data); SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, contractList); }); }; payContractSpreadObj.del = function (sheet) { const selection = sheet.getSelections(); const row = selection[0].row, count = selection[0].rowCount; const sortData = sheet.zh_data; const ids = []; for (let iRow = 0; iRow < count; iRow++) { if (sortData[iRow + row]) { ids.push(sortData[iRow + row].id); } } if (ids.length > 0) { postData(preUrl + '/save', {type: 'contract_del', ids}, function (result) { contractList = result.contractList; $('#pay-total-price').val(result.tp || 0); SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, contractList); }); } }; payContractSpreadObj.editEnded = function (e, info) { if (info.sheet.zh_setting) { const type = SpreadJsObj.getSelectObject(info.sheet) ? 'contract_update' : false; if (!type) { toastr.error('该数据不存在'); SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } const select = type === 'contract_update' ? SpreadJsObj.getSelectObject(info.sheet) : {}; const col = info.sheet.zh_setting.cols[info.col]; if (col.field === 'small_expenses' || col.field === 'bill' || col.field === 'attachment') { return; } // 未改变值则不提交 let validText = col.type === 'Number' ? (is_numeric(info.editingText) ? parseFloat(info.editingText) : 0) : (info.editingText ? trimInvalidChar(info.editingText) : ''); const orgValue = type === 'contract_update' ? select[col.field] : ''; if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) { SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } if (col.field === 'accumulate_pay_price' || col.field === 'accumulate_settle_price' || col.field === 'not_pay_price') { SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } // 判断部分值是否输入的是数字判断和数据计算 if (col.type === 'Number') { if (isNaN(validText)) { toastr.error('不能输入其它非数字类型字符'); SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } } if (col.field === 'pay_price') { select.accumulate_pay_price = ZhCalc.add(ZhCalc.sub(select.accumulate_pay_price, select.pay_price), validText); } if (col.field === 'settle_price') { select.accumulate_settle_price = ZhCalc.add(ZhCalc.sub(select.accumulate_settle_price, select.settle_price), validText); } select[col.field] = validText; const uData = { id: select.id, }; uData[col.field] = validText; console.log(select, type); delete select.waitingLoading; // 更新至服务器 postData(preUrl + '/save', { type, updateData: uData }, function (result) { if(type === 'contract_update') { contractList.splice(info.row, 1, select); SpreadJsObj.reLoadRowData(info.sheet, info.row); $('#pay-total-price').val(result.tp || 0); } }, function () { select[col.field] = orgValue; SpreadJsObj.reLoadRowData(info.sheet, info.row); }); } }; payContractSpreadObj.clipboardPasted = function(e, info, cellRange) { if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) { info.sheet.setColumnCount(info.sheet.zh_setting.cols.length); } const hint = { cellError: {type: 'error', msg: '粘贴内容超出了表格范围'}, numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'}, }; if (info.sheet.zh_setting) { const sortData = info.sheet.zh_data || []; const range = info.cellRange; const data = []; let haveNew = false; for (let iRow = 0; iRow < range.rowCount; iRow++) { let bPaste = true; const curRow = range.row + iRow; // const materialData = JSON.parse(JSON.stringify(sortData[curRow])); const cLData = curRow >= sortData.length ? {} : {id: sortData[curRow].id}; haveNew = curRow >= sortData.length ? curRow : false; const hintRow = range.rowCount > 1 ? curRow : ''; let sameCol = 0; for (let iCol = 0; iCol < range.colCount; iCol++) { const curCol = range.col + iCol; const colSetting = info.sheet.zh_setting.cols[curCol]; if (!colSetting) continue; // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol)); let validText = info.sheet.getText(curRow, curCol); validText = colSetting.type === 'Number' ? (is_numeric(validText) ? parseFloat(validText) : 0) : (validText ? trimInvalidChar(validText) : ''); const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field]; if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) { sameCol++; if (range.colCount === sameCol) { bPaste = false; } continue; } if (colSetting.type === 'Number') { if (isNaN(validText)) { // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow)); toastMessageUniq(hint.numberExpr); bPaste = false; continue; } } cLData[colSetting.field] = validText; } if (bPaste) { data.push(cLData); // rowData.push(curRow); } else { SpreadJsObj.reLoadRowData(info.sheet, curRow); } } if (data.length === 0) { SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount); return; } console.log(data); // 更新至服务器 postData(preUrl + '/save', { type:'contract_paste', updateData: data }, function (result) { contractList = result.contractList; if (haveNew) { SpreadJsObj.initSheet(payContractSpreadSheet, payContractSpreadSetting); } SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, contractList); if (haveNew) { payContractSpreadSheet.setSelection(haveNew, 1, 1, 1); payContractSpreadSheet.getParent().focus(); payContractSpreadSheet.showRow(haveNew, spreadNS.VerticalPosition.center); } $('#pay-total-price').val(result.tp || 0); }, function () { SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount); return; }); } }; payContractSpreadObj.buttonClicked = function (e, info) { if (info.sheet.zh_setting) { const select = SpreadJsObj.getSelectObject(info.sheet); const col = info.sheet.zh_setting.cols[info.col]; if (!select) { toastr.error('请添加合同金额再勾选'); if (info.sheet.isEditing()) { info.sheet.endEdit(true); } return; } else if (col.field === 'small_expenses' || col.field === 'bill') { if (info.sheet.isEditing()) { info.sheet.endEdit(true); } const is_select = info.sheet.getValue(info.row, info.col) ? 0 : 1; if (select[col.field] !== is_select) { const uData = { id: select.id }; select[col.field] = is_select; uData[col.field] = select[col.field]; console.log(uData); postData(preUrl + '/save', { type: 'contract_update', updateData: uData }, function (result) { contractList.splice(info.row, 1, select); SpreadJsObj.reLoadRowData(info.sheet, info.row); }, function () { select[col.field] = info.sheet.getValue(info.row, info.col) ? 1 : 0; SpreadJsObj.reLoadRowData(info.sheet, info.row); }); } } } }; payContractSpread.bind(spreadNS.Events.EditEnded, payContractSpreadObj.editEnded); payContractSpread.bind(spreadNS.Events.ButtonClicked, payContractSpreadObj.buttonClicked); payContractSpread.bind(spreadNS.Events.ClipboardPasted, payContractSpreadObj.clipboardPasted); payContractSpread.bind(spreadNS.Events.ValueChanged, payContractSpreadObj.valueChanged); SpreadJsObj.addDeleteBind(payContractSpread, payContractSpreadObj.deletePress); // 右键菜单 $.contextMenu({ selector: '#pay-contract-spread', build: function ($trigger, e) { const target = SpreadJsObj.safeRightClickSelection($trigger, e, payContractSpread); return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader; }, items: { 'createAdd': { name: '添加', icon: 'fa-sign-in', callback: function (key, opt) { payContractSpreadObj.add(payContractSpreadSheet); }, }, 'createAdd2': { name: '添加合同', icon: 'fa-sign-in', callback: function (key, opt) { $('#add-deal').modal('show'); }, }, 'delete': { name: '删除', icon: 'fa-remove', callback: function (key, opt) { payContractSpreadObj.del(payContractSpreadSheet); }, disabled: function (key, opt) { if (payContractSpreadSheet.zh_data) { const selection = payContractSpreadSheet.getSelections(); // return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount; return payContractSpreadSheet.getRowCount() < selection[0].row + selection[0].rowCount; } else { return true; } } }, } }); $('#add-white-contract').click(function () { payContractSpreadObj.add(payContractSpreadSheet); }); let contracts = []; let contractTrees = []; const sqTreeSetting = { id: 'contract_id', pid: 'contract_pid', order: 'order', level: 'level', rootId: -1, keys: ['id', 'tid', 'spid'], }; const sqTree = createNewPathTree('base', sqTreeSetting); $('#add-deal').on('show.bs.modal', function () { $('#contract-tree').val('0'); $('#contract-keyword').val(''); $('#select-all-contract').prop('checked', false); postData(preUrl + '/save', { type: 'contract_list' }, function (result) { contracts = result.contracts; contractTrees = result.contractTrees; sqTree.loadDatas(contractTrees); const level2Tree = _.filter(sqTree.nodes, function (item) { return item.level === 2; }); makeContractListHtml(contracts); let html2 = ''; for (const t of level2Tree) { html2 += ``; } $('#contract-tree').html(html2); }); }); function makeContractListHtml(list) { let html = ''; for (const c of list) { const tree = _.find(contractTrees, function (item) { return item.contract_id === parseInt(c.full_path.split('-')[1] || 0); }); html += ` ${tree ? tree.name : ''} ${c.c_code} ${c.name} ${c.total_price} ${c.entity} ${c.bank_account} `; } $('#contract-list').html(html); } $('body').on('change', '#contract-tree', function () { searchContracts(); }); $('#search-contract-btn').click(function () { searchContracts(); }); // 回车提交 $('#contract-keyword').on('keypress', function () { if(window.event.keyCode === 13) { searchContracts(); } }); function searchContracts() { $('#select-all-contract').prop('checked', false); const keyword = $('#contract-keyword').val(); const selectTree = $('#contract-tree').val(); const list = _.filter(contracts, function (item) { return (selectTree !== '0' ? _.includes(item.full_path, '-' + selectTree + '-') : true) && (keyword !== '' ? (item.c_code.indexOf(keyword) > -1 || item.name.indexOf(keyword) > -1) : true); }); makeContractListHtml(list); } $('#select-all-contract').click(function () { $('#contract-list input:not(:disabled)').prop('checked', $(this).prop('checked')); }); $('#add-contract-btn').click(function () { const selects = []; $('#contract-list input:checked:not(:disabled)').each(function () { selects.push($(this).data('contract-id')); }); if (selects.length === 0) { toastr.warning('请选择合同再添加'); return; } console.log(selects); postData(preUrl + '/save', { type: 'contract_add', contract_ids: selects }, function (result) { $('#add-deal').modal('hide'); contractList = result.contractList; SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, contractList); // $('#pay-total-price').val(result.tp || 0); }); }); } SpreadJsObj.initSpreadSettingEvents(payContractSpreadSetting, payContractCol); SpreadJsObj.initSheet(payContractSpreadSheet, payContractSpreadSetting); postData(preUrl + '/save', { type: 'pay_contract_list' }, function (result) { contractList = result; SpreadJsObj.loadSheetData(payContractSpreadSheet, SpreadJsObj.DataType.Data, result); }); // 上传附件 $('#pay-contract-file input[type="file"]').change(function () { const files = Array.from(this.files); const valiData = files.map(v => { const ext = v.name.substring(v.name.lastIndexOf('.') + 1) return { size: v.size, ext } }); const fpcid = $('#file-contract-id').val(); if (!$('#pay-contract-file input[name="type"]:checked').val()) { toastr.error('请选择资料类型'); return false; } const fpcInfo = _.find(contractList, { id: parseInt(fpcid) }); if (!fpcInfo) { toastr.warning('不存在该资金支付明细'); $('#pay-contract-file input[type="file"]').val(''); return; } if (validateFiles(valiData)) { if (files.length) { const formData = new FormData() formData.append('type', $('#pay-contract-file input[name="type"]:checked').val()); formData.append('fpcid', fpcInfo.id); files.forEach(file => { formData.append('name', file.name) formData.append('size', file.size) formData.append('file', file) }) postDataWithFile(preUrl + '/file/upload', formData, function (result) { fpcInfo.files = result; makeAttTable(fpcInfo); SpreadJsObj.reLoadRowData(payContractSpreadSheet, contractList.indexOf(fpcInfo)); }); } } $('#transfer-file input[type="file"]').val(''); }); $('body').on('click', '#pay-contract-file .file-del', function () { const fpcid = $('#file-contract-id').val(); const fpcInfo = _.find(contractList, { id: parseInt(fpcid) }); if (!fpcInfo) { toastr.warning('不存在该资金支付明细'); return; } const fid = $(this).data('id'); deleteAfterHint(function () { postData(preUrl + '/file/delete', { fpcid: fpcInfo.id, id: fid }, (result) => { fpcInfo.files = result; makeAttTable(fpcInfo); SpreadJsObj.reLoadRowData(payContractSpreadSheet, contractList.indexOf(fpcInfo)); }); }, '确认删除该文件?'); }); function makeAttTable(payNode) { $('#file-contract-id').val(payNode.id); const files = payNode.files; let filesHtml = ''; const newFiles = files.map(file => { let showDel = false; if (file.uid === cur_uid) { if (file.type === 1 && financialPay.readOnly) { showDel = false; } else { showDel = true; } } return {...file, showDel} }); newFiles.forEach((file, idx) => { filesHtml += ` ${idx + 1}${file.filename} ${file.username} ${file.type === 1 ? (financialPay.status !== auditConst.status.checked && file.uid === cur_uid ? '' : file.bill) : '' } ${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}
${file.viewpath ? `` : ''} ${file.showDel ? `` : ''}
`; }); $('#contract-files').html(filesHtml); } $('body').on('change', '#contract-files .file-bill', function () { const bill = $(this).val(); const fid = $(this).data('id'); saveBills(bill, fid); }); function saveBills(bill, fid) { const fpcid = $('#file-contract-id').val(); const fpcInfo = _.find(contractList, { id: parseInt(fpcid) }); if (!fpcInfo) { toastr.warning('不存在该资金支付明细'); return; } postData(preUrl + '/save', { type: 'file_bill', id: fid, bill }, function (result) { const fileInfo = _.find(fpcInfo.files, { id: fid }); fileInfo.bill = bill; }); } $.subMenu({ menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list', toMenu: '#to-menu', toMiniMenu: '#to-mini-menu', key: 'menu.1.0.0', miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1', callback: function (info) { if (info.mini) { $('.panel-title').addClass('fluid'); $('#sub-menu').removeClass('panel-sidebar'); } else { $('.panel-title').removeClass('fluid'); $('#sub-menu').addClass('panel-sidebar'); } autoFlashHeight(); } }); }); function checkStartFrom() { // 判断发票是否已上传 if (!contractList || contractList.length === 0) { toastr.error('请添加合同再上报'); return false; } let notBills = []; for (const c of contractList) { if (c.bill && _.findIndex(c.files, { type: 1 }) === -1) { notBills.push(c); } } if (notBills.length > 0) { for (const c of notBills) { toastr.error(`合同${c.c_code}未上传发票`); } return false; } return true; } // texterea换行 function auditCheck(i) { // const inlineRadio1 = $('#inlineRadio1:checked').val() // const inlineRadio2 = $('#inlineRadio2:checked').val() const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '
').replace(/\n/g, '
').replace(/\s/g, ' '); $('textarea[name="opinion"]').eq(i).val(opinion); // if (i === 1) { // if (!inlineRadio1 && !inlineRadio2) { // if (!$('#warning-text').length) { // $('#reject-process').prepend('

请选择退回流程

'); // } // return false; // } // if ($('#warning-text').length) $('#warning-text').remove() // } return true; } /** * 校验文件大小、格式 * @param {Array} files 文件数组 */ function validateFiles(files) { if (files.length > 10) { toastr.error('至多同时上传10个文件'); return false } return files.every(file => { if (file.size > 1024 * 1024 * 30) { toastr.error('文件大小限制为30MB'); return false } if (whiteList.indexOf('.' + file.ext.toLowerCase()) === -1) { toastr.error('请上传正确的格式文件'); return false } return true }) } const is_numeric = (value) => { if (typeof(value) === 'object') { return false; } else { return !Number.isNaN(Number(value)) && value.toString().trim() !== ''; } };