stage.js 134 KB

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