stage.js 134 KB

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