contract_detail.js 93 KB

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