contract_detail.js 99 KB

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