stage.js 141 KB

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