stage.js 135 KB

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