contract_detail.js 99 KB

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