stage.js 131 KB

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