stage.js 158 KB

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