const copyBlockTag = 'zh.calc.copyBlock'; $(document).ready(function() { const ckBillsSpread = '/contract/' + window.location.pathname.split('/')[2] + '/' + contractConst.typeMap[contract_type] + '/detail/contract-billsSelect'; autoFlashHeight(); const contractSpreadSetting = { cols: [ {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@', readOnly: 'readOnly.code', cellType: 'tree'}, {title: '合同编号', colSpan: '1', rowSpan: '2', field: 'c_code', hAlign: 0, width: 120, formatter: '@', readOnly: true}, {title: '项目名称/合同名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 360, formatter: '@', readOnly: 'readOnly.code', wordWrap: true}, {title: '创建人', colSpan: '1', rowSpan: '2', field: 'username', hAlign: 1, width: 80, formatter: '@', readOnly: true}, {title: '合同金额', colSpan: '1', rowSpan: '2', field: 'total_price', hAlign: 2, width: 120, formatter: '@', readOnly: true}, ], emptyRows: 0, headRows: 2, headRowHeight: [25, 25], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', // readOnly: readOnly, rowHeader:[ { rowHeaderType: 'circle', setting: { size: 5, indent: 16, getColor: function (index, data) { if (!data) return; if (is_admin) return; if (_.findIndex(contractTreeAudits, { contract_id: data.contract_id, uid: user_id }) !== -1) { return '#dc3545'; } } }, }, ], localCache: { key: 'contract-spread', colWidth: true, }, }; const contractCol = { getValue: { status: function (data) { return data.c_code ? (data.settle_code ? '● 已结算' : data.yf_price < data.total_price ? '● 履行中' : '● 已完成') : ''; } }, foreColor: { status: function (data) { return data.c_code ? (data.settle_code ? '#6c757d' : data.yf_price < data.total_price ? '#da9500' : '#28a745') : ''; } }, readOnly: { code: function (data) { return !permission_edit || data.c_code; } } } const getStackedBarTip = function (data) { return data.stackedBarTips ? data.stackedBarTips.join('\n') : ''; }; if (contract_type === contractConst.type.expenses) { contractSpreadSetting.cols.push({title: '累计应付', colSpan: '1', rowSpan: '2', field: 'yf_price', hAlign: 2, width: 120, formatter: '@', readOnly: true}); contractSpreadSetting.cols.push({title: '支付进度', colSpan: '1', rowSpan: '2', formatter: '@', readOnly: true, field: 'stackedBar', hAlign: 0, width: 200, cellType: 'stackedBar', stackedBarCover: true, bc_type: 'grid', getTip: getStackedBarTip, hintNum: true}); } else if (contract_type === contractConst.type.income) { contractSpreadSetting.cols.push({title: '累计应回', colSpan: '1', rowSpan: '2', field: 'yf_price', hAlign: 2, width: 120, formatter: '@', readOnly: true}); contractSpreadSetting.cols.push({title: '回款进度', colSpan: '1', rowSpan: '2', formatter: '@', readOnly: true, field: 'stackedBar', hAlign: 0, width: 200, cellType: 'stackedBar', stackedBarCover: true, bc_type: 'grid', getTip: getStackedBarTip, hintNum: true}); } contractSpreadSetting.cols.push({title: '合同状态', colSpan: '1', rowSpan: '2', field: 'status', hAlign: 1, width: 100, formatter: '@', readOnly: true, getValue:'getValue.status', foreColor:'foreColor.status'}); contractSpreadSetting.cols.push({title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.code', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-1'}); const contractSpread = SpreadJsObj.createNewSpread($('#contract-spread')[0]); const contractSheet = contractSpread.getActiveSheet(); // sjsSettingObj.setGridSelectStyle(contractSpreadSetting); sjsSettingObj.setFxTreeStyle(contractSpreadSetting, sjsSettingObj.FxTreeStyle.contract); SpreadJsObj.initSpreadSettingEvents(contractSpreadSetting, contractCol); SpreadJsObj.initSheet(contractSheet, contractSpreadSetting); const treeSetting = { id: 'contract_id', pid: 'contract_pid', order: 'order', level: 'level', rootId: -1, keys: ['id', 'tid', 'spid', 'contract_type'], calcFields: ['pay_price', 'total_price', 'sf_price', 'debit_price', 'yf_price'], autoExpand: 3, markExpandKey: 'contract-bills-expand' + window.location.pathname.split('/')[2] + contractConst.typeMap[contract_type], markExpandSubKey: window.location.pathname.split('/')[2] + contractConst.typeMap[contract_type], }; const calcField = ['total_price', 'yf_price']; const calcFieldColor = {'total_price': '#bbb', 'yf_price': '#28a745'}; const calcFieldCaption = {'total_price': '合同金额', 'yf_price': contract_type === contractConst.type.expenses ? '累计应付' : '累计应回'}; treeSetting.calcFun = function (node) { if (node && node.c_code) { const base = node.total_price; node.stackedBar = []; node.stackedBarTips = []; for (const cf of calcField) { node.stackedBar.push({ color: calcFieldColor[cf], percent: ZhCalc.div(node[cf], base), field: cf, hintNum: cf === 'yf_price' }); node.stackedBarTips.push(`${calcFieldCaption[cf]}: ${node[cf] || 0}`); } } }; const contractTree = createNewPathTree('revise', treeSetting); const contractDetail = ['c_code', 'name', 'total_price', 'pay_price', 'debit_price','yf_price', 'sf_price', 'party_a', 'party_a_user', 'party_b', 'party_b_user', 'sign_date', 'address', 'entity', 'bank', 'bank_account', 'remark', 'settle_code', 'create_time']; // 清单 相关方法&绑定spreadjs事件 const contractTreeSpreadObj = { getDefaultSelectInfo: function (sheet) { const tree = sheet.zh_tree; if (!tree) return; const sel = sheet.getSelections()[0]; const node = sheet.zh_tree.nodes[sel.row]; if (!node) return; let count = 1; if (sel.rowCount > 1) { for (let r = 1; r < sel.rowCount; r++) { const rNode = sheet.zh_tree.nodes[sel.row + r]; if (rNode.level > node.level) continue; if ((rNode.level < node.level) || (rNode.level === node.level && rNode.contract_pid !== node.contract_pid)) { toastr.warning('请选择同一节点下的节点,进行该操作'); return; } count += 1; } } return [tree, node, count]; }, /** * 刷新顶部按钮是否可用 * @param sheet * @param selections */ refreshOperationValid: function (sheet, selection) { const setObjEnable = function (obj, enable) { if (enable) { obj.removeClass('disabled'); } else { obj.addClass('disabled'); } }; const invalidAll = function () { setObjEnable($('a[name=base-opr][type=add]'), false); setObjEnable($('a[name=base-opr][type=add-child]'), false); setObjEnable($('a[name=base-opr][type=delete]'), false); setObjEnable($('a[name=base-opr][type=up-move]'), false); setObjEnable($('a[name=base-opr][type=down-move]'), false); setObjEnable($('a[name=base-opr][type=up-level]'), false); setObjEnable($('a[name=base-opr][type=down-level]'), false); }; const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) { invalidAll(); return; } const first = sheet.zh_tree.nodes[row]; if (first && first.c_code) { const parent = tree.getParent(first) if (parent && permission_add && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: parent.contract_id, uid: user_id }) !== -1)) { $('#add-cons-btn').show(); } else { $('#add-cons-btn').hide(); } } else { if (first && permission_add && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: first.contract_id, uid: user_id }) !== -1)) { $('#add-cons-btn').show(); } else { $('#add-cons-btn').hide(); } } if (!first) { invalidAll(); return; } let last = first, sameParent = true, childCanDel = true; // hadContract = this.checkContract(first); if (sel.rowCount > 1 && first) { for (let r = 1; r < sel.rowCount; r++) { const rNode = tree.nodes[sel.row + r]; childCanDel = this.checkDelete(rNode, childCanDel); // if (!hadContract) hadContract = this.checkContract(rNode); if (!rNode) { sameParent = false; break; } if (rNode.level > first.level) continue; if ((rNode.level < first.level) || (rNode.level === first.level && rNode.contract_pid !== first.contract_pid)) { sameParent = false; break; } last = rNode; } } const preNode = tree.getPreSiblingNode(first); // if (!hadContract && preNode) hadContract = preNode.c_code !== undefined; // const siblings = tree.getChildren(tree.getParent(first)); let upPower = true; // for (let order = last.order; order < siblings.length - 1; order ++) { // if (!siblings[order].formc) { // upPower = false; // break; // } // } const nextNodes = _.filter(tree.getChildren(tree.getParent(first)), function (item){ return item.order > first.order }); // let nextHadContract = false; // for (const next of nextNodes) { // if (nextHadContract) continue; // nextHadContract = this.checkContract(next); // } const nextHadContract = _.findIndex(nextNodes, function(item) { return item.c_code; }) !== -1; const valid = !sheet.zh_setting.readOnly; setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1); setObjEnable($('a[name=base-opr][type=add-child]'), valid && first && !first.c_code && first.level >= 1); setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && childCanDel && this.checkDelete(first)); setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode); setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last)); setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && first.level > 2 && (!nextHadContract || tree.isLastSibling(last)) && upPower && first.c_code === undefined); setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent && first.level > 1 && preNode && (preNode.children.length > 0 || preNode.children.length === 0) && preNode.c_code === undefined); // setObjEnable($('#cut'), valid); // setObjEnable($('#paste'), valid); }, /** * * @param sheet * @param data */ refreshTree: function (sheet, data) { SpreadJsObj.massOperationSheet(sheet, function () { const tree = sheet.zh_tree; // 处理删除 if (data.delete) { data.delete.sort(function (a, b) { return b.deleteIndex - a.deleteIndex; }); for (const d of data.delete) { sheet.deleteRows(d.deleteIndex, 1); } } // 处理新增 if (data.create) { const newNodes = data.create; if (newNodes) { newNodes.sort(function (a, b) { return a.index - b.index; }); for (const node of newNodes) { sheet.addRows(node.index, 1); SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1); } } } // 处理更新 if (data.update) { const rows = []; for (const u of data.update) { rows.push(tree.nodes.indexOf(u)); } SpreadJsObj.reLoadRowsData(sheet, rows); } // 处理展开 if (data.expand) { const expanded = []; for (const e of data.expand) { if (expanded.indexOf(e) === -1) { const posterity = tree.getPosterity(e); for (const p of posterity) { sheet.setRowVisible(tree.nodes.indexOf(p), p.visible); expanded.push(p); } } } } }); }, changeContractTab: function (node, need = false) { if ($('.bc-bar .nav li .active').attr('href') === '#htdetail') { if (node.settle_code) { $('#edit_contract_btn').hide(); } else { $('#edit_contract_btn').show(); } $('#save_contract_btn').hide(); $('#cancel_contract_btn').hide(); $('#add_contract_pay_btn').hide(); $('a[href*="#cons-upfile"]').hide(); if (need) { for (const c of contractDetail) { if (c === 'create_time') { $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD HH:mm:ss') : ''); continue; } else if (c === 'sign_date') { $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : ''); continue; } $('#htdetail_' + c).text(node[c] || ''); } $('#htdetail_df_price').text(ZhCalc.sub(node.yf_price, node.sf_price) || ''); } } else if ($('.bc-bar .nav li .active').attr('href') === '#htpay') { $('#edit_contract_btn').hide(); $('#save_contract_btn').hide(); $('#cancel_contract_btn').hide(); if (node.settle_code) { $('#add_contract_pay_btn').hide(); if (need) { $('#htpay-table tbody').find('.pay-edit').hide(); $('#htpay-table tbody').find('.pay-del').hide(); } } else { $('#add_contract_pay_btn').show(); if (need && contractPays && contractPays.length > 0) { for (const [i, cp] of contractPays.entries()) { if (cp.uid === user_id) { $('#htpay-table tbody tr').eq(i).find('.pay-edit').show(); $('#htpay-table tbody tr').eq(i).find('.pay-del').show(); } } } } $('a[href*="#cons-upfile"]').hide(); } else if ($('.bc-bar .nav li .active').attr('href') === '#htfile') { $('#edit_contract_btn').hide(); $('#save_contract_btn').hide(); $('#cancel_contract_btn').hide(); $('#add_contract_pay_btn').hide(); $('a[href*="#cons-upfile"]').show(); } }, openContractPayFiles: function (pay) { this.setContractFiles(pay.files, pay.cid, pay.id, '#cons-pay-file table tbody'); }, setContractFiles: function (files, cid, cpid = null, _this = '#htfile-table tbody') { let filesHtml = ''; const newFiles = files.map(file => { let showDel = false; if (file.uid === user_id) { showDel = true } return {...file, showDel} }) newFiles.forEach((file, idx) => { filesHtml += ` ${idx + 1}${file.filename}${file.username}${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}
${file.viewpath ? `` : ''} ${file.showDel ? `` : ''}
`; }); $(_this).html(filesHtml); }, setContractPays: function (pays, node) { contractPays = pays; let paysHtml = ''; const newPays = pays.map(pay => { let showEdit = false; if (pay.uid === user_id && !node.settle_code) { showEdit = true } return {...pay, showEdit} }) console.log(pays); newPays.forEach((pay, idx) => { paysHtml += ` ${idx + 1} ${moment(pay.pay_time).format('YYYY-MM-DD')} ${pay.pay_price} ${pay.debit_price} ${pay.yf_price} ${pay.sf_price} ${pay.pay_type} ${pay.username} ${moment(pay.create_time).format('YYYY-MM-DD HH:mm:ss')} ${pay.remark} ${pay.files.length > 0 ? pay.files.length : ''} 编辑 删除 `; }); $('#htpay-table tbody').html(paysHtml); }, setContract: function (sheet) { const node = SpreadJsObj.getSelectObject(sheet); if (node && node.c_code) { $('#htdetail-table').show(); $('#htpay-table').show(); $('#htfile-table').show(); for (const c of contractDetail) { if (c === 'create_time') { $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD HH:mm:ss') : ''); continue; } else if (c === 'sign_date') { $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : ''); continue; } $('#htdetail_' + c).text(node[c] || ''); } $('#htdetail_df_price').text(ZhCalc.sub(node.yf_price, node.sf_price) || ''); postData(window.location.pathname + '/update', {postType: 'get-contract', postData: node.id}, function (result) { contractTreeSpreadObj.setContractPays(result.pays, node); contractTreeSpreadObj.setContractFiles(result.files, node.id); }); if (node.uid === user_id) { if (node.settle_code) { $('a[href*="#cons-unlock"]').show(); $('a[href*="#cons-close"]').hide(); } else { $('a[href*="#cons-unlock"]').hide(); $('a[href*="#cons-close"]').show(); } contractTreeSpreadObj.changeContractTab(node); } else { $('#edit_contract_btn').hide(); $('#save_contract_btn').hide(); $('#cancel_contract_btn').hide(); $('a[href*="#cons-unlock"]').hide(); $('a[href*="#cons-close"]').hide(); $('a[href*="#cons-upfile"]').hide(); if (node && node.c_code && $('.bc-bar .nav li .active').attr('href') === '#htfile' && permission_att) $('a[href*="#cons-upfile"]').show(); $('#add_contract_pay_btn').hide(); } } else { $('#htdetail-table').hide(); $('#htpay-table').hide(); $('#htfile-table').hide(); $('#edit_contract_btn').hide(); $('#save_contract_btn').hide(); $('#cancel_contract_btn').hide(); $('a[href*="#cons-unlock"]').hide(); $('a[href*="#cons-close"]').hide(); $('a[href*="#cons-upfile"]').hide(); if (node && node.c_code && $('.bc-bar .nav li .active').attr('href') === '#htfile' && permission_att) $('a[href*="#cons-upfile"]').show(); $('#add_contract_pay_btn').hide(); } }, selectionChanged: function (e, info) { if (info.newSelections) { if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) { contractTreeSpreadObj.refreshOperationValid(info.sheet); contractTreeSpreadObj.setContract(info.sheet); SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread); } } else { $('#add-cons-btn').hide(); } }, cleanData: function (result) { if (result && result.update && result.update.length > 0) { for (const r of result.update) { if (!r.c_code) { r.total_price = null; r.yf_price = null; } } } return result; }, /** * 新增节点 * @param spread */ baseOpr: function (sheet, type, addCount = 1) { const self = this; const [tree, node, count] = this.getDefaultSelectInfo(sheet); if (!tree || !node || !count) return; // if (type === 'delete') { // const parent = tree.getParent(node); // const children = parent ? parent.children : tree.children; // const index = children.indexOf(node); // for (let i = 0; i < count; i++) { // const child = children[i+index]; // if (tree.checkNodeUsed(child, pos)) { // toastr.warning('选中的节点已计量,不可删除'); // return; // } // } // } else if (type === 'up-level') { // const parent = tree.getParent(node); // const children = parent ? parent.children : tree.children; // const index = children.indexOf(node); // const lastSelect = children[index + count - 1]; // // if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) { // // toastr.warning('选中的节点已计量,不可升级'); // // return; // // } // } else if (type === 'down-level') { // const parent = tree.getParent(node); // const children = parent ? parent.children : tree.children; // const index = children.indexOf(node); // if (index > 0 && children[index-1].used) { // toastr.warning('其前节点已计量,选中的节点不可降级'); // return; // } // for (let i = index; i < count; i++) { // const child = children[i+index]; // if (tree.checkNodeUsed(child, pos)) { // toastr.warning('选中的节点已计量,不可降级'); // return; // } // } // } if (type === 'delete') { deleteAfterHint(function () { postData(window.location.pathname + '/update', { postType: type, postData: { id: node.contract_id, count: type === 'add' ? addCount : count, } }, function (result) { const refreshData = tree.loadPostData(result); self.refreshTree(sheet, refreshData); const sel = sheet.getSelections()[0]; if (sel) { sheet.setSelection(sel.row, sel.col, 1, sel.colCount); } contractTreeSpreadObj.setContract(sheet); self.refreshOperationValid(sheet); }); }, '确认删除「当前合同或节点及子项」?'); } else { postData(window.location.pathname + '/update', { postType: type, postData: { id: node.contract_id, count: type === 'add' ? addCount : count, } }, function (result) { self.cleanData(result); const refreshData = tree.loadPostData(result); self.refreshTree(sheet, refreshData); if (['up-move', 'down-move'].indexOf(type) > -1) { const sel = sheet.getSelections()[0]; if (sel) { sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount); SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]); } } else if (type === 'add' || type === 'add-child') { const sel = sheet.getSelections()[0]; if (sel) { sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount); SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]); } } self.refreshOperationValid(sheet); }); } }, /** * 编辑单元格响应事件 * @param {Object} e * @param {Object} info */ editEnded: function (e, info) { if (info.sheet.zh_setting) { const col = info.sheet.zh_setting.cols[info.col]; const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data; const node = sortData[info.row]; const data = { id: node.id, }; // 未改变值则不提交 const orgValue = node[col.field]; const newValue = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText); if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) { return; } // 获取更新数据 if (info.editingText) { const text = newValue; data[col.field] = text; } else { data[col.field] = null; } console.log(data); // 更新至服务器 postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) { const refreshNode = contractTree.loadPostData(result); contractTreeSpreadObj.refreshTree(info.sheet, refreshNode); }); } }, clipboardPasting: function (e, info) { const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting; info.cancel = true; if (!setting || !tree) return; const pasteData = info.pasteData.html ? SpreadJsObj.analysisPasteHtml(info.pasteData.html) : (info.pasteData.text === '' ? SpreadJsObj.Clipboard.getAnalysisPasteText() : SpreadJsObj.analysisPasteText(info.pasteData.text)); const datas = [], filterNodes = []; let level, filterRow = 0; for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) { const curRow = info.cellRange.row + iRow; const node = tree.nodes[curRow]; if (!node) continue; if (!level) level = node.level; if (node.level < level) break; let bPaste = false; const data = info.sheet.zh_tree.getNodeKeyData(node); for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) { const curCol = info.cellRange.col + iCol; const colSetting = info.sheet.zh_setting.cols[curCol]; const value = colSetting.wordWrap ? pasteData[iRow-filterRow][iCol] : trimInvalidChar(pasteData[iRow-filterRow][iCol]); data[colSetting.field] = value; bPaste = true; } if (bPaste) { datas.push(data); } else { filterNodes.push(node); } } if (datas.length > 0) { postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) { const refreshNode = tree.loadPostData(result); if (refreshNode.update) { refreshNode.update = refreshNode.update.concat(filterNodes); } contractTreeSpreadObj.refreshTree(info.sheet, refreshNode); }, function () { SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount); }); } else { SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount); } }, clipboardPasted: function (e, info) { const tree = info.sheet.zh_tree; if (!tree) { return; } const sortData = info.sheet.zh_tree.nodes; const datas = [], filterNodes = []; for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) { let bPaste = false; const curRow = info.cellRange.row + iRow; const node = sortData[curRow]; if (node) { const data = info.sheet.zh_tree.getNodeKeyData(node); for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) { const curCol = info.cellRange.col + iCol; const colSetting = info.sheet.zh_setting.cols[curCol]; const value = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol)); data[colSetting.field] = value; bPaste = true; } if (bPaste) { datas.push(data); } else { filterNodes.push(node); } } } if (datas.length > 0) { postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) { const refreshNode = tree.loadPostData(result); if (refreshNode.update) { refreshNode.update = refreshNode.update.concat(filterNodes); } contractTreeSpreadObj.refreshTree(info.sheet, refreshNode); }, function () { SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount); }); } else { SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount); } }, deletePress: function (sheet) { if (!sheet.zh_setting) return; const sel = sheet.getSelections()[0], datas = []; for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) { let bDel = false; const node = sheet.zh_tree.nodes[iRow]; const data = sheet.zh_tree.getNodeKeyData(node); for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) { const col = sheet.zh_setting.cols[iCol]; const style = sheet.getStyle(iRow, iCol); if (style.locked) continue; data[col.field] = null; bDel = true; } if (bDel) datas.push(data); } if (datas.length > 0) { postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) { const refreshNode = sheet.zh_tree.loadPostData(result); contractTreeSpreadObj.refreshTree(sheet, refreshNode); }); } }, pasteBlock: function (spread, copyInfo) { const self = this; const sheet = spread.getActiveSheet(); const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet()); postData(window.location.pathname + '/update', { postType: 'paste-block', postData: { id: tree.getNodeKey(node), // tid: copyInfo.tid, block: copyInfo.block, } }, function (data) { const result = tree.loadPostData(data.ledger); self.refreshTree(sheet, result); const sel = sheet.getSelections()[0]; if (sel) { sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount); SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]); } self.refreshOperationValid(sheet); removeLocalCache(copyBlockTag); }, null, true); }, topRowChanged: function (e, info) { SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread); }, editStarting(e, info) { if (!info.sheet.zh_setting || !info.sheet.zh_tree) return; const col = info.sheet.zh_setting.cols[info.col]; const node = info.sheet.zh_tree.nodes[info.row]; if (!node) { info.cancel = true; return; } }, cut: function (sheet, sel, callback) { if (!sheet || !sel) return; if (sel.colCount >= sheet.zh_setting.cols.length) { toastr.warning('请勿选中整行剪切'); return; } const sortData = SpreadJsObj.getSortData(sheet), datas = []; for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) { const node = sortData[iRow]; if (node) { const data = sheet.zh_tree.getNodeKeyData(node); for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) { const style = sheet.getStyle(iRow, iCol); if (style.locked) { toastr.error('不可剪切'); return; } const colSetting = sheet.zh_setting.cols[iCol]; data[colSetting.field] = null; } datas.push(data); } } if (datas.length > 0) { callback(); postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) { const refreshNode = sheet.zh_tree.loadPostData(result); contractTreeSpreadObj.refreshTree(sheet, refreshNode); }); } }, sortCode: function (sheet) { const tree = sheet.zh_tree; if (!tree) return; const select = SpreadJsObj.getSelectObject(sheet); if (!select || !select.code || select.code === '') return; const recursiveSortCode = function (data, parentCode, children) { if (!children || children.length === 0) return; for (const [i, child] of children.entries()) { if (!child.b_code || child.b_code === '') { const code = parentCode + '-' + (i + 1); const cData = tree.getNodeKeyData(child); cData.code = code; data.push(cData); if (!tree.isLeafXmj(child)) { recursiveSortCode(data, code, child.children); } } } }; const data = []; recursiveSortCode(data, select.code, select.children); if (data.length > 0) { postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) { const refreshNode = tree.loadPostData(result); contractTreeSpreadObj.refreshTree(sheet, refreshNode); }) } }, checkContract: function (select) { let haveContract = false; if (select.c_code) { haveContract = true; } else { const selects = contractSheet.zh_tree.getPosterity(select); const select_contracts = _.filter(selects, function (item) { return item.c_code; }); if (select_contracts.length > 0) haveContract = true; } return haveContract; }, checkDelete: function (select, oldFlag = true) { let canDelete = oldFlag; if (select.c_code) { if (!(select.uid === user_id || is_admin)) { canDelete = false; } else if (select.exist_pay) { canDelete = false; } } else { const selects = contractSheet.zh_tree.getPosterity(select); const select_contracts = _.filter(selects, function (item) { return item.c_code; }); if (select_contracts.length > 0) { for (const sc of select_contracts) { if (!(sc.uid === user_id || is_admin)) { canDelete = false; break; } else if (sc.exist_pay) { canDelete = false; break; } } } } return canDelete; } }; contractSpread.bind(spreadNS.Events.SelectionChanged, contractTreeSpreadObj.selectionChanged); contractSpread.bind(spreadNS.Events.topRowChanged, contractTreeSpreadObj.topRowChanged); // 右键菜单 let batchInsertObj; $.contextMenu.types.batchInsert = function (item, opt, root) { const self = this; if ($.isFunction(item.icon)) { item._icon = item.icon.call(this, this, $t, key, item); } else { if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') { // to enable font awesome item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon; } else { item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon; } } this.addClass(item._icon); const $obj = $('
' + item.name + '
') .appendTo(this); const $input = $obj.find('input'); const event = () => { if (self.hasClass('context-menu-disabled')) return; item.batchInsert($input[0], root); }; $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }}); $input.click((e) => {e.stopPropagation();}) .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);}) .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');}); }; const contractContextMenuOptions = { selector: '#contract-spread', build: function ($trigger, e) { const target = SpreadJsObj.safeRightClickSelection($trigger, e, contractSpread); return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader; }, items: {} }; if (permission_edit) { contractSpread.bind(spreadNS.Events.EditStarting, contractTreeSpreadObj.editStarting); contractSpread.bind(spreadNS.Events.EditEnded, contractTreeSpreadObj.editEnded); contractSpread.bind(spreadNS.Events.ButtonClicked, contractTreeSpreadObj.buttonClicked); contractSpread.bind(spreadNS.Events.ClipboardPasting, contractTreeSpreadObj.clipboardPasting); contractSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) { const copyText = SpreadJsObj.getFilterCopyText(info.sheet); SpreadJsObj.Clipboard.setCopyData(copyText); }); SpreadJsObj.addDeleteBind(contractSpread, contractTreeSpreadObj.deletePress); SpreadJsObj.addCutEvents(contractSpread, contractTreeSpreadObj.cut); $('a[name="base-opr"]').click(function () { contractTreeSpreadObj.baseOpr(contractSheet, this.getAttribute('type')); }); $('a[name=cpc]').click(function () { contractSpread.commandManager().execute({ cmd: this.getAttribute('type'), sheetName: contractSheet.name() }); }); contractContextMenuOptions.items.create = { name: '新增节点', icon: 'fa-plus', callback: function (key, opt) { contractTreeSpreadObj.baseOpr(contractSheet, 'add'); }, disabled: function (key, opt) { const sheet = contractSheet; const selection = sheet.getSelections(); const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) return true; const first = sheet.zh_tree.nodes[row]; const valid = !sheet.zh_setting.readOnly; return !(valid && first && first.level > 1); } }; contractContextMenuOptions.items.create3 = { name: '新增子节点', icon: 'fa-sign-in', callback: function (key, opt) { contractTreeSpreadObj.baseOpr(contractSheet, 'add-child'); }, disabled: function (key, opt) { const sheet = contractSheet; const selection = sheet.getSelections(); const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) return true; const first = sheet.zh_tree.nodes[row]; const valid = !sheet.zh_setting.readOnly; return !(valid && first && !first.c_code && first.level >= 1); } }; } if (permission_add) { contractContextMenuOptions.items.create2 = { name: '新增合同', icon: 'fa-sign-in', callback: function (key, opt) { $('#cons-add').modal('show'); }, visible: function (key, opt) { const sheet = contractSheet; const selection = sheet.getSelections(); const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) return false; const first = sheet.zh_tree.nodes[row]; if (first && first.c_code) { const parent = sheet.zh_tree.getParent(first); return parent && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: parent.contract_id, uid: user_id }) !== -1); } return first && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: first.contract_id, uid: user_id }) !== -1); }, disabled: function (key, opt) { const sheet = contractSheet; const selection = sheet.getSelections(); const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) return true; const first = sheet.zh_tree.nodes[row]; const valid = !sheet.zh_setting.readOnly; return !(valid && first && first.level > 1); } }; } contractContextMenuOptions.items.delete = { name: '删除', icon: 'fa-remove', callback: function (key, opt) { contractTreeSpreadObj.baseOpr(contractSheet, 'delete'); }, visible: function (key, opt) { const sheet = contractSheet; const selection = sheet.getSelections(); const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) return false; const first = sheet.zh_tree.nodes[row]; return (first && first.c_code) || permission_edit; }, disabled: function (key, opt) { const sheet = contractSheet; const selection = sheet.getSelections(); const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) return true; const first = sheet.zh_tree.nodes[row]; let last = first, sameParent = true, childCanDel = true; if (sel.rowCount > 1 && first) { for (let r = 1; r < sel.rowCount; r++) { const rNode = tree.nodes[sel.row + r]; childCanDel = contractTreeSpreadObj.checkDelete(rNode, childCanDel); if (!rNode) { sameParent = false; break; } if (rNode.level > first.level) continue; if ((rNode.level < first.level) || (rNode.level === first.level && rNode.contract_pid !== first.contract_pid)) { sameParent = false; break; } last = rNode; } } const valid = !sheet.zh_setting.readOnly; return !(valid && first && first.level > 1 && sameParent && childCanDel && contractTreeSpreadObj.checkDelete(first)); } }; contractContextMenuOptions.items.sprBase = '----'; // contractContextMenuOptions.items.copyBlock = { // name: '复制整块(只复制节点)', // icon: 'fa-files-o', // callback: function (key, opt) { // const copyBlockList = []; // const sheet = contractSheet; // const sel = sheet.getSelections()[0]; // let iRow = sel.row; // const pid = sheet.zh_tree.nodes[iRow].contract_pid; // while (iRow < sel.row + sel.rowCount) { // const node = sheet.zh_tree.nodes[iRow]; // if (node.contract_pid !== pid) { // toastr.error('仅可同时选中同层节点'); // return; // } // const posterity = sheet.zh_tree.getPosterity(node); // iRow += posterity.length + 1; // posterity.unshift(node); // const copyData = sheet.zh_tree.getDefaultData(posterity); // const newCopyData = _.filter(_.cloneDeep(copyData), function (d) { // return d.c_code === undefined; // }); // const newCopyBlock = []; // for (const p of newCopyData) { // const children = _.filter(newCopyData, function (item) { // return item.contract_pid === p.contract_id; // }); // if (children.length > 0) { // let i = 1; // for (const c of children) { // c.order = i; // i++; // } // } else { // p.is_leaf = 1; // } // if (_.findIndex(newCopyBlock, { contract_id: p.contract_id }) === -1) { // newCopyBlock.push(p); // } // } // copyBlockList.push(newCopyBlock); // } // setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList })); // }, // visible: function (key, opt) { // const sheet = contractSheet; // const selection = sheet.getSelections(); // const row = selection[0].row; // const select = contractTree.nodes[row]; // return select; // }, // disabled: function (key, opt) { // const sheet = contractSheet; // const selection = sheet.getSelections(); // const row = selection[0].row; // const select = contractTree.nodes[row]; // console.log(select); // return !(select && select.level > 1 && !select.c_code); // } // }; // if (permission_edit) { // contractContextMenuOptions.items.pasteBlock = { // name: '粘贴整块', // icon: 'fa-clipboard', // disabled: function (key, opt) { // //const block = treeOperationObj.block || []; // const copyInfo = JSON.parse(getLocalCache(copyBlockTag)); // return !(copyInfo && copyInfo.block && copyInfo.block.length > 0); // }, // callback: function (key, opt) { // //const block = treeOperationObj.block || []; // const copyInfo = JSON.parse(getLocalCache(copyBlockTag)); // if (copyInfo.block.length > 0) { // contractTreeSpreadObj.pasteBlock(contractSpread, copyInfo); // } else { // document.execCommand('paste'); // } // }, // visible: function (key, opt) { // return permission_edit; // } // }; // contractContextMenuOptions.items.sprBlock = '----'; // } if (permission_edit) { contractContextMenuOptions.items.batchInsert = { name: '批量插入', type: 'batchInsert', value: '2', icon: 'fa-sign-in', batchInsert: function (obj, root) { if (_.toNumber(obj.value) > _.toNumber(obj.max)) { obj.value = obj.max; toastr.warning('批量插入不可多于' + obj.max); } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) { obj.value = obj.min; toastr.warning('批量插入不可少于' + obj.min); } else { contractTreeSpreadObj.baseOpr(contractSheet, 'add', parseInt(obj.value)); root.$menu.trigger('contextmenu:hide'); } }, disabled: function (key, opt) { const sheet = contractSheet; const selection = sheet.getSelections(); const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) return true; const first = sheet.zh_tree.nodes[row]; const valid = !sheet.zh_setting.readOnly; return !(valid && first && first.level > 1); } }; contractContextMenuOptions.items.sprTag = '----'; } contractContextMenuOptions.items.showLast = { name: '显示至最底层', callback: function (key, opt, menu, e) { const node = SpreadJsObj.getSelectObject(contractSheet); setTimeout(() => { showWaitingView(); contractTree.expandByCustom(x => { return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.contract_id + '-') >= 0); }); SpreadJsObj.refreshTreeRowVisible(contractSheet); closeWaitingView(); }, 100); }, }; $.contextMenu(contractContextMenuOptions); $('.bc-bar ul li a[data-toggle="tab"]').on('shown.bs.tab', function (e) { const node = SpreadJsObj.getSelectObject(contractSheet); $('a[href*="#cons-upfile"]').hide(); if (node && node.c_code) { if ($('.bc-bar .nav li .active').attr('href') === '#htfile' && permission_att) $('a[href*="#cons-upfile"]').show(); if (node.uid === user_id) contractTreeSpreadObj.changeContractTab(node, true); } }); $('#edit_contract_btn').on('click', function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (node && node.c_code && node.uid === user_id) { $('#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(''); continue; } else if (c === 'remark') { $('#htdetail_' + c).html(''); continue; } $('#htdetail_' + c).html(''); } } } }); $('#save_contract_btn').on('click', function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (node && node.c_code && node.uid === user_id) { const data = { id: node.id, }; for (const c of contractDetail) { if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) { if (c === 'sign_date') { data[c] = $('#htdetail_' + c + ' input').val() || null; continue; } else if (c === 'remark') { data[c] = $('#htdetail_' + c + ' textarea').val(); continue; } data[c] = $('#htdetail_' + c + ' input').val(); } } if (data.c_code === '' || data.name === '') { toastr.warning('合同编号和合同名称不能为空'); return; } if (data.total_price === '') { toastr.warning('合同金额不能为空'); return; } else if (!/^\d+(\.\d+)?$/.test(data.total_price)) { toastr.warning('合同金额只能输入数字'); return; } if (parseFloat(data.total_price) < node.yf_price) { const name = contract_type === contractConst.type.expenses ? '付' : '回'; toastr.warning('合同金额不能小于累计应' + name); return; } if (data.party_b === '') { toastr.warning('签订单位(乙方)不能为空'); return; } console.log(data); // 更新至服务器 postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) { toastr.success('已编辑成功'); const refreshNode = contractTree.loadPostData(result); console.log(refreshNode); contractTreeSpreadObj.refreshTree(contractSheet, refreshNode); const newNode = SpreadJsObj.getSelectObject(contractSheet); contractTreeSpreadObj.changeContractTab(newNode, true); }); } }); $('#cancel_contract_btn').on('click', function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (node && node.c_code && node.uid === user_id) { $('#edit_contract_btn').show(); $('#save_contract_btn').hide(); $('#cancel_contract_btn').hide(); for (const c of contractDetail) { if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) { if (c === 'sign_date') { $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : ''); } else { $('#htdetail_' + c).html(node[c]); } } } } }); $('#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 } }) const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.warning('请选择合同再上传文件'); return; } 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(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/file/upload`, formData, function (result) { contractTreeSpreadObj.setContractFiles(result, node.id); $('#file-modal').val(''); $('#file-cancel').click() }); } } }); $('body').on('click', '#htfile .file-del', function () { const node = SpreadJsObj.getSelectObject(contractSheet); const fid = $(this).data('id'); deleteAfterHint(function () { postData(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/file/delete`, { id: fid }, function (result) { contractTreeSpreadObj.setContractFiles(result, node.id); }); }, '确认删除该文件?'); }); $('body').on('click', '#htpay .pay-del', function () { const node = SpreadJsObj.getSelectObject(contractSheet); const cpid = $(this).data('id'); if (!node || !node.c_code) { toastr.warning('请选择合同节点'); return; } if (node.settle_code) { toastr.warning('已结算的合同不能删除合同' + contractConst.typeName[contract_type]); return; } deleteAfterHint(function () { postData(window.location.pathname + '/update', {postType: 'del-contract-pay', postData: { select: node.id, pay: cpid }}, function (result) { const refreshNode = contractTree.loadPostData(result.node); contractTreeSpreadObj.refreshTree(contractSheet, refreshNode); contractTreeSpreadObj.setContractPays(result.pays, node); }) }, '确认删除该合同' + contractConst.typeName[contract_type] + '?'); }); const payTime = $('#cons-addpay input[name="pay_time"]').datepicker().data('datepicker'); $('.datepicker-here').datepicker({ autoClose: true, }); $('#add_contract_pay_btn').on('click', function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); return; } $('#cons-addpay .modal-title').text('添加' + contractConst.typeName[contract_type]); $('#cons-addpay input[name="cpid"]').val(''); $('#add-contract-pay').show(); $('#save-contract-pay').hide(); setPayModalInfo(); $('#cons-addpay').modal('show'); }); $('body').on('click', '#htpay .pay-edit', function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); return; } const cpid = $(this).data('id'); const cpInfo = _.find(contractPays, { id: parseInt(cpid) }); if (!cpInfo) { toastr.error('未找到该合同' + contractConst.typeName[contract_type]); return } $('#cons-addpay .modal-title').text('编辑' + contractConst.typeName[contract_type]); $('#cons-addpay input[name="cpid"]').val(cpid); $('#add-contract-pay').hide(); $('#save-contract-pay').show(); setPayModalInfo(cpInfo); $('#cons-addpay').modal('show'); }); function setPayModalInfo(cpInfo = null) { $('#cons-addpay input[name="pay_time"]').val(cpInfo ? moment(cpInfo.pay_time).format('YYYY-MM-DD') : ''); payTime.selectDate(cpInfo ? new Date(cpInfo.pay_time) : ''); $('#cons-addpay input[name="pay_price"]').val(cpInfo ? cpInfo.pay_price : ''); $('#cons-addpay input[name="debit_price"]').val(cpInfo ? cpInfo.debit_price : ''); $('#cons-addpay input[name="yf_price"]').val(cpInfo ? cpInfo.yf_price : ''); $('#cons-addpay input[name="sf_price"]').val(cpInfo ? cpInfo.sf_price : ''); $('#cons-addpay select[name="pay_type"]').val(cpInfo ? cpInfo.pay_type : $('#cons-addpay select[name="pay_type"] option:first').text()); $('#cons-addpay textarea[name="remark"]').val(cpInfo ? cpInfo.remark : ''); $('#cons-addpay .yf-tips').text(''); $('#cons-addpay .sf-tips').text(''); } // 上传附件 $('#cons-pay-file input[type="file"]').change(function () { const files = Array.from(this.files); console.log(files); const valiData = files.map(v => { const ext = v.name.substring(v.name.lastIndexOf('.') + 1) return { size: v.size, ext } }) const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.warning('请选择合同再上传文件'); $('#cons-pay-file input[type="file"]').val(''); return; } const cpid = $('#cons-pay-file input[name="cpid"]').val(); const cpInfo = _.find(contractPays, { id: parseInt(cpid) }); if (!cpInfo) { toastr.warning('请选择合同'+ contractConst.typeName[contract_type] +'再上传文件'); $('#cons-pay-file input[type="file"]').val(''); return; } 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(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/pay/${cpInfo.id}/file/upload`, formData, function (result) { cpInfo.files = result; contractTreeSpreadObj.openContractPayFiles(cpInfo); $('#htpay-table tbody').find('tr[data-cpid="' + cpInfo.id + '"]').find('.files-num').text(result.length || ''); }); } } $('#cons-pay-file input[type="file"]').val(''); }); $('body').on('click', '#cons-pay-file .file-del', function () { const node = SpreadJsObj.getSelectObject(contractSheet); const cpid = $('#cons-pay-file input[name="cpid"]').val(); const cpInfo = _.find(contractPays, { id: parseInt(cpid) }); if (!cpInfo) { toastr.warning('未选择合同' + contractConst.typeName[contract_type]); return; } const fid = $(this).data('id'); deleteAfterHint(function () { postData(`${thisUrl}/${contractConst.typeMap[contract_type]}/${node.id}/pay/${cpInfo.id}/file/delete`, { id: fid }, function (result) { cpInfo.files = result; contractTreeSpreadObj.openContractPayFiles(cpInfo); $('#htpay-table tbody').find('tr[data-cpid="' + cpInfo.id + '"]').find('.files-num').text(result.length || ''); }); }, '确认删除该文件?'); }); postData(window.location.pathname + '/load', {}, function (result) { const datas = result.contractTree.concat(result.contractList); for (const t of datas) { if (!t.is_leaf && _.findIndex(datas, { contract_pid: t.contract_id }) === -1) { t.is_leaf = 1; } } contractTree.loadDatas(datas); treeCalc.calculateAll(contractTree); // contractTree.setExpanded(node, !node.expanded); // SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol); SpreadJsObj.loadSheetData(contractSheet, SpreadJsObj.DataType.Tree, contractTree); SpreadJsObj.loadTopAndSelect(contractSheet, ckBillsSpread); contractTreeSpreadObj.setContract(contractSheet); checkShowLast(result.contractTree.length); contractTreeSpreadObj.refreshOperationValid(contractSheet); // contractTreeSpreadObj.setAllForeColor(contractSheet); console.log(contractTree); }); if (is_admin) { const sqSpreadSetting = { cols: [ {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@', cellType: 'tree'}, {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 240, formatter: '@'}, ], emptyRows: 0, headRows: 2, headRowHeight: [25, 25], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', readOnly: true, rowHeader:[ // { // rowHeaderType: 'circle', // setting: { // size: 5, // indent: 16, // getColor: function (index, data) { // if (!data) return; // if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) { // return '#dc3545'; // } // if(data.lid != 0) return; // return '#007bff'; // } // }, // }, ], localCache: { key: 'contract-sq-spread', colWidth: true, } }; const sqSpread = SpreadJsObj.createNewSpread($('#sq-spread')[0]); const sqSheet = sqSpread.getActiveSheet(); // sjsSettingObj.setGridSelectStyle(sqSpreadSetting); sjsSettingObj.setFxTreeStyle(sqSpreadSetting, sjsSettingObj.FxTreeStyle.jz); SpreadJsObj.initSheet(sqSheet, sqSpreadSetting); const sqTreeSetting = { id: 'contract_id', pid: 'contract_pid', order: 'order', level: 'level', rootId: -1, keys: ['id', 'tid', 'spid'], autoExpand: 3, markExpandKey: 'contract-sq-bills-expand', markExpandSubKey: window.location.pathname.split('/')[2], }; sqTreeSetting.calcFun = function (node) { }; const sqTree = createNewPathTree('base', sqTreeSetting); const sqTreeSpreadObj = { setTreeAudits: function (sheet, selection) { const sel = selection ? selection[0] : sheet.getSelections()[0]; const row = sel ? sel.row : -1; const tree = sheet.zh_tree; if (!tree) { return; } const first = sheet.zh_tree.nodes[row]; const auditList = _.orderBy(_.filter(contractTreeAudits, { contract_id: first.contract_id }), ['create_time'], ['desc']); let auditHtml = ''; for (const audit of auditList) { audit.name = _.find(accountList, { id: audit.uid }).name; auditHtml += ` ${audit.name}${moment(new Date(audit.create_time)).format('YYYY-MM-DD HH:mm:ss')}${this.setAuditPermissionTxt(audit)} `; } $('#contract-tree-audits').html(auditHtml); }, setAuditPermissionTxt: function (audit) { const txt = []; const ca = _.find(contractAudits, { uid: audit.uid }); if (ca && ca.permission_edit) { txt.push('编辑节点'); } if (ca && ca.permission_add) { txt.push('添加合同'); } if (ca && ca.permission_show_unit) { txt.push('查看本单位合同'); } if (ca && ca.permission_show_node) { txt.push('查看本节点合同'); } if (ca && !ca.permission_show_unit && !ca.permission_show_node) { txt.push('查看本人合同'); } return txt.join(','); }, selectionChanged: function (e, info) { if (info.newSelections) { if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) { $('#select-permission-tree-audit-all').prop('checked', false); sqTreeSpreadObj.setTreeAudits(info.sheet); } } }, } sqSpread.bind(spreadNS.Events.SelectionChanged, sqTreeSpreadObj.selectionChanged); let contractAudits = []; let contractAccountGroup = []; $('#empower').on('shown.bs.modal', function () { postData(window.location.pathname + '/load', {}, function (result) { const tree = result.contractTree; for (const t of tree) { if (!t.is_leaf && _.findIndex(tree, { contract_pid: t.contract_id }) === -1) { t.is_leaf = 1; } } sqTree.loadDatas(tree); SpreadJsObj.loadSheetData(sqSheet, SpreadJsObj.DataType.Tree, sqTree); sqSpread.refresh(); contractAudits = result.contractAudits; contractAccountGroup = result.accountGroup; let groupBookListHtml = ''; result.accountGroup.forEach((group, idx) => { groupBookListHtml += '
'+ group.groupName +'
\n' + '
\n'; let groupListHtml = ''; group.groupList.forEach(item => { groupListHtml += '
\n' + '

'+ item.name + '' + item.mobile + '

\n' + ' '+ item.role +'\n' + '
\n'; }); groupBookListHtml = groupBookListHtml + groupListHtml + '
'; }); $('#empower .book-list').html(groupBookListHtml); sqTreeSpreadObj.setTreeAudits(sqSheet); }); }); let timer2 = null let oldSearchVal2 = null $('#gr-search2').bind('input propertychange', function (e) { oldSearchVal2 = e.target.value timer2 && clearTimeout(timer2) timer2 = setTimeout(() => { const newVal = $('#gr-search2').val() let html = '' if (newVal && newVal === oldSearchVal2) { contractAudits.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => { html += `

${item.name}${item.mobile || ''}

${item.role || ''}
` }) $('#empower .book-list').empty() $('#empower .book-list').append(html) } else { if (!$('#empower .acc-btn').length) { contractAccountGroup.forEach((group, idx) => { if (!group) return html += `
${group.groupName}
` group.groupList.forEach(item => { html += `

${item.name}${item.mobile || ''}

${item.role || ''}
` }); html += '
' }) $('#empower .book-list').empty() $('#empower .book-list').append(html) } } }, 400); }); // 添加到成员中 $('body').on('click', '#empower dl dd', function () { const id = parseInt($(this).data('id')); const node = SpreadJsObj.getSelectObject(sqSheet); if (!node) { toastr.error('请选择节点'); return; } if (!isNaN(id) && id !== 0) { if (_.findIndex(contractTreeAudits, { uid: id, contract_id: node.contract_id }) !== -1) { toastr.error('该成员已存在, 请勿重复添加'); return; } postData(window.location.pathname + '/update', {postType: 'add-tree-audit', postData: { select: node, auditId: id }}, function (result) { contractTreeAudits.push(result); sqTreeSpreadObj.setTreeAudits(sqSheet); }) } }); $('#select-permission-tree-audit-all').on('click', function () { $('#contract-tree-audits').find('input[type="checkbox"]').prop('checked', $(this).prop('checked')); }); $('#batch-del-audits').on('click', function () { let uids = []; $('#contract-tree-audits').find('input[type="checkbox"]:checked').each(function () { uids.push(parseInt($(this).parents('tr').data('id'))); }); if (uids.length === 0) { toastr.warning('请选择要移除的成员'); return; } deleteAfterHint(function () { postData(window.location.pathname + '/update', { postType: 'del-tree-audit', postData: { select: SpreadJsObj.getSelectObject(sqSheet), auditIds: uids, } }, function (result) { // contractTreeAudits数组清空再赋值 contractTreeAudits = result; sqTreeSpreadObj.setTreeAudits(sqSheet); }); }, '确认移除「当前节点已勾选授权用户」?'); }); $('body').on('click', '#empower .del-tree-audit', function () { const uid = parseInt($(this).parents('tr').data('id')); deleteAfterHint(function () { postData(window.location.pathname + '/update', { postType: 'del-tree-audit', postData: { select: SpreadJsObj.getSelectObject(sqSheet), auditIds: uid, } }, function (result) { // contractTreeAudits数组清空再赋值 contractTreeAudits = result; sqTreeSpreadObj.setTreeAudits(sqSheet); }); }, '确认移除「当前节点授权用户」?'); }); } if (permission_add) { $('#cons-add').on('show.bs.modal', function () { $('#cons-add input[name="code"]').val(''); $('#cons-add input[name="name"]').val(''); $('#cons-add input[name="total_price"]').val(''); $('#cons-add input[name="party_b"]').val(''); $('#cons-add textarea[name="remark"]').val(''); }); $('#add-contract').click(function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (!node) { toastr.error('请选择一个节点'); return; } console.log(node); const data = { code: $('#cons-add input[name="code"]').val(), name: $('#cons-add input[name="name"]').val(), total_price: $('#cons-add input[name="total_price"]').val(), party_b: $('#cons-add input[name="party_b"]').val(), remark: $('#cons-add textarea[name="remark"]').val(), } if (!data.code) { toastr.error('请输入合同编号'); return; } if (!data.name) { toastr.error('请输入合同名称'); return; } if (!data.total_price) { toastr.error('请输入合同金额'); return; } // 金额只能输入数字 if (!/^\d+(\.\d+)?$/.test(data.total_price)) { toastr.error('合同金额只能输入数字'); return; } if (!data.party_b) { toastr.error('请输入签订单位(乙方)'); return; } console.log(node, data); postData(window.location.pathname + '/update', {postType: 'add-contract', postData: { select: node, contract: data }}, function (result) { const refreshNode = contractTree.loadPostData(result); contractTreeSpreadObj.refreshTree(contractSheet, refreshNode); $('#cons-add').modal('hide'); }) }); } $('#cons-addpay input[type="number"]').change(function () { const name = $(this).attr('name'); const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); return; } if (node.uid !== user_id) { toastr.error('只能修改自己的合同' + contractConst.typeName[contract_type]); return; } if (node.settle_code) { toastr.error('该合同已结算,不能修改'); return; } let sf_price = $('#cons-addpay input[name="sf_price"]').val() || 0; const pay_price = $('#cons-addpay input[name="pay_price"]').val() || 0; const debit_price = $('#cons-addpay input[name="debit_price"]').val() || 0; const yf_price = ZhCalc.sub(pay_price, debit_price); $('#cons-addpay .yf-tips').text(''); const cpid = $('#cons-addpay input[name="cpid"]').val(); if (cpid) { const cpInfo = _.find(contractPays, { id: parseInt(cpid) }); const newNodePayPrice = ZhCalc.add(ZhCalc.sub(node.pay_price, cpInfo.pay_price), parseFloat(pay_price)); const newNodeDebitPrice = ZhCalc.add(ZhCalc.sub(node.debit_price, cpInfo.debit_price), parseFloat(debit_price)); const newNodeYfPrice = ZhCalc.sub(newNodePayPrice, newNodeDebitPrice); if (parseFloat(sf_price) > ZhCalc.add(cpInfo.sf_price, ZhCalc.sub(newNodeYfPrice, node.sf_price))) { $('#cons-addpay .sf-tips').text(' ≤ ' + ZhCalc.add(cpInfo.sf_price, ZhCalc.sub(newNodeYfPrice, node.sf_price))); } else { $('#cons-addpay .sf-tips').text(''); } if (parseFloat(yf_price) > ZhCalc.add(cpInfo.yf_price, ZhCalc.sub(node.total_price, node.yf_price))) { $('#cons-addpay .yf-tips').text(' ≤ ' + ZhCalc.add(cpInfo.yf_price, ZhCalc.sub(node.total_price, node.yf_price))); } else { $('#cons-addpay .yf-tips').text(''); } } else { if (name !== 'sf_price') { $('#cons-addpay input[name="sf_price"]').val(yf_price); sf_price = yf_price; } if (parseFloat(sf_price) > ZhCalc.sub(ZhCalc.add(node.yf_price, yf_price), node.sf_price)) { $('#cons-addpay .sf-tips').text(' ≤ ' + ZhCalc.sub(ZhCalc.add(node.yf_price, yf_price), node.sf_price)); } else { $('#cons-addpay .sf-tips').text(''); } if (parseFloat(yf_price) > ZhCalc.sub(node.total_price, node.yf_price)) { $('#cons-addpay .yf-tips').text(' ≤ ' + ZhCalc.sub(node.total_price, node.yf_price)); } else { $('#cons-addpay .yf-tips').text(''); } } if (name === 'pay_price' || name === 'debit_price') { $('#cons-addpay input[name="yf_price"]').val(yf_price); } }); $('#add-contract-pay').click(function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); return; } if (node.uid !== user_id) { toastr.error('只能添加自己的合同' + contractConst.typeName[contract_type]); return; } if (node.settle_code) { toastr.error('该合同已结算,不能添加'); return; } const data = { pay_time: $('#cons-addpay input[name="pay_time"]').val(), pay_price: $('#cons-addpay input[name="pay_price"]').val() || 0, debit_price: $('#cons-addpay input[name="debit_price"]').val() || 0, yf_price: $('#cons-addpay input[name="yf_price"]').val() || 0, sf_price: $('#cons-addpay input[name="sf_price"]').val() || 0, pay_type: $('#cons-addpay select[name="pay_type"]').val(), remark: $('#cons-addpay textarea[name="remark"]').val(), } const name = contract_type === contractConst.type.expenses ? '付' : '回'; if (!judgePays(node, data, name)) { return; } console.log(node, data); postData(window.location.pathname + '/update', {postType: 'add-contract-pay', postData: { select: node.id, pay: data }}, function (result) { const refreshNode = contractTree.loadPostData(result.node); contractTreeSpreadObj.refreshTree(contractSheet, refreshNode); contractTreeSpreadObj.setContractPays(result.pays, node); // const selection = contractSheet.getSelections(); // const sel = selection ? selection[0] : contractSheet.getSelections()[0]; // const row = sel ? sel.row : -1; // contractTreeSpreadObj.setForeColor(contractSheet, row); $('#cons-addpay').modal('hide'); }) }); $('#save-contract-pay').click(function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); return; } if (node.settle_code) { toastr.error('该合同已结算,不能修改'); return; } const cpid = $('#cons-addpay input[name="cpid"]').val(); const cpInfo = _.find(contractPays, { id: parseInt(cpid) }); if (!cpInfo) { toastr.error('未找到该合同' + contractConst.typeName[contract_type]); return } if (cpInfo.uid !== user_id) { toastr.error('只能编辑自己的合同' + contractConst.typeName[contract_type]); return; } const data = { id: cpInfo.id, pay_time: $('#cons-addpay input[name="pay_time"]').val(), pay_price: $('#cons-addpay input[name="pay_price"]').val() || 0, debit_price: $('#cons-addpay input[name="debit_price"]').val() || 0, yf_price: $('#cons-addpay input[name="yf_price"]').val() || 0, sf_price: $('#cons-addpay input[name="sf_price"]').val() || 0, pay_type: $('#cons-addpay select[name="pay_type"]').val(), remark: $('#cons-addpay textarea[name="remark"]').val(), } const name = contract_type === contractConst.type.expenses ? '付' : '回'; if (!judgePays(node, data, name, cpInfo)) { return; } console.log(node, data); postData(window.location.pathname + '/update', {postType: 'save-contract-pay', postData: { select: node.id, pay: data }}, function (result) { const refreshNode = contractTree.loadPostData(result.node); contractTreeSpreadObj.refreshTree(contractSheet, refreshNode); contractTreeSpreadObj.setContractPays(result.pays, node); // const selection = contractSheet.getSelections(); // const sel = selection ? selection[0] : contractSheet.getSelections()[0]; // const row = sel ? sel.row : -1; // contractTreeSpreadObj.setForeColor(contractSheet, row); $('#cons-addpay').modal('hide'); }) }); function judgePays(node, data, name, cpInfo = null) { let flag = true; if (!data.pay_time) { toastr.error('请输入'+ (name === '付' ? '支付' : '回款') +'日期'); return false; } if (!data.pay_price) { toastr.error('请输入'+ name +'款金额'); return false; } // 金额只能输入数字 if (!/^\d+(\.\d+)?$/.test(data.pay_price)) { toastr.error(name + '款金额只能输入数字'); return false; } if (data.debit_price && !/^\d+(\.\d+)?$/.test(data.debit_price)) { toastr.error('扣款金额只能输入数字'); return false; } if (parseFloat(data.debit_price) > parseFloat(data.pay_price)) { toastr.error('扣款金额不能大于'+ name +'款金额'); return false; } if (data.sf_price && !/^\d+(\.\d+)?$/.test(data.sf_price)) { toastr.error('实'+ name +'金额只能输入数字'); return false; } if (cpInfo) { const newNodePayPrice = ZhCalc.add(ZhCalc.sub(node.pay_price, cpInfo.pay_price), parseFloat(data.pay_price)); const newNodeDebitPrice = ZhCalc.add(ZhCalc.sub(node.debit_price, cpInfo.debit_price), parseFloat(data.debit_price)); const newNodeYfPrice = ZhCalc.sub(newNodePayPrice, newNodeDebitPrice); const newNodeSfPrice = ZhCalc.add(ZhCalc.sub(node.sf_price, cpInfo.sf_price), parseFloat(data.sf_price)); if (newNodeYfPrice > node.total_price) { toastr.error('累计应'+ name +'金额不能大于合同金额'); return false; } if (newNodeSfPrice > newNodeYfPrice) { toastr.error('累计实'+ name +'金额不能大于累计应'+ name +'金额'); return false; } } else { if (ZhCalc.add(parseFloat(data.yf_price), node.yf_price) > node.total_price) { toastr.error('累计应'+ name +'金额不能大于合同金额'); return false; } if (ZhCalc.add(parseFloat(data.sf_price), node.sf_price) > ZhCalc.add(parseFloat(data.yf_price), node.yf_price)) { toastr.error('累计实'+ name +'金额不能大于累计应'+ name +'金额'); return false; } } // if (parseFloat(data.sf_price) > parseFloat(data.yf_price)) { // toastr.error('实'+ name +'金额不能大于应'+ name +'金额'); // return false; // } if (!data.pay_type) { toastr.error('请选择' + contractConst.typeName[contract_type] + '方式'); return false; } return flag; } $('body').on('click', '.open-pay-files', function () { const cpid = $(this).attr('data-cpid'); if (!cpid) { toastr.error('获取合同'+ contractConst.typeName[contract_type] +'信息失败'); return; } const pay = _.find(contractPays, { id: parseInt(cpid) }); if (!pay) { toastr.error('获取合同'+ contractConst.typeName[contract_type] +'信息失败'); return; } const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); return; } if (node.uid !== user_id && !permission_att) { $('#cons-pay-file .upload-permission').hide(); } else { $('#cons-pay-file .upload-permission').show(); } $('#cons-pay-file').modal('show'); $('#cons-pay-file input[name="cpid"]').val(cpid); contractTreeSpreadObj.openContractPayFiles(pay); }); $('#cons-close').on('show.bs.modal', function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); $('#cons-close').modal('hide'); return; } const df_price = ZhCalc.sub(ZhCalc.sub(node.yf_price, node.sf_price) || 0); if (df_price !== 0) { $('#close_df_price').text(df_price); $('#close_df_price').parents('h5').show(); } else { $('#close_df_price').parents('h5').hide(); } $('#close_contract_code').text(node.c_code + '/' + node.name); $('#close_settle_code').val(''); }); $('#close_contract_btn').click(function () { const settle_code = $('#close_settle_code').val(); if (!settle_code) { toastr.error('请输入结算书编号'); return; } const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); return; } const data = { id: node.id, settle_code, } // 更新至服务器 postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) { const refreshNode = contractTree.loadPostData(result); contractTreeSpreadObj.refreshTree(contractSheet, refreshNode); const newNode = SpreadJsObj.getSelectObject(contractSheet); contractTreeSpreadObj.changeContractTab(newNode, true); // const selection = contractSheet.getSelections(); // const sel = selection ? selection[0] : contractSheet.getSelections()[0]; // const row = sel ? sel.row : -1; // contractTreeSpreadObj.setForeColor(contractSheet, row); $('#cons-close').modal('hide'); $('a[href*="#cons-unlock"]').show(); $('a[href*="#cons-close"]').hide(); }); }); $('#unlock_contract_btn').click(function () { const node = SpreadJsObj.getSelectObject(contractSheet); if (!node || !node.c_code) { toastr.error('请选择一个合同节点'); return; } const data = { id: node.id, settle_code: '', } // 更新至服务器 postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) { const refreshNode = contractTree.loadPostData(result); contractTreeSpreadObj.refreshTree(contractSheet, refreshNode); const newNode = SpreadJsObj.getSelectObject(contractSheet); contractTreeSpreadObj.changeContractTab(newNode, true); // const selection = contractSheet.getSelections(); // const sel = selection ? selection[0] : contractSheet.getSelections()[0]; // const row = sel ? sel.row : -1; // contractTreeSpreadObj.setForeColor(contractSheet, row); $('#cons-unlock').modal('hide'); $('a[href*="#cons-unlock"]').hide(); $('a[href*="#cons-close"]').show(); }); }); // 显示层次 (function (select, sheet) { $(select).click(function () { if (!sheet.zh_tree) return; const tag = $(this).attr('tag'); const tree = sheet.zh_tree; setTimeout(() => { showWaitingView(); switch (tag) { case "1": case "2": case "3": case "4": case "5": tree.expandByLevel(parseInt(tag)); SpreadJsObj.refreshTreeRowVisible(sheet); break; case "last": tree.expandByCustom(() => { return true; }); SpreadJsObj.refreshTreeRowVisible(sheet); break; case "leafXmj": tree.expandToLeafXmj(); SpreadJsObj.refreshTreeRowVisible(sheet); break; } closeWaitingView(); }, 100); }); })('a[name=showLevel]', contractSheet); $.divResizer({ select: '#contract-resize', callback: function () { contractSpread.refresh(); let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0; $(".sp-wrap").height(bcontent-30); // posSpread.refresh(); } }); $.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(); contractSpread.refresh(); } }); }); /** * 校验文件大小、格式 * @param {Array} files 文件数组 */ function validateFiles(files) { if (files.length > 10) { toastr.error('至多同时上传10个文件'); return false } return files.every(file => { if (file.size > 1024 * 1024 * 50) { toastr.error('文件大小限制为50MB'); return false } if (whiteList.indexOf('.' + file.ext.toLowerCase()) === -1) { toastr.error('请上传正确的格式文件'); return false } return true }) }