stage.js 132 KB

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