contract_detail.js 105 KB

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