contract_detail.js 90 KB

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