stage.js 132 KB

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