stage.js 166 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
  32. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  33. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  34. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  35. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  36. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  37. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
  38. { title: '本期批注', fields: ['postil'], visible: true },
  39. { title: '图册号', fields: ['drawing_code'], visible: true },
  40. { title: '备注', fields: ['memo'], visible: true },
  41. { title: '总额计量', fields: ['is_tp'], visible: true},
  42. ];
  43. if (checkTzMeasureType()) {
  44. defaultSetting.splice(0, 1);
  45. }
  46. const settingStr = Cookies.get(ckColSetting);
  47. return settingStr ? JSON.parse(settingStr) : defaultSetting;
  48. }
  49. /**
  50. * 根据列显示设置,调整setting中的列是否显示
  51. * @param setting
  52. * @param customDisplay
  53. */
  54. function customizeStageTreeSetting(setting, customDisplay) {
  55. for (const cd of customDisplay) {
  56. for (const c of setting.cols) {
  57. if (cd.fields.indexOf(c.field) !== -1) {
  58. c.visible = cd.visible;
  59. }
  60. }
  61. }
  62. }
  63. /**
  64. * 初始化 树结构 列事件
  65. * @param setting
  66. */
  67. function initTreeColSettingEvents(setting) {
  68. const Events = {
  69. readOnly: {
  70. measureData: function (node) {
  71. return node.children && node.children.length > 0;
  72. },
  73. },
  74. };
  75. const getEvent = function (eventName) {
  76. const names = eventName.split('.');
  77. let event = Events;
  78. for (let name of names) {
  79. if (event[name]) {
  80. event = event[name];
  81. } else {
  82. return null;
  83. }
  84. }
  85. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  86. return null;
  87. } else {
  88. return event;
  89. }
  90. };
  91. for (const col of setting.cols) {
  92. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  93. col.readOnly = getEvent(col.readOnly);
  94. }
  95. }
  96. }
  97. // 生成所有附件列表
  98. function getAllList(currPageNum = 1) {
  99. // 每页最多几个附件
  100. const pageCount = 11;
  101. // 附件总数
  102. const total = attData.length;
  103. // 总页数
  104. const pageNum = Math.ceil(total/pageCount);
  105. $('#totalPage').text(pageNum);
  106. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  107. // 当前页附件内容
  108. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  109. let html = '';
  110. for(const att of currPageAttData) {
  111. html += '<tr ><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  112. }
  113. $('#alllist-table').html(html);
  114. $('#alllist-table').on('click', 'tr', function() {
  115. $('#alllist-table tr').removeClass('bg-light')
  116. $(this).addClass('bg-light')
  117. })
  118. }
  119. // 生成当前节点列表
  120. function getNodeList(node) {
  121. let html = '';
  122. for(const att of attData) {
  123. if (node === att.lid) {
  124. html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  125. }
  126. }
  127. $('#nodelist-table').html(html);
  128. $('#nodelist-table').on('click', 'tr', function() {
  129. $('#nodelist-table tr').removeClass('bg-light')
  130. $(this).addClass('bg-light')
  131. })
  132. }
  133. $(document).ready(() => {
  134. let detail, searchLedger, checkedChanges;
  135. // 界面布局
  136. autoFlashHeight();
  137. // 初始化 台账树结构 数据结构
  138. const stageTreeSetting = {
  139. id: 'ledger_id',
  140. pid: 'ledger_pid',
  141. order: 'order',
  142. level: 'level',
  143. rootId: -1,
  144. keys: ['id', 'tender_id', 'ledger_id'],
  145. stageId: 'id',
  146. };
  147. // 台账树结构计算相关设置
  148. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
  149. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  150. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
  151. stageTreeSetting.calcFun = function (node) {
  152. if (node.children && node.children.length === 0) {
  153. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  154. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  155. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  156. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  157. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  158. }
  159. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  160. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  161. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  162. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  163. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  164. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  165. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  166. node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
  167. };
  168. const stageTree = createNewPathTree('stage', stageTreeSetting);
  169. // 初始化 计量单元 数据结构
  170. const stagePosSetting = {
  171. id: 'id', ledgerId: 'lid',
  172. updateFields: ['contract_qty', 'qc_qty', 'postil', 'contract_expr'],
  173. };
  174. stagePosSetting.calcFun = function (pos) {
  175. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  176. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  177. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  178. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  179. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  180. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  181. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  182. pos.estimate_qty = !checkZero(pos.real_qty)
  183. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  184. : null;
  185. };
  186. const stagePos = new StagePosData(stagePosSetting);
  187. class Changes {
  188. constructor(obj) {
  189. const self = this;
  190. this.obj = obj;
  191. // 初始化 清单编号窗口 参数
  192. this.spreadSetting = {
  193. cols: [
  194. {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
  195. if (data.uamount && !checkZero(data.uamount)) {
  196. return $('#icon-ok')[0];
  197. } else {
  198. return null;
  199. }
  200. }},
  201. {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  202. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  203. {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
  204. //{title: '总数量', field: 'b_amount', width: 60, readOnly: true, hAlign: 2, },
  205. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, type: 'Number', getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  206. {title: '本期计量', field: 'uamount', width: 60, hAlign: 2, type: 'Number', },
  207. ],
  208. emptyRows: 0,
  209. headRows: 1,
  210. headRowHeight: [32],
  211. headerFont: '12px 微软雅黑',
  212. font: '12px 微软雅黑',
  213. getColor: function (sheet, data, row, col, defaultColor) {
  214. if (col.field === 'uamount') {
  215. if (data.bamount > 0) {
  216. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  217. return usedAmount < 0 || usedAmount > data.bamount ? '#ff6f5c' : defaultColor;
  218. } else if (data.bamount < 0) {
  219. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  220. return usedAmount > 0 || usedAmount < data.bamount ? '#ff6f5c' : defaultColor;
  221. } else {
  222. return data.uamount ? '#ff6f5c' : defaultColor;
  223. }
  224. } else {
  225. return defaultColor;
  226. }
  227. }
  228. };
  229. this.curChangeId = '';
  230. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  231. this.firstView = true;
  232. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  233. // 初次显示,需刷新spread界面,保证界面绘制正确
  234. this.obj.bind('shown.bs.modal', function () {
  235. if (self.firstView) {
  236. self.firstView = false;
  237. self.spread.refresh();
  238. }
  239. });
  240. // 切换变更令,加载右侧明细数据
  241. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  242. const change = SpreadJsObj.getSelectObject(info.sheet);
  243. self._loadChangeDetail(change);
  244. });
  245. // 填写本期计量
  246. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  247. if (info.sheet.zh_setting) {
  248. const col = info.sheet.zh_setting.cols[info.col];
  249. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  250. const node = sortData[info.row];
  251. node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
  252. // 刷新界面
  253. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  254. }
  255. });
  256. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  257. if (info.sheet.zh_setting) {
  258. const sortData = SpreadJsObj.getSortData(info.sheet);
  259. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  260. const curRow = iRow + info.cellRange.row;
  261. const curCol = info.cellRange.col;
  262. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  263. sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
  264. }
  265. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  266. }
  267. });
  268. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  269. if (sheet.zh_setting) {
  270. const sel = sheet.getSelections()[0];
  271. const sortData = SpreadJsObj.getSortData(sheet);
  272. // 仅本期计量可删除
  273. if (sel.col === 5 && sel.colCount === 1) {
  274. const col = sheet.zh_setting.cols[sel.col];
  275. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  276. const data = sortData[iRow];
  277. data[col.field] = null;
  278. }
  279. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  280. }
  281. }
  282. });
  283. // 过滤可变更数量为0
  284. $('#filterEmpty').click(function () {
  285. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  286. });
  287. // 匹配编号
  288. $('#matchPos').click(function () {
  289. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  290. });
  291. // 展开收起 变更令详细信息
  292. $('#show-bgl-detail').bind('click', function () {
  293. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  294. if (detail.hasClass('col-4')) {
  295. detail.attr('class', 'col').hide();
  296. bgl.attr('class', 'col-12');
  297. $('a', obj).attr('title', '展开侧栏');
  298. $('i', obj).attr('class', 'fa fa-chevron-left');
  299. self.spread.refresh();
  300. } else {
  301. detail.attr('class', 'col-4').show();
  302. bgl.attr('class', 'col-8');
  303. $('a', obj).attr('title', '收起侧栏');
  304. $('i', obj).attr('class', 'fa fa-chevron-right');
  305. self.spread.refresh();
  306. }
  307. });
  308. // 添加调用变更令
  309. $('#usg-bg-ok').click(function () {
  310. const data = { target: self.callData, change: [] };
  311. for (const c of self.displayChanges) {
  312. if (c.uamount) {
  313. if (c.bamount > 0) {
  314. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  315. if (usedAmount < 0 || usedAmount > c.bamount) {
  316. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  317. return;
  318. }
  319. } else if (c.bamount < 0) {
  320. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  321. if (usedAmount > 0 || usedAmount < c.bamount) {
  322. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  323. return;
  324. }
  325. } else {
  326. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  327. return;
  328. }
  329. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
  330. }
  331. }
  332. // 提交数据到后端
  333. postData(window.location.pathname + '/use-change', data, function(result) {
  334. if (result.pos) {
  335. stagePos.loadCurStageData(result.pos.curStageData);
  336. }
  337. const nodes = stageTree.loadPostStageData(result.bills);
  338. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  339. stagePosSpreadObj.loadCurPosData();
  340. if (detail) {
  341. detail.loadStageChangeUpdateData(result);
  342. } else {
  343. stageIm.loadUpdateChangeData(result)
  344. }
  345. self.obj.modal('hide');
  346. });
  347. })
  348. }
  349. _calculateAmount() {
  350. for (const c of this.changes) {
  351. c.bamount = _.toNumber(c.b_amount);
  352. c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
  353. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
  354. if (uc) {
  355. c.org_uamount = uc.qty;
  356. c.uamount = uc.qty;
  357. c.vamount = ZhCalc.add(c.vamount, c.uamount);
  358. }
  359. c.pre_amount = ZhCalc.sub(c.used_amount, c.uamount);
  360. }
  361. }
  362. _loadChangeDetail(change) {
  363. if (change) {
  364. if (change.cid === this.curChangeId) { return; }
  365. this.curChangeId = change.cid;
  366. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  367. for (const i of inputs) {
  368. const field = $(i).attr('name');
  369. const text = (field && change[field]) ? change[field] : '';
  370. $(i).val(text);
  371. }
  372. const textareas = $('textarea', this.obj);
  373. for (const ta of textareas) {
  374. const field = $(ta).attr('name');
  375. const text = (field && change[field]) ? change[field] : '';
  376. ta.textContent = text;
  377. }
  378. const html = [];
  379. for (const a of change.attachments) {
  380. html.push('<tr>');
  381. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  382. html.push('<td>', a.u_name, '</td>');
  383. html.push('</tr>');
  384. }
  385. // 变更类型
  386. if (change.type) {
  387. const cType = change.type.split(',');
  388. $('input[name="type"]').prop("checked", false);
  389. for (const c of cType) {
  390. $('input[name="type"][value='+ c +']').prop("checked", true);
  391. }
  392. }
  393. // 变更类别
  394. $('select[name=class]').val(change.class);
  395. // 变更性质
  396. $('select[name=quality]').val(change.quality);
  397. // 变更单位
  398. $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
  399. // 费用承担方
  400. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  401. // 附件
  402. $('#attachment').html(html.join(''));
  403. } else {
  404. const inputs = $('input', this.obj);
  405. for (const i of inputs) {
  406. $(i).val('');
  407. }
  408. const textareas = $('textarea', this.obj);
  409. for (const ta of textareas) {
  410. ta.innerText = '';
  411. }
  412. $('#attachment').html('');
  413. }
  414. }
  415. _viewChanges() {
  416. const sheet = this.spread.getActiveSheet();
  417. if (this.changes) {
  418. sheet.setSelection(0, 0, 1, 1);
  419. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  420. this._loadChangeDetail(this.changes[0]);
  421. } else {
  422. toastr.error('查询变更令有误,请刷新页面后重试');
  423. }
  424. }
  425. _filterChange(filterEmpty, matchPosName) {
  426. this.displayChanges = [];
  427. for (const c of this.changes) {
  428. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  429. const matchVisible = matchPosName && this.callData.pos ? c.b_bwmx === this.callData.pos.name : true;
  430. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  431. this.displayChanges.push(c);
  432. }
  433. }
  434. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  435. }
  436. loadChanges(data) {
  437. this.callData = data;
  438. if (this.callData.pos) {
  439. $('#matchPos').parent().show();
  440. } else {
  441. $('#matchPos').parent().hide();
  442. }
  443. const self = this;
  444. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  445. postData(window.location.pathname + '/valid-change', data, function (result) {
  446. self.changes = result.changes;
  447. self.useChanges = result.useChanges;
  448. self._calculateAmount();
  449. self._viewChanges();
  450. self.obj.modal('show');
  451. });
  452. }
  453. }
  454. const changesObj = new Changes($('#use-bg'));
  455. // 初始化 台账 spread
  456. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  457. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  458. // 数量变更列,添加按钮
  459. const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
  460. col.readOnly = true;
  461. col.cellType = 'activeImageBtn';
  462. col.normalImg = '#ellipsis-icon';
  463. col.indent = 5;
  464. col.showImage = function (data) {
  465. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  466. return false;
  467. } else {
  468. const nodePos = stagePos.getLedgerPos(data.id);
  469. return !(nodePos && nodePos.length > 0);
  470. }
  471. };
  472. ledgerSpreadSetting.imageClick = function (data) {
  473. if (data.children && data.children.length > 0) return;
  474. const nodePos = stagePos.getLedgerPos(data.id);
  475. if (nodePos && nodePos.length > 0) return;
  476. changesObj.loadChanges({bills: data});
  477. };
  478. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  479. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  480. if (data) {
  481. const posRange = stagePos.ledgerPos[itemsPre + data.id] || [];
  482. if (posRange.length > 0) {
  483. for (const p of posRange) {
  484. if (p.end_contract_qty > p.quantity) return '#f8d7da';
  485. }
  486. }
  487. if (data.is_tp) {
  488. return data.end_contract_tp > data.total_price ? '#f8d7da' : defaultColor;
  489. } else {
  490. return data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
  491. }
  492. } else {
  493. return defaultColor;
  494. }
  495. };
  496. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  497. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  498. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  499. slSpread.getActiveSheet().frozenColumnCount(5);
  500. slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
  501. //初始化所有附件列表
  502. getAllList();
  503. // 初始化 计量单元 Spread
  504. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  505. const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
  506. spCol.readOnly = true;
  507. spCol.cellType = 'activeImageBtn';
  508. spCol.normalImg = '#ellipsis-icon';
  509. spCol.indent = 5;
  510. spCol.showImage = function (data) {
  511. return data !== undefined && data !== null;
  512. };
  513. posSpreadSetting.imageClick = function (data) {
  514. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  515. changesObj.loadChanges({bills: node, pos: data});
  516. };
  517. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  518. return data && data.end_contract_qty > data.quantity ? '#f8d7da' : defaultColor;
  519. };
  520. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  521. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  522. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  523. const errorList = $.cs_errorList({
  524. tabSelector: '#error-list-tab',
  525. selector: '#error-list',
  526. relaSpread: slSpread,
  527. storeKey: 'stage-error-' + stage.id,
  528. afterLocated: function () {
  529. stagePosSpreadObj.loadCurPosData();
  530. },
  531. afterShow: function () {
  532. slSpread.refresh();
  533. if (spSpread) spSpread.refresh();
  534. },
  535. });
  536. const stageTreeSpreadObj = {
  537. loadExprToInput(sheet) {
  538. const sel = sheet.getSelections()[0];
  539. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  540. if (col.type === 'Number') {
  541. const data = SpreadJsObj.getSelectObject(sheet);
  542. if (!data) {
  543. $('#bills-expr').val('').attr('readOnly', true);
  544. $('#bills-expr').removeAttr('data-row');
  545. return;
  546. }
  547. const nodePos = stagePos.getLedgerPos(data.id);
  548. if (nodePos && nodePos.length > 0) {
  549. $('#bills-expr').val('').attr('readOnly', true);
  550. } else {
  551. const exprInfo = getExprInfo(col.field);
  552. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  553. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  554. if (col.field.indexOf('tp') >= 0) {
  555. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  556. } else {
  557. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  558. }
  559. }
  560. $('#bills-expr').attr('data-row', sel.row);
  561. } else {
  562. $('#bills-expr').val('').attr('readOnly', true);
  563. $('#bills-expr').removeAttr('data-row');
  564. }
  565. },
  566. refreshTreeNodes: function (sheet, nodes) {
  567. const tree = sheet.zh_tree;
  568. if (!tree) { return }
  569. const rows = [];
  570. for (const node of nodes) {
  571. rows.push(tree.nodes.indexOf(node));
  572. }
  573. SpreadJsObj.reLoadRowsData(sheet, rows);
  574. },
  575. editEnded: function (e, info) {
  576. if (info.sheet.zh_setting) {
  577. const col = info.sheet.zh_setting.cols[info.col];
  578. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  579. const node = sortData[info.row], updateData = {};
  580. const orgValue = node[col.field];
  581. let newValue = trimInvalidChar(info.editingText);
  582. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  583. return;
  584. }
  585. if (col.type === 'Number' && newValue && newValue !== '') {
  586. const num = _.toNumber(newValue);
  587. if (_.isFinite(num)) {
  588. newValue = num;
  589. } else {
  590. try {
  591. newValue = math.evaluate(transExpr(newValue));
  592. } catch(err) {
  593. toastr.error('输入的表达式非法');
  594. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  595. return;
  596. }
  597. }
  598. }
  599. if (col.field.indexOf('_dgn_') > 0) {
  600. if (node.b_code && node.b_code !== '') {
  601. toastr.error('仅项目节可输入项目节数量');
  602. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  603. return;
  604. }
  605. } else if (col.field !== 'postil' && col.field !== 'memo') {
  606. if (node.children && node.children.length > 0) {
  607. toastr.error('清单父项不可计量');
  608. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  609. return;
  610. } else {
  611. const nodePos = stagePos.getLedgerPos(node.id);
  612. if (nodePos && nodePos.length > 0) {
  613. toastr.error('该清单有计量单元,请在计量单元处计量');
  614. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  615. return;
  616. }
  617. }
  618. }
  619. if (col.field === 'memo') {
  620. updateData.main = {
  621. id: node.id
  622. };
  623. updateData.main[col.field] = newValue;
  624. } else if (col.field.indexOf('_dgn_') > 0) {
  625. updateData.dgn = {
  626. id: node.id
  627. };
  628. updateData.dgn[col.field] = newValue;
  629. } else if (col.field !== 'is_tp') {
  630. updateData.stage = {
  631. lid: node.id
  632. };
  633. updateData.stage[col.field] = newValue;
  634. const exprInfo = getExprInfo(col.field);
  635. if (exprInfo) {
  636. updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
  637. }
  638. }
  639. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  640. // tag update
  641. const nodes = stageTree.loadPostStageData(data);
  642. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  643. if (detail) {
  644. detail.loadStageLedgerUpdateData(data);
  645. } else {
  646. stageIm.loadUpdateLedgerData(data);
  647. }
  648. }, function () {
  649. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  650. });
  651. }
  652. },
  653. selectionChanged: function (e, info) {
  654. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  655. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  656. stagePosSpreadObj.loadCurPosData();
  657. if (posSearch) {
  658. posSearch.search();
  659. }
  660. }
  661. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  662. stageTreeSpreadObj.loadExprToInput(info.sheet);
  663. },
  664. deletePress(sheet) {
  665. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  666. const tree = sheet.zh_tree;
  667. if (!tree) { return; }
  668. const sel = sheet.getSelections()[0];
  669. const validCols = [];
  670. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  671. const colSetting = sheet.zh_setting.cols[iCol];
  672. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  673. validCols.push(iCol);
  674. }
  675. }
  676. if (validCols.length === 0) { return; }
  677. const sortData = sheet.zh_tree.nodes;
  678. const datas = [], dgnDatas = [], mainDatas = [];
  679. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  680. const node = sortData[iRow];
  681. if (node) {
  682. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  683. let filter = true, filterDgn = true, filterMain = true;
  684. for (const iCol of validCols) {
  685. const colSetting = sheet.zh_setting.cols[iCol];
  686. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  687. if (node.b_code && node.b_code !== '') continue;
  688. } else if (colSetting.field !== 'postil') {
  689. if (node.children && node.children.length > 0) { continue; }
  690. const nodePos = stagePos.getLedgerPos(node.id);
  691. if (nodePos && nodePos.length > 0) { continue; }
  692. }
  693. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  694. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  695. dgnData[colSetting.field] = 0;
  696. filterDgn = false;
  697. }
  698. } else if (colSetting.field === 'memo') {
  699. mainData[colSetting.field] = null;
  700. filterMain = false;
  701. } else {
  702. data[colSetting.field] = null;
  703. const exprInfo = getExprInfo(colSetting.field);
  704. if (exprInfo) {
  705. data[exprInfo.expr] = '';
  706. }
  707. filter = false;
  708. }
  709. }
  710. if (!filter) datas.push(data);
  711. if (!filterDgn) dgnDatas.push(dgnData);
  712. if (!filterMain) mainDatas.push(mainData);
  713. }
  714. }
  715. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  716. const bills = {};
  717. if (datas.length > 0) bills.stage = datas;
  718. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  719. if (mainDatas.length > 0) bills.main = mainDatas;
  720. postData(window.location.href + '/update', {bills: bills}, function (result) {
  721. const nodes = stageTree.loadPostStageData(result);
  722. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  723. if (detail) {
  724. detail.loadStageLedgerUpdateData(result);
  725. } else {
  726. stageIm.loadUpdateLedgerData(result);
  727. }
  728. stageTreeSpreadObj.loadExprToInput(sheet);
  729. });
  730. }
  731. }
  732. },
  733. clipboardPasting(e, info) {
  734. if (info.sheet.zh_setting) {
  735. const setting = info.sheet.zh_setting;
  736. const range = info.cellRange;
  737. const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
  738. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  739. const col = info.sheet.zh_setting.cols[iCol];
  740. if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1
  741. && col.field !== 'memo') {
  742. toastr.error('不可修改此数据');
  743. info.cancel = true;
  744. return;
  745. }
  746. }
  747. }
  748. },
  749. clipboardPasted(e, info) {
  750. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  751. const sheet = info.sheet, setting = info.sheet.zh_setting;
  752. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  753. let bHint = false;
  754. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  755. const curRow = iRow + info.cellRange.row;
  756. const node = sheet.zh_tree.getItemsByIndex(curRow);
  757. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  758. let filter = true, filterDgn = true, filterMain = true;
  759. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  760. const curCol = info.cellRange.col + iCol;
  761. const col = info.sheet.zh_setting.cols[curCol];
  762. if (col.field === 'contract_tp') {
  763. if (!node.is_tp) continue;
  764. } else if (col.field === 'contract_qty') {
  765. if (node.is_tp) continue;
  766. }
  767. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  768. if (node.b_code && node.b_code !== '') continue;
  769. } else if (col.field !== 'postil') {
  770. if (node.children && node.children.length > 0) continue;
  771. const nodePos = stagePos.getLedgerPos(node.id);
  772. if (nodePos && nodePos.length > 0) continue;
  773. }
  774. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  775. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  776. const num = _.toNumber(text);
  777. if (num) {
  778. dgnData[col.field] = num;
  779. filterDgn = false;
  780. } else {
  781. try {
  782. dgnData[col.field] = math.evaluate(transExpr(text));
  783. filterDgn = false;
  784. } catch(err) {
  785. if (!bHint) {
  786. toastr.warning('粘贴了非法表达式,已过滤');
  787. bHint = true;
  788. }
  789. }
  790. }
  791. } else if (col.field === 'memo') {
  792. mainData.memo = text;
  793. filterMain = false;
  794. } else {
  795. if (col.type === 'Number') {
  796. const num = _.toNumber(text);
  797. if (_.isFinite(num)) {
  798. data[col.field] = num;
  799. filter = false;
  800. } else {
  801. try {
  802. data[col.field] = math.evaluate(transExpr(text));
  803. const exprInfo = getExprInfo(col.field);
  804. if (exprInfo) {
  805. data[exprInfo.expr] = text;
  806. }
  807. filter = false;
  808. } catch(err) {
  809. if (!bHint) {
  810. toastr.warning('粘贴了非法表达式,已过滤');
  811. bHint = true;
  812. }
  813. }
  814. }
  815. } else {
  816. data[col.field] = text;
  817. }
  818. }
  819. }
  820. if (filter && filterDgn && filterMain) {
  821. filterNodes.push(node);
  822. } else {
  823. if (!filter) datas.push(data);
  824. if (!filterDgn) dgnDatas.push(dgnData);
  825. if (!filterMain) mainDatas.push(mainData);
  826. }
  827. }
  828. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  829. const updateData = {};
  830. if (datas.length > 0) updateData.stage = datas;
  831. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  832. if (mainDatas.length > 0) updateData.main = mainDatas;
  833. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  834. const nodes = stageTree.loadPostStageData(data);
  835. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  836. if (detail) {
  837. detail.loadStageLedgerUpdateData(data);
  838. } else {
  839. stageIm.loadUpdateLedgerData(data);
  840. }
  841. stageTreeSpreadObj.loadExprToInput(sheet);
  842. }, function () {
  843. // todo
  844. //stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  845. });
  846. } else {
  847. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  848. }
  849. }
  850. },
  851. measureAllPosInNode(node, ratio = 1) {
  852. const posterity = stageTree.getPosterity(node)
  853. const data = {updateType: 'update', updateData: []};
  854. for (const p of posterity) {
  855. if (p.children && p.children.length > 0) continue;
  856. const posRange = stagePos.getLedgerPos(p.id);
  857. if (posRange && posRange.length > 0) {
  858. for (const pr of posRange) {
  859. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  860. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  861. if (validValue <= 0) continue;
  862. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  863. const pData = {
  864. pid: pr.id,
  865. lid: pr.lid,
  866. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  867. };
  868. data.updateData.push(pData);
  869. }
  870. }
  871. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  872. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  873. break;
  874. }
  875. }
  876. if (data.updateData.length === 0) {
  877. toastr.info('其下全部计量单元均已计量');
  878. return;
  879. }
  880. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  881. if (result.pos) {
  882. stagePos.updateDatas(result.pos.pos);
  883. stagePos.loadCurStageData(result.pos.curStageData);
  884. }
  885. const nodes = stageTree.loadPostStageData(result.ledger);
  886. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  887. stagePosSpreadObj.loadCurPosData();
  888. if (detail) {
  889. detail.loadStagePosUpdateData(result);
  890. } else {
  891. stageIm.loadUpdatePosData(result);
  892. }
  893. toastr.success('已计量' + data.updateData.length + '条');
  894. }, function () {
  895. stagePosSpreadObj.loadCurPosData();
  896. });
  897. },
  898. topRowChanged(e, info) {
  899. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  900. },
  901. editStarting(e, info) {
  902. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  903. const col = info.sheet.zh_setting.cols[info.col];
  904. const node = info.sheet.zh_tree.nodes[info.row];
  905. const exprInfo = getExprInfo(col.field);
  906. if (exprInfo) {
  907. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  908. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  909. }
  910. }
  911. switch (col.field) {
  912. case 'contract_qty':
  913. case 'qc_qty':
  914. info.cancel = node.is_tp;
  915. break;
  916. case 'contract_tp':
  917. info.cancel = !node.is_tp;
  918. break;
  919. case 'is_tp':
  920. info.cancel = true;
  921. break;
  922. }
  923. },
  924. buttonClicked: function (e, info) {
  925. if (info.sheet.zh_setting) {
  926. const node = SpreadJsObj.getSelectObject(info.sheet);
  927. const col = info.sheet.zh_setting.cols[info.col];
  928. const posRange = stagePos.getLedgerPos(node.id);
  929. if (node.pre_used === 1 || node.unit !== '总额' || (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  930. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  931. return;
  932. }
  933. const postIsTp = function () {
  934. const data = { calcType: {id: node.id} };
  935. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  936. // 更新至服务器
  937. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  938. const nodes = stageTree.loadPostStageData(result);
  939. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  940. if (detail) {
  941. detail.loadStageLedgerUpdateData(result);
  942. } else {
  943. stageIm.loadUpdateLedgerData(result);
  944. }
  945. });
  946. };
  947. if (col.field === 'is_tp') {
  948. if (info.sheet.isEditing()) {
  949. info.sheet.endEdit(true);
  950. }
  951. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp)) {
  952. $.msgBox({
  953. id: 'calc-type',
  954. title: '提示',
  955. message: '切换计量模式,已计量数据会被清空。',
  956. ok: {
  957. caption: '确定',
  958. callback: postIsTp,
  959. },
  960. cancel: {
  961. caption: '取消',
  962. callback: function () {
  963. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  964. }
  965. }
  966. });
  967. } else {
  968. postIsTp();
  969. }
  970. }
  971. }
  972. },
  973. };
  974. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  975. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  976. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  977. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  978. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  979. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  980. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  981. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  982. if (!readOnly) {
  983. $('#bills-expr').bind('change onblur', function () {
  984. if (this.readOnly) return;
  985. const expr = $(this);
  986. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  987. const select = stageTree.getItemsByIndex(row);
  988. if (!select) return;
  989. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  990. let newValue = expr.val();
  991. const num = _.toNumber(newValue);
  992. if (_.isFinite(num)) {
  993. newValue = num;
  994. } else {
  995. try {
  996. newValue = math.evaluate(transExpr(newValue));
  997. } catch(err) {
  998. toastr.error('输入的表达式非法');
  999. return;
  1000. }
  1001. }
  1002. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1003. if (field.indexOf('_dgn_') > 0) {
  1004. updateData.dgn = {
  1005. id: select.id
  1006. };
  1007. updateData.dgn[field] = newValue;
  1008. } else {
  1009. updateData.stage = {
  1010. lid: select.id
  1011. };
  1012. updateData.stage[field] = newValue;
  1013. const exprInfo = getExprInfo(field);
  1014. if (exprInfo) {
  1015. updateData.stage[exprInfo.expr] = expr.val();
  1016. }
  1017. }
  1018. // 更新至服务器
  1019. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1020. const nodes = stageTree.loadPostStageData(result);
  1021. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1022. });
  1023. });
  1024. }
  1025. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1026. $.contextMenu({
  1027. selector: '#stage-ledger',
  1028. build: function ($trigger, e) {
  1029. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1030. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1031. },
  1032. items: {
  1033. 'locateZjjl': {
  1034. name: '定位至中间计量',
  1035. icon: 'fa-sign-in',
  1036. callback: function (key, opt) {
  1037. if (!detail) {
  1038. detail = new Detail($('#detail-spread'));
  1039. }
  1040. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1041. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1042. if (leafUsedBills) {
  1043. if (!$('#zhongjian').hasClass('active')) {
  1044. const tab = $('#zhongjian'), tabPanel = $(tab.attr('content'));
  1045. $('a', '.side-menu').removeClass('active');
  1046. $('.tab-content .tab-select-show').removeClass('active');
  1047. tab.addClass('active');
  1048. tabPanel.addClass('active');
  1049. showSideTools(tab.hasClass('active'));
  1050. slSpread.refresh();
  1051. spSpread.refresh();
  1052. }
  1053. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1054. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1055. SpreadJsObj.locateData(detail.sheet, im);
  1056. detail.spread.refresh();
  1057. $('#zhongjian .sjs-bottom').height('400px');
  1058. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1059. detail.reLoadDetailData();
  1060. } else {
  1061. toastr.error('无可定位中间计量');
  1062. }
  1063. },
  1064. },
  1065. }
  1066. });
  1067. const stagePosSpreadObj = {
  1068. loadExprToInput(sheet) {
  1069. const sel = sheet.getSelections()[0];
  1070. if (!sel) return;
  1071. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1072. if (col && col.type === 'Number') {
  1073. const data = SpreadJsObj.getSelectObject(sheet);
  1074. if (data) {
  1075. const exprInfo = getExprInfo(col.field);
  1076. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1077. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1078. .attr('readOnly', readOnly || cell.locked());
  1079. $('#pos-expr').attr('data-row', sel.row);
  1080. } else {
  1081. $('#pos-expr').val('').attr('readOnly', true);
  1082. $('#pos-expr').removeAttr('data-row');
  1083. }
  1084. } else {
  1085. $('#pos-expr').val('').attr('readOnly', true);
  1086. $('#pos-expr').removeAttr('data-row');
  1087. }
  1088. },
  1089. /**
  1090. * 加载计量单元 根据当前台账选择节点
  1091. */
  1092. loadCurPosData: function () {
  1093. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1094. if (node) {
  1095. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1096. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  1097. getNodeList(node.id);
  1098. // 如果是附件是当前节点,隐藏
  1099. // if ($('#dqjiedian').hasClass('active')) {
  1100. // $('#showAttachment').hide();
  1101. // }
  1102. } else {
  1103. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1104. }
  1105. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1106. },
  1107. editEnded: function (e, info) {
  1108. if (info.sheet.zh_setting) {
  1109. // 未改变过,则直接跳过
  1110. const sortData = info.sheet.zh_data;
  1111. const posData = sortData ? sortData[info.row] : null;
  1112. const col = info.sheet.zh_setting.cols[info.col];
  1113. const orgText = posData ? posData[col.field] : null;
  1114. const newText = trimInvalidChar(info.editingText);
  1115. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1116. return;
  1117. }
  1118. // 台账模式下,不可新增
  1119. if (checkTzMeasureType() && !posData) {
  1120. toastr.error('台账模式不可新增计量单元数据');
  1121. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1122. return ;
  1123. }
  1124. // 不同节点下,计量单元检查输入
  1125. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1126. const node = stagePosSpreadObj.stageTreeNode;
  1127. if (!node) {
  1128. toastr.warning('数据错误, 请刷新页面后再试');
  1129. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1130. return;
  1131. } else if (newText !== '' && node.children && node.children > 0) {
  1132. toastr.error('父节点不可插入计量单元');
  1133. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1134. return;
  1135. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1136. toastr.error('项目节不可插入计量单元');
  1137. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1138. return;
  1139. }
  1140. // 生成提交数据
  1141. const data = {};
  1142. if (col.field === 'name') {
  1143. if ((!newText || newText === '') && posData) {
  1144. toastr.error('部位名称不可为空');
  1145. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1146. return;
  1147. } else if (!posData) {
  1148. if (newText !== '') {
  1149. data.updateType = 'add';
  1150. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1151. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1152. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1153. return;
  1154. }
  1155. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1156. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1157. } else {
  1158. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1159. return;
  1160. }
  1161. } else {
  1162. data.updateType = 'update';
  1163. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1164. }
  1165. } else if (!posData) {
  1166. toastr.warning('新增计量单元请先输入名称');
  1167. } else {
  1168. data.updateType = 'update';
  1169. data.updateData = {pid: posData.id, lid: posData.lid};
  1170. if (col.type === 'Number') {
  1171. const exprInfo = getExprInfo(col.field);
  1172. const num = _.toNumber(newText);
  1173. if (_.isFinite(num)) {
  1174. data.updateData[col.field] = num;
  1175. if (exprInfo) {
  1176. data.updateData[exprInfo.expr] = '';
  1177. }
  1178. } else {
  1179. try {
  1180. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1181. if (exprInfo) {
  1182. data.updateData[exprInfo.expr] = newText;
  1183. }
  1184. } catch(err) {
  1185. toastr.error('输入的表达式非法');
  1186. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1187. return;
  1188. }
  1189. }
  1190. } else {
  1191. data.updateData[col.field] = newText;
  1192. }
  1193. }
  1194. // 提交数据到服务器
  1195. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1196. if (result.pos) {
  1197. stagePos.updateDatas(result.pos.pos);
  1198. stagePos.loadCurStageData(result.pos.curStageData);
  1199. }
  1200. const refreshData = stageTree.loadPostStageData(result.ledger);
  1201. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1202. stagePosSpreadObj.loadCurPosData();
  1203. if (detail) {
  1204. detail.loadStagePosUpdateData(result);
  1205. } else {
  1206. stageIm.loadUpdatePosData(result);
  1207. }
  1208. }, function () {
  1209. stagePosSpreadObj.loadCurPosData();
  1210. });
  1211. }
  1212. },
  1213. editStarting: function (e, info) {
  1214. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1215. const sel = info.sheet.getSelections();
  1216. if (!sel || !sel[0]) return;
  1217. const col = info.sheet.zh_setting.cols[sel[0].col];
  1218. const node = SpreadJsObj.getSelectObject(info.sheet);
  1219. const exprInfo = getExprInfo(col.field);
  1220. if (exprInfo) {
  1221. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1222. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1223. }
  1224. }
  1225. },
  1226. clipboardPasting: function (e, info) {
  1227. if (info.sheet.zh_setting) {
  1228. const sortData = info.sheet.zh_data;
  1229. const range = info.cellRange;
  1230. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty'];
  1231. if (!checkTzMeasureType()) {
  1232. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1233. }
  1234. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1235. const col = info.sheet.zh_setting.cols[iCol];
  1236. if (validField.indexOf(col.field) === -1) {
  1237. if (checkTzMeasureType()) {
  1238. toastr.error('不可修改此数据');
  1239. info.cancel = true;
  1240. return;
  1241. } else {
  1242. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1243. const pos = sortData(iRow);
  1244. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1245. toastr.error('不可修改此数据');
  1246. info.cancel = true;
  1247. return;
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. },
  1255. clipboardPasted: function (e, info) {
  1256. if (info.sheet.zh_setting) {
  1257. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1258. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1259. }
  1260. const data = { updateType: '', updateData: [], };
  1261. const sortData = info.sheet.zh_data;
  1262. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1263. if (sortData && (info.cellRange.row >= sortData.length)) {
  1264. data.updateType = 'add';
  1265. if (info.cellRange.col !== 0) {
  1266. toastr.warning('新增计量单元请先输入名称');
  1267. stagePosSpreadObj.loadCurPosData();
  1268. return;
  1269. }
  1270. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1271. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1272. stagePosSpreadObj.loadCurPosData();
  1273. return;
  1274. }
  1275. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1276. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1277. const curRow = info.cellRange.row + iRow;
  1278. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1279. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1280. const curCol = info.cellRange.col + iCol;
  1281. const colSetting = info.sheet.zh_setting.cols[curCol];
  1282. if (!colSetting) continue;
  1283. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1284. if (colSetting.type === 'Number') {
  1285. const num = _.toNumber(newValue);
  1286. if (num) {
  1287. newData[colSetting.field] = num;
  1288. } else {
  1289. try {
  1290. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1291. const exprInfo = getExprInfo(colSetting.field);
  1292. if (exprInfo) {
  1293. newData[exprInfo.expr] = newValue;
  1294. }
  1295. } catch(err) {
  1296. toastr.error('输入的表达式非法');
  1297. stagePosSpreadObj.loadCurPosData();
  1298. return;
  1299. }
  1300. }
  1301. } else {
  1302. newData[colSetting.field] = newValue;
  1303. }
  1304. }
  1305. data.updateData.push(newData);
  1306. }
  1307. } else {
  1308. data.updateType = 'update';
  1309. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1310. const curRow = info.cellRange.row + iRow;
  1311. const curPos = sortData[curRow];
  1312. if (curPos) {
  1313. const newData = {pid: curPos.id, lid: curPos.lid};
  1314. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1315. const curCol = info.cellRange.col + iCol;
  1316. const colSetting = info.sheet.zh_setting.cols[curCol];
  1317. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1318. if (colSetting.type === 'Number') {
  1319. const num = _.toNumber(newValue);
  1320. if (num) {
  1321. newData[colSetting.field] = num;
  1322. } else {
  1323. try {
  1324. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1325. const exprInfo = getExprInfo(colSetting.field);
  1326. if (exprInfo) {
  1327. newData[exprInfo.expr] = newValue;
  1328. }
  1329. } catch(err) {
  1330. toastr.error('输入的表达式非法');
  1331. stagePosSpreadObj.loadCurPosData();
  1332. return;
  1333. }
  1334. }
  1335. } else {
  1336. newData[colSetting.field] = newValue;
  1337. }
  1338. }
  1339. data.updateData.push(newData);
  1340. }
  1341. }
  1342. }
  1343. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1344. if (result.pos) {
  1345. stagePos.updateDatas(result.pos.pos);
  1346. stagePos.loadCurStageData(result.pos.curStageData);
  1347. }
  1348. const nodes = stageTree.loadPostStageData(result.ledger);
  1349. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1350. stagePosSpreadObj.loadCurPosData();
  1351. if (detail) {
  1352. detail.loadStagePosUpdateData(result);
  1353. } else {
  1354. stageIm.loadUpdatePosData(result);
  1355. }
  1356. }, function () {
  1357. stagePosSpreadObj.loadCurPosData();
  1358. });
  1359. }
  1360. },
  1361. deletePress: function (sheet) {
  1362. if (sheet.zh_setting && sheet.zh_data) {
  1363. const sortData = sheet.zh_data;
  1364. if (!sortData || sortData.length === 0) { return; }
  1365. const sel = sheet.getSelections()[0];
  1366. const validCols = [];
  1367. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1368. const colSetting = sheet.zh_setting.cols[iCol];
  1369. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1370. validCols.push(iCol);
  1371. }
  1372. }
  1373. if (validCols.length === 0) { return; }
  1374. const datas = [], posSelects = [];
  1375. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1376. const node = sortData[iRow];
  1377. if (node) {
  1378. const data = {pid: node.id, lid: node.lid};
  1379. for (const iCol of validCols) {
  1380. const colSetting = sheet.zh_setting.cols[iCol];
  1381. if (colSetting.field === 'name') {
  1382. toastr.error('部位名称不能为空');
  1383. return;
  1384. }
  1385. data[colSetting.field] = null;
  1386. const exprInfo = getExprInfo(colSetting.field);
  1387. if (exprInfo) {
  1388. data[exprInfo.expr] = '';
  1389. }
  1390. }
  1391. datas.push(data);
  1392. posSelects.push(node);
  1393. }
  1394. }
  1395. if (datas.length > 0) {
  1396. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1397. if (result.pos) {
  1398. stagePos.updateDatas(result.pos.pos);
  1399. stagePos.loadCurStageData(result.pos.curStageData);
  1400. }
  1401. const nodes = stageTree.loadPostStageData(result.ledger);
  1402. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1403. if (detail) {
  1404. detail.loadStagePosUpdateData(result);
  1405. } else {
  1406. stageIm.loadUpdatePosData(result);
  1407. }
  1408. // todo 只加载改变项
  1409. stagePosSpreadObj.loadCurPosData();
  1410. });
  1411. }
  1412. }
  1413. },
  1414. deletePos: function (sheet) {
  1415. const sels = sheet.getSelections();
  1416. const sel = sels ? sels[0] : null;
  1417. if (sheet.zh_data && sel) {
  1418. const data = {updateType: 'delete', updateData: []};
  1419. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1420. const posData = sheet.zh_data[sel.row + iRow];
  1421. if (posData) {
  1422. data.updateData.push(posData.id);
  1423. }
  1424. }
  1425. if (data.updateData.length > 0) {
  1426. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1427. stagePos.removeDatas(result.pos.pos);
  1428. const refreshData = stageTree.loadPostStageData(result.ledger);
  1429. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1430. stagePosSpreadObj.loadCurPosData();
  1431. if (detail) {
  1432. detail.loadStagePosUpdateData(result);
  1433. } else {
  1434. stageIm.loadUpdatePosData(result);
  1435. }
  1436. });
  1437. }
  1438. }
  1439. },
  1440. selectionChanged: function (e, info) {
  1441. stagePosSpreadObj.loadExprToInput(info.sheet);
  1442. },
  1443. addPegs: function (pegs) {
  1444. if (!pegs || pegs.length <= 0) return;
  1445. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1446. if (!node) return;
  1447. const sheet = spSpread.getActiveSheet();
  1448. const sortData = sheet.zh_data || [];
  1449. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1450. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1451. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1452. if (result.pos) {
  1453. stagePos.updateDatas(result.pos.pos);
  1454. }
  1455. stagePosSpreadObj.loadCurPosData();
  1456. });
  1457. }
  1458. };
  1459. // 加载上下窗口resizer
  1460. $.divResizer({
  1461. select: '#main-resize',
  1462. callback: function () {
  1463. slSpread.refresh();
  1464. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1465. $(".sp-wrap").height(bcontent-30);
  1466. spSpread.refresh();
  1467. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1468. }
  1469. });
  1470. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1471. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change' }, function (result) {
  1472. // 加载树结构
  1473. stageTree.loadDatas(result.ledgerData);
  1474. // stageTree.loadCurStageData(curStageData);
  1475. // stageTree.loadPreStageData(preStageData);
  1476. treeCalc.calculateAll(stageTree);
  1477. // 加载部位明细
  1478. stagePos.loadDatas(result.posData);
  1479. stagePos.calculateAll();
  1480. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1481. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1482. stagePosSpreadObj.loadCurPosData();
  1483. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1484. // 加载中间计量
  1485. stageIm.init(stage, imType, tenderInfo.decimal);
  1486. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1487. errorList.loadHisErrorData();
  1488. }, null, true);
  1489. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1490. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1491. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1492. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1493. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1494. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1495. if (!readOnly) {
  1496. $('#pos-expr').bind('change onblur', function () {
  1497. if (this.readOnly) return;
  1498. const expr = $(this);
  1499. const posSheet = spSpread.getActiveSheet();
  1500. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1501. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1502. if (!select) return;
  1503. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  1504. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1505. const data = {pid: select.id, lid: select.lid};
  1506. const exprInfo = getExprInfo(field);
  1507. if (newValue !== '') {
  1508. const num = _.toNumber(newValue);
  1509. if (num) {
  1510. data[field] = num;
  1511. if (exprInfo) data[exprInfo.expr] = '';
  1512. } else {
  1513. try {
  1514. data[field] = math.evaluate(transExpr(newValue));
  1515. if (exprInfo) data[exprInfo.expr] = newValue;
  1516. } catch (err) {
  1517. toastr.error('输入的表达式非法');
  1518. return;
  1519. }
  1520. }
  1521. } else {
  1522. data[field] = null;
  1523. if (exprInfo) data[exprInfo.expr] = '';
  1524. }
  1525. // 提交数据到服务器
  1526. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1527. if (result.pos) {
  1528. stagePos.updateDatas(result.pos.pos);
  1529. stagePos.loadCurStageData(result.pos.curStageData);
  1530. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1531. }
  1532. const refreshData = stageTree.loadPostStageData(result.ledger);
  1533. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1534. });
  1535. });
  1536. }
  1537. if (!checkTzMeasureType()) {
  1538. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1539. $.contextMenu({
  1540. selector: '#stage-pos',
  1541. build: function ($trigger, e) {
  1542. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1543. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1544. },
  1545. items: {
  1546. 'del': {
  1547. name: '删除',
  1548. icon: 'fa-remove',
  1549. disabled: function (key, opt) {
  1550. const sheet = spSpread.getActiveSheet();
  1551. if (sheet.zh_data && !readOnly) {
  1552. const selection = sheet.getSelections();
  1553. if (selection && selection[0]) {
  1554. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1555. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  1556. const posData = sheet.zh_data[selection[0].row + iRow];
  1557. if (posData) {
  1558. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  1559. valid = true;
  1560. break;
  1561. }
  1562. } else {
  1563. valid = true;
  1564. break;
  1565. }
  1566. }
  1567. return valid;
  1568. } else {
  1569. return true;
  1570. }
  1571. } else {
  1572. return true;
  1573. }
  1574. },
  1575. callback: function (key, opt) {
  1576. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  1577. }
  1578. },
  1579. 'merge-peg': {
  1580. name: '合并起讫桩号',
  1581. disabled: function (key, opt) {
  1582. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1583. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1584. },
  1585. callback: function (key, opt) {
  1586. mergePeg.show();
  1587. }
  1588. }
  1589. }
  1590. })
  1591. } else {
  1592. SpreadJsObj.forbiddenSpreadContextMenu('#stage-pos', spSpread);
  1593. }
  1594. $.subMenu({
  1595. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1596. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1597. key: 'menu.1.0.0',
  1598. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1599. callback: function (info) {
  1600. if (info.mini) {
  1601. $('.panel-title').addClass('fluid');
  1602. $('#sub-menu').removeClass('panel-sidebar');
  1603. } else {
  1604. $('.panel-title').removeClass('fluid');
  1605. $('#sub-menu').addClass('panel-sidebar');
  1606. }
  1607. autoFlashHeight();
  1608. slSpread.refresh();
  1609. spSpread.refresh();
  1610. if (searchLedger) {
  1611. searchLedger.spread.refresh();
  1612. }
  1613. if (detail) {
  1614. detail.spread.refresh();
  1615. }
  1616. if (checkedChanges) checkedChanges.refresh();
  1617. }
  1618. });
  1619. $('#row-view').on('show.bs.modal', function () {
  1620. const html = [], customDisplay = customColDisplay();
  1621. for (const cd of customDisplay) {
  1622. html.push('<tr>');
  1623. html.push('<td>', cd.title, '</td>');
  1624. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  1625. html.push('</tr>');
  1626. }
  1627. $('#row-view-list').html(html.join(''));
  1628. });
  1629. $('#row-view-ok').click(function () {
  1630. const customDisplay = customColDisplay();
  1631. const cvl = $('#row-view-list').children();
  1632. for (const cv of cvl) {
  1633. const title = $(cv).children()[0].innerHTML;
  1634. const check = $('input', cv)[0].checked;
  1635. const cd = customDisplay.find(function (c) {
  1636. return c.title === title;
  1637. });
  1638. cd.visible = check;
  1639. }
  1640. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  1641. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  1642. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  1643. $('#row-view').modal('hide');
  1644. });
  1645. const posSearch = (function () {
  1646. let resultArr = [];
  1647. const search = function () {
  1648. resultArr = [];
  1649. const keyword = $('#pos-search-keyword').val();
  1650. const checkOver = $('#pos-over-search')[0].checked;
  1651. const checkEmpty = $('#pos-empty-search')[0].checked;
  1652. const sortData = spSpread.getActiveSheet().zh_data;
  1653. if (checkOver || checkEmpty) {
  1654. if (sortData) {
  1655. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1656. const sd = sortData[i];
  1657. let match = false;
  1658. if (checkOver) {
  1659. if (sd.end_gather_qty) {
  1660. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  1661. }
  1662. }
  1663. if (checkEmpty) {
  1664. if (sd.quantity) {
  1665. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  1666. }
  1667. }
  1668. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  1669. if (match) {
  1670. resultArr.push({index: i, data: sd});
  1671. }
  1672. }
  1673. }
  1674. } else if (keyword && keyword !== '') {
  1675. if (sortData) {
  1676. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  1677. const sd = sortData[i];
  1678. if (sd.name && sd.name.indexOf(keyword) > -1) {
  1679. resultArr.push({index: i, data: sd});
  1680. }
  1681. }
  1682. }
  1683. }
  1684. $('#pos-search-result').html('结果:' + resultArr.length);
  1685. };
  1686. const searchAndLocate = function () {
  1687. search();
  1688. if (resultArr.length > 0) {
  1689. const sheet = spSpread.getActiveSheet();
  1690. const sel = sheet.getSelections()[0];
  1691. const curRow = sel ? sel.row : 0;
  1692. const pos = resultArr[0];
  1693. if (pos.index !== curRow) {
  1694. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  1695. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  1696. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  1697. }
  1698. }
  1699. };
  1700. const locateNext = function () {
  1701. if (resultArr.length > 0) {
  1702. const sheet = spSpread.getActiveSheet();
  1703. const sel = sheet.getSelections()[0];
  1704. const curRow = sel ? sel.row : 0;
  1705. let next = _.find(resultArr, function (d) {
  1706. return d.index > curRow;
  1707. });
  1708. if (!next) next = resultArr[0];
  1709. if (next.index !== curRow) {
  1710. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1711. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1712. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  1713. }
  1714. }
  1715. };
  1716. const locatePre = function () {
  1717. if (resultArr.length > 0) {
  1718. const sheet = spSpread.getActiveSheet();
  1719. const sel = sheet.getSelections()[0];
  1720. const curRow = sel ? sel.row : 0;
  1721. let next = _.findLast(resultArr, function (d) {
  1722. return d.index < curRow;
  1723. });
  1724. if (!next) next = resultArr[resultArr.length - 1];
  1725. if (next.index !== curRow) {
  1726. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  1727. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  1728. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  1729. }
  1730. }
  1731. };
  1732. return {search, searchAndLocate, locateNext, locatePre};
  1733. })();
  1734. $('#pos-search-keyword').bind('keydown', function(e){
  1735. if (e.keyCode == 13) posSearch.searchAndLocate();
  1736. });
  1737. $('#pos-empty-search').click(function () {
  1738. if (this.checked) {
  1739. $('[for=' + this.id +']').addClass('text-warning');
  1740. } else {
  1741. $('[for=' + this.id +']').removeClass('text-warning');
  1742. }
  1743. if (this.checked) {
  1744. if ($('#pos-over-search')[0].checked) {
  1745. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1746. } else {
  1747. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1748. }
  1749. } else {
  1750. if ($('#pos-over-search')[0].checked) {
  1751. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1752. } else {
  1753. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1754. }
  1755. }
  1756. posSearch.searchAndLocate();
  1757. });
  1758. $('#pos-over-search').click(function () {
  1759. if (this.checked) {
  1760. $('[for=' + this.id +']').addClass('text-danger');
  1761. } else {
  1762. $('[for=' + this.id +']').removeClass('text-danger');
  1763. }
  1764. if (this.checked) {
  1765. if ($('#pos-empty-search')[0].checked) {
  1766. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1767. } else {
  1768. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  1769. }
  1770. } else {
  1771. if ($('#pos-empty-search')[0].checked) {
  1772. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  1773. } else {
  1774. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  1775. }
  1776. }
  1777. posSearch.searchAndLocate();
  1778. });
  1779. $('#pos-search-next').click(() => {posSearch.locateNext()});
  1780. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  1781. $.divResizer({
  1782. select: '#right-spr',
  1783. callback: function () {
  1784. slSpread.refresh();
  1785. spSpread.refresh();
  1786. if (searchLedger) {
  1787. searchLedger.spread.refresh();
  1788. }
  1789. if (detail) {
  1790. detail.spread.refresh();
  1791. }
  1792. if (checkedChanges) checkedChanges.refresh();
  1793. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1794. }
  1795. });
  1796. // 中间计量加载上下窗口resizer
  1797. $.divResizer({
  1798. select: '#zhongjian-spr',
  1799. callback: function () {
  1800. if (detail) {
  1801. detail.spread.refresh();
  1802. }
  1803. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1804. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1805. }
  1806. });
  1807. // 附件加载上下窗口resizer
  1808. $.divResizer({
  1809. select: '#file-spr',
  1810. callback: function () {
  1811. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1812. }
  1813. });
  1814. // 变更令加载上下窗口resizer
  1815. $.divResizer({
  1816. select: '#change-spr',
  1817. callback: function () {
  1818. if (checkedChanges) checkedChanges.refresh();
  1819. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1820. }
  1821. });
  1822. class Detail {
  1823. constructor (obj) {
  1824. const self = this;
  1825. this.spreadSetting = {
  1826. cols: [
  1827. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  1828. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1829. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  1830. {
  1831. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  1832. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  1833. },
  1834. ],
  1835. headRows: 1,
  1836. emptyRows: 0,
  1837. headRowHeight: [32],
  1838. headColWidth: [30],
  1839. defaultRowHeight: 21,
  1840. headerFont: '12px 微软雅黑',
  1841. font: '12px 微软雅黑',
  1842. readOnly: readOnly,
  1843. selectedBackColor: '#fffacd',
  1844. };
  1845. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  1846. this.sheet = this.spread.getActiveSheet();
  1847. this.spread.options.allowUserDragFill = true;
  1848. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  1849. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1850. this.detailObj = {
  1851. selectionChanged: function (e, info) {
  1852. self.reLoadDetailData();
  1853. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  1854. self.loadLocateInfo();
  1855. }
  1856. },
  1857. editEnded: function(e, info) {
  1858. if (info.sheet.zh_setting) {
  1859. const col = info.sheet.zh_setting.cols[info.col];
  1860. if (col.field !== 'doc_code') {
  1861. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1862. return;
  1863. }
  1864. const data = SpreadJsObj.getSelectObject(info.sheet);
  1865. if (data) {
  1866. const updateData = {lid: data.lid, pid: data.pid};
  1867. if (data.uuid) {
  1868. updateData.uuid = data.uuid;
  1869. } else {
  1870. updateData.code = data.code;
  1871. updateData.name = data.name;
  1872. updateData.unit = data.unit;
  1873. updateData.unit_price = data.unit_price;
  1874. updateData.pid = data.pid;
  1875. updateData.pos_name = data.pos_name;
  1876. }
  1877. if (data.custom_define.indexOf('doc_code') === -1) {
  1878. updateData.custom_define = data.custom_define;
  1879. updateData.custom_define.push('doc_code');
  1880. updateData.custom_define = updateData.custom_define.join(',');
  1881. }
  1882. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  1883. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  1884. stageIm.loadUpdateDetailData(result);
  1885. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1886. }, function () {
  1887. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1888. });
  1889. } else {
  1890. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1891. }
  1892. }
  1893. },
  1894. clipboardPasted: function (e, info) {
  1895. if (info.sheet.zh_setting && info.sheet.zh_data) {
  1896. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  1897. if (info.cellRange.colCount > 1) {
  1898. toastr.warning('请勿同时复制粘贴多列数据');
  1899. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1900. return;
  1901. }
  1902. if (col.field !== 'doc_code') {
  1903. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  1904. return;
  1905. }
  1906. const datas = [];
  1907. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1908. const curRow = info.cellRange.row + iRow;
  1909. const data = info.sheet.zh_data[curRow];
  1910. if (data) {
  1911. const updateData = {lid: data.lid, pid: data.pid};
  1912. if (data.uuid) {
  1913. updateData.uuid = data.uuid;
  1914. } else {
  1915. updateData.code = data.code;
  1916. updateData.name = data.name;
  1917. updateData.unit = data.unit;
  1918. updateData.unit_price = data.unit_price;
  1919. updateData.pid = data.pid;
  1920. updateData.pos_name = data.pos_name;
  1921. }
  1922. if (data.custom_define.indexOf('doc_code') === -1) {
  1923. updateData.custom_define = data.custom_define;
  1924. updateData.custom_define.push('doc_code');
  1925. updateData.custom_define = updateData.custom_define.join(',');
  1926. }
  1927. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  1928. datas.push(updateData);
  1929. }
  1930. }
  1931. if (datas.length > 0) {
  1932. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1933. stageIm.loadUpdateDetailData(result);
  1934. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1935. }, function () {
  1936. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1937. })
  1938. }
  1939. }
  1940. },
  1941. deletePress: function (sheet) {
  1942. if (sheet.zh_setting) {
  1943. const datas = [];
  1944. const sel = sheet.getSelections()[0];
  1945. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1946. const col = sheet.zh_setting.cols[iCol];
  1947. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1948. const data = sheet.zh_data[iRow];
  1949. if (col.field === 'doc_code') {
  1950. const updateData = {lid: data.lid};
  1951. if (data.uuid) {
  1952. updateData.uuid = data.uuid;
  1953. updateData.doc_code = '';
  1954. datas.push(updateData);
  1955. }
  1956. }
  1957. }
  1958. }
  1959. if (datas.length > 0) {
  1960. postData(window.location.pathname + '/detail/save', datas, function (result) {
  1961. stageIm.loadUpdateDetailData(result);
  1962. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  1963. }, function () {
  1964. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  1965. });
  1966. }
  1967. }
  1968. },
  1969. dragFillBlock: function (e, info) {
  1970. info.cancel = true;
  1971. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  1972. const sel = info.sheet.getSelections()[0];
  1973. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  1974. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  1975. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  1976. if (text === '') return;
  1977. const regRst = /(\d+)$/g.exec(text), datas = [];
  1978. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  1979. const curRow = info.fillRange.row + iRow;
  1980. const data = info.sheet.zh_data[curRow];
  1981. if (data) {
  1982. const updateData = {lid: data.lid};
  1983. if (data.uuid) {
  1984. updateData.uuid = data.uuid;
  1985. } else {
  1986. updateData.code = data.code;
  1987. updateData.name = data.name;
  1988. updateData.unit = data.unit;
  1989. updateData.unit_price = data.unit_price;
  1990. updateData.pid = data.pid;
  1991. updateData.pos_name = data.pos_name;
  1992. }
  1993. if (regRst) {
  1994. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  1995. } else {
  1996. updateData.doc_code = text.replace('\n', '');
  1997. }
  1998. if (data.custom_define.indexOf('doc_code') === -1) {
  1999. updateData.custom_define = data.custom_define;
  2000. updateData.custom_define.push('doc_code');
  2001. updateData.custom_define = updateData.custom_define.join(',');
  2002. }
  2003. datas.push(updateData);
  2004. }
  2005. }
  2006. if (datas.length > 0) {
  2007. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2008. stageIm.loadUpdateDetailData(result);
  2009. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2010. }, function () {
  2011. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2012. })
  2013. }
  2014. },
  2015. };
  2016. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2017. if (!readOnly) {
  2018. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2019. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2020. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2021. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2022. }
  2023. this._initImTypeSetRela();
  2024. this._initModifyDetail();
  2025. this._initLocateRela();
  2026. // 草图相关
  2027. this._initImageRela();
  2028. this.reBuildImData();
  2029. }
  2030. _initImTypeSetRela() {
  2031. const self = this;
  2032. const gatherConfirmPopover = {
  2033. reBind: function (obj, eventName, fun) {
  2034. obj.unbind(eventName);
  2035. obj.bind(eventName, fun);
  2036. },
  2037. check: function (pos, hint, okCallback) {
  2038. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2039. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2040. this.reBind(cancelObj, 'click', function () {
  2041. confirmObj.hide();
  2042. });
  2043. this.reBind(okObj, 'click', function () {
  2044. okCallback();
  2045. confirmObj.hide();
  2046. });
  2047. hintObj.text(hint);
  2048. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2049. }
  2050. };
  2051. this.gsTree = stageIm.getGsTree();
  2052. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2053. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2054. jlCol.title = '本期计量金额';
  2055. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2056. $('#type-title-contract').text('本期合同计量金额');
  2057. $('#type-title-qc').text('本期变更计量金额');
  2058. } else {
  2059. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2060. jlCol.title = '本期计量数量';
  2061. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2062. $('#type-title-contract').text('本期合同计量数量');
  2063. $('#type-title-qc').text('本期变更计量数量');
  2064. }
  2065. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2066. $('#show-jldy').parent().show();
  2067. $('#jldy').parent().show();
  2068. $('#show-xm-name').parent().hide();
  2069. $('#xm-name').parent().hide();
  2070. } else {
  2071. $('#show-jldy').parent().hide();
  2072. $('#jldy').parent().hide();
  2073. $('#show-xm-name').parent().show();
  2074. $('#xm-name').parent().show();
  2075. }
  2076. // 选择中间计量模式
  2077. $('div[name="im-type"]').click(function () {
  2078. function chooseType(obj) {
  2079. obj.style.cursor = 'default';
  2080. $(obj).children().addClass('text-primary');
  2081. $(obj).addClass('border-primary');
  2082. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2083. }
  2084. function validType(obj) {
  2085. obj.style.cursor = 'pointer';
  2086. $(obj).children().removeClass('text-primary');
  2087. $(obj).removeClass('border-primary');
  2088. $('i', obj).remove();
  2089. }
  2090. if (this.style.cursor === 'pointer') {
  2091. const typeArr = $('div[name="im-type"]');
  2092. for (const t of typeArr) {
  2093. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2094. chooseType(t);
  2095. } else {
  2096. validType(t)
  2097. }
  2098. }
  2099. }
  2100. });
  2101. $('#choose').on('show.bs.modal', function () {
  2102. function chooseType(obj) {
  2103. obj.style.cursor = 'default';
  2104. $(obj).children().addClass('text-primary');
  2105. $('i', obj).remove();
  2106. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2107. }
  2108. function validType(obj) {
  2109. obj.style.cursor = 'pointer';
  2110. $(obj).children().removeClass('text-primary');
  2111. $('i', obj).remove();
  2112. }
  2113. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2114. const typeArr = $('div[name="im-type"]');
  2115. for (const t of typeArr) {
  2116. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2117. chooseType(t);
  2118. } else {
  2119. validType(t)
  2120. }
  2121. }
  2122. });
  2123. // 提交 中间计量模式
  2124. $('#choose-ok').click(() => {
  2125. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2126. return it.style.cursor !== 'pointer';
  2127. });
  2128. const data = {
  2129. im_type: parseInt($(chooseType).attr('im-type')),
  2130. im_pre: $('#im-pre').val(),
  2131. };
  2132. postData(window.location.pathname + '/detail/build', data, function (result) {
  2133. stage.im_type = data.im_type;
  2134. stage.im_pre = data.im_pre;
  2135. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2136. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2137. jlCol.title = '本期计量金额';
  2138. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2139. $('#type-title-contract').text('本期合同计量金额');
  2140. $('#type-title-qc').text('本期变更计量金额');
  2141. } else {
  2142. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2143. jlCol.title = '本期计量数量';
  2144. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2145. $('#type-title-contract').text('本期合同计量数量');
  2146. $('#type-title-qc').text('本期变更计量数量');
  2147. }
  2148. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2149. $('#show-jldy').parent().show();
  2150. $('#jldy').parent().show();
  2151. $('#show-xm-name').parent().hide();
  2152. $('#xm-name').parent().hide();
  2153. } else {
  2154. $('#show-jldy').parent().hide();
  2155. $('#jldy').parent().hide();
  2156. $('#show-xm-name').parent().show();
  2157. $('#xm-name').parent().show();
  2158. }
  2159. // 加载生成数据
  2160. self.reBuildImData();
  2161. $('#choose').modal('hide');
  2162. });
  2163. });
  2164. // 显示树结构信息
  2165. $('#choose2').on('shown.bs.modal', function () {
  2166. if (!self.gsSpread) {
  2167. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2168. const setting = {
  2169. cols: [
  2170. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2171. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2172. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2173. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2174. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2175. ],
  2176. headRows: 1,
  2177. emptyRows: 0,
  2178. headRowHeight: [32],
  2179. defaultRowHeight: 21,
  2180. headerFont: '12px 微软雅黑',
  2181. font: '12px 微软雅黑',
  2182. };
  2183. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2184. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2185. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2186. function checkParent(node) {
  2187. const parent = self.gsTree.getParent(node);
  2188. if (parent) {
  2189. return parent.check ? parent.check : checkParent(parent);
  2190. } else {
  2191. return false;
  2192. }
  2193. }
  2194. function checkChildren(node) {
  2195. for (const child of node.children) {
  2196. if (child.check) {
  2197. return true;
  2198. } else if (checkChildren(child)) {
  2199. return true;
  2200. }
  2201. }
  2202. return false;
  2203. }
  2204. if (!$('#im-gather-check')[0].checked) { return; }
  2205. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2206. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2207. if (sheet.isEditing()) {
  2208. sheet.endEdit(true);
  2209. }
  2210. }
  2211. if (info.sheet.zh_setting) {
  2212. const col = info.sheet.zh_setting.cols[info.col];
  2213. if (col.field !== 'check') {
  2214. return;
  2215. }
  2216. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2217. const node = sortData[info.row];
  2218. if (!node.check) {
  2219. if (checkParent(node)) {
  2220. const rect = info.sheet.getCellRect(info.row, info.col);
  2221. gatherConfirmPopover.check({
  2222. x: rect.x + rect.width / 2 + 25,
  2223. y: rect.y + rect.height / 2 + 3,
  2224. }, '父项已勾选,继续将取消父项勾选。', function () {
  2225. node.check = true;
  2226. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2227. const rows = [self.gsTree.nodes.indexOf(node)];
  2228. for (const p of parents) {
  2229. if (p.check) {
  2230. p.check = false;
  2231. rows.push(self.gsTree.nodes.indexOf(p));
  2232. }
  2233. }
  2234. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2235. });
  2236. } else if (checkChildren(node)) {
  2237. const rect = info.sheet.getCellRect(info.row, info.col);
  2238. gatherConfirmPopover.check({
  2239. x: rect.x + rect.width / 2 + 25,
  2240. y: rect.y + rect.height / 2 + 3,
  2241. }, '子项已勾选,继续将取消子项勾选。', function () {
  2242. node.check = true;
  2243. const posterity = self.gsTree.getPosterity(node);
  2244. const rows = [self.gsTree.nodes.indexOf(node)];
  2245. for (const p of posterity) {
  2246. if (p.check) {
  2247. rows.push(self.gsTree.nodes.indexOf(p));
  2248. p.check = false;
  2249. }
  2250. }
  2251. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2252. });
  2253. } else {
  2254. node.check = true;
  2255. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2256. }
  2257. } else {
  2258. node.check = false;
  2259. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2260. }
  2261. }
  2262. });
  2263. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2264. for (const node of self.gsTree.datas) {
  2265. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2266. }
  2267. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2268. self.gsTree.expandByLevel(4);
  2269. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2270. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2271. } else {
  2272. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2273. for (const node of self.gsTree.datas) {
  2274. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2275. }
  2276. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2277. }
  2278. });
  2279. // 提交 高级设置
  2280. $('#choose2-ok').click(() => {
  2281. if (!self.gsTree) { return; }
  2282. const nodes = [];
  2283. for (const node of self.gsTree.datas) {
  2284. if (node.check) {
  2285. nodes.push(node.id);
  2286. }
  2287. }
  2288. const data = {
  2289. im_gather: $('#im-gather-check')[0].checked,
  2290. im_gather_node: nodes.join(','),
  2291. };
  2292. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2293. stage.im_gather = data.im_gather;
  2294. stage.im_gather_node = data.im_gather_node;
  2295. $('#choose2').modal('hide');
  2296. });
  2297. });
  2298. }
  2299. _initLocateRela() {
  2300. const self = this;
  2301. $('#im-locate2bills').click(function () {
  2302. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2303. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2304. if (select && select.source) {
  2305. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  2306. stagePosSpreadObj.loadCurPosData();
  2307. }
  2308. });
  2309. $('#im-locate-pre').click(function () {
  2310. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2311. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2312. if (select && select.source) {
  2313. const targetIndex = math.max(curIndex-1, 1);
  2314. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2315. stagePosSpreadObj.loadCurPosData();
  2316. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2317. }
  2318. });
  2319. $('#im-locate-next').click(function () {
  2320. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2321. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2322. if (select && select.source) {
  2323. const targetIndex = math.min(curIndex+1, select.source.length);
  2324. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2325. stagePosSpreadObj.loadCurPosData();
  2326. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2327. }
  2328. });
  2329. }
  2330. _initModifyDetail() {
  2331. const self = this;
  2332. // 编辑
  2333. $('#edit-detail').click(function () {
  2334. $(this).hide();
  2335. $('#save-detail').show();
  2336. $('#cancel-detail').show();
  2337. $('#detail-show').hide();
  2338. $('#detail-edit').show();
  2339. self.updateImageData = null;
  2340. });
  2341. // 保存
  2342. $('#save-detail').click(() => {
  2343. function check(field, obj, org, update) {
  2344. const newValue = obj.val();
  2345. if (!org[field]) {
  2346. if (newValue !== '') {
  2347. update[field] = newValue;
  2348. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2349. }
  2350. } else if (newValue !== org[field]){
  2351. update[field] = newValue;
  2352. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2353. }
  2354. }
  2355. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2356. const updateData = {lid: data.lid, pid: data.pid};
  2357. if (data.uuid) {
  2358. updateData.uuid = data.uuid;
  2359. updateData.custom_define = data.custom_define;
  2360. } else {
  2361. updateData.code = data.code;
  2362. updateData.name = data.name;
  2363. updateData.unit = data.unit;
  2364. updateData.unit_price = data.unit_price;
  2365. updateData.pid = data.pid;
  2366. updateData.pos_name = data.pos_name;
  2367. updateData.custom_define = [];
  2368. }
  2369. check('bw', $('#bw-name'), data, updateData);
  2370. check('peg', $('#peg'), data, updateData);
  2371. check('xm', $('#xm-name'), data, updateData);
  2372. check('position', $('#position'), data, updateData);
  2373. check('jldy', $('#jldy'), data, updateData);
  2374. check('drawing_code', $('#drawing-code'), data, updateData);
  2375. check('calc_memo', $('#calc-memo'), data, updateData);
  2376. updateData.custom_define = updateData.custom_define.join(',');
  2377. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2378. stageIm.loadUpdateDetailData(result);
  2379. self.reLoadDetailData();
  2380. if (self.updateImageData && !self.updateImageData.uuid) {
  2381. self.updateImageData.uuid = result.uuid;
  2382. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2383. stageIm.loadUpdateDetailData(result);
  2384. self.reLoadDetailData();
  2385. });
  2386. }
  2387. });
  2388. if (self.updateImageData && self.updateImageData.uuid) {
  2389. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2390. stageIm.loadUpdateDetailData(result);
  2391. self.reLoadDetailData();
  2392. });
  2393. }
  2394. });
  2395. // 取消
  2396. $('#cancel-detail').click(() => {
  2397. self.reLoadDetailData();
  2398. });
  2399. }
  2400. _initImageRela() {
  2401. const self = this;
  2402. $('#edit-detail').click(function () {
  2403. loadImageItem();
  2404. });
  2405. function setdraggrable(){
  2406. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2407. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2408. stop: function( event, ui ) {
  2409. }
  2410. });
  2411. }
  2412. // 移动图片
  2413. const moveImageItem = function (ev) {
  2414. const item = this;
  2415. const view = $('.img-view')[0];
  2416. let oEvent = ev;
  2417. // 浏览器有一些图片的默认事件,这里要阻止
  2418. oEvent.preventDefault();
  2419. let disX = oEvent.clientX - item.offsetLeft;
  2420. let disY = oEvent.clientY - item.offsetTop;
  2421. view.onmousemove = function (ev) {
  2422. oEvent = ev;
  2423. oEvent.preventDefault();
  2424. let x = oEvent.clientX -disX;
  2425. let y = oEvent.clientY -disY;
  2426. // 图形移动的边界判断
  2427. x = x <= 0 ? 0 : x;
  2428. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2429. y = y <= 0 ? 0 : y;
  2430. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2431. item.style.left = x + 'px';
  2432. item.style.top = y + 'px';
  2433. };
  2434. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2435. view.onmouseleave = function () {
  2436. view.onmousemove = null;
  2437. view.onmouseup = null;
  2438. };
  2439. // 鼠标弹起后停止移动
  2440. view.onmouseup=function() {
  2441. view.onmousemove = null;
  2442. view.onmouseup = null;
  2443. };
  2444. };
  2445. const removeImageItem = function () {
  2446. $(this).parent().remove();
  2447. };
  2448. // 加载草图组成
  2449. const loadImageItem = function () {
  2450. self.updateImageData = null;
  2451. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2452. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  2453. const html = [];
  2454. for (const item of items) {
  2455. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  2456. html.push('<div class="img-item" style="' + itemStyle + '">');
  2457. html.push('<div class="img-bar">');
  2458. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2459. html.push('</div>');
  2460. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  2461. html.push('</div>');
  2462. }
  2463. $('.img-view').html(html.join(''));
  2464. $('.img-bar').click(removeImageItem);
  2465. setdraggrable();
  2466. };
  2467. // 上传图片
  2468. $('#upload-img').click(function () {
  2469. $('#upload-img-file').trigger('click');
  2470. });
  2471. $('#upload-img-file').change(function () {
  2472. const file = this.files[0];
  2473. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  2474. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  2475. if (!imgStr.test(ext)) {
  2476. toastr.error('请上传正确的图片格式文件');
  2477. return
  2478. }
  2479. if ($(this).val()) {
  2480. const formData = new FormData();
  2481. formData.append('file', this.files[0]);
  2482. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2483. const html = [];
  2484. html.push('<div class="img-item">');
  2485. html.push('<div class="img-bar">');
  2486. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2487. html.push('</div>');
  2488. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2489. html.push('</div>');
  2490. $('.img-view').append(html.join(''));
  2491. $('.img-bar').click(removeImageItem);
  2492. setdraggrable();
  2493. $('#upload-img-file').val('');
  2494. });
  2495. }
  2496. });
  2497. // 保存草图修改结果
  2498. $('#edit-img-ok').click(function () {
  2499. // 记录上传的图片的信息
  2500. const items = $('.img-item');
  2501. const img_remark = $('#text-edit').val()
  2502. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2503. if (items.length > 0) {
  2504. const itemInfo = [];
  2505. for (const item of items) {
  2506. const itemData = {
  2507. src: $('img', item).attr('src'),
  2508. left: item.style.left,
  2509. top: item.style.top,
  2510. width: item.style.width,
  2511. height: item.style.height,
  2512. };
  2513. itemInfo.push(itemData);
  2514. }
  2515. // 获取合并好的图片数据
  2516. const canvas = document.createElement('canvas');
  2517. const view = $('.img-view')[0];
  2518. canvas.height = view.clientHeight;
  2519. canvas.width = view.clientWidth;
  2520. const ctx = canvas.getContext('2d');
  2521. ctx.fillStyle = '#ffffff';
  2522. ctx.fillRect(0, 0, canvas.width, canvas.height);
  2523. for (const b of $('.img-item')) {
  2524. const pos = $(b).position();
  2525. const img = $('img', b)[0];
  2526. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  2527. }
  2528. // 生成上传数据
  2529. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  2530. if (data.uuid) {
  2531. updateData.uuid = data.uuid;
  2532. }
  2533. if (data.custom_define.indexOf('calc_img') === -1) {
  2534. updateData.custom_define = data.custom_define;
  2535. updateData.custom_define.push('calc_img');
  2536. updateData.custom_define = updateData.custom_define.join(',');
  2537. }
  2538. updateData.img = canvas.toDataURL('image/png');
  2539. updateData.imgInfo = itemInfo;
  2540. updateData.calc_img_remark = img_remark;
  2541. self.updateImageData = updateData;
  2542. $('#calc-img').attr('src', updateData.img);
  2543. $('#view-calc-img').attr('src', updateData.img);
  2544. $('#show-calc-img').attr('src', updateData.img);
  2545. $('#view-calc-remark').text(img_remark);
  2546. $('#edit-img').modal('hide');
  2547. // updateImageData = updateData;
  2548. // $('#edit-img').modal('hide');
  2549. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  2550. // stageIm.loadUpdateDetailData(result);
  2551. // data.calc_img = result.calc_img;
  2552. // data.calc_img_org = result.calc_img_org;
  2553. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2554. // $('#show-calc-img').attr('src', calcImgSrc);
  2555. // $('#calc-img').attr('src', calcImgSrc);
  2556. // $('#view-calc-img').attr('src', calcImgSrc);
  2557. // $('#edit-img').modal('hide');
  2558. // });
  2559. } else if (data.calc_img) {
  2560. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid};
  2561. $('#show-calc-img').attr('src', '');
  2562. $('#calc-img').attr('src', '');
  2563. $('#view-calc-img').attr('src', '');
  2564. $('#view-calc-remark').val('');
  2565. $('#text-edit').val('')
  2566. $('#edit-img').modal('hide');
  2567. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  2568. // stageIm.loadUpdateDetailData(result);
  2569. // data.calc_img = result.calc_img;
  2570. // data.calc_img_org = result.calc_img_org;
  2571. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2572. // $('#show-calc-img').attr('src', calcImgSrc);
  2573. // $('#calc-img').attr('src', calcImgSrc);
  2574. // $('#view-calc-img').attr('src', calcImgSrc);
  2575. // $('#edit-img').modal('hide');
  2576. // });
  2577. } else {
  2578. self.updateImageData = null;
  2579. $('#show-calc-img').attr('src', '');
  2580. $('#calc-img').attr('src', '');
  2581. $('#view-calc-img').attr('src', '');
  2582. $('#view-calc-remark').val('');
  2583. $('#text-edit').val('')
  2584. $('#edit-img').modal('hide');
  2585. }
  2586. });
  2587. }
  2588. reBuildImData() {
  2589. const imData = stageIm.buildImData();
  2590. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2591. this.reLoadDetailData();
  2592. this.loadLocateInfo();
  2593. }
  2594. loadStageLedgerUpdateData(data) {
  2595. const imData = stageIm.loadUpdateLedgerData(data);
  2596. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2597. this.reLoadDetailData();
  2598. }
  2599. loadStagePosUpdateData(data) {
  2600. const imData = stageIm.loadUpdatePosData(data);
  2601. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2602. this.reLoadDetailData();
  2603. }
  2604. loadStageChangeUpdateData(data) {
  2605. const imData = stageIm.loadUpdateChangeData(data);
  2606. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  2607. this.reLoadDetailData();
  2608. }
  2609. loadLocateInfo() {
  2610. const select = SpreadJsObj.getSelectObject(this.sheet);
  2611. if (select && select.source.length > 1) {
  2612. $('#im-locate2bills').next().show();
  2613. } else {
  2614. $('#im-locate2bills').next().hide();
  2615. }
  2616. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  2617. }
  2618. reLoadDetailData() {
  2619. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  2620. if (data) {
  2621. $('#edit-detail').show();
  2622. $('#modify-img').show();
  2623. } else {
  2624. $('#edit-detail').hide();
  2625. $('#modify-img').hide();
  2626. }
  2627. $('#save-detail').hide();
  2628. $('#cancel-detail').hide();
  2629. $('#detail-show').show();
  2630. $('#detail-edit').hide();
  2631. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  2632. $('#show-contract-jl').text(contractJl);
  2633. $('#contract-jl').val(contractJl);
  2634. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  2635. $('#show-qc-jl').text(qcJl);
  2636. $('#qc-jl').val(qcJl);
  2637. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  2638. $('#show-bgl-code').text(bglCode);
  2639. $('#bgl-code').val(bglCode);
  2640. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  2641. $('#show-bgl-drawing-code').text(bglDrawingCode);
  2642. $('#bgl-drawing-code').val(bglDrawingCode);
  2643. const bwName = data && data.bw ? data.bw : '';
  2644. $('#show-bw-name').text(bwName);
  2645. $('#bw-name').val(bwName);
  2646. const position = data && data.position ? data.position : '';
  2647. $('#show-position').text(position);
  2648. $('#position').val(position);
  2649. const peg = data && data.peg ? data.peg : '';
  2650. $('#show-peg').text(peg);
  2651. $('#peg').val(peg);
  2652. const xmName = data && data.xm ? data.xm: '';
  2653. $('#show-xm-name').text(xmName);
  2654. $('#xm-name').val(xmName);
  2655. const jldy = data && data.jldy ? data.jldy: '';
  2656. $('#show-jldy').text(jldy);
  2657. $('#jldy').val(jldy);
  2658. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  2659. $('#show-drawing-code').text(drawingCode);
  2660. $('#drawing-code').val(drawingCode);
  2661. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  2662. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  2663. $('#calc-memo').val(calcMemo);
  2664. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  2665. $('#show-calc-img').attr('src', calcImgSrc);
  2666. $('#calc-img').attr('src', calcImgSrc);
  2667. $('#view-calc-img').attr('src', calcImgSrc);
  2668. const calcImgRemark = data && data.calc_img_remark || '';
  2669. $('#view-calc-remark').val(calcImgRemark);
  2670. $("#view-calc-remark").attr('readonly', true);
  2671. // 处理 编辑 -> 添加草图中textarea多余的空格
  2672. $('#text-edit').val(calcImgRemark)
  2673. }
  2674. }
  2675. class CheckedChange {
  2676. constructor (setting) {
  2677. const self = this;
  2678. this.changeSpreadSetting = {
  2679. cols: [
  2680. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  2681. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  2682. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  2683. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  2684. ],
  2685. emptyRows: 0,
  2686. headRows: 1,
  2687. headRowHeight: [32],
  2688. headColWidth: [30],
  2689. defaultRowHeight: 21,
  2690. headerFont: '12px 微软雅黑',
  2691. font: '12px 微软雅黑',
  2692. readOnly: true,
  2693. };
  2694. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  2695. this.changeSheet = this.changeSpread.getActiveSheet();
  2696. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  2697. this.changeBillsSpreadSetting = {
  2698. cols: [
  2699. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2700. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number'},
  2701. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2702. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  2703. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  2704. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  2705. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  2706. ],
  2707. emptyRows: 0,
  2708. headRows: 1,
  2709. headRowHeight: [32],
  2710. defaultRowHeight: 21,
  2711. headerFont: '12px 微软雅黑',
  2712. font: '12px 微软雅黑',
  2713. readOnly: true
  2714. };
  2715. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  2716. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  2717. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  2718. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2719. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  2720. if (change.cid === self.curChangeId) { return; }
  2721. self.curChangeId = change.cid;
  2722. if (change.detail) {
  2723. self.loadChangeDetailData();
  2724. } else {
  2725. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  2726. change.detail = result;
  2727. self.analyzeChange(change);
  2728. self.loadChangeDetailData();
  2729. });
  2730. }
  2731. });
  2732. this.changes = null;
  2733. this.reloadChangeData();
  2734. setting.reloadObj.click(function() {
  2735. self.reloadChangeData();
  2736. });
  2737. }
  2738. loadChangeDetailData() {
  2739. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  2740. if (change) {
  2741. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  2742. } else {
  2743. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  2744. }
  2745. }
  2746. refresh() {
  2747. this.changeSpread.refresh();
  2748. this.changeBillsSpread.refresh();
  2749. }
  2750. reloadChangeData() {
  2751. const self = this;
  2752. postData(window.location.pathname + '/change/data', null, function (result) {
  2753. self.changes = result.changes;
  2754. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  2755. self.changeSheet.setSelection(0, 0, 1, 1);
  2756. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  2757. self.loadChangeDetailData();
  2758. });
  2759. }
  2760. analyzeChange(change) {
  2761. change.bills = change.detail.bills;
  2762. for (const b of change.bills) {
  2763. const aub = change.detail.addUsedBills.find(function (x) {
  2764. return x.id === b.id;
  2765. });
  2766. if (aub) {
  2767. b.used_qty = aub.used_qty;
  2768. }
  2769. b.qty = _.toNumber(b.samount);
  2770. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  2771. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  2772. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  2773. b.cur_qty = 0;
  2774. for (const p of b.pos) {
  2775. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  2776. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  2777. }
  2778. }
  2779. }
  2780. }
  2781. // 展开收起附件
  2782. $('a', '.right-nav').bind('click', function () {
  2783. //const main = $('#main-view'), tool = $('#tools-view');
  2784. const tab = $(this), tabPanel = $(tab.attr('content'));
  2785. if (!tab.hasClass('active')) {
  2786. $('a', '.side-menu').removeClass('active');
  2787. $('.tab-content .tab-select-show').removeClass('active');
  2788. tab.addClass('active');
  2789. tabPanel.addClass('active');
  2790. showSideTools(tab.hasClass('active'));
  2791. if (tab.attr('content') === '#search' && !searchLedger) {
  2792. searchLedger = $.billsSearch({
  2793. selector: '#search',
  2794. searchSpread: slSpread,
  2795. searchRangeStr: '项目节编号/名称',
  2796. searchOver: true,
  2797. searchEmpty: true,
  2798. resultSpreadSetting: {
  2799. cols: [
  2800. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  2801. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2802. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2803. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2804. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2805. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2806. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  2807. ],
  2808. emptyRows: 0,
  2809. headRows: 1,
  2810. headRowHeight: [32],
  2811. headColWidth: [30],
  2812. defaultRowHeight: 21,
  2813. headerFont: '12px 微软雅黑',
  2814. font: '12px 微软雅黑',
  2815. selectedBackColor: '#fffacd',
  2816. },
  2817. afterLocated: function () {
  2818. stagePosSpreadObj.loadCurPosData();
  2819. },
  2820. customSearch: [
  2821. {
  2822. key: 'less', title: '漏计', valid: true,
  2823. check: function (node) {
  2824. if (node.quantity) {
  2825. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  2826. } else if (node.total_price) {
  2827. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  2828. }
  2829. }
  2830. }, {
  2831. key: 'over', title: '超计', valid: true,
  2832. check: function (node) {
  2833. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  2834. if (posRange.length > 0) {
  2835. for (const p of posRange) {
  2836. if (p.end_contract_qty > p.quantity) return true;
  2837. }
  2838. return false;
  2839. } else if (node.end_gather_qty) {
  2840. return !node.quantity || Math.abs(node.end_gather_qty) > Math.abs(ZhCalc.add(node.quantity, node.end_qc_qty));
  2841. } else if (node.end_gather_tp) {
  2842. return !node.total_price || Math.abs(node.end_gather_tp) > Math.abs(ZhCalc.add(node.total_price, node.end_qc_tp));
  2843. }
  2844. }
  2845. }, {
  2846. key: 'empty', title: '漏计', valid: false,
  2847. check: function (node) {
  2848. if (node.quantity) {
  2849. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  2850. } else if (node.total_price) {
  2851. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  2852. }
  2853. }
  2854. }, {
  2855. key: 'estimate', title: '预计变更', valid: true,
  2856. check: function (node) {
  2857. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  2858. if (posRange.length > 0) {
  2859. for (const p of posRange) {
  2860. if (!checkZero(p.estimate_qty)) return true;
  2861. }
  2862. return false;
  2863. } else {
  2864. return false;
  2865. }
  2866. }
  2867. }
  2868. ],
  2869. });
  2870. searchLedger.spread.refresh();
  2871. }
  2872. if (tab.attr('content') === '#fujian') {
  2873. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2874. getNodeList(node.id);
  2875. }
  2876. if (tab.attr('content') === '#zhongjian') {
  2877. if (!detail) {
  2878. detail = new Detail($('#detail-spread'));
  2879. detail.spread.refresh();
  2880. $('#zhongjian .sjs-bottom').height('400px');
  2881. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2882. } else {
  2883. detail.spread.refresh();
  2884. $('#zhongjian .sjs-bottom').height('400px');
  2885. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2886. }
  2887. }
  2888. if (tab.attr('content') === '#checked-change') {
  2889. if (!checkedChanges) {
  2890. checkedChanges = new CheckedChange({
  2891. changeObj: $('#cc-spread'),
  2892. changeBillsObj: $('#ccb-spread'),
  2893. reloadObj: $('#refresh-cc'),
  2894. });
  2895. checkedChanges.refresh();
  2896. } else {
  2897. $('#ccb-spread').height('400px');
  2898. checkedChanges.refresh();
  2899. }
  2900. }
  2901. if (tab.attr('content') === '#error-list') {
  2902. errorList.spread.refresh();
  2903. }
  2904. } else {
  2905. tab.removeClass('active');
  2906. tabPanel.removeClass('active');
  2907. showSideTools(tab.hasClass('active'));
  2908. }
  2909. slSpread.refresh();
  2910. spSpread.refresh();
  2911. });
  2912. // 切换附件里节点和所有附件
  2913. $('#fujian .nav-link').on('click', function () {
  2914. const tabPanel = $(this).attr('fujian-content');
  2915. if (tabPanel !== 'syfujian') {
  2916. $('#showPage').hide();
  2917. } else {
  2918. $('#showPage').show();
  2919. }
  2920. $('#showAttachment').hide();
  2921. });
  2922. // 上传附件
  2923. $('#upload-file-btn').click(function () {
  2924. if (curAuditor && curAuditor.aid !== parseInt(cur_uid)) {
  2925. return toastr.error('无法上传图片!');
  2926. }
  2927. const files = $('#upload-file')[0].files;
  2928. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2929. const formData = new FormData();
  2930. formData.append('lid', node.id);
  2931. for (const file of files) {
  2932. if (file === undefined) {
  2933. toastr.error('未选择上传文件!');
  2934. return false;
  2935. }
  2936. const filesize = file.size;
  2937. if (filesize > 30 * 1024 * 1024) {
  2938. toastr.error('存在上传文件大小过大!');
  2939. return false;
  2940. }
  2941. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  2942. if (whiteList.indexOf(fileext) === -1) {
  2943. toastr.error('只能上传指定格式的附件!');
  2944. return false;
  2945. }
  2946. formData.append('size', filesize);
  2947. formData.append('file[]', file);
  2948. }
  2949. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  2950. $('#upload').modal('hide');
  2951. // 插入到attData中
  2952. attData = data.concat(attData);
  2953. // 重新生成List
  2954. getAllList();
  2955. getNodeList(node.id);
  2956. }, function () {
  2957. toastr.error('附件上传失败');
  2958. });
  2959. $('#upload-file').val('');
  2960. });
  2961. // 获取附件信息
  2962. $('body').on('click', '.list-table a', function () {
  2963. const fid = $(this).attr('file-id');
  2964. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  2965. return;
  2966. }
  2967. const att = attData.find(function (item) {
  2968. return item.id === parseInt(fid);
  2969. });
  2970. $('#edit-att').hide();
  2971. $('#show-att').show();
  2972. if (att !== undefined) {
  2973. // 进来先把编辑功能隐藏
  2974. $('#btn-att a').eq(3).hide()
  2975. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  2976. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  2977. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  2978. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  2979. $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  2980. $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
  2981. $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
  2982. $('#show-att tr').eq(4).children('td').text(att.remark);
  2983. // 附件uid等于当前用户id, 附件上传本人
  2984. if (parseInt(cur_uid) === att.uid) {
  2985. $('#btn-att').show();
  2986. let showDel = false;
  2987. if (!curAuditor) {
  2988. stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  2989. stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  2990. stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  2991. } else {
  2992. curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  2993. }
  2994. if (showDel) $('#btn-att a').eq(3).show();
  2995. // $('#btn-att a').eq(3).show();
  2996. $('#btn-att a').eq(2).hide();
  2997. $('#btn-att a').eq(4).hide();
  2998. $('#btn-att a').eq(5).hide();
  2999. } else {
  3000. $('#btn-att').hide();
  3001. $('#btn-att a').eq(3).hide();
  3002. $('#btn-att a').eq(2).hide();
  3003. $('#btn-att a').eq(4).hide();
  3004. $('#btn-att a').eq(5).hide();
  3005. }
  3006. $('#showAttachment').attr('file-id', fid);
  3007. $('#showAttachment').show();
  3008. } else {
  3009. $('#showAttachment').hide();
  3010. $('#showAttachment').attr('file-id', '');
  3011. toastr.error('附件信息获取失败');
  3012. }
  3013. });
  3014. // $('body').on('click', '.alllist-table a', handleFileList);
  3015. $('body').on('click', '#btn-att a', function () {
  3016. const content = $(this).attr('content');
  3017. const fid = $('#showAttachment').attr('file-id');
  3018. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3019. if (content === 'edit') {
  3020. $('#btn-att a').eq(3).hide();
  3021. $('#btn-att a').eq(2).show();
  3022. $('#btn-att a').eq(4).show();
  3023. $('#btn-att a').eq(5).show();
  3024. $('#show-att').hide();
  3025. $('#edit-att').show();
  3026. const att = attData.find(function (item) {
  3027. return item.id === parseInt(fid);
  3028. });
  3029. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3030. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3031. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3032. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3033. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3034. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3035. } else if (content === 'cancel') {
  3036. $('#show-att').show();
  3037. $('#edit-att').hide();
  3038. $('#btn-att a').eq(3).show();
  3039. $('#btn-att a').eq(2).hide();
  3040. $('#btn-att a').eq(4).hide();
  3041. $('#btn-att a').eq(5).hide();
  3042. } else if (content === 'save') {
  3043. const formData = new FormData();
  3044. formData.append('id', fid);
  3045. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3046. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3047. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3048. const file = $('#change-att-btn')[0];
  3049. if (file.files[0] !== undefined) {
  3050. const filesize = file.files[0].size;
  3051. formData.append('size', filesize);
  3052. formData.append('file', file.files[0]);
  3053. }
  3054. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3055. // 替换到attData中
  3056. const att_index = attData.findIndex(function (item) {
  3057. return item.id === parseInt(fid);
  3058. });
  3059. attData.splice(att_index, 1, data);
  3060. // 重新生成List
  3061. getAllList(parseInt($('#currentPage').text()));
  3062. getNodeList(node.id);
  3063. $('#show-att').show();
  3064. $('#edit-att').hide();
  3065. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3066. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3067. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3068. $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  3069. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  3070. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  3071. $('#show-att tr').eq(4).children('td').text(data.remark);
  3072. $('#btn-att a').eq(3).show();
  3073. $('#btn-att a').eq(2).hide();
  3074. $('#btn-att a').eq(4).hide();
  3075. $('#btn-att a').eq(5).hide();
  3076. }, function () {
  3077. toastr.error('附件上传失败');
  3078. });
  3079. $('#change-att-btn').val('');
  3080. } else if (content === 'del') {
  3081. const data = {id: fid};
  3082. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  3083. // 删除到attData中
  3084. const att_index = attData.findIndex(function (item) {
  3085. return item.id === parseInt(fid);
  3086. });
  3087. attData.splice(att_index, 1);
  3088. // 重新生成List
  3089. if ($('#alllist-table tr').length === 1) {
  3090. getAllList(parseInt($('#currentPage').text()) - 1);
  3091. } else {
  3092. getAllList(parseInt($('#currentPage').text()));
  3093. }
  3094. getNodeList(node.id);
  3095. $('#showAttachment').hide();
  3096. $('#showAttachment').attr('file-id', '');
  3097. });
  3098. } else if (content === 'view') {
  3099. const data = {id: fid};
  3100. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  3101. const { filepath } = result
  3102. $('#show-att tr').eq(2).find('a').attr('href', filepath)
  3103. $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  3104. });
  3105. } else if (content === 'location') {
  3106. const att = attData.find(item => item.id === parseInt(fid));
  3107. if (Object.keys(att).length) {
  3108. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  3109. stagePosSpreadObj.loadCurPosData();
  3110. }
  3111. }
  3112. });
  3113. // 替换附件
  3114. $('#change-att-btn').on('change', function () {
  3115. const file = $('#change-att-btn')[0].files[0];
  3116. const name = file.name;
  3117. const filename = name.substring(0, name.lastIndexOf("."));
  3118. const fileext = name.substr(name.indexOf("."));
  3119. const filesize = file.size;
  3120. if (filesize > 10 * 1024 * 1024) {
  3121. toastr.error('文件大小过大!');
  3122. $('#change-att-btn').val('');
  3123. return false;
  3124. }
  3125. if (whiteList.indexOf(fileext) === -1) {
  3126. toastr.error('只能上传指定格式的附件!');
  3127. $('#change-att-btn').val('');
  3128. return false;
  3129. }
  3130. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3131. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3132. });
  3133. // 切换页数
  3134. $('.page-select').on('click', function () {
  3135. const totalPageNum = parseInt($('#totalPage').text());
  3136. const lastPageNum = parseInt($('#currentPage').text());
  3137. const status = $(this).attr('content');
  3138. if (status === 'pre' && lastPageNum > 1) {
  3139. getAllList(lastPageNum-1);
  3140. $('#showAttachment').hide();
  3141. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3142. getAllList(lastPageNum+1);
  3143. $('#showAttachment').hide();
  3144. }
  3145. });
  3146. // 显示层次
  3147. (function (select, sheet) {
  3148. $(select).click(function () {
  3149. if (!sheet.zh_tree) return;
  3150. const tag = $(this).attr('tag');
  3151. const tree = sheet.zh_tree;
  3152. switch (tag) {
  3153. case "1":
  3154. case "2":
  3155. case "3":
  3156. case "4":
  3157. case "5":
  3158. tree.expandByLevel(parseInt(tag));
  3159. SpreadJsObj.refreshTreeRowVisible(sheet);
  3160. break;
  3161. case "last":
  3162. tree.expandByCustom(() => { return true; });
  3163. SpreadJsObj.refreshTreeRowVisible(sheet);
  3164. break;
  3165. case "leafXmj":
  3166. tree.expandToLeafXmj();
  3167. SpreadJsObj.refreshTreeRowVisible(sheet);
  3168. break;
  3169. case "curMeasure":
  3170. tree.expandByCustom(function (node) {
  3171. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  3172. if (node[field]) {
  3173. return true;
  3174. }
  3175. }
  3176. return false;
  3177. });
  3178. SpreadJsObj.refreshTreeRowVisible(sheet);
  3179. break;
  3180. }
  3181. });
  3182. })('a[name=showLevel]', slSpread.getActiveSheet());
  3183. const dataChecker = DataChecker({
  3184. checkUrl: window.location.pathname + '/check',
  3185. completeData: function (data) {
  3186. stagePos.updateDatas({pos: data.source.pos});
  3187. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  3188. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  3189. stagePosSpreadObj.loadCurPosData();
  3190. for (const e of data.error) {
  3191. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  3192. }
  3193. },
  3194. errorList: errorList,
  3195. });
  3196. $('[name=stage-start]').submit(function (e) {
  3197. if (checkAuditorFrom()) {
  3198. $(this).parent().parent().parent().modal('hide');
  3199. dataChecker.checkAndPost(this.action, {});
  3200. $('#hide-all').hide();
  3201. }
  3202. return false;
  3203. });
  3204. $('#audit-check0').submit(function (e) {
  3205. $(this).parent().parent().modal('hide');
  3206. const data = {
  3207. opinion: $('[name=opinion]', this).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3208. checkType: parseInt($('[name=checkType]', this).val()),
  3209. };
  3210. dataChecker.checkAndPost(this.action, data);
  3211. $('#hide-all').hide();
  3212. return false;
  3213. });
  3214. $('#audit-check2').submit(function (e) {
  3215. $(this).parent().parent().modal('hide');
  3216. const data = {
  3217. opinion: $('[name=opinion]', this).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3218. checkType: parseInt($('[name=checkType]', this).val()),
  3219. };
  3220. dataChecker.checkAndPost(this.action, data);
  3221. $('#hide-all').hide();
  3222. return false;
  3223. });
  3224. $('#exportExcel').click(function () {
  3225. const data = [];
  3226. const setting = {
  3227. cols: [
  3228. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  3229. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  3230. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  3231. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  3232. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  3233. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  3234. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  3235. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  3236. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  3237. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  3238. {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  3239. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  3240. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  3241. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  3242. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  3243. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  3244. {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  3245. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  3246. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  3247. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  3248. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, type: 'Number'},
  3249. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  3250. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  3251. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  3252. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  3253. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  3254. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  3255. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  3256. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  3257. ],
  3258. headRows: 2,
  3259. headRowHeight: [25, 25],
  3260. defaultRowHeight: 21,
  3261. headerFont: 'bold 10px 微软雅黑',
  3262. font: '10px 微软雅黑'
  3263. };
  3264. for (const node of stageTree.nodes) {
  3265. data.push({
  3266. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  3267. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  3268. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  3269. qc_qty: node.qc_qty, qc_tp: node.qc_tp,
  3270. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  3271. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  3272. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp,
  3273. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_gather_percent: node.end_gather_percent,
  3274. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  3275. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  3276. final_dgn_price: node.final_dgn_price,
  3277. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  3278. });
  3279. const posRange = stagePos.getLedgerPos(node.id);
  3280. if (posRange && posRange.length > 0) {
  3281. for (const [i, p] of posRange.entries()) {
  3282. data.push({
  3283. pos_code: (i + 1) + '', name: p.name,
  3284. quantity: p.quantity,
  3285. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  3286. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  3287. drawing_code: p.drawing_code, memo: p.memo
  3288. });
  3289. }
  3290. }
  3291. }
  3292. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, $('.sidebar-title').attr('data-original-title') + "计量台账.xlsx");
  3293. });
  3294. });