contract_detail.js 100 KB

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