contract_detail.js 89 KB

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