123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- $(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 ? `<tr><td colspan="5"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
- newFiles.forEach((file, idx) => {
- if (file.showDel) {
- html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/financial/${file.spid}/pay/${file.fpid}/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
- } else {
- html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/financial/${file.spid}/pay/${file.fpid}/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
- }
- })
- $('#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: 1, width: 80, readOnly: 'readOnly.isEdit2', 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.concat(contracts));
- const level2Tree = _.filter(sqTree.nodes, function (item) {
- return item.level === 2 && !item.c_code;
- });
- contracts = _.filter(sqTree.nodes, function (item) {
- return item.c_code && item.c_code !== '';
- });
- makeContractListHtml(contracts);
- let html2 = '<option value="0">全部</option>';
- for (const t of level2Tree) {
- html2 += `<option value="${t.contract_id}">${t.name}</option>`;
- }
- $('#contract-tree').html(html2);
- });
- });
- function makeContractListHtml(list, hide = false) {
- let html = '';
- if (!hide) {
- for (const c of list) {
- const tree = _.find(contractTrees, function (item) {
- return item.contract_id === parseInt(c.full_path.split('-')[1] || 0);
- });
- html += `<tr class="text-center tr-show" data-id="${c.id}">
- <td><input type="checkbox" data-contract-id="${c.id}" ${_.findIndex(contractList, { cid: c.id }) !== -1 ? 'checked disabled' : ''}></td>
- <td>${tree ? tree.name : ''}</td>
- <td class="text-left">${c.c_code}</td>
- <td class="text-left">${c.name}</td>
- <td class="text-right">${c.total_price}</td>
- <td>${c.entity}</td>
- <td>${c.bank_account}</td>
- </tr>`;
- }
- $('#contract-list').html(html);
- } else {
- $('#contract-list tr').removeClass('tr-show').hide();
- for (const c of list) {
- $(`#contract-list tr[data-id="${c.id}"]`).addClass('tr-show').show();
- }
- }
- }
- $('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, true);
- }
- $('#select-all-contract').click(function () {
- $('#contract-list tr[class*="tr-show"] 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 += `<tr class="text-center">
- <td>${idx + 1}</td><td class="text-left"><a href="${file.filepath}" target="_blank">${file.filename}</a></td>
- <td>${file.username}</td>
- <td>${file.type === 1 ? (financialPay.status !== auditConst.status.checked && file.uid === cur_uid ? '<input type="text" data-id="' + file.id + '" class="file-bill form-control form-control-sm" value="' + file.bill + '" />' : file.bill) : '' }</td>
- <td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td>
- <td>
- <div class="btn-group-table">
- ${file.viewpath ? `<a href="${file.viewpath}" target="_blank" class="mr-1"><i class="fa fa-eye fa-fw"></i></a>` : ''}
- <a href="/financial/${payNode.spid}/pay/${payNode.fpid}/file/${file.id}/download" class="mr-1"><i class="fa fa-download fa-fw"></i></a>
- ${file.showDel ? `<a href="javascript: void(0);" class="text-danger file-del mr-1" data-id="${file.id}"><i class="fa fa-trash-o fa-fw text-danger"></i></a>` : ''}
- </div>
- </td>
- </tr>`;
- });
- $('#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) {
- if (c.cid) {
- toastr.error(`合同 ${c.c_code} 未上传发票`);
- } else {
- toastr.error(`收款单位 ${c.entity} 未上传发票`);
- }
- }
- 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, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
- $('textarea[name="opinion"]').eq(i).val(opinion);
- // if (i === 1) {
- // if (!inlineRadio1 && !inlineRadio2) {
- // if (!$('#warning-text').length) {
- // $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
- // }
- // 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() !== '';
- }
- };
|