contract_detail.js 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  1. const copyBlockTag = 'zh.calc.copyBlock';
  2. $(document).ready(function() {
  3. const ckBillsSpread = '/contract/' + window.location.pathname.split('/')[2] + '/' + contractConst.typeMap[contract_type] + '/detail/contract-billsSelect';
  4. autoFlashHeight();
  5. const contractSpreadSetting = {
  6. cols: [
  7. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@', readOnly: 'readOnly.code', cellType: 'tree'},
  8. {title: '合同编号', colSpan: '1', rowSpan: '2', field: 'c_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  9. {title: '项目名称/合同名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 240, formatter: '@', readOnly: 'readOnly.code', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-1'},
  10. {title: '创建人', colSpan: '1', rowSpan: '2', field: 'username', hAlign: 1, width: 80, formatter: '@', readOnly: true},
  11. {title: '合同金额', colSpan: '1', rowSpan: '2', field: 'total_price', hAlign: 2, width: 120, formatter: '@', readOnly: true},
  12. ],
  13. emptyRows: 0,
  14. headRows: 2,
  15. headRowHeight: [25, 25],
  16. defaultRowHeight: 21,
  17. headerFont: '12px 微软雅黑',
  18. font: '12px 微软雅黑',
  19. // readOnly: readOnly,
  20. rowHeader:[
  21. {
  22. rowHeaderType: 'circle',
  23. setting: {
  24. size: 5,
  25. indent: 16,
  26. getColor: function (index, data) {
  27. if (!data) return;
  28. if (is_admin) return;
  29. if (_.findIndex(contractTreeAudits, { contract_id: data.contract_id, uid: user_id }) !== -1) {
  30. return '#dc3545';
  31. }
  32. }
  33. },
  34. },
  35. ],
  36. localCache: {
  37. key: 'contract-spread',
  38. colWidth: true,
  39. },
  40. };
  41. const contractCol = {
  42. getValue: {
  43. status: function (data) {
  44. return data.c_code ? (data.settle_code ? '● 已结算' : data.yf_price < data.total_price ? '● 履行中' : '● 已完成') : '';
  45. }
  46. },
  47. foreColor: {
  48. status: function (data) {
  49. return data.c_code ? (data.settle_code ? '#6c757d' : data.yf_price < data.total_price ? '#da9500' : '#28a745') : '';
  50. }
  51. },
  52. readOnly: {
  53. code: function (data) {
  54. return !permission_edit || data.c_code;
  55. }
  56. }
  57. }
  58. const getStackedBarTip = function (data) {
  59. return data.stackedBarTips ? data.stackedBarTips.join('\n') : '';
  60. };
  61. if (contract_type === contractConst.type.expenses) {
  62. contractSpreadSetting.cols.push({title: '累计应付', colSpan: '1', rowSpan: '2', field: 'yf_price', hAlign: 2, width: 120, formatter: '@', readOnly: true});
  63. 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});
  64. } else if (contract_type === contractConst.type.income) {
  65. contractSpreadSetting.cols.push({title: '累计应回', colSpan: '1', rowSpan: '2', field: 'yf_price', hAlign: 2, width: 120, formatter: '@', readOnly: true});
  66. 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});
  67. }
  68. contractSpreadSetting.cols.push({title: '合同状态', colSpan: '1', rowSpan: '2', field: 'status', hAlign: 1, width: 100, formatter: '@', readOnly: true, getValue:'getValue.status', foreColor:'foreColor.status'});
  69. contractSpreadSetting.cols.push({title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.code', cellType: 'ellipsisAutoTip', scrollHeightClass: '.sjs-height-1'});
  70. const contractSpread = SpreadJsObj.createNewSpread($('#contract-spread')[0]);
  71. const contractSheet = contractSpread.getActiveSheet();
  72. // sjsSettingObj.setGridSelectStyle(contractSpreadSetting);
  73. sjsSettingObj.setFxTreeStyle(contractSpreadSetting, sjsSettingObj.FxTreeStyle.contract);
  74. SpreadJsObj.initSpreadSettingEvents(contractSpreadSetting, contractCol);
  75. SpreadJsObj.initSheet(contractSheet, contractSpreadSetting);
  76. const treeSetting = {
  77. id: 'contract_id',
  78. pid: 'contract_pid',
  79. order: 'order',
  80. level: 'level',
  81. rootId: -1,
  82. keys: ['id', 'tid', 'spid', 'contract_type'],
  83. calcFields: ['pay_price', 'total_price', 'sf_price', 'debit_price', 'yf_price'],
  84. autoExpand: 3,
  85. markExpandKey: 'contract-bills-expand' + window.location.pathname.split('/')[2] + contractConst.typeMap[contract_type],
  86. markExpandSubKey: window.location.pathname.split('/')[2] + contractConst.typeMap[contract_type],
  87. };
  88. const calcField = ['total_price', 'yf_price'];
  89. const calcFieldColor = {'total_price': '#bbb', 'yf_price': '#28a745'};
  90. const calcFieldCaption = {'total_price': '合同金额', 'yf_price': contract_type === contractConst.type.expenses ? '累计应付' : '累计应回'};
  91. treeSetting.calcFun = function (node) {
  92. if (node && node.c_code) {
  93. const base = node.total_price;
  94. node.stackedBar = [];
  95. node.stackedBarTips = [];
  96. for (const cf of calcField) {
  97. node.stackedBar.push({ color: calcFieldColor[cf], percent: ZhCalc.div(node[cf], base), field: cf });
  98. node.stackedBarTips.push(`${calcFieldCaption[cf]}: ${node[cf] || 0}`);
  99. }
  100. }
  101. };
  102. const contractTree = createNewPathTree('revise', treeSetting);
  103. 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'];
  104. // 清单 相关方法&绑定spreadjs事件
  105. const contractTreeSpreadObj = {
  106. getDefaultSelectInfo: function (sheet) {
  107. const tree = sheet.zh_tree;
  108. if (!tree) return;
  109. const sel = sheet.getSelections()[0];
  110. const node = sheet.zh_tree.nodes[sel.row];
  111. if (!node) return;
  112. let count = 1;
  113. if (sel.rowCount > 1) {
  114. for (let r = 1; r < sel.rowCount; r++) {
  115. const rNode = sheet.zh_tree.nodes[sel.row + r];
  116. if (rNode.level > node.level) continue;
  117. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.contract_pid !== node.contract_pid)) {
  118. toastr.warning('请选择同一节点下的节点,进行该操作');
  119. return;
  120. }
  121. count += 1;
  122. }
  123. }
  124. return [tree, node, count];
  125. },
  126. /**
  127. * 刷新顶部按钮是否可用
  128. * @param sheet
  129. * @param selections
  130. */
  131. refreshOperationValid: function (sheet, selection) {
  132. const setObjEnable = function (obj, enable) {
  133. if (enable) {
  134. obj.removeClass('disabled');
  135. } else {
  136. obj.addClass('disabled');
  137. }
  138. };
  139. const invalidAll = function () {
  140. setObjEnable($('a[name=base-opr][type=add]'), false);
  141. setObjEnable($('a[name=base-opr][type=add-child]'), false);
  142. setObjEnable($('a[name=base-opr][type=delete]'), false);
  143. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  144. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  145. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  146. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  147. };
  148. const sel = selection ? selection[0] : sheet.getSelections()[0];
  149. const row = sel ? sel.row : -1;
  150. const tree = sheet.zh_tree;
  151. if (!tree) {
  152. invalidAll();
  153. return;
  154. }
  155. const first = sheet.zh_tree.nodes[row];
  156. if (first && permission_add && (is_admin || _.findIndex(contractTreeAudits, { uid: user_id }) === -1 || _.findIndex(contractTreeAudits, { contract_id: first.contract_id, uid: user_id }) !== -1)) {
  157. $('#add-cons-btn').show();
  158. } else {
  159. $('#add-cons-btn').hide();
  160. }
  161. if (!first) {
  162. invalidAll();
  163. return;
  164. }
  165. let last = first, sameParent = true, childCanDel = true, hadContract = this.checkContract(first);
  166. if (sel.rowCount > 1 && first) {
  167. for (let r = 1; r < sel.rowCount; r++) {
  168. const rNode = tree.nodes[sel.row + r];
  169. childCanDel = this.checkDelete(rNode, childCanDel);
  170. if (!hadContract) hadContract = this.checkContract(rNode);
  171. if (!rNode) {
  172. sameParent = false;
  173. break;
  174. }
  175. if (rNode.level > first.level) continue;
  176. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.contract_pid !== first.contract_pid)) {
  177. sameParent = false;
  178. break;
  179. }
  180. last = rNode;
  181. }
  182. }
  183. const preNode = tree.getPreSiblingNode(first);
  184. // if (!hadContract && preNode) hadContract = preNode.c_code !== undefined;
  185. // const siblings = tree.getChildren(tree.getParent(first));
  186. let upPower = true;
  187. // for (let order = last.order; order < siblings.length - 1; order ++) {
  188. // if (!siblings[order].formc) {
  189. // upPower = false;
  190. // break;
  191. // }
  192. // }
  193. const valid = !sheet.zh_setting.readOnly;
  194. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1);
  195. setObjEnable($('a[name=base-opr][type=add-child]'), valid && first && !first.c_code && first.level >= 1);
  196. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && childCanDel && this.checkDelete(first));
  197. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
  198. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  199. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first)
  200. && first.level > 2 && tree.isLastSibling(last) && upPower && !hadContract);
  201. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  202. && first.level > 1 && preNode && (preNode.children.length > 0 || preNode.children.length === 0) && !hadContract && preNode.c_code === undefined);
  203. // setObjEnable($('#cut'), valid);
  204. // setObjEnable($('#paste'), valid);
  205. },
  206. /**
  207. *
  208. * @param sheet
  209. * @param data
  210. */
  211. refreshTree: function (sheet, data) {
  212. SpreadJsObj.massOperationSheet(sheet, function () {
  213. const tree = sheet.zh_tree;
  214. // 处理删除
  215. if (data.delete) {
  216. data.delete.sort(function (a, b) {
  217. return b.deleteIndex - a.deleteIndex;
  218. });
  219. for (const d of data.delete) {
  220. sheet.deleteRows(d.deleteIndex, 1);
  221. }
  222. }
  223. // 处理新增
  224. if (data.create) {
  225. const newNodes = data.create;
  226. if (newNodes) {
  227. newNodes.sort(function (a, b) {
  228. return a.index - b.index;
  229. });
  230. for (const node of newNodes) {
  231. sheet.addRows(node.index, 1);
  232. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  233. }
  234. }
  235. }
  236. // 处理更新
  237. if (data.update) {
  238. const rows = [];
  239. for (const u of data.update) {
  240. rows.push(tree.nodes.indexOf(u));
  241. }
  242. SpreadJsObj.reLoadRowsData(sheet, rows);
  243. }
  244. // 处理展开
  245. if (data.expand) {
  246. const expanded = [];
  247. for (const e of data.expand) {
  248. if (expanded.indexOf(e) === -1) {
  249. const posterity = tree.getPosterity(e);
  250. for (const p of posterity) {
  251. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  252. expanded.push(p);
  253. }
  254. }
  255. }
  256. }
  257. });
  258. },
  259. changeContractTab: function (node, need = false) {
  260. if ($('.bc-bar .nav li .active').attr('href') === '#htdetail') {
  261. if (node.settle_code) {
  262. $('#edit_contract_btn').hide();
  263. } else {
  264. $('#edit_contract_btn').show();
  265. }
  266. $('#save_contract_btn').hide();
  267. $('#cancel_contract_btn').hide();
  268. $('#add_contract_pay_btn').hide();
  269. $('a[href*="#cons-upfile"]').hide();
  270. if (need) {
  271. for (const c of contractDetail) {
  272. if (c === 'create_time') {
  273. $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD HH:mm:ss') : '');
  274. continue;
  275. } else if (c === 'sign_date') {
  276. $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : '');
  277. continue;
  278. }
  279. $('#htdetail_' + c).text(node[c] || '');
  280. }
  281. $('#htdetail_df_price').text(ZhCalc.sub(node.yf_price, node.sf_price) || '');
  282. }
  283. } else if ($('.bc-bar .nav li .active').attr('href') === '#htpay') {
  284. $('#edit_contract_btn').hide();
  285. $('#save_contract_btn').hide();
  286. $('#cancel_contract_btn').hide();
  287. if (node.settle_code) {
  288. $('#add_contract_pay_btn').hide();
  289. if (need) {
  290. $('#htpay-table tbody').find('.pay-edit').hide();
  291. $('#htpay-table tbody').find('.pay-del').hide();
  292. }
  293. } else {
  294. $('#add_contract_pay_btn').show();
  295. if (need && contractPays && contractPays.length > 0) {
  296. for (const [i, cp] of contractPays.entries()) {
  297. if (cp.uid === user_id) {
  298. $('#htpay-table tbody tr').eq(i).find('.pay-edit').show();
  299. $('#htpay-table tbody tr').eq(i).find('.pay-del').show();
  300. }
  301. }
  302. }
  303. }
  304. $('a[href*="#cons-upfile"]').hide();
  305. } else if ($('.bc-bar .nav li .active').attr('href') === '#htfile') {
  306. $('#edit_contract_btn').hide();
  307. $('#save_contract_btn').hide();
  308. $('#cancel_contract_btn').hide();
  309. $('#add_contract_pay_btn').hide();
  310. $('a[href*="#cons-upfile"]').show();
  311. }
  312. },
  313. openContractPayFiles: function (pay) {
  314. this.setContractFiles(pay.files, pay.cid, pay.id, '#cons-pay-file table tbody');
  315. },
  316. setContractFiles: function (files, cid, cpid = null, _this = '#htfile-table tbody') {
  317. let filesHtml = '';
  318. const newFiles = files.map(file => {
  319. let showDel = false;
  320. if (file.uid === user_id) {
  321. showDel = true
  322. }
  323. return {...file, showDel}
  324. })
  325. newFiles.forEach((file, idx) => {
  326. filesHtml += `<tr class="text-center">
  327. <td>${idx + 1}</td><td class="text-left"><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>
  328. <td>
  329. <div class="btn-group-table">
  330. ${file.viewpath ? `<a href="${file.viewpath}" target="_blank" class="mr-1"><i class="fa fa-eye fa-fw"></i></a>` : ''}
  331. <a href="/contract/${stid}/detail/${contractConst.typeMap[contract_type]}/${cid}${cpid ? '/pay/' + cpid : ''}/file/${file.id}/download" class="mr-1"><i class="fa fa-download fa-fw"></i></a>
  332. ${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>` : ''}
  333. </div>
  334. </td>
  335. </tr>`;
  336. });
  337. $(_this).html(filesHtml);
  338. },
  339. setContractPays: function (pays, node) {
  340. contractPays = pays;
  341. let paysHtml = '';
  342. const newPays = pays.map(pay => {
  343. let showEdit = false;
  344. if (pay.uid === user_id && !node.settle_code) {
  345. showEdit = true
  346. }
  347. return {...pay, showEdit}
  348. })
  349. console.log(pays);
  350. newPays.forEach((pay, idx) => {
  351. paysHtml += `<tr class="text-center" data-cpid="${pay.id}">
  352. <td>${idx + 1}</td>
  353. <td>${moment(pay.pay_time).format('YYYY-MM-DD')}</td>
  354. <td>${pay.pay_price}</td>
  355. <td>${pay.debit_price}</td>
  356. <td>${pay.yf_price}</td>
  357. <td>${pay.sf_price}</td>
  358. <td>${pay.pay_type}</td>
  359. <td>${pay.username}</td>
  360. <td>${moment(pay.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>
  361. <td>${pay.remark}</td>
  362. <td><a href="javascript:void(0);" class="text-primary open-pay-files" data-cpid="${pay.id}"><i class="fa fa-paperclip fa-rotate-90"></i></a> <span class="files-num">${pay.files.length > 0 ? pay.files.length : ''}</span></td>
  363. <td><a href="javascript:void(0);" class="text-primary pay-edit" data-id="${pay.id}" ${ !pay.showEdit ? `style="display:none"` : ''}>编辑</a> <a href="javascript:void(0);" class="text-danger pay-del" data-id="${pay.id}" ${ !pay.showEdit ? `style="display:none"` : ''}>删除</a></td>
  364. </tr>`;
  365. });
  366. $('#htpay-table tbody').html(paysHtml);
  367. },
  368. setContract: function (sheet) {
  369. const node = SpreadJsObj.getSelectObject(sheet);
  370. if (node && node.c_code) {
  371. $('#htdetail-table').show();
  372. $('#htpay-table').show();
  373. $('#htfile-table').show();
  374. for (const c of contractDetail) {
  375. if (c === 'create_time') {
  376. $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD HH:mm:ss') : '');
  377. continue;
  378. } else if (c === 'sign_date') {
  379. $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : '');
  380. continue;
  381. }
  382. $('#htdetail_' + c).text(node[c] || '');
  383. }
  384. $('#htdetail_df_price').text(ZhCalc.sub(node.yf_price, node.sf_price) || '');
  385. postData(window.location.pathname + '/update', {postType: 'get-contract', postData: node.id}, function (result) {
  386. contractTreeSpreadObj.setContractPays(result.pays, node);
  387. contractTreeSpreadObj.setContractFiles(result.files, node.id);
  388. });
  389. if (node.uid === user_id) {
  390. if (node.settle_code) {
  391. $('a[href*="#cons-unlock"]').show();
  392. $('a[href*="#cons-close"]').hide();
  393. } else {
  394. $('a[href*="#cons-unlock"]').hide();
  395. $('a[href*="#cons-close"]').show();
  396. }
  397. contractTreeSpreadObj.changeContractTab(node);
  398. } else {
  399. $('#edit_contract_btn').hide();
  400. $('#save_contract_btn').hide();
  401. $('#cancel_contract_btn').hide();
  402. $('a[href*="#cons-unlock"]').hide();
  403. $('a[href*="#cons-close"]').hide();
  404. $('a[href*="#cons-upfile"]').hide();
  405. $('#add_contract_pay_btn').hide();
  406. }
  407. } else {
  408. $('#htdetail-table').hide();
  409. $('#htpay-table').hide();
  410. $('#htfile-table').hide();
  411. $('#edit_contract_btn').hide();
  412. $('#save_contract_btn').hide();
  413. $('#cancel_contract_btn').hide();
  414. $('a[href*="#cons-unlock"]').hide();
  415. $('a[href*="#cons-close"]').hide();
  416. $('a[href*="#cons-upfile"]').hide();
  417. $('#add_contract_pay_btn').hide();
  418. }
  419. },
  420. selectionChanged: function (e, info) {
  421. if (info.newSelections) {
  422. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  423. contractTreeSpreadObj.refreshOperationValid(info.sheet);
  424. contractTreeSpreadObj.setContract(info.sheet);
  425. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  426. }
  427. } else {
  428. $('#add-cons-btn').hide();
  429. }
  430. },
  431. /**
  432. * 新增节点
  433. * @param spread
  434. */
  435. baseOpr: function (sheet, type, addCount = 1) {
  436. const self = this;
  437. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  438. if (!tree || !node || !count) return;
  439. // if (type === 'delete') {
  440. // const parent = tree.getParent(node);
  441. // const children = parent ? parent.children : tree.children;
  442. // const index = children.indexOf(node);
  443. // for (let i = 0; i < count; i++) {
  444. // const child = children[i+index];
  445. // if (tree.checkNodeUsed(child, pos)) {
  446. // toastr.warning('选中的节点已计量,不可删除');
  447. // return;
  448. // }
  449. // }
  450. // } else if (type === 'up-level') {
  451. // const parent = tree.getParent(node);
  452. // const children = parent ? parent.children : tree.children;
  453. // const index = children.indexOf(node);
  454. // const lastSelect = children[index + count - 1];
  455. // // if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  456. // // toastr.warning('选中的节点已计量,不可升级');
  457. // // return;
  458. // // }
  459. // } else if (type === 'down-level') {
  460. // const parent = tree.getParent(node);
  461. // const children = parent ? parent.children : tree.children;
  462. // const index = children.indexOf(node);
  463. // if (index > 0 && children[index-1].used) {
  464. // toastr.warning('其前节点已计量,选中的节点不可降级');
  465. // return;
  466. // }
  467. // for (let i = index; i < count; i++) {
  468. // const child = children[i+index];
  469. // if (tree.checkNodeUsed(child, pos)) {
  470. // toastr.warning('选中的节点已计量,不可降级');
  471. // return;
  472. // }
  473. // }
  474. // }
  475. if (type === 'delete') {
  476. deleteAfterHint(function () {
  477. postData(window.location.pathname + '/update', {
  478. postType: type,
  479. postData: {
  480. id: node.contract_id,
  481. count: type === 'add' ? addCount : count,
  482. }
  483. }, function (result) {
  484. const refreshData = tree.loadPostData(result);
  485. self.refreshTree(sheet, refreshData);
  486. const sel = sheet.getSelections()[0];
  487. if (sel) {
  488. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  489. }
  490. self.refreshOperationValid(sheet);
  491. });
  492. }, '确认删除「当前合同或节点及子项」?');
  493. } else {
  494. postData(window.location.pathname + '/update', {
  495. postType: type,
  496. postData: {
  497. id: node.contract_id,
  498. count: type === 'add' ? addCount : count,
  499. }
  500. }, function (result) {
  501. const refreshData = tree.loadPostData(result);
  502. self.refreshTree(sheet, refreshData);
  503. if (['up-move', 'down-move'].indexOf(type) > -1) {
  504. const sel = sheet.getSelections()[0];
  505. if (sel) {
  506. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  507. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  508. }
  509. } else if (type === 'add' || type === 'add-child') {
  510. const sel = sheet.getSelections()[0];
  511. if (sel) {
  512. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  513. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  514. }
  515. }
  516. self.refreshOperationValid(sheet);
  517. });
  518. }
  519. },
  520. /**
  521. * 编辑单元格响应事件
  522. * @param {Object} e
  523. * @param {Object} info
  524. */
  525. editEnded: function (e, info) {
  526. if (info.sheet.zh_setting) {
  527. const col = info.sheet.zh_setting.cols[info.col];
  528. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  529. const node = sortData[info.row];
  530. const data = {
  531. id: node.id,
  532. };
  533. // 未改变值则不提交
  534. const orgValue = node[col.field];
  535. const newValue = trimInvalidChar(info.editingText);
  536. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  537. return;
  538. }
  539. // 获取更新数据
  540. if (info.editingText) {
  541. const text = newValue;
  542. data[col.field] = text;
  543. } else {
  544. data[col.field] = null;
  545. }
  546. console.log(data);
  547. // 更新至服务器
  548. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  549. const refreshNode = contractTree.loadPostData(result);
  550. contractTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  551. });
  552. }
  553. },
  554. clipboardPasting: function (e, info) {
  555. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  556. info.cancel = true;
  557. if (!setting || !tree) return;
  558. const pasteData = info.pasteData.html
  559. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  560. : (info.pasteData.text === ''
  561. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  562. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  563. const datas = [], filterNodes = [];
  564. let level, filterRow = 0;
  565. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  566. const curRow = info.cellRange.row + iRow;
  567. const node = tree.nodes[curRow];
  568. if (!node) continue;
  569. if (!level) level = node.level;
  570. if (node.level < level) break;
  571. let bPaste = false;
  572. const data = info.sheet.zh_tree.getNodeKeyData(node);
  573. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  574. const curCol = info.cellRange.col + iCol;
  575. const colSetting = info.sheet.zh_setting.cols[curCol];
  576. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  577. data[colSetting.field] = value;
  578. bPaste = true;
  579. }
  580. if (bPaste) {
  581. datas.push(data);
  582. } else {
  583. filterNodes.push(node);
  584. }
  585. }
  586. if (datas.length > 0) {
  587. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  588. const refreshNode = tree.loadPostData(result);
  589. if (refreshNode.update) {
  590. refreshNode.update = refreshNode.update.concat(filterNodes);
  591. }
  592. contractTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  593. }, function () {
  594. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  595. });
  596. } else {
  597. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  598. }
  599. },
  600. clipboardPasted: function (e, info) {
  601. const tree = info.sheet.zh_tree;
  602. if (!tree) { return; }
  603. const sortData = info.sheet.zh_tree.nodes;
  604. const datas = [], filterNodes = [];
  605. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  606. let bPaste = false;
  607. const curRow = info.cellRange.row + iRow;
  608. const node = sortData[curRow];
  609. if (node) {
  610. const data = info.sheet.zh_tree.getNodeKeyData(node);
  611. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  612. const curCol = info.cellRange.col + iCol;
  613. const colSetting = info.sheet.zh_setting.cols[curCol];
  614. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  615. data[colSetting.field] = value;
  616. bPaste = true;
  617. }
  618. if (bPaste) {
  619. datas.push(data);
  620. } else {
  621. filterNodes.push(node);
  622. }
  623. }
  624. }
  625. if (datas.length > 0) {
  626. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  627. const refreshNode = tree.loadPostData(result);
  628. if (refreshNode.update) {
  629. refreshNode.update = refreshNode.update.concat(filterNodes);
  630. }
  631. contractTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  632. }, function () {
  633. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  634. });
  635. } else {
  636. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  637. }
  638. },
  639. deletePress: function (sheet) {
  640. if (!sheet.zh_setting) return;
  641. const sel = sheet.getSelections()[0], datas = [];
  642. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  643. let bDel = false;
  644. const node = sheet.zh_tree.nodes[iRow];
  645. const data = sheet.zh_tree.getNodeKeyData(node);
  646. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  647. const col = sheet.zh_setting.cols[iCol];
  648. const style = sheet.getStyle(iRow, iCol);
  649. if (style.locked) continue;
  650. data[col.field] = null;
  651. bDel = true;
  652. }
  653. if (bDel) datas.push(data);
  654. }
  655. if (datas.length > 0) {
  656. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  657. const refreshNode = sheet.zh_tree.loadPostData(result);
  658. contractTreeSpreadObj.refreshTree(sheet, refreshNode);
  659. });
  660. }
  661. },
  662. pasteBlock: function (spread, copyInfo) {
  663. const self = this;
  664. const sheet = spread.getActiveSheet();
  665. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  666. postData(window.location.pathname + '/update', {
  667. postType: 'paste-block',
  668. postData: {
  669. id: tree.getNodeKey(node),
  670. // tid: copyInfo.tid,
  671. block: copyInfo.block,
  672. }
  673. }, function (data) {
  674. const result = tree.loadPostData(data.ledger);
  675. self.refreshTree(sheet, result);
  676. const sel = sheet.getSelections()[0];
  677. if (sel) {
  678. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  679. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  680. }
  681. self.refreshOperationValid(sheet);
  682. removeLocalCache(copyBlockTag);
  683. }, null, true);
  684. },
  685. topRowChanged: function (e, info) {
  686. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  687. },
  688. editStarting(e, info) {
  689. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  690. const col = info.sheet.zh_setting.cols[info.col];
  691. const node = info.sheet.zh_tree.nodes[info.row];
  692. if (!node) {
  693. info.cancel = true;
  694. return;
  695. }
  696. },
  697. cut: function (sheet, sel, callback) {
  698. if (!sheet || !sel) return;
  699. if (sel.colCount >= sheet.zh_setting.cols.length) {
  700. toastr.warning('请勿选中整行剪切');
  701. return;
  702. }
  703. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  704. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  705. const node = sortData[iRow];
  706. if (node) {
  707. const data = sheet.zh_tree.getNodeKeyData(node);
  708. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  709. const style = sheet.getStyle(iRow, iCol);
  710. if (style.locked) {
  711. toastr.error('不可剪切');
  712. return;
  713. }
  714. const colSetting = sheet.zh_setting.cols[iCol];
  715. data[colSetting.field] = null;
  716. }
  717. datas.push(data);
  718. }
  719. }
  720. if (datas.length > 0) {
  721. callback();
  722. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  723. const refreshNode = sheet.zh_tree.loadPostData(result);
  724. contractTreeSpreadObj.refreshTree(sheet, refreshNode);
  725. });
  726. }
  727. },
  728. sortCode: function (sheet) {
  729. const tree = sheet.zh_tree;
  730. if (!tree) return;
  731. const select = SpreadJsObj.getSelectObject(sheet);
  732. if (!select || !select.code || select.code === '') return;
  733. const recursiveSortCode = function (data, parentCode, children) {
  734. if (!children || children.length === 0) return;
  735. for (const [i, child] of children.entries()) {
  736. if (!child.b_code || child.b_code === '') {
  737. const code = parentCode + '-' + (i + 1);
  738. const cData = tree.getNodeKeyData(child);
  739. cData.code = code;
  740. data.push(cData);
  741. if (!tree.isLeafXmj(child)) {
  742. recursiveSortCode(data, code, child.children);
  743. }
  744. }
  745. }
  746. };
  747. const data = [];
  748. recursiveSortCode(data, select.code, select.children);
  749. if (data.length > 0) {
  750. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  751. const refreshNode = tree.loadPostData(result);
  752. contractTreeSpreadObj.refreshTree(sheet, refreshNode);
  753. })
  754. }
  755. },
  756. checkContract: function (select) {
  757. let haveContract = false;
  758. if (select.c_code) {
  759. haveContract = true;
  760. } else {
  761. const selects = contractSheet.zh_tree.getPosterity(select);
  762. const select_contracts = _.filter(selects, function (item) {
  763. return item.c_code;
  764. });
  765. if (select_contracts.length > 0) haveContract = true;
  766. }
  767. return haveContract;
  768. },
  769. checkDelete: function (select, oldFlag = true) {
  770. let canDelete = oldFlag;
  771. if (select.c_code) {
  772. if (!(select.uid === user_id || is_admin)) {
  773. canDelete = false;
  774. } else if (select.exist_pay) {
  775. canDelete = false;
  776. }
  777. } else {
  778. const selects = contractSheet.zh_tree.getPosterity(select);
  779. const select_contracts = _.filter(selects, function (item) {
  780. return item.c_code;
  781. });
  782. if (select_contracts.length > 0) {
  783. for (const sc of select_contracts) {
  784. if (!(sc.uid === user_id || is_admin)) {
  785. canDelete = false;
  786. break;
  787. } else if (sc.exist_pay) {
  788. canDelete = false;
  789. break;
  790. }
  791. }
  792. }
  793. }
  794. return canDelete;
  795. }
  796. };
  797. contractSpread.bind(spreadNS.Events.SelectionChanged, contractTreeSpreadObj.selectionChanged);
  798. contractSpread.bind(spreadNS.Events.topRowChanged, contractTreeSpreadObj.topRowChanged);
  799. // 右键菜单
  800. let batchInsertObj;
  801. $.contextMenu.types.batchInsert = function (item, opt, root) {
  802. const self = this;
  803. if ($.isFunction(item.icon)) {
  804. item._icon = item.icon.call(this, this, $t, key, item);
  805. } else {
  806. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  807. // to enable font awesome
  808. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  809. } else {
  810. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  811. }
  812. }
  813. this.addClass(item._icon);
  814. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  815. .appendTo(this);
  816. const $input = $obj.find('input');
  817. const event = () => {
  818. if (self.hasClass('context-menu-disabled')) return;
  819. item.batchInsert($input[0], root);
  820. };
  821. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  822. $input.click((e) => {e.stopPropagation();})
  823. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  824. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  825. };
  826. const contractContextMenuOptions = {
  827. selector: '#contract-spread',
  828. build: function ($trigger, e) {
  829. const target = SpreadJsObj.safeRightClickSelection($trigger, e, contractSpread);
  830. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  831. },
  832. items: {}
  833. };
  834. if (permission_edit) {
  835. contractSpread.bind(spreadNS.Events.EditStarting, contractTreeSpreadObj.editStarting);
  836. contractSpread.bind(spreadNS.Events.EditEnded, contractTreeSpreadObj.editEnded);
  837. contractSpread.bind(spreadNS.Events.ButtonClicked, contractTreeSpreadObj.buttonClicked);
  838. contractSpread.bind(spreadNS.Events.ClipboardPasting, contractTreeSpreadObj.clipboardPasting);
  839. contractSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  840. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  841. SpreadJsObj.Clipboard.setCopyData(copyText);
  842. });
  843. SpreadJsObj.addDeleteBind(contractSpread, contractTreeSpreadObj.deletePress);
  844. SpreadJsObj.addCutEvents(contractSpread, contractTreeSpreadObj.cut);
  845. $('a[name="base-opr"]').click(function () {
  846. contractTreeSpreadObj.baseOpr(contractSheet, this.getAttribute('type'));
  847. });
  848. $('a[name=cpc]').click(function () {
  849. contractSpread.commandManager().execute({
  850. cmd: this.getAttribute('type'),
  851. sheetName: contractSheet.name()
  852. });
  853. });
  854. contractContextMenuOptions.items.create = {
  855. name: '新增节点',
  856. icon: 'fa-plus',
  857. callback: function (key, opt) {
  858. contractTreeSpreadObj.baseOpr(contractSheet, 'add');
  859. },
  860. disabled: function (key, opt) {
  861. const sheet = contractSheet;
  862. const selection = sheet.getSelections();
  863. const sel = selection ? selection[0] : sheet.getSelections()[0];
  864. const row = sel ? sel.row : -1;
  865. const tree = sheet.zh_tree;
  866. if (!tree) return true;
  867. const first = sheet.zh_tree.nodes[row];
  868. const valid = !sheet.zh_setting.readOnly;
  869. return !(valid && first && first.level > 1);
  870. }
  871. };
  872. contractContextMenuOptions.items.create3 = {
  873. name: '新增子节点',
  874. icon: 'fa-sign-in',
  875. callback: function (key, opt) {
  876. contractTreeSpreadObj.baseOpr(contractSheet, 'add-child');
  877. },
  878. disabled: function (key, opt) {
  879. const sheet = contractSheet;
  880. const selection = sheet.getSelections();
  881. const sel = selection ? selection[0] : sheet.getSelections()[0];
  882. const row = sel ? sel.row : -1;
  883. const tree = sheet.zh_tree;
  884. if (!tree) return true;
  885. const first = sheet.zh_tree.nodes[row];
  886. const valid = !sheet.zh_setting.readOnly;
  887. return !(valid && first && !first.c_code && first.level >= 1);
  888. }
  889. };
  890. }
  891. if (permission_add) {
  892. contractContextMenuOptions.items.create2 = {
  893. name: '新增合同',
  894. icon: 'fa-sign-in',
  895. callback: function (key, opt) {
  896. $('#cons-add').modal('show');
  897. },
  898. disabled: function (key, opt) {
  899. const sheet = contractSheet;
  900. const selection = sheet.getSelections();
  901. const sel = selection ? selection[0] : sheet.getSelections()[0];
  902. const row = sel ? sel.row : -1;
  903. const tree = sheet.zh_tree;
  904. if (!tree) return true;
  905. const first = sheet.zh_tree.nodes[row];
  906. const valid = !sheet.zh_setting.readOnly;
  907. return !(valid && first && first.level > 1);
  908. }
  909. };
  910. }
  911. contractContextMenuOptions.items.delete = {
  912. name: '删除',
  913. icon: 'fa-remove',
  914. callback: function (key, opt) {
  915. contractTreeSpreadObj.baseOpr(contractSheet, 'delete');
  916. },
  917. visible: function (key, opt) {
  918. const sheet = contractSheet;
  919. const selection = sheet.getSelections();
  920. const sel = selection ? selection[0] : sheet.getSelections()[0];
  921. const row = sel ? sel.row : -1;
  922. const tree = sheet.zh_tree;
  923. if (!tree) return false;
  924. const first = sheet.zh_tree.nodes[row];
  925. return (first && first.c_code) || permission_edit;
  926. },
  927. disabled: function (key, opt) {
  928. const sheet = contractSheet;
  929. const selection = sheet.getSelections();
  930. const sel = selection ? selection[0] : sheet.getSelections()[0];
  931. const row = sel ? sel.row : -1;
  932. const tree = sheet.zh_tree;
  933. if (!tree) return true;
  934. const first = sheet.zh_tree.nodes[row];
  935. let last = first, sameParent = true, childCanDel = true;
  936. if (sel.rowCount > 1 && first) {
  937. for (let r = 1; r < sel.rowCount; r++) {
  938. const rNode = tree.nodes[sel.row + r];
  939. childCanDel = contractTreeSpreadObj.checkDelete(rNode, childCanDel);
  940. if (!rNode) {
  941. sameParent = false;
  942. break;
  943. }
  944. if (rNode.level > first.level) continue;
  945. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.contract_pid !== first.contract_pid)) {
  946. sameParent = false;
  947. break;
  948. }
  949. last = rNode;
  950. }
  951. }
  952. const valid = !sheet.zh_setting.readOnly;
  953. return !(valid && first && first.level > 1 && sameParent && childCanDel && contractTreeSpreadObj.checkDelete(first));
  954. }
  955. };
  956. contractContextMenuOptions.items.sprBase = '----';
  957. contractContextMenuOptions.items.copyBlock = {
  958. name: '复制整块(只复制节点)',
  959. icon: 'fa-files-o',
  960. callback: function (key, opt) {
  961. const copyBlockList = [];
  962. const sheet = contractSheet;
  963. const sel = sheet.getSelections()[0];
  964. let iRow = sel.row;
  965. const pid = sheet.zh_tree.nodes[iRow].contract_pid;
  966. while (iRow < sel.row + sel.rowCount) {
  967. const node = sheet.zh_tree.nodes[iRow];
  968. if (node.contract_pid !== pid) {
  969. toastr.error('仅可同时选中同层节点');
  970. return;
  971. }
  972. const posterity = sheet.zh_tree.getPosterity(node);
  973. iRow += posterity.length + 1;
  974. posterity.unshift(node);
  975. const copyData = sheet.zh_tree.getDefaultData(posterity);
  976. const newCopyData = _.filter(_.cloneDeep(copyData), function (d) {
  977. return d.c_code === undefined;
  978. });
  979. const newCopyBlock = [];
  980. for (const p of newCopyData) {
  981. const children = _.filter(newCopyData, function (item) {
  982. return item.contract_pid === p.contract_id;
  983. });
  984. if (children.length > 0) {
  985. let i = 1;
  986. for (const c of children) {
  987. c.order = i;
  988. i++;
  989. }
  990. } else {
  991. p.is_leaf = 1;
  992. }
  993. if (_.findIndex(newCopyBlock, { contract_id: p.contract_id }) === -1) {
  994. newCopyBlock.push(p);
  995. }
  996. }
  997. copyBlockList.push(newCopyBlock);
  998. }
  999. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1000. },
  1001. visible: function (key, opt) {
  1002. const sheet = contractSheet;
  1003. const selection = sheet.getSelections();
  1004. const row = selection[0].row;
  1005. const select = contractTree.nodes[row];
  1006. return select;
  1007. },
  1008. disabled: function (key, opt) {
  1009. const sheet = contractSheet;
  1010. const selection = sheet.getSelections();
  1011. const row = selection[0].row;
  1012. const select = contractTree.nodes[row];
  1013. console.log(select);
  1014. return !(select && select.level > 1 && !select.c_code);
  1015. }
  1016. };
  1017. if (permission_edit) {
  1018. contractContextMenuOptions.items.pasteBlock = {
  1019. name: '粘贴整块',
  1020. icon: 'fa-clipboard',
  1021. disabled: function (key, opt) {
  1022. //const block = treeOperationObj.block || [];
  1023. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1024. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1025. },
  1026. callback: function (key, opt) {
  1027. //const block = treeOperationObj.block || [];
  1028. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1029. if (copyInfo.block.length > 0) {
  1030. contractTreeSpreadObj.pasteBlock(contractSpread, copyInfo);
  1031. } else {
  1032. document.execCommand('paste');
  1033. }
  1034. },
  1035. visible: function (key, opt) {
  1036. return permission_edit;
  1037. }
  1038. };
  1039. contractContextMenuOptions.items.sprBlock = '----';
  1040. }
  1041. if (permission_edit) {
  1042. contractContextMenuOptions.items.batchInsert = {
  1043. name: '批量插入',
  1044. type: 'batchInsert',
  1045. value: '2',
  1046. icon: 'fa-sign-in',
  1047. batchInsert: function (obj, root) {
  1048. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1049. obj.value = obj.max;
  1050. toastr.warning('批量插入不可多于' + obj.max);
  1051. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1052. obj.value = obj.min;
  1053. toastr.warning('批量插入不可少于' + obj.min);
  1054. } else {
  1055. contractTreeSpreadObj.baseOpr(contractSheet, 'add', parseInt(obj.value));
  1056. root.$menu.trigger('contextmenu:hide');
  1057. }
  1058. },
  1059. disabled: function (key, opt) {
  1060. const sheet = contractSheet;
  1061. const selection = sheet.getSelections();
  1062. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1063. const row = sel ? sel.row : -1;
  1064. const tree = sheet.zh_tree;
  1065. if (!tree) return true;
  1066. const first = sheet.zh_tree.nodes[row];
  1067. const valid = !sheet.zh_setting.readOnly;
  1068. return !(valid && first && first.level > 1);
  1069. }
  1070. };
  1071. }
  1072. contractContextMenuOptions.items.sprTag = '----';
  1073. contractContextMenuOptions.items.showLast = {
  1074. name: '显示至最底层',
  1075. callback: function (key, opt, menu, e) {
  1076. const node = SpreadJsObj.getSelectObject(contractSheet);
  1077. setTimeout(() => {
  1078. showWaitingView();
  1079. contractTree.expandByCustom(x => {
  1080. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.contract_id + '-') >= 0);
  1081. });
  1082. SpreadJsObj.refreshTreeRowVisible(contractSheet);
  1083. closeWaitingView();
  1084. }, 100);
  1085. },
  1086. };
  1087. $.contextMenu(contractContextMenuOptions);
  1088. $('.bc-bar ul li a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  1089. const node = SpreadJsObj.getSelectObject(contractSheet);
  1090. if (node && node.c_code && node.uid === user_id) {
  1091. contractTreeSpreadObj.changeContractTab(node, true);
  1092. }
  1093. });
  1094. $('#edit_contract_btn').on('click', function () {
  1095. const node = SpreadJsObj.getSelectObject(contractSheet);
  1096. if (node && node.c_code && node.uid === user_id) {
  1097. $('#edit_contract_btn').hide();
  1098. $('#save_contract_btn').show();
  1099. $('#cancel_contract_btn').show();
  1100. for (const c of contractDetail) {
  1101. if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
  1102. if (c === 'sign_date') {
  1103. $('#htdetail_' + c).html('<input type="date" class="form-control form-control-sm" value="' + moment(node[c]).format('YYYY-MM-DD') + '">');
  1104. continue;
  1105. } else if (c === 'remark') {
  1106. $('#htdetail_' + c).html('<textarea class="form-control form-control-sm" rows="3">' + node[c] + '</textarea>');
  1107. continue;
  1108. }
  1109. $('#htdetail_' + c).html('<input type="text" class="form-control form-control-sm" value="' + node[c] + '">');
  1110. }
  1111. }
  1112. }
  1113. });
  1114. $('#save_contract_btn').on('click', function () {
  1115. const node = SpreadJsObj.getSelectObject(contractSheet);
  1116. if (node && node.c_code && node.uid === user_id) {
  1117. const data = {
  1118. id: node.id,
  1119. };
  1120. for (const c of contractDetail) {
  1121. if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
  1122. if (c === 'sign_date') {
  1123. data[c] = $('#htdetail_' + c + ' input').val() || null;
  1124. continue;
  1125. } else if (c === 'remark') {
  1126. data[c] = $('#htdetail_' + c + ' textarea').val();
  1127. continue;
  1128. }
  1129. data[c] = $('#htdetail_' + c + ' input').val();
  1130. }
  1131. }
  1132. if (data.c_code === '' || data.c_name === '') {
  1133. toastr.warning('合同编号和合同名称不能为空');
  1134. return;
  1135. }
  1136. if (data.total_price === '') {
  1137. toastr.warning('合同金额不能为空');
  1138. return;
  1139. } else if (!/^\d+(\.\d+)?$/.test(data.total_price)) {
  1140. toastr.warning('合同金额只能输入数字');
  1141. return;
  1142. }
  1143. if (parseFloat(data.total_price) < node.yf_price) {
  1144. const name = contract_type === contractConst.type.expenses ? '付' : '回';
  1145. toastr.warning('合同金额不能小于累计应' + name);
  1146. return;
  1147. }
  1148. if (data.party_b === '') {
  1149. toastr.warning('签订单位(乙方)不能为空');
  1150. return;
  1151. }
  1152. console.log(data);
  1153. // 更新至服务器
  1154. postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) {
  1155. toastr.success('已编辑成功');
  1156. const refreshNode = contractTree.loadPostData(result);
  1157. console.log(refreshNode);
  1158. contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
  1159. const newNode = SpreadJsObj.getSelectObject(contractSheet);
  1160. contractTreeSpreadObj.changeContractTab(newNode, true);
  1161. });
  1162. }
  1163. });
  1164. $('#cancel_contract_btn').on('click', function () {
  1165. const node = SpreadJsObj.getSelectObject(contractSheet);
  1166. if (node && node.c_code && node.uid === user_id) {
  1167. $('#edit_contract_btn').show();
  1168. $('#save_contract_btn').hide();
  1169. $('#cancel_contract_btn').hide();
  1170. for (const c of contractDetail) {
  1171. if ($('#htdetail_' + c) && $('#htdetail_' + c).hasClass('change-input-td')) {
  1172. if (c === 'sign_date') {
  1173. $('#htdetail_' + c).text(node[c] ? moment(node[c]).format('YYYY-MM-DD') : '');
  1174. } else {
  1175. $('#htdetail_' + c).html(node[c]);
  1176. }
  1177. }
  1178. }
  1179. }
  1180. });
  1181. $('#file-ok').click(function () {
  1182. const files = Array.from($('#file-modal')[0].files)
  1183. const valiData = files.map(v => {
  1184. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  1185. return {
  1186. size: v.size,
  1187. ext
  1188. }
  1189. })
  1190. const node = SpreadJsObj.getSelectObject(contractSheet);
  1191. if (!node || !node.c_code) {
  1192. toastr.warning('请选择合同再上传文件');
  1193. return;
  1194. }
  1195. if (validateFiles(valiData)) {
  1196. if (files.length) {
  1197. const formData = new FormData()
  1198. files.forEach(file => {
  1199. formData.append('name', file.name)
  1200. formData.append('size', file.size)
  1201. formData.append('file', file)
  1202. })
  1203. postDataWithFile('/contract/' + stid + '/detail/' + contractConst.typeMap[contract_type] + '/' + node.id + '/file/upload', formData, function (result) {
  1204. contractTreeSpreadObj.setContractFiles(result, node.id);
  1205. $('#file-modal').val('');
  1206. $('#file-cancel').click()
  1207. });
  1208. }
  1209. }
  1210. });
  1211. $('body').on('click', '#htfile .file-del', function () {
  1212. const node = SpreadJsObj.getSelectObject(contractSheet);
  1213. const fid = $(this).data('id');
  1214. deleteAfterHint(function () {
  1215. postData('/contract/' + stid + '/detail/' + contractConst.typeMap[contract_type] + '/' + node.id + '/file/delete', { id: fid }, function (result) {
  1216. contractTreeSpreadObj.setContractFiles(result, node.id);
  1217. });
  1218. }, '确认删除该文件?');
  1219. });
  1220. $('body').on('click', '#htpay .pay-del', function () {
  1221. const node = SpreadJsObj.getSelectObject(contractSheet);
  1222. const cpid = $(this).data('id');
  1223. if (!node || !node.c_code) {
  1224. toastr.warning('请选择合同节点');
  1225. return;
  1226. }
  1227. if (node.settle_code) {
  1228. toastr.warning('已结算的合同不能删除合同' + contractConst.typeName[contract_type]);
  1229. return;
  1230. }
  1231. deleteAfterHint(function () {
  1232. postData(window.location.pathname + '/update', {postType: 'del-contract-pay', postData: { select: node.id, pay: cpid }}, function (result) {
  1233. const refreshNode = contractTree.loadPostData(result.node);
  1234. contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
  1235. contractTreeSpreadObj.setContractPays(result.pays, node);
  1236. })
  1237. }, '确认删除该合同' + contractConst.typeName[contract_type] + '?');
  1238. });
  1239. const payTime = $('#cons-addpay input[name="pay_time"]').datepicker().data('datepicker');
  1240. $('.datepicker-here').datepicker({
  1241. autoClose: true,
  1242. });
  1243. $('#add_contract_pay_btn').on('click', function () {
  1244. const node = SpreadJsObj.getSelectObject(contractSheet);
  1245. if (!node || !node.c_code) {
  1246. toastr.error('请选择一个合同节点');
  1247. return;
  1248. }
  1249. $('#cons-addpay .modal-title').text('添加' + contractConst.typeName[contract_type]);
  1250. $('#cons-addpay input[name="cpid"]').val('');
  1251. $('#add-contract-pay').show();
  1252. $('#save-contract-pay').hide();
  1253. setPayModalInfo();
  1254. $('#cons-addpay').modal('show');
  1255. });
  1256. $('body').on('click', '#htpay .pay-edit', function () {
  1257. const node = SpreadJsObj.getSelectObject(contractSheet);
  1258. if (!node || !node.c_code) {
  1259. toastr.error('请选择一个合同节点');
  1260. return;
  1261. }
  1262. const cpid = $(this).data('id');
  1263. const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
  1264. if (!cpInfo) {
  1265. toastr.error('未找到该合同' + contractConst.typeName[contract_type]);
  1266. return
  1267. }
  1268. $('#cons-addpay .modal-title').text('编辑' + contractConst.typeName[contract_type]);
  1269. $('#cons-addpay input[name="cpid"]').val(cpid);
  1270. $('#add-contract-pay').hide();
  1271. $('#save-contract-pay').show();
  1272. setPayModalInfo(cpInfo);
  1273. $('#cons-addpay').modal('show');
  1274. });
  1275. function setPayModalInfo(cpInfo = null) {
  1276. $('#cons-addpay input[name="pay_time"]').val(cpInfo ? moment(cpInfo.pay_time).format('YYYY-MM-DD') : '');
  1277. payTime.selectDate(cpInfo ? new Date(cpInfo.pay_time) : '');
  1278. $('#cons-addpay input[name="pay_price"]').val(cpInfo ? cpInfo.pay_price : '');
  1279. $('#cons-addpay input[name="debit_price"]').val(cpInfo ? cpInfo.debit_price : '');
  1280. $('#cons-addpay input[name="yf_price"]').val(cpInfo ? cpInfo.yf_price : '');
  1281. $('#cons-addpay input[name="sf_price"]').val(cpInfo ? cpInfo.sf_price : '');
  1282. $('#cons-addpay select[name="pay_type"]').val(cpInfo ? cpInfo.pay_type : $('#cons-addpay select[name="pay_type"] option:first').text());
  1283. $('#cons-addpay textarea[name="remark"]').val(cpInfo ? cpInfo.remark : '');
  1284. $('#cons-addpay .yf-tips').text('');
  1285. $('#cons-addpay .sf-tips').text('');
  1286. }
  1287. // 上传附件
  1288. $('#cons-pay-file input[type="file"]').change(function () {
  1289. const files = Array.from(this.files);
  1290. console.log(files);
  1291. const valiData = files.map(v => {
  1292. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  1293. return {
  1294. size: v.size,
  1295. ext
  1296. }
  1297. })
  1298. const node = SpreadJsObj.getSelectObject(contractSheet);
  1299. if (!node || !node.c_code) {
  1300. toastr.warning('请选择合同再上传文件');
  1301. $('#cons-pay-file input[type="file"]').val('');
  1302. return;
  1303. }
  1304. const cpid = $('#cons-pay-file input[name="cpid"]').val();
  1305. const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
  1306. if (!cpInfo) {
  1307. toastr.warning('请选择合同'+ contractConst.typeName[contract_type] +'再上传文件');
  1308. $('#cons-pay-file input[type="file"]').val('');
  1309. return;
  1310. }
  1311. if (validateFiles(valiData)) {
  1312. if (files.length) {
  1313. const formData = new FormData()
  1314. files.forEach(file => {
  1315. formData.append('name', file.name)
  1316. formData.append('size', file.size)
  1317. formData.append('file', file)
  1318. })
  1319. postDataWithFile('/contract/' + stid + '/detail/' + contractConst.typeMap[contract_type] + '/' + node.id + '/pay/' + cpInfo.id + '/file/upload', formData, function (result) {
  1320. cpInfo.files = result;
  1321. contractTreeSpreadObj.openContractPayFiles(cpInfo);
  1322. $('#htpay-table tbody').find('tr[data-cpid="' + cpInfo.id + '"]').find('.files-num').text(result.length || '');
  1323. });
  1324. }
  1325. }
  1326. $('#cons-pay-file input[type="file"]').val('');
  1327. });
  1328. $('body').on('click', '#cons-pay-file .file-del', function () {
  1329. const node = SpreadJsObj.getSelectObject(contractSheet);
  1330. const cpid = $('#cons-pay-file input[name="cpid"]').val();
  1331. const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
  1332. if (!cpInfo) {
  1333. toastr.warning('未选择合同' + contractConst.typeName[contract_type]);
  1334. return;
  1335. }
  1336. const fid = $(this).data('id');
  1337. deleteAfterHint(function () {
  1338. postData('/contract/' + stid + '/detail/' + contractConst.typeMap[contract_type] + '/' + node.id + '/pay/' + cpInfo.id + '/file/delete', { id: fid }, function (result) {
  1339. cpInfo.files = result;
  1340. contractTreeSpreadObj.openContractPayFiles(cpInfo);
  1341. $('#htpay-table tbody').find('tr[data-cpid="' + cpInfo.id + '"]').find('.files-num').text(result.length || '');
  1342. });
  1343. }, '确认删除该文件?');
  1344. });
  1345. postData(window.location.pathname + '/load', {}, function (result) {
  1346. const datas = result.contractTree.concat(result.contractList);
  1347. for (const t of datas) {
  1348. if (!t.is_leaf && _.findIndex(datas, { contract_pid: t.contract_id }) === -1) {
  1349. t.is_leaf = 1;
  1350. }
  1351. }
  1352. contractTree.loadDatas(datas);
  1353. treeCalc.calculateAll(contractTree);
  1354. // contractTree.setExpanded(node, !node.expanded);
  1355. // SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  1356. SpreadJsObj.loadSheetData(contractSheet, SpreadJsObj.DataType.Tree, contractTree);
  1357. SpreadJsObj.loadTopAndSelect(contractSheet, ckBillsSpread);
  1358. contractTreeSpreadObj.setContract(contractSheet);
  1359. checkShowLast(result.contractTree.length);
  1360. contractTreeSpreadObj.refreshOperationValid(contractSheet);
  1361. // contractTreeSpreadObj.setAllForeColor(contractSheet);
  1362. console.log(contractTree);
  1363. });
  1364. if (is_admin) {
  1365. const sqSpreadSetting = {
  1366. cols: [
  1367. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@', cellType: 'tree'},
  1368. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 240, formatter: '@'},
  1369. ],
  1370. emptyRows: 0,
  1371. headRows: 2,
  1372. headRowHeight: [25, 25],
  1373. defaultRowHeight: 21,
  1374. headerFont: '12px 微软雅黑',
  1375. font: '12px 微软雅黑',
  1376. readOnly: true,
  1377. rowHeader:[
  1378. // {
  1379. // rowHeaderType: 'circle',
  1380. // setting: {
  1381. // size: 5,
  1382. // indent: 16,
  1383. // getColor: function (index, data) {
  1384. // if (!data) return;
  1385. // if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
  1386. // return '#dc3545';
  1387. // }
  1388. // if(data.lid != 0) return;
  1389. // return '#007bff';
  1390. // }
  1391. // },
  1392. // },
  1393. ],
  1394. localCache: {
  1395. key: 'contract-sq-spread',
  1396. colWidth: true,
  1397. }
  1398. };
  1399. const sqSpread = SpreadJsObj.createNewSpread($('#sq-spread')[0]);
  1400. const sqSheet = sqSpread.getActiveSheet();
  1401. // sjsSettingObj.setGridSelectStyle(sqSpreadSetting);
  1402. sjsSettingObj.setFxTreeStyle(sqSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  1403. SpreadJsObj.initSheet(sqSheet, sqSpreadSetting);
  1404. const sqTreeSetting = {
  1405. id: 'contract_id',
  1406. pid: 'contract_pid',
  1407. order: 'order',
  1408. level: 'level',
  1409. rootId: -1,
  1410. keys: ['id', 'tid', 'spid'],
  1411. autoExpand: 3,
  1412. markExpandKey: 'contract-sq-bills-expand',
  1413. markExpandSubKey: window.location.pathname.split('/')[2],
  1414. };
  1415. sqTreeSetting.calcFun = function (node) {
  1416. };
  1417. const sqTree = createNewPathTree('base', sqTreeSetting);
  1418. const sqTreeSpreadObj = {
  1419. setTreeAudits: function (sheet, selection) {
  1420. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1421. const row = sel ? sel.row : -1;
  1422. const tree = sheet.zh_tree;
  1423. if (!tree) {
  1424. return;
  1425. }
  1426. const first = sheet.zh_tree.nodes[row];
  1427. const auditList = _.orderBy(_.filter(contractTreeAudits, { contract_id: first.contract_id }), ['create_time'], ['desc']);
  1428. let auditHtml = '';
  1429. for (const audit of auditList) {
  1430. audit.name = _.find(accountList, { id: audit.uid }).name;
  1431. auditHtml += `<tr data-id="${audit.uid}">
  1432. <td><input type="checkbox"></td><td>${audit.name}</td><td>${moment(new Date(audit.create_time)).format('YYYY-MM-DD HH:mm:ss')}</td><td>${this.setAuditPermissionTxt(audit)}</td>
  1433. <td><button class="btn btn-sm btn-outline-danger del-tree-audit">移除</button></td>
  1434. </tr>`;
  1435. }
  1436. $('#contract-tree-audits').html(auditHtml);
  1437. },
  1438. setAuditPermissionTxt: function (audit) {
  1439. const txt = [];
  1440. const ca = _.find(contractAudits, { uid: audit.uid });
  1441. if (ca && ca.permission_edit) {
  1442. txt.push('编辑节点');
  1443. }
  1444. if (ca && ca.permission_add) {
  1445. txt.push('添加合同');
  1446. }
  1447. if (ca && ca.permission_show_unit) {
  1448. txt.push('查看本单位合同');
  1449. }
  1450. if (ca && ca.permission_show_node) {
  1451. txt.push('查看本节点合同');
  1452. }
  1453. if (ca && !ca.permission_show_unit && !ca.permission_show_node) {
  1454. txt.push('查看本人合同');
  1455. }
  1456. return txt.join(',');
  1457. },
  1458. selectionChanged: function (e, info) {
  1459. if (info.newSelections) {
  1460. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  1461. $('#select-permission-tree-audit-all').prop('checked', false);
  1462. sqTreeSpreadObj.setTreeAudits(info.sheet);
  1463. }
  1464. }
  1465. },
  1466. }
  1467. sqSpread.bind(spreadNS.Events.SelectionChanged, sqTreeSpreadObj.selectionChanged);
  1468. let contractAudits = [];
  1469. let contractAccountGroup = [];
  1470. $('#empower').on('shown.bs.modal', function () {
  1471. postData(window.location.pathname + '/load', {}, function (result) {
  1472. const tree = result.contractTree;
  1473. for (const t of tree) {
  1474. if (!t.is_leaf && _.findIndex(tree, { contract_pid: t.contract_id }) === -1) {
  1475. t.is_leaf = 1;
  1476. }
  1477. }
  1478. sqTree.loadDatas(tree);
  1479. SpreadJsObj.loadSheetData(sqSheet, SpreadJsObj.DataType.Tree, sqTree);
  1480. sqSpread.refresh();
  1481. contractAudits = result.contractAudits;
  1482. contractAccountGroup = result.accountGroup;
  1483. let groupBookListHtml = '';
  1484. result.accountGroup.forEach((group, idx) => {
  1485. groupBookListHtml += '<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="'+ idx +'" data-type="hide"><i class="fa fa-plus-square"></i></a> '+ group.groupName +'</dt>\n' +
  1486. ' <div class="dd-content" data-toggleid="'+ idx +'">\n';
  1487. let groupListHtml = '';
  1488. group.groupList.forEach(item => {
  1489. groupListHtml += '<dd class="border-bottom p-2 mb-0 " data-id="'+ item.uid + '" >\n' +
  1490. ' <p class="mb-0 d-flex"><span class="text-primary">'+ item.name + '</span><span\n' +
  1491. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  1492. ' <span class="text-muted">'+ item.role +'</span>\n' +
  1493. ' </dd>\n';
  1494. });
  1495. groupBookListHtml = groupBookListHtml + groupListHtml + '</div>';
  1496. });
  1497. $('#empower .book-list').html(groupBookListHtml);
  1498. sqTreeSpreadObj.setTreeAudits(sqSheet);
  1499. });
  1500. });
  1501. let timer2 = null
  1502. let oldSearchVal2 = null
  1503. $('#gr-search2').bind('input propertychange', function (e) {
  1504. oldSearchVal2 = e.target.value
  1505. timer2 && clearTimeout(timer2)
  1506. timer2 = setTimeout(() => {
  1507. const newVal = $('#gr-search2').val()
  1508. let html = ''
  1509. if (newVal && newVal === oldSearchVal2) {
  1510. contractAudits.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  1511. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.uid}" >
  1512. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  1513. class="ml-auto">${item.mobile || ''}</span></p>
  1514. <span class="text-muted">${item.role || ''}</span>
  1515. </dd>`
  1516. })
  1517. $('#empower .book-list').empty()
  1518. $('#empower .book-list').append(html)
  1519. } else {
  1520. if (!$('#empower .acc-btn').length) {
  1521. contractAccountGroup.forEach((group, idx) => {
  1522. if (!group) return
  1523. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  1524. </a> ${group.groupName}</dt>
  1525. <div class="dd-content" data-toggleid="${idx}">`
  1526. group.groupList.forEach(item => {
  1527. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.uid}" >
  1528. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  1529. class="ml-auto">${item.mobile || ''}</span></p>
  1530. <span class="text-muted">${item.role || ''}</span>
  1531. </dd>`
  1532. });
  1533. html += '</div>'
  1534. })
  1535. $('#empower .book-list').empty()
  1536. $('#empower .book-list').append(html)
  1537. }
  1538. }
  1539. }, 400);
  1540. });
  1541. // 添加到成员中
  1542. $('body').on('click', '#empower dl dd', function () {
  1543. const id = parseInt($(this).data('id'));
  1544. const node = SpreadJsObj.getSelectObject(sqSheet);
  1545. if (!node) {
  1546. toastr.error('请选择节点');
  1547. return;
  1548. }
  1549. if (!isNaN(id) && id !== 0) {
  1550. if (_.findIndex(contractTreeAudits, { uid: id, contract_id: node.contract_id }) !== -1) {
  1551. toastr.error('该成员已存在, 请勿重复添加');
  1552. return;
  1553. }
  1554. postData(window.location.pathname + '/update', {postType: 'add-tree-audit', postData: { select: node, auditId: id }}, function (result) {
  1555. contractTreeAudits.push(result);
  1556. sqTreeSpreadObj.setTreeAudits(sqSheet);
  1557. })
  1558. }
  1559. });
  1560. $('#select-permission-tree-audit-all').on('click', function () {
  1561. $('#contract-tree-audits').find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
  1562. });
  1563. $('#batch-del-audits').on('click', function () {
  1564. let uids = [];
  1565. $('#contract-tree-audits').find('input[type="checkbox"]:checked').each(function () {
  1566. uids.push(parseInt($(this).parents('tr').data('id')));
  1567. });
  1568. if (uids.length === 0) {
  1569. toastr.warning('请选择要删除的成员');
  1570. return;
  1571. }
  1572. deleteAfterHint(function () {
  1573. postData(window.location.pathname + '/update', {
  1574. postType: 'del-tree-audit',
  1575. postData: {
  1576. select: SpreadJsObj.getSelectObject(sqSheet),
  1577. auditIds: uids,
  1578. }
  1579. }, function (result) {
  1580. // contractTreeAudits数组清空再赋值
  1581. contractTreeAudits = result;
  1582. sqTreeSpreadObj.setTreeAudits(sqSheet);
  1583. });
  1584. }, '确认删除「当前节点已勾选授权用户」?');
  1585. });
  1586. $('body').on('click', '#empower .del-tree-audit', function () {
  1587. const uid = parseInt($(this).parents('tr').data('id'));
  1588. deleteAfterHint(function () {
  1589. postData(window.location.pathname + '/update', {
  1590. postType: 'del-tree-audit',
  1591. postData: {
  1592. select: SpreadJsObj.getSelectObject(sqSheet),
  1593. auditIds: uid,
  1594. }
  1595. }, function (result) {
  1596. // contractTreeAudits数组清空再赋值
  1597. contractTreeAudits = result;
  1598. sqTreeSpreadObj.setTreeAudits(sqSheet);
  1599. });
  1600. }, '确认删除「当前节点授权用户」?');
  1601. });
  1602. }
  1603. if (permission_add) {
  1604. $('#cons-add').on('show.bs.modal', function () {
  1605. $('#cons-add input[name="code"]').val('');
  1606. $('#cons-add input[name="name"]').val('');
  1607. $('#cons-add input[name="total_price"]').val('');
  1608. $('#cons-add input[name="party_b"]').val('');
  1609. $('#cons-add textarea[name="remark"]').val('');
  1610. });
  1611. $('#add-contract').click(function () {
  1612. const node = SpreadJsObj.getSelectObject(contractSheet);
  1613. if (!node) {
  1614. toastr.error('请选择一个节点');
  1615. return;
  1616. }
  1617. console.log(node);
  1618. const data = {
  1619. code: $('#cons-add input[name="code"]').val(),
  1620. name: $('#cons-add input[name="name"]').val(),
  1621. total_price: $('#cons-add input[name="total_price"]').val(),
  1622. party_b: $('#cons-add input[name="party_b"]').val(),
  1623. remark: $('#cons-add textarea[name="remark"]').val(),
  1624. }
  1625. if (!data.code) {
  1626. toastr.error('请输入合同编号');
  1627. return;
  1628. }
  1629. if (!data.name) {
  1630. toastr.error('请输入合同名称');
  1631. return;
  1632. }
  1633. if (!data.total_price) {
  1634. toastr.error('请输入合同金额');
  1635. return;
  1636. }
  1637. // 金额只能输入数字
  1638. if (!/^\d+(\.\d+)?$/.test(data.total_price)) {
  1639. toastr.error('合同金额只能输入数字');
  1640. return;
  1641. }
  1642. if (!data.party_b) {
  1643. toastr.error('请输入签订单位(乙方)');
  1644. return;
  1645. }
  1646. console.log(node, data);
  1647. postData(window.location.pathname + '/update', {postType: 'add-contract', postData: { select: node, contract: data }}, function (result) {
  1648. const refreshNode = contractTree.loadPostData(result);
  1649. contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
  1650. $('#cons-add').modal('hide');
  1651. })
  1652. });
  1653. }
  1654. $('#cons-addpay input[type="number"]').change(function () {
  1655. const name = $(this).attr('name');
  1656. const node = SpreadJsObj.getSelectObject(contractSheet);
  1657. if (!node || !node.c_code) {
  1658. toastr.error('请选择一个合同节点');
  1659. return;
  1660. }
  1661. if (node.uid !== user_id) {
  1662. toastr.error('只能修改自己的合同' + contractConst.typeName[contract_type]);
  1663. return;
  1664. }
  1665. if (node.settle_code) {
  1666. toastr.error('该合同已结算,不能修改');
  1667. return;
  1668. }
  1669. const sf_price = $('#cons-addpay input[name="sf_price"]').val() || 0;
  1670. const pay_price = $('#cons-addpay input[name="pay_price"]').val() || 0;
  1671. const debit_price = $('#cons-addpay input[name="debit_price"]').val() || 0;
  1672. const yf_price = ZhCalc.sub(pay_price, debit_price);
  1673. $('#cons-addpay .yf-tips').text('');
  1674. const cpid = $('#cons-addpay input[name="cpid"]').val();
  1675. if (cpid) {
  1676. const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
  1677. const newNodePayPrice = ZhCalc.add(ZhCalc.sub(node.pay_price, cpInfo.pay_price), parseFloat(pay_price));
  1678. const newNodeDebitPrice = ZhCalc.add(ZhCalc.sub(node.debit_price, cpInfo.debit_price), parseFloat(debit_price));
  1679. const newNodeYfPrice = ZhCalc.sub(newNodePayPrice, newNodeDebitPrice);
  1680. if (parseFloat(sf_price) > ZhCalc.add(cpInfo.sf_price, ZhCalc.sub(newNodeYfPrice, node.sf_price))) {
  1681. $('#cons-addpay .sf-tips').text(' ≤ ' + ZhCalc.add(cpInfo.sf_price, ZhCalc.sub(newNodeYfPrice, node.sf_price)));
  1682. } else {
  1683. $('#cons-addpay .sf-tips').text('');
  1684. }
  1685. if (parseFloat(yf_price) > ZhCalc.add(cpInfo.yf_price, ZhCalc.sub(node.total_price, node.yf_price))) {
  1686. $('#cons-addpay .yf-tips').text(' ≤ ' + ZhCalc.add(cpInfo.yf_price, ZhCalc.sub(node.total_price, node.yf_price)));
  1687. } else {
  1688. $('#cons-addpay .yf-tips').text('');
  1689. }
  1690. } else {
  1691. if (parseFloat(sf_price) > ZhCalc.sub(ZhCalc.add(node.yf_price, yf_price), node.sf_price)) {
  1692. $('#cons-addpay .sf-tips').text(' ≤ ' + ZhCalc.sub(ZhCalc.add(node.yf_price, yf_price), node.sf_price));
  1693. } else {
  1694. $('#cons-addpay .sf-tips').text('');
  1695. }
  1696. if (parseFloat(yf_price) > ZhCalc.sub(node.total_price, node.yf_price)) {
  1697. $('#cons-addpay .yf-tips').text(' ≤ ' + ZhCalc.sub(node.total_price, node.yf_price));
  1698. } else {
  1699. $('#cons-addpay .yf-tips').text('');
  1700. }
  1701. }
  1702. if (name === 'pay_price' || name === 'debit_price') {
  1703. $('#cons-addpay input[name="yf_price"]').val(yf_price);
  1704. }
  1705. });
  1706. $('#add-contract-pay').click(function () {
  1707. const node = SpreadJsObj.getSelectObject(contractSheet);
  1708. if (!node || !node.c_code) {
  1709. toastr.error('请选择一个合同节点');
  1710. return;
  1711. }
  1712. if (node.uid !== user_id) {
  1713. toastr.error('只能添加自己的合同' + contractConst.typeName[contract_type]);
  1714. return;
  1715. }
  1716. if (node.settle_code) {
  1717. toastr.error('该合同已结算,不能添加');
  1718. return;
  1719. }
  1720. const data = {
  1721. pay_time: $('#cons-addpay input[name="pay_time"]').val(),
  1722. pay_price: $('#cons-addpay input[name="pay_price"]').val() || 0,
  1723. debit_price: $('#cons-addpay input[name="debit_price"]').val() || 0,
  1724. yf_price: $('#cons-addpay input[name="yf_price"]').val() || 0,
  1725. sf_price: $('#cons-addpay input[name="sf_price"]').val() || 0,
  1726. pay_type: $('#cons-addpay select[name="pay_type"]').val(),
  1727. remark: $('#cons-addpay textarea[name="remark"]').val(),
  1728. }
  1729. const name = contract_type === contractConst.type.expenses ? '付' : '回';
  1730. if (!judgePays(node, data, name)) {
  1731. return;
  1732. }
  1733. console.log(node, data);
  1734. postData(window.location.pathname + '/update', {postType: 'add-contract-pay', postData: { select: node.id, pay: data }}, function (result) {
  1735. const refreshNode = contractTree.loadPostData(result.node);
  1736. contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
  1737. contractTreeSpreadObj.setContractPays(result.pays, node);
  1738. // const selection = contractSheet.getSelections();
  1739. // const sel = selection ? selection[0] : contractSheet.getSelections()[0];
  1740. // const row = sel ? sel.row : -1;
  1741. // contractTreeSpreadObj.setForeColor(contractSheet, row);
  1742. $('#cons-addpay').modal('hide');
  1743. })
  1744. });
  1745. $('#save-contract-pay').click(function () {
  1746. const node = SpreadJsObj.getSelectObject(contractSheet);
  1747. if (!node || !node.c_code) {
  1748. toastr.error('请选择一个合同节点');
  1749. return;
  1750. }
  1751. if (node.settle_code) {
  1752. toastr.error('该合同已结算,不能修改');
  1753. return;
  1754. }
  1755. const cpid = $('#cons-addpay input[name="cpid"]').val();
  1756. const cpInfo = _.find(contractPays, { id: parseInt(cpid) });
  1757. if (!cpInfo) {
  1758. toastr.error('未找到该合同' + contractConst.typeName[contract_type]);
  1759. return
  1760. }
  1761. if (cpInfo.uid !== user_id) {
  1762. toastr.error('只能编辑自己的合同' + contractConst.typeName[contract_type]);
  1763. return;
  1764. }
  1765. const data = {
  1766. id: cpInfo.id,
  1767. pay_time: $('#cons-addpay input[name="pay_time"]').val(),
  1768. pay_price: $('#cons-addpay input[name="pay_price"]').val() || 0,
  1769. debit_price: $('#cons-addpay input[name="debit_price"]').val() || 0,
  1770. yf_price: $('#cons-addpay input[name="yf_price"]').val() || 0,
  1771. sf_price: $('#cons-addpay input[name="sf_price"]').val() || 0,
  1772. pay_type: $('#cons-addpay select[name="pay_type"]').val(),
  1773. remark: $('#cons-addpay textarea[name="remark"]').val(),
  1774. }
  1775. const name = contract_type === contractConst.type.expenses ? '付' : '回';
  1776. if (!judgePays(node, data, name, cpInfo)) {
  1777. return;
  1778. }
  1779. console.log(node, data);
  1780. postData(window.location.pathname + '/update', {postType: 'save-contract-pay', postData: { select: node.id, pay: data }}, function (result) {
  1781. const refreshNode = contractTree.loadPostData(result.node);
  1782. contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
  1783. contractTreeSpreadObj.setContractPays(result.pays, node);
  1784. // const selection = contractSheet.getSelections();
  1785. // const sel = selection ? selection[0] : contractSheet.getSelections()[0];
  1786. // const row = sel ? sel.row : -1;
  1787. // contractTreeSpreadObj.setForeColor(contractSheet, row);
  1788. $('#cons-addpay').modal('hide');
  1789. })
  1790. });
  1791. function judgePays(node, data, name, cpInfo = null) {
  1792. let flag = true;
  1793. if (!data.pay_time) {
  1794. toastr.error('请输入'+ (name === '付' ? '支付' : '回款') +'日期');
  1795. return false;
  1796. }
  1797. if (!data.pay_price) {
  1798. toastr.error('请输入'+ name +'款金额');
  1799. return false;
  1800. }
  1801. // 金额只能输入数字
  1802. if (!/^\d+(\.\d+)?$/.test(data.pay_price)) {
  1803. toastr.error(name + '款金额只能输入数字');
  1804. return false;
  1805. }
  1806. if (data.debit_price && !/^\d+(\.\d+)?$/.test(data.debit_price)) {
  1807. toastr.error('扣款金额只能输入数字');
  1808. return false;
  1809. }
  1810. if (parseFloat(data.debit_price) > parseFloat(data.pay_price)) {
  1811. toastr.error('扣款金额不能大于'+ name +'款金额');
  1812. return false;
  1813. }
  1814. if (data.sf_price && !/^\d+(\.\d+)?$/.test(data.sf_price)) {
  1815. toastr.error('实'+ name +'金额只能输入数字');
  1816. return false;
  1817. }
  1818. if (cpInfo) {
  1819. const newNodePayPrice = ZhCalc.add(ZhCalc.sub(node.pay_price, cpInfo.pay_price), parseFloat(data.pay_price));
  1820. const newNodeDebitPrice = ZhCalc.add(ZhCalc.sub(node.debit_price, cpInfo.debit_price), parseFloat(data.debit_price));
  1821. const newNodeYfPrice = ZhCalc.sub(newNodePayPrice, newNodeDebitPrice);
  1822. const newNodeSfPrice = ZhCalc.add(ZhCalc.sub(node.sf_price, cpInfo.sf_price), parseFloat(data.sf_price));
  1823. if (newNodeYfPrice > node.total_price) {
  1824. toastr.error('累计应'+ name +'金额不能大于合同金额');
  1825. return false;
  1826. }
  1827. if (newNodeSfPrice > newNodeYfPrice) {
  1828. toastr.error('累计实'+ name +'金额不能大于累计应'+ name +'金额');
  1829. return false;
  1830. }
  1831. } else {
  1832. if (ZhCalc.add(parseFloat(data.yf_price), node.yf_price) > node.total_price) {
  1833. toastr.error('累计应'+ name +'金额不能大于合同金额');
  1834. return false;
  1835. }
  1836. if (ZhCalc.add(parseFloat(data.sf_price), node.sf_price) > ZhCalc.add(parseFloat(data.yf_price), node.yf_price)) {
  1837. toastr.error('累计实'+ name +'金额不能大于累计应'+ name +'金额');
  1838. return false;
  1839. }
  1840. }
  1841. // if (parseFloat(data.sf_price) > parseFloat(data.yf_price)) {
  1842. // toastr.error('实'+ name +'金额不能大于应'+ name +'金额');
  1843. // return false;
  1844. // }
  1845. if (!data.pay_type) {
  1846. toastr.error('请选择' + contractConst.typeName[contract_type] + '方式');
  1847. return false;
  1848. }
  1849. return flag;
  1850. }
  1851. $('body').on('click', '.open-pay-files', function () {
  1852. const cpid = $(this).attr('data-cpid');
  1853. if (!cpid) {
  1854. toastr.error('获取合同'+ contractConst.typeName[contract_type] +'信息失败');
  1855. return;
  1856. }
  1857. const pay = _.find(contractPays, { id: parseInt(cpid) });
  1858. if (!pay) {
  1859. toastr.error('获取合同'+ contractConst.typeName[contract_type] +'信息失败');
  1860. return;
  1861. }
  1862. const node = SpreadJsObj.getSelectObject(contractSheet);
  1863. if (!node || !node.c_code) {
  1864. toastr.error('请选择一个合同节点');
  1865. return;
  1866. }
  1867. if (node.uid !== user_id) {
  1868. $('#cons-pay-file .upload-permission').hide();
  1869. } else {
  1870. $('#cons-pay-file .upload-permission').show();
  1871. }
  1872. $('#cons-pay-file').modal('show');
  1873. $('#cons-pay-file input[name="cpid"]').val(cpid);
  1874. contractTreeSpreadObj.openContractPayFiles(pay);
  1875. });
  1876. $('#cons-close').on('show.bs.modal', function () {
  1877. const node = SpreadJsObj.getSelectObject(contractSheet);
  1878. if (!node || !node.c_code) {
  1879. toastr.error('请选择一个合同节点');
  1880. $('#cons-close').modal('hide');
  1881. return;
  1882. }
  1883. const df_price = ZhCalc.sub(ZhCalc.sub(node.yf_price, node.sf_price) || 0);
  1884. if (df_price !== 0) {
  1885. $('#close_df_price').text(df_price);
  1886. $('#close_df_price').parents('h5').show();
  1887. } else {
  1888. $('#close_df_price').parents('h5').hide();
  1889. }
  1890. $('#close_contract_code').text(node.c_code + '/' + node.name);
  1891. $('#close_settle_code').val('');
  1892. });
  1893. $('#close_contract_btn').click(function () {
  1894. const settle_code = $('#close_settle_code').val();
  1895. if (!settle_code) {
  1896. toastr.error('请输入结算书编号');
  1897. return;
  1898. }
  1899. const node = SpreadJsObj.getSelectObject(contractSheet);
  1900. if (!node || !node.c_code) {
  1901. toastr.error('请选择一个合同节点');
  1902. return;
  1903. }
  1904. const data = {
  1905. id: node.id,
  1906. settle_code,
  1907. }
  1908. // 更新至服务器
  1909. postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) {
  1910. const refreshNode = contractTree.loadPostData(result);
  1911. contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
  1912. const newNode = SpreadJsObj.getSelectObject(contractSheet);
  1913. contractTreeSpreadObj.changeContractTab(newNode, true);
  1914. // const selection = contractSheet.getSelections();
  1915. // const sel = selection ? selection[0] : contractSheet.getSelections()[0];
  1916. // const row = sel ? sel.row : -1;
  1917. // contractTreeSpreadObj.setForeColor(contractSheet, row);
  1918. $('#cons-close').modal('hide');
  1919. $('a[href*="#cons-unlock"]').show();
  1920. $('a[href*="#cons-close"]').hide();
  1921. });
  1922. });
  1923. $('#unlock_contract_btn').click(function () {
  1924. const node = SpreadJsObj.getSelectObject(contractSheet);
  1925. if (!node || !node.c_code) {
  1926. toastr.error('请选择一个合同节点');
  1927. return;
  1928. }
  1929. const data = {
  1930. id: node.id,
  1931. settle_code: '',
  1932. }
  1933. // 更新至服务器
  1934. postData(window.location.pathname + '/update', {postType: 'update-contract', postData: data}, function (result) {
  1935. const refreshNode = contractTree.loadPostData(result);
  1936. contractTreeSpreadObj.refreshTree(contractSheet, refreshNode);
  1937. const newNode = SpreadJsObj.getSelectObject(contractSheet);
  1938. contractTreeSpreadObj.changeContractTab(newNode, true);
  1939. // const selection = contractSheet.getSelections();
  1940. // const sel = selection ? selection[0] : contractSheet.getSelections()[0];
  1941. // const row = sel ? sel.row : -1;
  1942. // contractTreeSpreadObj.setForeColor(contractSheet, row);
  1943. $('#cons-unlock').modal('hide');
  1944. $('a[href*="#cons-unlock"]').hide();
  1945. $('a[href*="#cons-close"]').show();
  1946. });
  1947. });
  1948. // 显示层次
  1949. (function (select, sheet) {
  1950. $(select).click(function () {
  1951. if (!sheet.zh_tree) return;
  1952. const tag = $(this).attr('tag');
  1953. const tree = sheet.zh_tree;
  1954. setTimeout(() => {
  1955. showWaitingView();
  1956. switch (tag) {
  1957. case "1":
  1958. case "2":
  1959. case "3":
  1960. case "4":
  1961. case "5":
  1962. tree.expandByLevel(parseInt(tag));
  1963. SpreadJsObj.refreshTreeRowVisible(sheet);
  1964. break;
  1965. case "last":
  1966. tree.expandByCustom(() => { return true; });
  1967. SpreadJsObj.refreshTreeRowVisible(sheet);
  1968. break;
  1969. case "leafXmj":
  1970. tree.expandToLeafXmj();
  1971. SpreadJsObj.refreshTreeRowVisible(sheet);
  1972. break;
  1973. }
  1974. closeWaitingView();
  1975. }, 100);
  1976. });
  1977. })('a[name=showLevel]', contractSheet);
  1978. $.divResizer({
  1979. select: '#contract-resize',
  1980. callback: function () {
  1981. contractSpread.refresh();
  1982. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1983. $(".sp-wrap").height(bcontent-30);
  1984. // posSpread.refresh();
  1985. }
  1986. });
  1987. $.subMenu({
  1988. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1989. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1990. key: 'menu.1.0.0',
  1991. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1992. callback: function (info) {
  1993. if (info.mini) {
  1994. $('.panel-title').addClass('fluid');
  1995. $('#sub-menu').removeClass('panel-sidebar');
  1996. } else {
  1997. $('.panel-title').removeClass('fluid');
  1998. $('#sub-menu').addClass('panel-sidebar');
  1999. }
  2000. autoFlashHeight();
  2001. contractSpread.refresh();
  2002. }
  2003. });
  2004. });
  2005. /**
  2006. * 校验文件大小、格式
  2007. * @param {Array} files 文件数组
  2008. */
  2009. function validateFiles(files) {
  2010. if (files.length > 10) {
  2011. toastr.error('至多同时上传10个文件');
  2012. return false
  2013. }
  2014. return files.every(file => {
  2015. if (file.size > 1024 * 1024 * 30) {
  2016. toastr.error('文件大小限制为30MB');
  2017. return false
  2018. }
  2019. if (whiteList.indexOf('.' + file.ext.toLowerCase()) === -1) {
  2020. toastr.error('请上传正确的格式文件');
  2021. return false
  2022. }
  2023. return true
  2024. })
  2025. }