stage.js 156 KB

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