contract_detail.js 99 KB

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