contract_detail.js 106 KB

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