contract_detail.js 100 KB

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