contract_detail.js 107 KB

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