stage.js 154 KB

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