material.js 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377
  1. 'use strict';
  2. /**
  3. * 材料调差 - 调差工料
  4. *
  5. * @author Mai
  6. * @date 2019/1/16
  7. * @version
  8. */
  9. // 编号排序,多重判断
  10. function sortByCode(a, b) {
  11. let code1 = a.code.split('-');
  12. let code2 = b.code.split('-');
  13. let code1length = code1.length;
  14. let code2length = code2.length;
  15. for (let i = 0; i < code1length; i ++) {
  16. if (i+1 <= code2length) {
  17. if (code1[i] != code2[i]) {
  18. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  19. return parseInt(code1[i]) - parseInt(code2[i]);
  20. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  21. return 1;
  22. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  23. return -1;
  24. } else {
  25. const str1length = code1[i].length;
  26. const str2length = code2[i].length;
  27. for (let j = 0; j < str1length; j++) {
  28. if (j+1 <= str2length) {
  29. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  30. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  31. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  32. if (str1length == str2length) {
  33. return 0;
  34. } else {
  35. return str1length - str2length;
  36. }
  37. }
  38. } else {
  39. if (j+1 >= str1length) {
  40. return 1;
  41. } else {
  42. return -1;
  43. }
  44. }
  45. }
  46. }
  47. } else if (i+1 == code1length && code1[i] == code2[i]) {
  48. if (code1length == code2length) {
  49. return 0;
  50. } else {
  51. return code1length - code2length;
  52. }
  53. }
  54. } else {
  55. if (i+1 >= code1length) {
  56. return 1;
  57. } else {
  58. return -1;
  59. }
  60. }
  61. }
  62. }
  63. function loadUpdateMaterials(newMaterial, fields) {
  64. const newMaterials = newMaterial instanceof Array ? newMaterial : [newMaterial];
  65. for (const nm of newMaterials) {
  66. const om = _.find(materialBillsData, {id: nm.id});
  67. for (const prop in nm) {
  68. if (!fields || fields.indexOf(prop) >= 0) {
  69. om[prop] = nm[prop];
  70. }
  71. }
  72. }
  73. }
  74. function DatePickerCellType() {
  75. }
  76. DatePickerCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  77. DatePickerCellType.prototype.createEditorElement = function () {
  78. //Create input presenter.
  79. var input = document.createElement("input");
  80. return input;
  81. };
  82. DatePickerCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect) {
  83. //Initialize input editor.
  84. if (editorContext) {
  85. const $editor = $(editorContext);
  86. GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.apply(this, arguments);
  87. $editor.datepicker({});
  88. $editor.css("position", "absolute");
  89. $editor.attr("gcUIElement", "gcEditingInput");
  90. $(".ui-datepicker").attr("gcUIElement", "gcEditingInput");
  91. }
  92. }
  93. DatePickerCellType.prototype.deactivateEditor = function (editorContext) {
  94. //Remove input editor when end editor status.
  95. if (editorContext) {
  96. var element = editorContext;
  97. // $(element).datepicker().data('datepicker').hide();
  98. // $(element).datepicker().data('datepicker').destroy();
  99. $(element).datepicker("hide");
  100. $(element).datepicker("destroy");
  101. }
  102. GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.apply(this, arguments)
  103. };
  104. DatePickerCellType.prototype.setEditorValue = function (editor, value) {
  105. //Sync value from Cell value to editor value.
  106. // console.log($(editor), value);
  107. $(editor).datepicker("setDate", value);
  108. // $(editor).datepicker().data('datepicker').selectDate(value ? new Date(value) : new Date());
  109. };
  110. DatePickerCellType.prototype.getEditorValue = function (editor, context) {
  111. // console.log($(editor).datepicker().data('datepicker'), context);
  112. //Sync value from editor value to cell value.
  113. // console.log($(editor).datepicker("getDate"));
  114. // return $(editor).datepicker("getDate");
  115. return $(editor).val();
  116. };
  117. DatePickerCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect) {
  118. if (editorContext) {
  119. const $editor = $(editorContext);
  120. $editor.css("width", cellRect.width - 1);
  121. $editor.css("height", cellRect.height - 3);
  122. }
  123. };
  124. function resetTpTable() {
  125. $('#tp_set').find('td').eq(1).text(ZhCalc.round(m_tp, materialDecimal.tp));
  126. $('#tp_set').find('td').eq(2).text(ZhCalc.add(pre_tp, ZhCalc.round(m_tp, materialDecimal.tp)));
  127. let sum = 0;
  128. if (isStageSelf) {
  129. let html = '';
  130. const rate = $('#rateInput').val();
  131. for (const ms of materialStageData) {
  132. if (!materialTax) {
  133. sum = ZhCalc.add(sum, ZhCalc.round(ZhCalc.mul(ms.m_tp, 1+rate/100), materialDecimal.tp));
  134. }
  135. const taxHtml = ' <td class="text-center">' + (materialTax ? (ms.m_tax_tp !== null ? ms.m_tax_tp : '') : ZhCalc.round(ZhCalc.mul(ms.m_tp, 1+rate/100), materialDecimal.tp) ) + '</td>\n';
  136. html += '<tr><td>第' + ms.order + '期</td><td class="text-center">' + (ms.m_tp !== null ? ms.m_tp : '') + '</td>\n' +
  137. taxHtml +
  138. ' </tr>';
  139. }
  140. const allTaxHtml = ' <td class="text-center">' + (materialTax ? m_tax_tp : sum) + '</td>\n';
  141. html += '<tr><td>合计</td><td class="text-center">' + m_tp + '</td>\n' +
  142. allTaxHtml +
  143. ' </tr>';
  144. $('#materialStageTable').html(html);
  145. }
  146. if (materialTax) {
  147. $('#tax_rate_set').find('td').eq(1).text(ZhCalc.round(m_tax_tp, materialDecimal.tp));
  148. $('#tax_rate_set').find('td').eq(2).text(ZhCalc.add(m_tax_pre_tp, ZhCalc.round(m_tax_tp, materialDecimal.tp)));
  149. } else {
  150. const rate = $('#rateInput').val();
  151. const bqhs = isStageSelf ? sum : ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  152. const jzbqhs = ZhCalc.add(pre_tp_hs, bqhs);
  153. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  154. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  155. }
  156. }
  157. function getPasteHint (str, row = '') {
  158. let returnObj = str;
  159. if (row) {
  160. returnObj.msg = '工料第' + (row+1) + '行' + str.msg;
  161. }
  162. return returnObj;
  163. }
  164. const is_numeric = (value) => {
  165. if (typeof(value) === 'object') {
  166. return false;
  167. } else {
  168. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  169. }
  170. };
  171. $(document).ready(() => {
  172. autoFlashHeight();
  173. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  174. const materialSpreadSetting = {
  175. emptyRows: 0,
  176. headRows: 2,
  177. headRowHeight: [25, 32],
  178. defaultRowHeight: 21,
  179. headerFont: '12px 微软雅黑',
  180. font: '12px 微软雅黑',
  181. readOnly: readOnly,
  182. };
  183. let materialSpreadSettingCols = [
  184. {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isUsed', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
  185. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isUsed'},
  186. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.isEdit'},
  187. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: 'readOnly.isEdit'},
  188. {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.isEdit'},
  189. {title: '工料分类', colSpan: '1', rowSpan: '2', field: 'm_type', hAlign: 1, width: 60, readOnly: 'readOnly.isEdit', cellType: 'customizeCombo', comboItems: materialType.m_type, cellTypeKey: 2},
  190. ];
  191. if (materialTax) {
  192. materialSpreadSettingCols.push({title: '税率(%)', colSpan: '1', rowSpan: '2', field: 'm_tax', hAlign: 2, width: 50, type: 'Number', readOnly: editTaxPermission ? 'readOnly.remark' : 'readOnly.isEdit'});
  193. }
  194. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  195. {title: '上涨 幅度(%)', colSpan: '1', rowSpan: '2', field: 'm_up_risk', hAlign: 2, width: 50, type: 'Number', readOnly: 'readOnly.isEdit'},
  196. {title: '下跌 幅度(%)', colSpan: '1', rowSpan: '2', field: 'm_down_risk', hAlign: 2, width: 50, type: 'Number', readOnly: 'readOnly.isEdit'},
  197. {title: '基准价', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit'},
  198. {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.remark'},
  199. {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
  200. {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.remark'},
  201. {title: '|单价差', colSpan: '|1', rowSpan: '|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.msg_spread'},]
  202. );
  203. if (materialTax) {
  204. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  205. {title: '本期材料调差|有效价差', colSpan: '4|1', rowSpan: '1|1', field: 'm_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
  206. {title: '|本期应耗数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 90, type: 'Number', readOnly: true},
  207. {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
  208. {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'm_tax_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tax_tp'},
  209. {title: '截止上期|调差金额', colSpan: '2|1', rowSpan: '1|1', field: 'pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  210. {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'tax_pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  211. ]);
  212. if (!isStageSelf) {
  213. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  214. {title: '截止本期|调差金额', colSpan: '2|1', rowSpan: '1|1', field: 'end_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.end_tp'},
  215. {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'tax_end_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.tax_end_tp'},
  216. ]);
  217. }
  218. } else {
  219. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  220. {title: '本期材料调差|有效价差', colSpan: '3|1', rowSpan: '1|1', field: 'm_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
  221. {title: '|本期应耗数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 90, type: 'Number', readOnly: true},
  222. {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
  223. {title: '截止上期|调差金额', colSpan: '1|1', rowSpan: '1|1', field: 'pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  224. ]);
  225. if (!isStageSelf) {
  226. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  227. {title: '截止本期|调差金额', colSpan: '1|1', rowSpan: '1|1', field: 'end_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.end_tp'},
  228. ]);
  229. }
  230. }
  231. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  232. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 50, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: 'readOnly.remark'},
  233. {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'},
  234. ]);
  235. materialSpreadSetting.cols = materialSpreadSettingCols;
  236. const spCol = _.find(materialSpreadSetting.cols, {field: 'quantity'});
  237. spCol.readOnly = true;
  238. spCol.cellType = 'activeImageBtn';
  239. spCol.normalImg = '#ellipsis-icon';
  240. spCol.indent = 5;
  241. spCol.showImage = function (data) {
  242. // return !readOnly && data.t_type === 2 && data.mid === materialID;
  243. return data && data.t_type === 2;
  244. };
  245. materialSpreadSetting.imageClick = function (data) {
  246. if (data.t_type === 2) {
  247. $('#bcyy').modal('show');
  248. $('#materialbillsId').val(data.id);
  249. $('#expr').val(data.expr);
  250. if (!readOnly) {
  251. $('#expr').attr('readOnly', false);
  252. $('#expr_btn').show();
  253. $('#expr_select').show();
  254. } else {
  255. $('#expr').attr('readOnly', true);
  256. $('#expr_btn').hide();
  257. $('#expr_select').hide();
  258. }
  259. }
  260. };
  261. const materialBase = {
  262. isUsed: function (data) {
  263. if (data.t_type === 2) {
  264. return data.mid === materialID;
  265. } else {
  266. const mlInfo = _.find(materialListData, { mb_id: data.id });
  267. return data.mid === materialID && mlInfo === undefined;
  268. }
  269. },
  270. isEdit: function (data) {
  271. // if (data.t_type === 2) {
  272. // return data.mid === materialID;
  273. // } else {
  274. // const mlInfo = _.find(materialListData, { mb_id: data.id });
  275. // return data.mid === materialID && mlInfo === undefined;
  276. // }
  277. return data.mid === materialID;
  278. },
  279. // isStage: function (data) {
  280. // return data.mid === materialID;
  281. // }
  282. }
  283. const materialCol = {
  284. getValue: {
  285. msg_spread: function (data) {
  286. return ZhCalc.round(ZhCalc.sub(data.msg_tp, data.basic_price), materialDecimal.up);
  287. },
  288. m_spread : function (data) {
  289. const msg_spread = materialCol.getValue.msg_spread(data);
  290. const cor = msg_spread >= 0 ? ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_up_risk, 100)) : ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_down_risk, 100));
  291. return Math.abs(msg_spread) > Math.abs(cor) ? (msg_spread > 0 ? ZhCalc.round(ZhCalc.sub(msg_spread, cor), materialDecimal.up) : ZhCalc.round(ZhCalc.add(msg_spread, cor), materialDecimal.up)) : 0;
  292. },
  293. m_tp: function (data) {
  294. return ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
  295. },
  296. m_tax_tp: function (data) {
  297. const m_tp = ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
  298. return data.m_tax ? ZhCalc.round(ZhCalc.mul(m_tp, (1+ZhCalc.div(data.m_tax, 100))), materialDecimal.tp) : m_tp;
  299. },
  300. end_tp: function (data) {
  301. return ZhCalc.add(data.m_tp, data.pre_tp) || '';
  302. },
  303. tax_end_tp: function (data) {
  304. return ZhCalc.add(data.m_tax_tp, data.tax_pre_tp) || '';
  305. }
  306. },
  307. readOnly: {
  308. isEdit: function (data) {
  309. return !(!readOnly && materialBase.isEdit(data));
  310. },
  311. isUsed: function (data) {
  312. return !(!readOnly && materialBase.isUsed(data));
  313. },
  314. remark: function () {
  315. return readOnly;
  316. },
  317. msg_tp: function () {
  318. return !(!readOnly && months.length === 0);
  319. }
  320. },
  321. };
  322. const needUpdateArray = ['quantity', 'expr', 'msg_tp', 'msg_times', 'msg_spread', 'm_spread', 'm_tp', 'm_tax_tp', 'is_summary', 'remark'];
  323. const materialSpreadObj = {
  324. getMaterialBillsData: function () {
  325. if (isStageSelf) {
  326. // 当前选中nav id
  327. const ms_id = $('#myTab').find('.active').data('msid');
  328. const msbList = _.filter(materialStageBillsData, { ms_id });
  329. for (const mb of materialBillsData) {
  330. mb.ms_id = ms_id;
  331. const msbInfo = _.find(msbList, { mb_id: mb.mb_id ? mb.mb_id : mb.id });
  332. if (msbInfo) {
  333. for (const nu of needUpdateArray) {
  334. mb[nu] = msbInfo[nu];
  335. }
  336. }
  337. }
  338. }
  339. return materialBillsData;
  340. },
  341. updateOneMaterialBill: function (data) {
  342. const ms_id = $('#myTab').find('.active').data('msid');
  343. const msbInfo = _.find(materialStageBillsData, { ms_id, mb_id: data.id });
  344. console.log(msbInfo);
  345. data.ms_id = ms_id;
  346. for (const nu of needUpdateArray) {
  347. data[nu] = msbInfo[nu];
  348. }
  349. return data;
  350. },
  351. updateMaterialData: function (datas) {
  352. if (datas.stageData && datas.stageData.length > 0) {
  353. if (datas.stageData.length === materialStageData.length) {
  354. // 全体替换
  355. materialStageData = datas.stageData;
  356. } else {
  357. // 替换对应的stage数据
  358. for (const s of datas.stageData) {
  359. const index = _.findIndex(materialStageData, { id: s.id });
  360. materialStageData.splice(index, 1, s);
  361. }
  362. }
  363. }
  364. if (datas.pushStageBillsData && datas.pushStageBillsData.length > 0) {
  365. materialStageBillsData = _.concat(materialStageBillsData, datas.pushStageBillsData);
  366. }
  367. if (datas.removeStageBillsData && datas.removeStageBillsData.length > 0) {
  368. materialStageBillsData = _.remove(materialStageBillsData, function (item) {
  369. return _.findIndex(datas.removeStageBillsData, { id: item.mb_id }) === -1
  370. })
  371. }
  372. if (datas.stageBillsData && datas.stageBillsData.length > 0) {
  373. if (datas.stageBillsData.length === materialStageBillsData.length) {
  374. // 全体替换
  375. materialStageBillsData = datas.stageBillsData;
  376. } else {
  377. // 替换对应的stage数据
  378. for (const s of datas.stageBillsData) {
  379. const index = _.findIndex(materialStageBillsData, { id: s.id });
  380. materialStageBillsData.splice(index, 1, s);
  381. }
  382. }
  383. }
  384. if (datas.billsData && datas.billsData.length > 0) {
  385. if (datas.billsData.length === materialBillsData.length) {
  386. // 全体替换
  387. materialBillsData = datas.billsData;
  388. materialSpreadObj.getMaterialBillsData();
  389. } else {
  390. for (const b of datas.billsData) {
  391. const index = _.findIndex(materialBillsData, {id: b.id});
  392. materialBillsData.splice(index, 1, b);
  393. materialSpreadObj.updateOneMaterialBill(materialBillsData[index]);
  394. }
  395. }
  396. }
  397. },
  398. materialSheetReset: function (redo = false) {
  399. let newMaterialBillsData = _.cloneDeep(materialBillsData);
  400. if($('#bills0_list').is(':checked')) {
  401. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  402. return item.quantity !== null && item.quantity !== 0;
  403. });
  404. }
  405. if (redo) {
  406. materialSpread.getActiveSheet().reset();
  407. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  408. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  409. }
  410. console.log(newMaterialBillsData);
  411. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  412. materialSpreadObj.refreshActn();
  413. },
  414. refreshActn: function (rowCount = 1) {
  415. const setObjEnable = function (obj, enable) {
  416. if (enable) {
  417. obj.removeClass('disabled');
  418. } else {
  419. obj.addClass('disabled');
  420. }
  421. };
  422. const sheet = materialSpread.getActiveSheet();
  423. const select = SpreadJsObj.getSelectObject(sheet);
  424. const selection = sheet.getSelections();
  425. const sel = selection ? selection[0] : sheet.getSelections()[0];
  426. const row = sel ? sel.row : -1;
  427. const first = materialBillsData[row];
  428. let last = first;
  429. if (sel.rowCount > 1 && first) {
  430. for (let r = 1; r < sel.rowCount; r++) {
  431. const rNode = materialBillsData[sel.row + r];
  432. if (!rNode) break;
  433. last = rNode;
  434. }
  435. }
  436. const preNode = materialBillsData[row - 1];
  437. // 还需判断是否已被调差清单调用
  438. setObjEnable($('#del'), !readOnly && select && materialBase.isUsed(select) && rowCount === 1);
  439. setObjEnable($('#up-move'), !readOnly && first && preNode && materialBillsData.indexOf(last) > 0 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
  440. setObjEnable($('#down-move'), !readOnly && first && materialBillsData.indexOf(last) < materialBillsData.length - 1 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
  441. },
  442. add: function () {
  443. const sheet = materialSpread.getActiveSheet();
  444. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  445. if (result) {
  446. materialBillsData.push(result.info);
  447. if (isStageSelf) {
  448. materialSpreadObj.updateMaterialData(result);
  449. materialSpreadObj.getMaterialBillsData();
  450. }
  451. // sheet.addRows(materialBillsData.length - 1, 1);
  452. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  453. let newMaterialBillsData = materialBillsData;
  454. if($('#bills0_list').is(':checked')) {
  455. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  456. return item.quantity !== null && item.quantity !== 0;
  457. });
  458. }
  459. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  460. // materialSpreadObj.materialSheetReset();
  461. sheet.setSelection(newMaterialBillsData.length - 1, 0, 1, 1);
  462. console.log(sheet);
  463. materialSpreadObj.refreshActn();
  464. // 月信息价需要同时添加空白的list
  465. if (months.length > 0) {
  466. const one_month ={ mb_id: result.info.id, code: '', name: null, origin: null, unit: null, order: result.info.order };
  467. for (const m of months) {
  468. one_month[m] = null;
  469. }
  470. monthsList.push(one_month);
  471. // const newMonthsList = _.filter(monthsList, function (item) {
  472. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  473. // });
  474. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  475. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  476. monthFunGather.monthsListSet();
  477. // materialMonthSpreadObj.monthsListSet();
  478. }
  479. }
  480. });
  481. },
  482. del: function () {
  483. const sheet = materialSpread.getActiveSheet();
  484. const select = SpreadJsObj.getSelectObject(sheet);
  485. const sel = sheet.getSelections();
  486. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  487. m_tp = result.m_tp;
  488. if (materialTax) {
  489. m_tax_tp = result.m_tax_tp;
  490. }
  491. const index = _.findIndex(materialBillsData, { id: select.id });
  492. materialBillsData.splice(index, 1);
  493. if (isStageSelf) {
  494. result.removeStageBillsData = [{ id: select.id }];
  495. materialSpreadObj.updateMaterialData(result);
  496. materialSpreadObj.getMaterialBillsData();
  497. }
  498. let newMaterialBillsData = materialBillsData;
  499. let newIndex = index;
  500. if($('#bills0_list').is(':checked')) {
  501. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  502. return item.quantity !== null && item.quantity !== 0;
  503. });
  504. newIndex = _.findIndex(newMaterialBillsData, { id: select.id });
  505. }
  506. // sheet.deleteRows(newIndex, 1);
  507. // sheet.zh_data.splice(newIndex, 1);
  508. materialSpreadObj.materialSheetReset(true);
  509. resetTpTable();
  510. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  511. sheet.setSelection(newIndex > 0 ? newIndex - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  512. materialSpreadObj.refreshActn();
  513. // 月信息价需要同时删除
  514. if (months.length > 0) {
  515. monthsList.splice(index, 1);
  516. materialMonthSpread.getActiveSheet().deleteRows(newIndex, 1);
  517. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  518. }
  519. });
  520. },
  521. upMove: function () {
  522. if($('#bills0_list').is(':checked')) {
  523. return;
  524. }
  525. const data = {
  526. type: 'changeOrder',
  527. postData: [],
  528. };
  529. const sheet = materialSpread.getActiveSheet();
  530. const selection = sheet.getSelections();
  531. const row = selection[0].row, count = selection[0].rowCount;
  532. const first = sheet.zh_data[row];
  533. if (!first) {
  534. materialSpreadObj.refreshActn();
  535. return false;
  536. }
  537. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  538. for (let iRow = 0; iRow < count; iRow++) {
  539. const posData = sheet.zh_data[iRow + row];
  540. if (posData) {
  541. data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row - 1].order});
  542. preUpdate.order = posData.order;
  543. }
  544. }
  545. console.log(monthsList);
  546. data.postData.push(preUpdate);
  547. console.log(data);
  548. if (data.postData.length > 0) {
  549. postData(window.location.pathname + '/save', data, function () {
  550. _.forEach(data.postData, function (item) {
  551. const cl = _.find(materialBillsData, { id: item.id });
  552. cl.order = item.order;
  553. });
  554. materialBillsData.sort(function (a, b) {
  555. return a.order - b.order
  556. });
  557. SpreadJsObj.reLoadSheetData(sheet);
  558. const sel = selection[0];
  559. if (sel) {
  560. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  561. }
  562. if (months.length > 0) {
  563. _.forEach(data.postData, function (item) {
  564. const cl = _.find(monthsList, { mb_id: item.id });
  565. cl.order = item.order;
  566. });
  567. monthsList.sort(function (a, b) {
  568. return a.order - b.order
  569. });
  570. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  571. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  572. }
  573. materialSpreadObj.refreshActn();
  574. });
  575. }
  576. },
  577. downMove: function () {
  578. if($('#bills0_list').is(':checked')) {
  579. return;
  580. }
  581. const data = {
  582. type: 'changeOrder',
  583. postData: [],
  584. };
  585. const sheet = materialSpread.getActiveSheet();
  586. const selection = sheet.getSelections();
  587. const row = selection[0].row, count = selection[0].rowCount;
  588. const first = sheet.zh_data[row];
  589. if (!first) {
  590. materialSpreadObj.refreshActn();
  591. return false;
  592. }
  593. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  594. for (let iRow = count - 1; iRow >= 0; iRow--) {
  595. const posData = sheet.zh_data[iRow + row];
  596. if (posData) {
  597. data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row + 1].order});
  598. nextUpdate.order = posData.order;
  599. }
  600. }
  601. data.postData.push(nextUpdate);
  602. console.log(data);
  603. if (data.postData.length > 0) {
  604. postData(window.location.pathname + '/save', data, function () {
  605. _.forEach(data.postData, function (item) {
  606. const cl = _.find(materialBillsData, { id: item.id });
  607. cl.order = item.order;
  608. });
  609. materialBillsData.sort(function (a, b) {
  610. return a.order - b.order
  611. });
  612. SpreadJsObj.reLoadSheetData(sheet);
  613. const sel = selection[0];
  614. if (sel) {
  615. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  616. }
  617. if (months.length > 0) {
  618. _.forEach(data.postData, function (item) {
  619. const cl = _.find(monthsList, { mb_id: item.id });
  620. cl.order = item.order;
  621. });
  622. monthsList.sort(function (a, b) {
  623. return a.order - b.order
  624. });
  625. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  626. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  627. }
  628. materialSpreadObj.refreshActn();
  629. });
  630. }
  631. },
  632. selectionChanged: function (e, info) {
  633. const sel = info.sheet.getSelections()[0];
  634. const col = info.sheet.zh_setting.cols[sel.col];
  635. materialSpreadObj.refreshActn(sel.rowCount);
  636. const data = SpreadJsObj.getSelectObject(info.sheet);
  637. materialSpreadObj.setReadOnly(true);
  638. // console.log(data);
  639. setCurBillSourceList(data ? (data.mb_id || data.id) : null, $('#myTab').find('.active').data('msid') || null);
  640. },
  641. editEnded: function (e, info) {
  642. if (info.sheet.zh_setting) {
  643. const select = SpreadJsObj.getSelectObject(info.sheet);
  644. const col = info.sheet.zh_setting.cols[info.col];
  645. if (col.field === 'is_summary') {
  646. return;
  647. }
  648. // 未改变值则不提交
  649. let validText = (col.type === 'Number' || col.field === 'm_type' || col.field === 't_type') && is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  650. const orgValue = select[col.field];
  651. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  652. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  653. return;
  654. }
  655. // 判断部分值是否输入的是数字判断和数据计算
  656. if (col.field === 'basic_price') {
  657. if (isNaN(validText)) {
  658. toastr.error('不能输入其它非数字类型字符');
  659. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  660. return;
  661. }
  662. let num = parseFloat(validText);
  663. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  664. if (validText !== null && (num < 0 || !reg.test(num))) {
  665. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  666. validText = ZhCalc.round(num, materialDecimal.up);
  667. }
  668. }
  669. if (col.field === 'msg_tp') {
  670. if (isNaN(validText)) {
  671. toastr.error('不能输入其它非数字类型字符');
  672. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  673. return;
  674. }
  675. const num = parseFloat(validText);
  676. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  677. if (validText !== null && (num < 0 || !reg.test(num))) {
  678. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  679. validText = ZhCalc.round(num, materialDecimal.up);
  680. }
  681. }
  682. if (col.field === 'm_up_risk' || col.field === 'm_down_risk' || col.field === 'm_tax') {
  683. // 只能输入正整数
  684. if (isNaN(validText)) {
  685. toastr.error('不能输入其它非数字类型字符');
  686. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  687. return;
  688. }
  689. const num = parseFloat(validText);
  690. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  691. toastr.error('只能输入0-100的正整数');
  692. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  693. return;
  694. }
  695. }
  696. if (col.field === 't_type') {
  697. if (validText === 1) {
  698. select.quantity = null;
  699. select.expr = null;
  700. select.m_tp = null;
  701. }
  702. }
  703. select[col.field] = validText;
  704. select.msg_spread = materialCol.getValue.msg_spread(select);
  705. select.m_spread = materialCol.getValue.m_spread(select);
  706. select.m_tp = materialCol.getValue.m_tp(select);
  707. select.m_tax_tp = materialCol.getValue.m_tax_tp(select);
  708. delete select.waitingLoading;
  709. // console.log(select);
  710. // 更新至服务器
  711. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  712. m_tp = result.m_tp;
  713. if (materialTax) {
  714. m_tax_tp = result.m_tax_tp;
  715. }
  716. if (isStageSelf) {
  717. materialSpreadObj.updateMaterialData(result);
  718. }
  719. resetTpTable();
  720. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  721. // 判断如果是更改了编号,名称,单位,月信息价需要跟着改变值
  722. if (months.length > 0 && (col.field === 'code' || col.field === 'name' || col.field === 'unit')) {
  723. const index = _.findIndex(materialBillsData, { id: select.id });
  724. monthsList[index][col.field] = validText;
  725. monthFunGather.monthsListSet();
  726. }
  727. }, function () {
  728. select[col.field] = orgValue;
  729. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  730. });
  731. }
  732. },
  733. buttonClicked: function (e, info) {
  734. if (info.sheet.zh_setting) {
  735. const select = SpreadJsObj.getSelectObject(info.sheet);
  736. const col = info.sheet.zh_setting.cols[info.col];
  737. if (materialCol.readOnly.isEdit(select)) {
  738. return;
  739. }
  740. if (col.field === 'is_summary') {
  741. if (info.sheet.isEditing()) {
  742. info.sheet.endEdit(true);
  743. }
  744. select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  745. delete select.waitingLoading;
  746. // 更新至服务器
  747. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  748. m_tp = result.m_tp;
  749. if (materialTax) {
  750. m_tax_tp = result.m_tax_tp;
  751. }
  752. if (isStageSelf) {
  753. materialSpreadObj.updateMaterialData(result);
  754. }
  755. resetTpTable();
  756. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  757. }, function () {
  758. select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  759. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  760. });
  761. }
  762. }
  763. },
  764. deletePress: function (sheet) {
  765. return;
  766. },
  767. clipboardPasted(e, info) {
  768. const hint = {
  769. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  770. codeEmpty: {type: 'error', msg: '请先输入编号,并且不超过15个字符'},
  771. codeUsed: {type: 'error', msg: '该编号已存在,请重新输入。'},
  772. codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
  773. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  774. riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
  775. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  776. };
  777. const range = info.cellRange;
  778. const sortData = info.sheet.zh_data || [];
  779. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  780. toastMessageUniq(hint.cellError);
  781. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  782. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  783. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  784. return;
  785. }
  786. if (sortData.length > 0 && range.col + range.colCount > 18) {
  787. toastMessageUniq(hint.cellError);
  788. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  789. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  790. return;
  791. }
  792. const data = [];
  793. // const rowData = [];
  794. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  795. let bPaste = true;
  796. const curRow = range.row + iRow;
  797. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  798. const materialData = { id: sortData[curRow].id };
  799. const hintRow = range.rowCount > 1 ? curRow : '';
  800. let sameCol = 0;
  801. for (let iCol = 0; iCol < range.colCount; iCol++) {
  802. const curCol = range.col + iCol;
  803. const colSetting = info.sheet.zh_setting.cols[curCol];
  804. if (!colSetting) continue;
  805. let validText = info.sheet.getText(curRow, curCol);
  806. validText = (colSetting.type === 'Number' || colSetting.field === 'm_type' || colSetting.field === 't_type') && is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  807. const orgValue = sortData[curRow][colSetting.field];
  808. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  809. sameCol++;
  810. if (range.colCount === sameCol) {
  811. bPaste = false;
  812. }
  813. continue;
  814. }
  815. if (colSetting.field === 'code' && (validText === '' || validText.length > 15)) {
  816. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  817. bPaste = false;
  818. continue;
  819. }
  820. if (colSetting.field === 'code' && validText.toString().indexOf('.') !== -1) {
  821. toastMessageUniq(getPasteHint(hint.codeError, hintRow));
  822. bPaste = false;
  823. continue;
  824. }
  825. if (colSetting.field === 'code' && _.find(sortData, { code: validText.toString() })) {
  826. toastMessageUniq(getPasteHint(hint.codeUsed, hintRow));
  827. bPaste = false;
  828. continue;
  829. }
  830. if (colSetting.field === 't_type' || colSetting.field === 'm_type') {
  831. continue;
  832. }
  833. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp'
  834. || colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
  835. if (isNaN(validText)) {
  836. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  837. bPaste = false;
  838. continue;
  839. }
  840. const num = parseFloat(validText);
  841. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
  842. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  843. if (validText !== null && (num < 0 || !reg.test(num))) {
  844. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  845. validText = ZhCalc.round(num, materialDecimal.up);
  846. }
  847. } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk' || colSetting.field === 'm_tax') {
  848. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  849. toastMessageUniq(getPasteHint(hint.riskCan, hintRow));
  850. bPaste = false;
  851. continue;
  852. }
  853. }
  854. }
  855. materialData[colSetting.field] = validText;
  856. sortData[curRow][colSetting.field] = validText;
  857. }
  858. if (materialData.code === '' || materialData.code === null) {
  859. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  860. bPaste = false;
  861. }
  862. if (bPaste) {
  863. materialData.msg_spread = materialCol.getValue.msg_spread(sortData[curRow]);
  864. materialData.m_spread = materialCol.getValue.m_spread(sortData[curRow]);
  865. materialData.m_tp = materialCol.getValue.m_tp(sortData[curRow]);
  866. materialData.m_tax_tp = materialCol.getValue.m_tax_tp(sortData[curRow]);
  867. data.push(materialData);
  868. // rowData.push(curRow);
  869. } else {
  870. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  871. }
  872. }
  873. if (data.length === 0) {
  874. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  875. return;
  876. }
  877. // console.log(data);
  878. // 更新至服务器
  879. postData(window.location.pathname + '/save', { type:'paste', updateData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  880. materialBillsData = result.info;
  881. m_tp = result.m_tp;
  882. if (materialTax) {
  883. m_tax_tp = result.m_tax_tp;
  884. }
  885. if (isStageSelf) {
  886. materialSpreadObj.updateMaterialData(result);
  887. materialSpreadObj.getMaterialBillsData();
  888. }
  889. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  890. materialSpreadObj.materialSheetReset();
  891. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  892. // for (const row in rowData) {
  893. // materialBillsData.splice(index, 1, result.info[row]);
  894. // SpreadJsObj.reLoadRowData(info.sheet, row);
  895. // }
  896. if (months.length > 0) {
  897. for (const [i,m] of monthsList.entries()) {
  898. m.code = materialBillsData[i].code;
  899. m.name = materialBillsData[i].name;
  900. m.unit = materialBillsData[i].unit;
  901. m.origin = materialBillsData[i].origin;
  902. }
  903. // SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  904. monthFunGather.monthsListSet();
  905. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  906. }
  907. resetTpTable();
  908. // materialSpreadObj.refreshActn();
  909. }, function () {
  910. // materialSpreadObj.refreshActn();
  911. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  912. return;
  913. });
  914. },
  915. setReadOnly: function(readOnly) {
  916. // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
  917. }
  918. };
  919. materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
  920. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  921. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  922. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  923. materialSpread.bind(spreadNS.Events.ButtonClicked, materialSpreadObj.buttonClicked);
  924. const sheet = materialSpread.getActiveSheet();
  925. sheet.suspendPaint();
  926. // materialSpreadObj.refreshActn();
  927. // const basic_range = sheet.getRange(-1, 8, -1, 1);
  928. // basic_range.cellType(new DatePickerCellType());
  929. // basic_range.formatter("yyyy-MM-dd");
  930. // const msg_range = sheet.getRange(-1, 10, -1, 1);
  931. // msg_range.cellType(new DatePickerCellType());
  932. // msg_range.formatter("yyyy-MM-dd");
  933. sheet.resumePaint();
  934. const static_cols = [
  935. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: true},
  936. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  937. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  938. {title: '来源地', colSpan: '1', rowSpan: '2', field: 'origin', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
  939. {title: '平均单价', colSpan: '1', rowSpan: '2', field: 'average_msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue:'getValue.average_msg_tp'},
  940. ];
  941. // 月信息价方法集合
  942. const monthFunGather = {
  943. _setMonthHtml: function() {
  944. let html = '';
  945. let qihtml = '';
  946. for (const m of months) {
  947. html += '<div class="custom-control custom-checkbox mb-2">\n' +
  948. ' <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
  949. ' <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
  950. ' </div>';
  951. qihtml += parseInt(m.split('-')[1]) + '月,';
  952. }
  953. if (months.length > 0) {
  954. qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
  955. qihtml = qihtml.substring(0, qihtml.length-1);
  956. }
  957. $('#show_month').html(html);
  958. $('#qi-month').html(qihtml);
  959. },
  960. _monthHeaderSet: function() {
  961. const newMonths = [];
  962. for (const m of months) {
  963. const year = m.split('-')[0];
  964. const month = parseInt(m.split('-')[1]);
  965. let one = _.find(newMonths, { 'year': year });
  966. let oneIndex = _.findIndex(newMonths, { 'year': year });
  967. if (one) {
  968. one.month.push(month);
  969. newMonths.splice(oneIndex, 1, one);
  970. } else {
  971. one = {
  972. year: year,
  973. month: [ month ],
  974. };
  975. newMonths.push(one);
  976. }
  977. }
  978. const pushMonth = [];
  979. for(const mo of newMonths) {
  980. for (let i in mo.month) {
  981. i = parseInt(i);
  982. const newCols = {
  983. title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
  984. colSpan: (i === 0 ? (mo.month.length === 1 ? '0' : mo.month.length) : '') + '|1',
  985. rowSpan: i === 0 ? '1|1' : '|1',
  986. field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
  987. hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
  988. pushMonth.push(newCols);
  989. }
  990. }
  991. return pushMonth;
  992. },
  993. monthSheetReset: function (ml = monthsList) {
  994. const monthCols = monthFunGather._monthHeaderSet();
  995. const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
  996. materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
  997. // 表头变化需要重新绘制,不然报错;
  998. materialMonthSpread.getActiveSheet().reset();
  999. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  1000. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  1001. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, ml);
  1002. monthFunGather._setMonthHtml();
  1003. },
  1004. monthsListSet: function (ml = materialBillsData, checked = true) {
  1005. if($('#bills0_list').is(':checked') && checked) {
  1006. ml = _.filter(materialBillsData, function (item) {
  1007. return item.quantity === null || item.quantity === 0;
  1008. });
  1009. }
  1010. const newMonthsList = _.filter(monthsList, function (item) {
  1011. return _.findIndex(ml, { code: item.code }) !== -1;
  1012. });
  1013. monthFunGather.monthSheetReset(newMonthsList);
  1014. }
  1015. };
  1016. const materialMonthSpread = SpreadJsObj.createNewSpread($('#material-month-spread')[0]);
  1017. const materialMonthSpreadSetting = {
  1018. cols: static_cols,
  1019. emptyRows: 0,
  1020. headRows: 2,
  1021. headRowHeight: [25, 25],
  1022. defaultRowHeight: 21,
  1023. headerFont: '12px 微软雅黑',
  1024. font: '12px 微软雅黑',
  1025. readOnly: readOnly,
  1026. };
  1027. if (months.length > 0) {
  1028. const monthCols = monthFunGather._monthHeaderSet();
  1029. const monthSpreadHeaderCols = static_cols.concat(monthCols);
  1030. materialMonthSpreadSetting.cols = monthSpreadHeaderCols;
  1031. }
  1032. const materialMonthCol = {
  1033. getValue: {
  1034. average_msg_tp: function (data) {
  1035. let msg_tp = 0;
  1036. let hadnum = 0;
  1037. for (const m of months) {
  1038. msg_tp += data[m];
  1039. if (data[m] !== null && data[m] !== '' && data[m] !== 0) {
  1040. hadnum++;
  1041. }
  1042. }
  1043. const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), materialDecimal.up) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), materialDecimal.up);
  1044. return average_tp;
  1045. },
  1046. },
  1047. readOnly: {
  1048. isEdit: function (data) {
  1049. return readOnly;
  1050. },
  1051. },
  1052. };
  1053. materialMonthSpread.getActiveSheet().frozenColumnCount(5);
  1054. materialMonthSpread.getActiveSheet().options.frozenlineColor = '#f1f1f1';
  1055. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  1056. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  1057. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  1058. const materialMonthSpreadObj = {
  1059. editEnded: function (e, info) {
  1060. if (info.sheet.zh_setting) {
  1061. const select = SpreadJsObj.getSelectObject(info.sheet);
  1062. const col = info.sheet.zh_setting.cols[info.col];
  1063. // 未改变值则不提交
  1064. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1065. const orgValue = select[col.field];
  1066. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1067. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1068. return;
  1069. }
  1070. if (col.field === 'origin') {
  1071. select[col.field] = validText;
  1072. postData(window.location.pathname + '/month/save', { type:'updateOrigin', updateData: { mb_id: select.mb_id, value: validText } }, function (result) {
  1073. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1074. materialBillsData = result.materialBillsData;
  1075. materialSpreadObj.materialSheetReset();
  1076. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1077. }, function () {
  1078. select[col.field] = orgValue;
  1079. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1080. });
  1081. } else {
  1082. // 判断部分值是否输入的是数字判断和数据计算
  1083. if (isNaN(validText)) {
  1084. toastr.error('不能输入其它非数字类型字符');
  1085. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1086. return;
  1087. }
  1088. const num = parseFloat(validText);
  1089. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1090. if (validText !== null && (num < 0 || !reg.test(num))) {
  1091. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  1092. validText = ZhCalc.round(num, materialDecimal.up);
  1093. }
  1094. select[col.field] = validText;
  1095. // 更新至服务器
  1096. postData(window.location.pathname + '/month/save', { type:'update', updateData: { mb_id: select.mb_id, yearmonth: col.field, value: validText } }, function (result) {
  1097. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1098. materialBillsData = result.materialBillsData;
  1099. materialSpreadObj.materialSheetReset();
  1100. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1101. m_tp = result.m_tp;
  1102. if (materialTax) {
  1103. m_tax_tp = result.m_tax_tp;
  1104. }
  1105. resetTpTable();
  1106. }, function () {
  1107. select[col.field] = orgValue;
  1108. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1109. });
  1110. }
  1111. }
  1112. },
  1113. deletePress: function (sheet) {
  1114. // if (sheet.zh_setting && sheet.zh_data) {
  1115. // const sel = sheet.getSelections()[0];
  1116. // if (!sel) return;
  1117. //
  1118. // const col = sheet.zh_setting.cols[sel.col];
  1119. // const select = SpreadJsObj.getSelectObject(sheet);
  1120. // const orgValue = select[col.field];
  1121. // if (sel.colCount > 1 || sel.rowCount > 1) {
  1122. // toastr.warning('请勿同时删除多行或多列数据');
  1123. // }
  1124. // console.log(sel, select, col);
  1125. // if (orgValue === null || col.field === 'type' || col.field === 'is_summary') {
  1126. // return;
  1127. // }
  1128. // select[col.field] = null;
  1129. // select.calc_num = materialExponentCol.getValue.calc_num(select);
  1130. // console.log(select);
  1131. // 更新至服务器
  1132. // postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  1133. // ex_tp = result.ex_tp;
  1134. // ex_expr = result.ex_expr;
  1135. // resetExTpTable();
  1136. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  1137. // materialExponentData.splice(sel.row, 1, select);
  1138. // }, function () {
  1139. // select[col.field] = orgValue;
  1140. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  1141. // });
  1142. // }
  1143. return;
  1144. },
  1145. clipboardPasted(e, info) {
  1146. const hint = {
  1147. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1148. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1149. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  1150. };
  1151. const range = info.cellRange;
  1152. const sortData = info.sheet.zh_data || [];
  1153. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1154. toastMessageUniq(hint.cellError);
  1155. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1156. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1157. return;
  1158. }
  1159. if (sortData.length > 0 && range.col + range.colCount > 5 + months.length) {
  1160. toastMessageUniq(hint.cellError);
  1161. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1162. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1163. return;
  1164. }
  1165. const data = [];
  1166. let pasteOrigin = false;
  1167. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1168. let bPaste = true;
  1169. const curRow = range.row + iRow;
  1170. const materialMonthData = sortData[curRow];
  1171. const hintRow = range.rowCount > 1 ? curRow : '';
  1172. let sameCol = 0;
  1173. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1174. const curCol = range.col + iCol;
  1175. const colSetting = info.sheet.zh_setting.cols[curCol];
  1176. if (!colSetting) continue;
  1177. let validText = info.sheet.getText(curRow, curCol);
  1178. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1179. const orgValue = sortData[curRow][colSetting.field];
  1180. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1181. sameCol++;
  1182. if (range.colCount === sameCol) {
  1183. bPaste = false;
  1184. }
  1185. continue;
  1186. }
  1187. if (colSetting.field === 'origin') {
  1188. pasteOrigin = true;
  1189. } else {
  1190. const num = parseFloat(validText);
  1191. if (isNaN(validText)) {
  1192. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1193. bPaste = false;
  1194. continue;
  1195. }
  1196. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1197. if (validText !== null && (num < 0 || !reg.test(num))) {
  1198. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1199. validText = ZhCalc.round(num, materialDecimal.up);
  1200. }
  1201. }
  1202. materialMonthData[colSetting.field] = validText;
  1203. sortData[curRow][colSetting.field] = validText;
  1204. }
  1205. if (bPaste) {
  1206. data.push(materialMonthData);
  1207. } else {
  1208. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1209. }
  1210. }
  1211. if (data.length === 0) {
  1212. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1213. return;
  1214. }
  1215. // console.log(data);
  1216. if (pasteOrigin) {
  1217. // 更新至服务器
  1218. postData(window.location.pathname + '/month/save', { type:'pasteOrigin', updateData: data }, function (result) {
  1219. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1220. materialBillsData = result.materialBillsData;
  1221. }, function () {
  1222. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1223. return;
  1224. });
  1225. } else {
  1226. // 更新至服务器
  1227. postData(window.location.pathname + '/month/save', { type:'paste', updateData: data }, function (result) {
  1228. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1229. materialBillsData = result.materialBillsData;
  1230. materialSpreadObj.materialSheetReset();
  1231. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1232. m_tp = result.m_tp;
  1233. if (materialTax) {
  1234. m_tax_tp = result.m_tax_tp;
  1235. }
  1236. resetTpTable();
  1237. }, function () {
  1238. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1239. return;
  1240. });
  1241. }
  1242. },
  1243. };
  1244. // 应耗来源sjs
  1245. const material_source_cols = [
  1246. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  1247. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  1248. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 70, formatter: '@'},
  1249. {title: '本期计量应耗', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, formatter: '@'},
  1250. {title: '本期应耗', colSpan: '1', rowSpan: '2', field: 'qty', hAlign: 2, width: 100, formatter: '@'},
  1251. ];
  1252. const materialSourceSpread = SpreadJsObj.createNewSpread($('#material-source-spread')[0]);
  1253. const materialSourceSpreadSetting = {
  1254. cols: material_source_cols,
  1255. emptyRows: 0,
  1256. headRows: 1,
  1257. headRowHeight: [32],
  1258. defaultRowHeight: 21,
  1259. headerFont: '12px 微软雅黑',
  1260. font: '12px 微软雅黑',
  1261. readOnly: true,
  1262. };
  1263. SpreadJsObj.initSheet(materialSourceSpread.getActiveSheet(), materialSourceSpreadSetting);
  1264. SpreadJsObj.loadSheetData(materialSourceSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  1265. // 项目节汇总sjs
  1266. const material_xmj_gather_cols = [
  1267. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'dwgc', hAlign: 0, width: 80, formatter: '@', visible: false},
  1268. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'fbgc', hAlign: 0, width: 80, formatter: '@', visible: false},
  1269. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'fxgc', hAlign: 0, width: 80, formatter: '@', visible: false},
  1270. {title: '细目', colSpan: '1', rowSpan: '2', field: 'jldy', hAlign: 0, width: 80, formatter: '@', visible: false},
  1271. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 80, formatter: '@'},
  1272. {title: '本期计量数量', colSpan: '1', rowSpan: '2', field: 'quantity', hAlign: 2, width: 100, type: 'Number'},
  1273. {title: '本期应耗数量', colSpan: '1', rowSpan: '2', field: 'qty', hAlign: 2, width: 100, type: 'Number'},
  1274. {title: '本期调差金额', colSpan: '1', rowSpan: '2', field: 'm_tp', hAlign: 2, width: 100, type: 'Number'},
  1275. ];
  1276. const materialXmjGatherSpread = SpreadJsObj.createNewSpread($('#material-xmj-gather-spread')[0]);
  1277. const materialXmjGatherSpreadSetting = {
  1278. cols: material_xmj_gather_cols,
  1279. emptyRows: 0,
  1280. headRows: 1,
  1281. headRowHeight: [32],
  1282. defaultRowHeight: 21,
  1283. headerFont: '12px 微软雅黑',
  1284. font: '12px 微软雅黑',
  1285. readOnly: true,
  1286. localCache: {
  1287. key: 'material-gather-gatherLeafXmj',
  1288. colWidth: true,
  1289. }
  1290. };
  1291. if (thousandth) sjsSettingObj.setTpThousandthFormat(materialXmjGatherSpreadSetting);
  1292. const materialXmjGatherSheet = materialXmjGatherSpread.getActiveSheet();
  1293. SpreadJsObj.initSheet(materialXmjGatherSheet, materialXmjGatherSpreadSetting);
  1294. // SpreadJsObj.loadSheetData(materialXmjGatherSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  1295. // 下部设置显示相关
  1296. $('a', '[id=material-bills-tab]').click(function() {
  1297. const relaTab = this.getAttribute('href');
  1298. const optionTab = $('#optionTab').children();
  1299. for (const ot of optionTab) {
  1300. if (ot.getAttribute('rela-tab') === relaTab) {
  1301. $(ot).show();
  1302. } else {
  1303. $(ot).hide();
  1304. }
  1305. }
  1306. setTimeout(refreshRelaSpread, 100);
  1307. });
  1308. $('[name=gather-xmj]').change(function() {
  1309. const checkOption = $('[name=gather-xmj]:checked');
  1310. if (checkOption.length === 0) {
  1311. toastr.warning('请至少选择一个汇总条件');
  1312. $(this).prop('checked', true);
  1313. return;
  1314. }
  1315. const fields = [];
  1316. for (const co of checkOption) {
  1317. fields.push(co.value);
  1318. }
  1319. for (const col of materialXmjGatherSpreadSetting.cols) {
  1320. col.visible = col.type === 'Number' || fields.indexOf(col.field) >= 0;
  1321. }
  1322. gatherFields = fields;
  1323. SpreadJsObj.refreshColumnVisible(materialXmjGatherSheet);
  1324. const data = SpreadJsObj.getSelectObject(materialSpread.getActiveSheet());
  1325. setCurBillSourceList(data ? (data.mb_id || data.id) : null, $('#myTab').find('.active').data('msid') || null, fields);
  1326. });
  1327. function refreshRelaSpread() {
  1328. materialSourceSpread.refresh();
  1329. materialXmjGatherSpread.refresh();
  1330. }
  1331. let first = true;
  1332. function setListsData(sid = null, ms_id = null) {
  1333. if (first) {
  1334. // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1335. postData(window.location.pathname + '/list/load', {sid}, async function (result) {
  1336. ledger = result.ledger;
  1337. curLedgerData = result.curLedgerData;
  1338. pos = result.pos;
  1339. curPosData = result.curPosData;
  1340. materialListData2 = result.materialListData;
  1341. gclList = result.gclList;
  1342. notJoinList = result.materialNotJoinListData;
  1343. selfList = result.materialSelfListData;
  1344. materialChecklistData = result.materialChecklistData;
  1345. if (isStageSelf) {
  1346. const newGclGatherListData = [];
  1347. for (const [index, s] of result.ledgerListData.entries()) {
  1348. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), s);
  1349. gclGatherModel.loadPosData(_.cloneDeep(pos), result.posListData[index]);
  1350. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  1351. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1352. });
  1353. newGclGatherListData.push(oneGclGatherData);
  1354. }
  1355. gclGatherListData = newGclGatherListData;
  1356. }
  1357. // 解析清单汇总数据
  1358. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  1359. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  1360. gclGatherData = gclGatherModel.gatherGclData();
  1361. gclGatherData = gclGatherData.filter(item => {
  1362. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1363. });
  1364. if (openMaterialChecklist) {
  1365. // 取交集
  1366. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  1367. gclGatherData = _.filter(gclGatherData, function (item) {
  1368. if (_.find(materialChecklistData, {
  1369. b_code: item.b_code,
  1370. name: item.name,
  1371. unit: item.unit,
  1372. unit_price: item.unit_price
  1373. })) {
  1374. return true;
  1375. } else {
  1376. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  1377. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  1378. if (jiaoji.length > 0) {
  1379. return true;
  1380. }
  1381. }
  1382. });
  1383. }
  1384. // calculateJiaCha(gclGatherData);
  1385. console.log(gclGatherData);
  1386. setCurBillSourceList(materialBillsData[0] ? materialBillsData[0].mb_id || materialBillsData[0].id : null, ms_id);
  1387. first = false;
  1388. // 判断是否需要更新contract_qty、qc_qty和qc_minus_qty
  1389. if (!materialIsNewQty && !readOnly && !editForAudit) {
  1390. let needUpdateList = [];
  1391. if (materialListData2.length > 0) {
  1392. if (isStageSelf) {
  1393. for (const msIndex in materialStageData) {
  1394. const materialStageList = _.filter(materialListData2, { ms_id: materialStageData[msIndex].id });
  1395. const gclIdList = _.uniq(_.map(materialListData2, 'gcl_id'));
  1396. let leafXmjList = [];
  1397. for (const id of gclIdList) {
  1398. const gcl = _.find(gclGatherListData[msIndex], function (item) {
  1399. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: id}) !== -1;
  1400. });
  1401. if (gcl) leafXmjList = [...leafXmjList, ...gcl.leafXmjs];
  1402. }
  1403. for (const ml of materialStageList) {
  1404. const leafXmjInfo = _.find(leafXmjList, function (item) {
  1405. return item.gcl_id === ml.gcl_id && item.id === ml.xmj_id && (item.mx_id === undefined || (item.mx_id !== undefined && item.mx_id === ml.mx_id));
  1406. });
  1407. if (leafXmjInfo) {
  1408. needUpdateList.push({ id: ml.id, contract_qty: leafXmjInfo.contract_qty, qc_qty: leafXmjInfo.qc_qty, qc_minus_qty: leafXmjInfo.qc_minus_qty });
  1409. }
  1410. }
  1411. }
  1412. } else {
  1413. // 找出所有gcl相同的,方便搜索gclGatherData值
  1414. const gclIdList = _.uniq(_.map(materialListData2, 'gcl_id'));
  1415. let leafXmjList = [];
  1416. for (const id of gclIdList) {
  1417. const gcl = _.find(gclGatherData, function (item) {
  1418. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: id}) !== -1;
  1419. });
  1420. if (gcl) leafXmjList = [...leafXmjList, ...gcl.leafXmjs];
  1421. }
  1422. for (const ml of materialListData2) {
  1423. const leafXmjInfo = _.find(leafXmjList, function (item) {
  1424. return item.gcl_id === ml.gcl_id && item.id === ml.xmj_id && (item.mx_id === undefined || (item.mx_id !== undefined && item.mx_id === ml.mx_id));
  1425. });
  1426. if (leafXmjInfo) {
  1427. needUpdateList.push({ id: ml.id, contract_qty: leafXmjInfo.contract_qty, qc_qty: leafXmjInfo.qc_qty, qc_minus_qty: leafXmjInfo.qc_minus_qty });
  1428. }
  1429. }
  1430. }
  1431. }
  1432. console.log(needUpdateList);
  1433. postData(window.location.pathname + '/save', { type: 'qty_update', needUpdateList }, function (result) {
  1434. materialListData2 = result.materialListData;
  1435. });
  1436. }
  1437. });
  1438. } else {
  1439. const i = _.findIndex(materialStageData, { sid });
  1440. gclGatherData = gclGatherListData[i];
  1441. gclGatherData = gclGatherData.filter(item => {
  1442. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1443. });
  1444. if (openMaterialChecklist) {
  1445. // 取交集
  1446. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  1447. gclGatherData = _.filter(gclGatherData, function (item) {
  1448. if (_.find(materialChecklistData, {
  1449. b_code: item.b_code,
  1450. name: item.name,
  1451. unit: item.unit,
  1452. unit_price: item.unit_price
  1453. })) {
  1454. return true;
  1455. } else {
  1456. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  1457. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  1458. if (jiaoji.length > 0) {
  1459. return true;
  1460. }
  1461. }
  1462. });
  1463. }
  1464. // calculateJiaCha(gclGatherData);
  1465. console.log(gclGatherData);
  1466. }
  1467. }
  1468. setListsData(isStageSelf ? materialStageData[0].sid : null, isStageSelf ? materialStageData[0].id : null);
  1469. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1470. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1471. materialSpreadObj.getMaterialBillsData();
  1472. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1473. materialSpreadObj.refreshActn();
  1474. materialMonthSpread.bind(spreadNS.Events.ClipboardPasted, materialMonthSpreadObj.clipboardPasted);
  1475. SpreadJsObj.addDeleteBind(materialMonthSpread, materialMonthSpreadObj.deletePress);
  1476. materialMonthSpread.bind(spreadNS.Events.EditEnded, materialMonthSpreadObj.editEnded);
  1477. // 期切换
  1478. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  1479. e.preventDefault();
  1480. showWaitingView();
  1481. setTimeout(function () {
  1482. materialSpreadObj.getMaterialBillsData();
  1483. materialSpreadObj.materialSheetReset(true);
  1484. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1485. // 消耗量表格更新
  1486. let html = '';
  1487. calcBase = _.find(calcBaseList, { ms_id: $('#myTab').find('.active').data('msid') }).calcBase;
  1488. for (let iBase = 0; iBase < calcBase.length; iBase++) {
  1489. if (!calcBase[iBase].cType || (calcBase[iBase].cType && calcBase[iBase].cType === 1 && calcBase[iBase].value)) {
  1490. html += '<tr><td>' + calcBase[iBase].name + '</td><td>' + calcBase[iBase].code + '</td><td>' + calcBase[iBase].value + '</td></tr>';
  1491. }
  1492. }
  1493. $('#calcBase').html(html);
  1494. const ms_id = parseInt($('#myTab').find('.active').data('msid'));
  1495. const msInfo = _.find(materialStageData, { id: ms_id });
  1496. setListsData(msInfo.sid, ms_id);
  1497. const data = SpreadJsObj.getSelectObject(materialSpread.getActiveSheet());
  1498. setCurBillSourceList(data ? (data.mb_id || data.id) : null, ms_id);
  1499. closeWaitingView();
  1500. }, 1000);
  1501. });
  1502. // 本条工料应耗来源数据信息
  1503. function setCurBillSourceList(mb_id, ms_id = null, fields = gatherFields) {
  1504. const showSourceList = [];
  1505. const showXmjList = [];
  1506. if (mb_id) {
  1507. const list = _.filter(materialListData2, function (item) {
  1508. return item.mb_id === mb_id && item.ms_id === ms_id && (item.is_join === 1 || item.is_join === 2);
  1509. });
  1510. console.log(list);
  1511. if (list.length > 0) {
  1512. for (const l of list) {
  1513. const gcl = _.find(gclGatherData, function (item) {
  1514. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, { gcl_id: l.gcl_id }) !== -1;
  1515. });
  1516. if (gcl) {
  1517. const index = _.findIndex(showSourceList, { code: gcl.b_code, name: gcl.name, unit: gcl.unit });
  1518. if (index === -1) {
  1519. showSourceList.push({
  1520. code: gcl.b_code,
  1521. name: gcl.name,
  1522. unit: gcl.unit,
  1523. quantity: ZhCalc.mul(calcQty(l), l.quantity),
  1524. qty: ZhCalc.mul(getQty(l), l.quantity),
  1525. });
  1526. } else {
  1527. showSourceList[index].quantity = ZhCalc.add(showSourceList[index].quantity, ZhCalc.mul(calcQty(l), l.quantity));
  1528. showSourceList[index].qty = ZhCalc.add(showSourceList[index].qty, ZhCalc.mul(getQty(l), l.quantity));
  1529. }
  1530. // const indexXmj = _.findIndex(showXmjList, { gcl_id: l.gcl_id, xmj_id: l.xmj_id, mx_id: l.mx_id });
  1531. const xmj = _.find(gcl.leafXmjs, { gcl_id: l.gcl_id, id: l.xmj_id, mx_id: l.mx_id });
  1532. if (xmj) {
  1533. const condition = {};
  1534. for (const f of fields) {
  1535. condition[f] = xmj[f];
  1536. }
  1537. let glx = _.find(showXmjList, condition);
  1538. if (!glx) {
  1539. const newGcl = _.cloneDeep(xmj);
  1540. newGcl.quantity = ZhCalc.mul(calcQty(l), l.quantity);
  1541. newGcl.qty = ZhCalc.mul(getQty(l), l.quantity);
  1542. showXmjList.push(newGcl);
  1543. } else {
  1544. glx.quantity = ZhCalc.add(glx.quantity, ZhCalc.mul(calcQty(l), l.quantity));
  1545. glx.qty = ZhCalc.add(glx.qty, ZhCalc.mul(getQty(l), l.quantity));
  1546. }
  1547. }
  1548. }
  1549. }
  1550. }
  1551. const data = SpreadJsObj.getSelectObject(materialSpread.getActiveSheet());
  1552. for (const xmj of showXmjList) {
  1553. const m_spread = data ? (data.m_spread || data.spread) : 0;
  1554. xmj.m_tp = ZhCalc.mul(m_spread, xmj.qty);
  1555. }
  1556. }
  1557. // 按清单编号排序
  1558. SpreadJsObj.loadSheetData(materialSourceSpread.getActiveSheet(), SpreadJsObj.DataType.Data, showSourceList.sort(sortByCode));
  1559. console.log(showXmjList);
  1560. SpreadJsObj.loadSheetData(materialXmjGatherSheet, SpreadJsObj.DataType.Data, showXmjList);
  1561. }
  1562. function getQty(info) {
  1563. if (info && info.qty !== null) {
  1564. return info.qty;
  1565. }
  1566. return calcQty(info);
  1567. }
  1568. function calcQty(info) {
  1569. let qty = '';
  1570. switch (qtySource) {
  1571. case qtySourceValueConst.gather_qty: qty = info.gather_qty; break;
  1572. case qtySourceValueConst.contract_qty: qty = info.contract_qty; break;
  1573. case qtySourceValueConst.gather_minus_qty: qty = ZhCalc.add(info.gather_qty, info.qc_minus_qty); break;
  1574. default: throw '未配置计量来源出错';
  1575. }
  1576. if (qtySource !== qtySourceValueConst.contract_qty && info.is_join === 2) {
  1577. qty = info.contract_qty;
  1578. }
  1579. return qty;
  1580. }
  1581. if (!readOnly || editForAudit) {
  1582. $('#expr_select button').on('click', function () {
  1583. const code = $(this).text();
  1584. // $('#expr').val($('#expr').val() + code);
  1585. $('#expr').insertAtCaret(code);
  1586. });
  1587. const ExprObj = {
  1588. _checkExprValid(expr, invalidParam) {
  1589. if (!expr) return [true, null];
  1590. const param = [];
  1591. let num = '', base = '';
  1592. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1593. if (/^[\d\.%]+/.test(expr[i])) {
  1594. if (base !== '') {
  1595. param.push({type: 'base', value: base});
  1596. base = '';
  1597. }
  1598. num = num + expr[i];
  1599. } else if (/^[a-z]/.test(expr[i])) {
  1600. if (num !== '') {
  1601. param.push({type: 'num', value: num});
  1602. num = '';
  1603. }
  1604. base = base + expr[i];
  1605. } else if (expr[i] === '(') {
  1606. if (num !== '') {
  1607. param.push({type: 'num', value: num});
  1608. num = '';
  1609. }
  1610. if (base !== '') {
  1611. param.push({type: 'base', value: base});
  1612. base = '';
  1613. }
  1614. param.push({type: 'left', value: '('});
  1615. } else if (expr[i] === ')') {
  1616. if (num !== '') {
  1617. param.push({type: 'num', value: num});
  1618. num = '';
  1619. }
  1620. if (base !== '') {
  1621. param.push({type: 'base', value: base});
  1622. base = '';
  1623. }
  1624. param.push({type: 'right', value: ')'});
  1625. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1626. if (num !== '') {
  1627. param.push({type: 'num', value: num});
  1628. num = '';
  1629. }
  1630. if (base !== '') {
  1631. param.push({type: 'base', value: base});
  1632. base = '';
  1633. }
  1634. param.push({type: 'calc', value: expr[i]});
  1635. } else {
  1636. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1637. }
  1638. }
  1639. if (num !== '') {
  1640. param.push({type: 'num', value: num});
  1641. num = '';
  1642. }
  1643. if (base !== '') {
  1644. param.push({type: 'base', value: base});
  1645. base = '';
  1646. }
  1647. if (param.length === 0) return true;
  1648. if (param.length > 1) {
  1649. if (param[0].value === '-' && param[1].type === 'num') {
  1650. param[1].value = '-' + param[1].value;
  1651. param.shift();
  1652. }
  1653. }
  1654. const iLen = param.length;
  1655. let iLeftCount = 0, iRightCount = 0;
  1656. for (const [i, p] of param.entries()) {
  1657. if (p.type === 'calc') {
  1658. if (i === 0 || i === iLen - 1)
  1659. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字或计算基数'];
  1660. }
  1661. if (p.type === 'num') {
  1662. num = p.value.replace('%', '');
  1663. if (p.value.length - num.length > 1)
  1664. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1665. num = _.toNumber(num);
  1666. if (num === undefined || num === null || _.isNaN(num))
  1667. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1668. if (i > 0) {
  1669. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1670. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1671. } else if (param[i - 1].value === '/' && num === 0) {
  1672. return [false, '输入的表达式非法:请勿除0'];
  1673. }
  1674. }
  1675. }
  1676. if (p.type === 'base') {
  1677. const baseParam = _.find(calcBase, {code: p.value});
  1678. if (!baseParam)
  1679. return [false, '输入的表达式非法:不存在计算基数' + p.value];
  1680. if (invalidParam && invalidParam.indexOf(p.value) >= 0)
  1681. return [false, '不可使用计算基数' + p.value];
  1682. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1683. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1684. }
  1685. if (p.type === 'left') {
  1686. iLeftCount += 1;
  1687. if (i !== 0 && param[i-1].type !== 'calc')
  1688. return [false, '输入的表达式非法:(前应有运算符'];
  1689. }
  1690. if (p.type === 'right') {
  1691. iRightCount += 1;
  1692. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1693. return [false, '输入的表达式非法:)后应有运算符'];
  1694. if (iRightCount > iLeftCount)
  1695. return [false, '输入的表达式非法:")"前无对应的"("'];
  1696. }
  1697. }
  1698. if (iLeftCount > iRightCount)
  1699. return [false, '输入的表达式非法:"("后无对应的")"'];
  1700. return [true, ''];
  1701. },
  1702. _checkExpr: function (text) {
  1703. if (text) {
  1704. const num = _.toNumber(text);
  1705. if (num) {
  1706. console.log(num);
  1707. } else {
  1708. const expr = text.replace('=', '').toLowerCase();
  1709. const [valid, msg] = this._checkExprValid(expr);
  1710. if (!valid) return [valid, msg];
  1711. }
  1712. }
  1713. return [true, ''];
  1714. },
  1715. };
  1716. $('#expr_btn').click(function () {
  1717. const expr = $('#expr').val();
  1718. // 判断表达式格式
  1719. const [valid, msg] = ExprObj._checkExpr(expr);
  1720. if (!valid) {
  1721. toastr.error(msg);
  1722. return false;
  1723. }
  1724. postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1725. m_tp = result.m_tp;
  1726. if (materialTax) {
  1727. m_tax_tp = result.m_tax_tp;
  1728. }
  1729. const sheet = materialSpread.getActiveSheet();
  1730. const select = SpreadJsObj.getSelectObject(sheet);
  1731. const index = _.findIndex(materialBillsData, { id: select.id });
  1732. let newIndex = index;
  1733. if (isStageSelf) {
  1734. materialSpreadObj.updateMaterialData(result);
  1735. result.info = materialSpreadObj.updateOneMaterialBill(result.info);
  1736. }
  1737. if($('#bills0_list').is(':checked')) {
  1738. const newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1739. return item.quantity !== null && item.quantity !== 0;
  1740. });
  1741. newIndex = _.findIndex(newMaterialBillsData, { id: select.id });
  1742. // newIndex = newMaterialBillsData.indexOf(select);
  1743. newMaterialBillsData.splice(newIndex, 1, result.info);
  1744. sheet.zh_data[newIndex] = result.info;
  1745. }
  1746. materialBillsData.splice(index, 1, result.info);
  1747. sheet.zh_data.splice(newIndex, 1, result.info);
  1748. SpreadJsObj.reLoadRowData(sheet, newIndex);
  1749. resetTpTable();
  1750. $('#bcyy').modal('hide');
  1751. });
  1752. });
  1753. }
  1754. if (!readOnly && !editForAudit) {
  1755. $('#add').click(materialSpreadObj.add);
  1756. $('#del').click(materialSpreadObj.del);
  1757. $('#up-move').click(materialSpreadObj.upMove);
  1758. $('#down-move').click(materialSpreadObj.downMove);
  1759. // 右键菜单
  1760. $.contextMenu({
  1761. selector: '#material-spread',
  1762. build: function ($trigger, e) {
  1763. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1764. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1765. },
  1766. items: {
  1767. 'create': {
  1768. name: '新增材料',
  1769. icon: 'fa-sign-in',
  1770. callback: function (key, opt) {
  1771. materialSpreadObj.add(materialSpread.getActiveSheet());
  1772. },
  1773. },
  1774. 'delete': {
  1775. name: '删除材料',
  1776. icon: 'fa-remove',
  1777. callback: function (key, opt) {
  1778. materialSpreadObj.del(materialSpread.getActiveSheet());
  1779. },
  1780. disabled: function (key, opt) {
  1781. const sheet = materialSpread.getActiveSheet();
  1782. const select = SpreadJsObj.getSelectObject(sheet);
  1783. const sel = sheet.getSelections()[0];
  1784. materialSpreadObj.refreshActn(sel.rowCount);
  1785. if (!readOnly && select && materialBase.isUsed(select) && sel.rowCount === 1) {
  1786. return false;
  1787. } else {
  1788. return true;
  1789. }
  1790. }
  1791. },
  1792. }
  1793. });
  1794. $('.changeRate').click(function () {
  1795. $('#rateInput').val(parseInt($(this).data('value')));
  1796. $('#rateInput').siblings('.dropdown-menu').hide();
  1797. });
  1798. $('#rateInput').click(function () {
  1799. $(this).siblings('.dropdown-menu').show();
  1800. })
  1801. // 回车提交
  1802. $('#rateInput').on('keypress', function () {
  1803. if(window.event.keyCode === 13) {
  1804. $(this).blur();
  1805. }
  1806. });
  1807. $('#rateInput').blur(function () {
  1808. const _self = $(this);
  1809. setTimeout(function () {
  1810. let rate = parseFloat(_self.val());
  1811. if (_.isNaN(rate)) {
  1812. toastr.error('请输入0-100之前的整数值');
  1813. $('#rateInput').val(materialRate);
  1814. return;
  1815. }
  1816. rate = _.round(rate);
  1817. if(rate < 0 || rate > 100) {
  1818. toastr.error('请输入0-100之前的整数值');
  1819. $('#rateInput').val(materialRate);
  1820. return;
  1821. }
  1822. $('#rateInput').siblings('.dropdown-menu').hide();
  1823. console.log(rate, materialRate);
  1824. if (rate !== materialRate) {
  1825. postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1826. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1827. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1828. const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1829. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1830. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1831. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1832. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1833. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1834. materialRate = rate;
  1835. $('#rateInput').val(rate);
  1836. });
  1837. } else {
  1838. $('#rateInput').val(rate);
  1839. }
  1840. }, 500);
  1841. });
  1842. // $('#changeRate').change(function () {
  1843. // const rate = parseInt($(this).val());
  1844. // postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1845. // const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1846. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1847. // const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1848. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1849. // $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1850. // $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1851. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1852. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1853. // });
  1854. // });
  1855. // 创建月信息价
  1856. $('#make-month').click(function() {
  1857. const yearmonth = $('#months').val();
  1858. const yearmonths = [];
  1859. if (yearmonth === '') {
  1860. toastr.error('请选择正确的信息价月份');
  1861. return false;
  1862. } else if (_.indexOf(yearmonth, '~') !== -1) {
  1863. const yearmonthArr = yearmonth.split('~');
  1864. // 对比两个年月,找出中间值年月push
  1865. const startYearMonth = yearmonthArr[0].trim();
  1866. const endYearMonth = yearmonthArr[1].trim();
  1867. const startYear = parseInt(startYearMonth.split('-')[0]);
  1868. const startMonth = parseInt(startYearMonth.split('-')[1]);
  1869. const endYear = parseInt(endYearMonth.split('-')[0]);
  1870. const endMonth = parseInt(endYearMonth.split('-')[1]);
  1871. if (startYear > endYear || (startYear === endYear && startMonth > endMonth)) {
  1872. toastr.error('请选择正确的信息价月份');
  1873. return false;
  1874. }
  1875. for (let i = startYear; i <= endYear; i++) {
  1876. for (let j = (i === startYear ? startMonth : 1); j <= (i === endYear ? endMonth : 12); j++) {
  1877. const monthStr = j < 10 ? `0${j}` : j;
  1878. const yearmonthStr = `${i}-${monthStr}`;
  1879. if (_.indexOf(yearmonths, yearmonthStr) === -1 && months.indexOf(yearmonthStr) === -1) {
  1880. yearmonths.push(yearmonthStr);
  1881. }
  1882. }
  1883. }
  1884. if (yearmonths.length === 0) {
  1885. toastr.error('调差期已创建过所选月区间所有的信息价');
  1886. return false;
  1887. }
  1888. } else {
  1889. const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
  1890. if (result === null) {
  1891. toastr.error('请选择正确的信息价月份');
  1892. return false;
  1893. }
  1894. if (months.indexOf(yearmonth) !== -1) {
  1895. toastr.error('调差期已创建过本月的信息价');
  1896. return false;
  1897. }
  1898. yearmonths.push(yearmonth);
  1899. }
  1900. console.log(yearmonths);
  1901. if (months.length + yearmonths.length > 24) {
  1902. toastr.error('月信息价不能超过24个月');
  1903. return false;
  1904. }
  1905. postData(window.location.pathname + '/month/save', { type: 'adds', updateData: { yearmonths } }, function (data) {
  1906. months.push(...yearmonths);
  1907. months.sort();
  1908. monthsList = data.monthsList;
  1909. monthFunGather.monthsListSet();
  1910. // 工料表单价显示也要更新
  1911. materialBillsData = data.materialBillsData;
  1912. materialSpreadObj.materialSheetReset();
  1913. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1914. m_tp = data.m_tp;
  1915. if (materialTax) {
  1916. m_tax_tp = data.m_tax_tp;
  1917. }
  1918. resetTpTable();
  1919. $('#add-month').modal('hide');
  1920. });
  1921. });
  1922. // 删除月信息价
  1923. $('#del-month').click(function () {
  1924. const del_month_array = [];
  1925. $("input[name='del_month']:checked").each(function () {
  1926. del_month_array.push($(this).val());
  1927. });
  1928. if (del_month_array.length === 0) {
  1929. toastr.error('请选择要移除的月信息价');
  1930. return false;
  1931. }
  1932. postData(window.location.pathname + '/month/save', { type: 'del', updateData: { del_yearmonth: del_month_array } }, function (data) {
  1933. for (const dm of del_month_array) {
  1934. // _.remove(materialMonthSpreadSetting.cols, function (n) {
  1935. // return n.field === dm;
  1936. // });
  1937. _.remove(months, function (n) {
  1938. return n === dm;
  1939. });
  1940. }
  1941. monthsList = data.monthsList;
  1942. monthFunGather.monthsListSet();
  1943. // 工料表单价显示也要更新
  1944. materialBillsData = data.materialBillsData;
  1945. materialSpreadObj.materialSheetReset();
  1946. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1947. m_tp = data.m_tp;
  1948. if (materialTax) {
  1949. m_tax_tp = data.m_tax_tp;
  1950. }
  1951. resetTpTable();
  1952. $('#remove-month').modal('hide');
  1953. });
  1954. });
  1955. // 导入功能
  1956. let importFile = null;
  1957. $('#upload-xls-file').change(function () {
  1958. const file = this.files[0];
  1959. importFile = file;
  1960. });
  1961. $('#import-bills-btn').click(function() {
  1962. if (!importFile) {
  1963. toastr.error('请选择excel文件再确定');
  1964. return;
  1965. }
  1966. const ext = importFile.name.toLowerCase().split('.').splice(-1)[0];
  1967. const imgStr = /(xls|xlsx|XLS|XLSX)$/;
  1968. if (!imgStr.test(ext)) {
  1969. toastr.error('请导入正确格式的excel文件。');
  1970. return
  1971. }
  1972. const fileReader = new FileReader();
  1973. fileReader.onload = async function(ev) {
  1974. try{
  1975. const data = ev.target.result;
  1976. let tree = [];
  1977. const includeSpec = $('#xls-spec').is(':checked');
  1978. if (/(xls|xlsx|XLS|XLSX)$/.test(ext)) {
  1979. const workbook = XLSX.read(data, {type: 'binary'}); // 以二进制流方式读取得到整份excel表格对象
  1980. const jsonData = transExcel(XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { defval: null }));
  1981. console.log(jsonData);
  1982. if (!(jsonData[0] && jsonData[0].code !== undefined && jsonData[0].code !== null && jsonData[0].unit !== undefined && jsonData[0].name !== undefined &&
  1983. jsonData[0].spec !== undefined && jsonData[0].msg_tp !== undefined && jsonData[0].msg_times !== undefined)) {
  1984. throw 'excel必须按指定格式内容上传';
  1985. }
  1986. // 去重
  1987. tree = _.unionWith(jsonData, function (item1, item2) {
  1988. return item1.code === item2.code && item1.name === item2.name && item1.unit === item2.unit && (!includeSpec || (includeSpec && item1.spec === item2.spec));
  1989. });
  1990. }
  1991. if (tree.length === 0) {
  1992. throw '该excel不存在导入的数据';
  1993. }
  1994. // 判断msg_tp格式,不符合则无法导入,还有excel日期转换问题
  1995. for (const t of tree) {
  1996. t.code = t.code.toString();
  1997. if (t.msg_tp) {
  1998. if (_.isNumber(t.msg_tp)) {
  1999. const num = parseFloat(t.msg_tp);
  2000. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  2001. if (num < 0 || !reg.test(num)) {
  2002. t.msg_tp = ZhCalc.round(num, materialDecimal.up);
  2003. }
  2004. } else {
  2005. throw '信息价数据存在非数字字符,无法导入';
  2006. }
  2007. }
  2008. if (_.isNumber(t.msg_times)) {
  2009. t.msg_times = formatDate(t.msg_times, '/');
  2010. }
  2011. t.spec = t.spec === null ? '' : t.spec;
  2012. }
  2013. console.log(tree);
  2014. postData(window.location.pathname + '/save', { type:'export', postData: tree, includeSpec, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  2015. m_tp = result.m_tp;
  2016. if (materialTax) {
  2017. m_tax_tp = result.m_tax_tp;
  2018. }
  2019. materialBillsData = result.billsData;
  2020. if (isStageSelf) {
  2021. materialStageData = result.stageData;
  2022. materialStageBillsData = result.stageBillsData;
  2023. }
  2024. materialSpreadObj.getMaterialBillsData();
  2025. materialSpreadObj.materialSheetReset(true);
  2026. if (months.length > 0) {
  2027. monthsList = result.monthsList;
  2028. monthFunGather.monthsListSet();
  2029. }
  2030. resetTpTable();
  2031. if (result.addNum || result.updateNum) {
  2032. let msg = [];
  2033. if (result.addNum !== undefined && result.addNum !== 0) {
  2034. msg.push('成功导入工料 ' + result.addNum + ' 条');
  2035. }
  2036. if (result.updateNum !== undefined && result.updateNum !== 0) {
  2037. msg.push('成功更新工料 ' + result.updateNum + ' 条');
  2038. }
  2039. toastr.success(msg.length > 1 ? msg.join(',并') : msg[0]);
  2040. } else {
  2041. toastr.warning('不存在可导入的信息价数据');
  2042. }
  2043. $('#import-info').modal('hide');
  2044. });
  2045. } catch (error) {
  2046. console.log(error);
  2047. toastr.error(error);
  2048. return
  2049. }
  2050. };
  2051. // 以二进制方式打开文件
  2052. fileReader.readAsBinaryString(importFile);
  2053. $('#upload-xls-file').val('');
  2054. importFile = null;
  2055. });
  2056. } else {
  2057. // SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
  2058. }
  2059. // 筛选调差工料本期应耗数量为0
  2060. $('#bills0_list').click(function () {
  2061. const isCheck = $(this).is(':checked');
  2062. let newMaterialBillsData = materialBillsData;
  2063. if (isCheck) {
  2064. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  2065. return item.quantity !== null && item.quantity !== 0;
  2066. });
  2067. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  2068. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  2069. }
  2070. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  2071. monthFunGather.monthsListSet(newMaterialBillsData, false);
  2072. materialSpreadObj.refreshActn();
  2073. });
  2074. let gljLib;
  2075. const gljLibCellDoubleClick = function (e, info) {
  2076. if (readOnly || editForAudit) return;
  2077. const gljSheet = info.sheet;
  2078. if (!gljSheet.zh_setting || !gljSheet.zh_tree) { return; }
  2079. const gljTree = gljSheet.zh_tree;
  2080. const gljNode = gljTree.nodes[info.row];
  2081. const sheet = materialSpread.getActiveSheet();
  2082. const select = SpreadJsObj.getSelectObject(sheet);
  2083. if (!gljNode) return;
  2084. if (gljNode && gljNode.is_leaf === 0) {
  2085. toastr.warning('非最底层项目下,不应添加');
  2086. return;
  2087. }
  2088. postData(window.location.pathname + '/save', { type:'add-glj', postData: gljNode, order: select ? select.order : null }, function (result) {
  2089. if (result) {
  2090. // 比order大的+1
  2091. const maxData = select ? _.filter(materialBillsData, (item) => { return item.order > select.order }) : [];
  2092. _.forEach(maxData, function (item) {
  2093. const cl = _.find(materialBillsData, { id: item.id });
  2094. cl.order = item.order + 1;
  2095. });
  2096. materialBillsData.push(result.info);
  2097. materialBillsData.sort(function (a, b) {
  2098. return a.order - b.order
  2099. });
  2100. console.log(materialBillsData);
  2101. if (isStageSelf) {
  2102. materialSpreadObj.updateMaterialData(result);
  2103. materialSpreadObj.getMaterialBillsData();
  2104. }
  2105. // sheet.addRows(materialBillsData.length - 1, 1);
  2106. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  2107. let newMaterialBillsData = materialBillsData;
  2108. if($('#bills0_list').is(':checked')) {
  2109. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  2110. return item.quantity !== null && item.quantity !== 0;
  2111. });
  2112. }
  2113. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  2114. // materialSpreadObj.materialSheetReset();
  2115. sheet.setSelection(sheet.zh_data.indexOf(select) + 1, 0, 1, 1);
  2116. materialSpreadObj.refreshActn();
  2117. // 月信息价需要同时添加空白的list
  2118. if (months.length > 0) {
  2119. const one_month ={ mb_id: result.info.id, code: result.info.code, name: result.info.name, origin: result.info.origin, unit: result.info.unit, order: result.info.order };
  2120. for (const m of months) {
  2121. one_month[m] = null;
  2122. }
  2123. _.forEach(maxData, function (item) {
  2124. const cl = _.find(monthsList, { mb_id: item.id });
  2125. cl.order = item.order + 1;
  2126. });
  2127. monthsList.push(one_month);
  2128. monthsList.sort(function (a, b) {
  2129. return a.order - b.order
  2130. });
  2131. console.log(monthsList);
  2132. // const newMonthsList = _.filter(monthsList, function (item) {
  2133. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  2134. // });
  2135. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  2136. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  2137. monthFunGather.monthsListSet();
  2138. // materialMonthSpreadObj.monthsListSet();
  2139. }
  2140. }
  2141. });
  2142. };
  2143. const gljLibSetting = {
  2144. selector: '#material-tab',
  2145. stdType: 'glj',
  2146. libs: gljLists,
  2147. treeSetting: {
  2148. id: 'glj_id',
  2149. pid: 'glj_pid',
  2150. order: 'order',
  2151. level: 'level',
  2152. rootId: -1,
  2153. keys: ['id', 'list_id', 'glj_id'],
  2154. },
  2155. spreadSetting: {
  2156. cols: [
  2157. {title: '编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2158. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2159. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2160. {title: '参考上涨幅度', field: 'rise_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2161. {title: '参考下跌幅度', field: 'fall_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2162. ],
  2163. treeCol: 0,
  2164. emptyRows: 0,
  2165. headRows: 1,
  2166. headRowHeight: [32],
  2167. defaultRowHeight: 21,
  2168. headerFont: '12px 微软雅黑',
  2169. font: '12px 微软雅黑',
  2170. headColWidth: [30],
  2171. selectedBackColor: '#fffacd',
  2172. },
  2173. spreadClassCss: 'sjs-material',
  2174. cellDoubleClick: gljLibCellDoubleClick,
  2175. page: 'material',
  2176. tid: window.location.pathname.split('/')[2],
  2177. };
  2178. $.subMenu({
  2179. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2180. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2181. key: 'menu.1.0.0',
  2182. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2183. callback: function (info) {
  2184. if (info.mini) {
  2185. $('.panel-title').addClass('fluid');
  2186. $('#sub-menu').removeClass('panel-sidebar');
  2187. } else {
  2188. $('.panel-title').removeClass('fluid');
  2189. $('#sub-menu').addClass('panel-sidebar');
  2190. }
  2191. autoFlashHeight();
  2192. materialSpread.refresh();
  2193. }
  2194. });
  2195. $.divResizer({
  2196. select: '#right-spr',
  2197. callback: function () {
  2198. materialSpread.refresh();
  2199. materialMonthSpread.refresh();
  2200. if (gljLib) gljLib.spread.refresh();
  2201. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  2202. setLocalCache('material_month_' + materialID, width);
  2203. }
  2204. });
  2205. $.divResizer({
  2206. select: '#main-resize',
  2207. callback: function () {
  2208. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2209. $(".sp-wrap").height(bcontent-30);
  2210. const height = $('.bcontent-wrap').height();
  2211. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  2212. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2213. updateSjsHeight();
  2214. materialSpread.refresh();
  2215. materialMonthSpread.refresh();
  2216. if (gljLib) gljLib.spread.refresh();
  2217. setLocalCache('material_bills_' + materialID, height);
  2218. }
  2219. });
  2220. // 展开收起月信息价并浏览器记住本期展开收起
  2221. $('a', '.right-nav').bind('click', function () {
  2222. //const main = $('#main-view'), tool = $('#tools-view');
  2223. const tab = $(this), tabPanel = $(tab.attr('content'));
  2224. if (!tab.hasClass('active')) {
  2225. $('a', '.side-menu').removeClass('active');
  2226. $('#right-view .tab-content .tab-pane').removeClass('active');
  2227. tab.addClass('active');
  2228. tabPanel.addClass('active');
  2229. showSideTools(tab.hasClass('active'));
  2230. if (tab.attr('content') === '#month-tab') {
  2231. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  2232. setLocalCache('material_month_' + materialID, width);
  2233. materialMonthSpread.refresh();
  2234. } else if (tab.attr('content') === '#material-tab') {
  2235. if (!gljLib) {
  2236. gljLib = $.gljLib(gljLibSetting);
  2237. }
  2238. updateSjsHeight();
  2239. gljLib.spread.refresh();
  2240. }
  2241. } else {
  2242. removeLocalCache('material_month_' + materialID);
  2243. tab.removeClass('active');
  2244. tabPanel.removeClass('active');
  2245. showSideTools(tab.hasClass('active'));
  2246. }
  2247. materialSpread.refresh();
  2248. // materialMonthSpread.refresh();
  2249. });
  2250. // 根据浏览器记录展开收起
  2251. if (getLocalCache('material_month_' + materialID) && !isStageSelf) {
  2252. const tab = $('.right-nav a[content="#month-tab"]'), tabPanel = $(tab.attr('content'));
  2253. $('a', '.side-menu').removeClass('active');
  2254. $('#right-view .tab-content .tab-pane').removeClass('active');
  2255. tab.addClass('active');
  2256. tabPanel.addClass('active');
  2257. $('#right-view').width(getLocalCache('material_month_' + materialID) + '%');
  2258. showSideTools(tab.hasClass('active'));
  2259. materialSpread.refresh();
  2260. materialMonthSpread.refresh();
  2261. }
  2262. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  2263. if (getLocalCache('material_bills_' + materialID)) {
  2264. $('.bcontent-wrap').height(getLocalCache('material_bills_' + materialID));
  2265. const cHeader = getObjHeight($(".c-header"));
  2266. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2267. $(".sp-wrap").height(bcontent-30);
  2268. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  2269. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2270. updateSjsHeight();
  2271. materialSpread.refresh();
  2272. materialMonthSpread.refresh();
  2273. if (gljLib) gljLib.spread.refresh();
  2274. } else {
  2275. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2276. updateSjsHeight();
  2277. materialSpread.refresh();
  2278. materialMonthSpread.refresh();
  2279. if (gljLib) gljLib.spread.refresh();
  2280. }
  2281. function updateSjsHeight() {
  2282. $('.sjs-height-material-month').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar-1')));
  2283. $('.material-table-height').height($('.bcontent-wrap').height() - getObjHeight($('.bc-bar')));
  2284. $('.sjs-material').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar')));
  2285. }
  2286. function getObjHeight(select) {
  2287. return select.length > 0 ? select.outerHeight() : 0;
  2288. }
  2289. function formatDate(numb, format) {
  2290. const old = numb - 1;
  2291. const t = Math.round((old - Math.floor(old)) * 24 * 60 * 60);
  2292. const time = new Date(1900, 0, old, 0, 0, t);
  2293. const year = time.getFullYear();
  2294. const month = time.getMonth() + 1;
  2295. const date = time.getDate();
  2296. return year + format + (month < 10 ? '0' + month : month) + format + (date < 10 ? '0' + date : date);
  2297. }
  2298. function transExcel(results) {
  2299. const mapInfo = {
  2300. '编号': 'code',
  2301. '名称': 'name',
  2302. '单位': 'unit',
  2303. '规格': 'spec',
  2304. '信息价': 'msg_tp',
  2305. '时间': 'msg_times',
  2306. };
  2307. return results.map(zhObj => {
  2308. const enObj = {}
  2309. const zhKeys = Object.keys(zhObj);
  2310. zhKeys.forEach(zhKey => {
  2311. const enKey = mapInfo[zhKey];
  2312. enObj[enKey] = zhObj[zhKey] && _.isString(zhObj[zhKey]) ? _.trim(zhObj[zhKey]) : zhObj[zhKey];
  2313. });
  2314. return enObj
  2315. })
  2316. }
  2317. });