material_list.js 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236
  1. 'use strict';
  2. /**
  3. * 材料调差 - 调差清单
  4. *
  5. * @author EllisRan
  6. * @date 2019/10/25
  7. * @version
  8. */
  9. function getStageId() {
  10. return window.location.pathname.split('/')[5];
  11. }
  12. function findNotJoinLeafXmj(x, type = '') {
  13. if (type === 'index') {
  14. return notJoinList.findIndex(function (item) {
  15. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  16. });
  17. }
  18. return notJoinList.find(function (item) {
  19. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  20. });
  21. }
  22. function findNotChangeLeafXmj(x, type = '') {
  23. if (type === 'index') {
  24. return notChangeList.findIndex(function (item) {
  25. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  26. });
  27. }
  28. return notChangeList.find(function (item) {
  29. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  30. });
  31. }
  32. function findSelfLeafXmj(x, type = '') {
  33. if (type === 'index') {
  34. return selfList.findIndex(function (item) {
  35. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  36. });
  37. }
  38. return selfList.find(function (item) {
  39. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  40. });
  41. }
  42. function getMpSpreadByMBData(id) {
  43. const info = materialBillsData.find(function (item) {
  44. return item.id === parseInt(id);
  45. });
  46. return info ? info.m_spread : 0;
  47. }
  48. function getMaterialListByLeafXmj(gcl_id, xmj_id, mx_id = '') {
  49. const list = [];
  50. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  51. for (const ml of materialListData) {
  52. if (gcl_id === ml.gcl_id && xmj_id === ml.xmj_id && (mx_id === '' || mx_id === ml.mx_id) && (ms_id === null || ms_id === ml.ms_id)) {
  53. list.push(ml);
  54. }
  55. }
  56. return list;
  57. }
  58. function calcOneBQJC(xmj) {
  59. let jiacha = 0;
  60. const notx = findNotJoinLeafXmj(xmj);
  61. if (notx === undefined) {
  62. const list = xmj.mx_id !== undefined ? getMaterialListByLeafXmj(xmj.gcl_id, xmj.id, xmj.mx_id) : getMaterialListByLeafXmj(xmj.gcl_id, xmj.id);
  63. const notx2 = findNotChangeLeafXmj(xmj);
  64. if (notx2 !== undefined) {
  65. for (const l of list) {
  66. jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.contract_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
  67. }
  68. } else {
  69. for (const l of list) {
  70. jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
  71. }
  72. }
  73. }
  74. return ZhCalc.round(jiacha, materialDecimal.tp);
  75. }
  76. function getPasteHint (str, row = '') {
  77. let returnObj = str;
  78. if (row) {
  79. returnObj.msg = '清单第' + (row+1) + '行' + (str.msg ? str.msg : str);
  80. }
  81. return returnObj;
  82. }
  83. // 重新计算列表的价差
  84. function calculateJiaCha(data, index) {
  85. // 计算单条的
  86. if (index) {
  87. const gcld = data[index]
  88. let total_jiacha = 0;
  89. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  90. const jiacha = calcOneBQJC(xmj);
  91. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  92. total_jiacha += jiacha;
  93. }
  94. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  95. } else {
  96. for(const gcld of data) {
  97. let total_jiacha = 0;
  98. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  99. const jiacha = calcOneBQJC(xmj);
  100. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  101. total_jiacha += jiacha;
  102. }
  103. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  104. }
  105. }
  106. }
  107. const is_numeric = (value) => {
  108. if (typeof(value) === 'object') {
  109. return false;
  110. } else {
  111. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  112. }
  113. };
  114. $(document).ready(() => {
  115. function TipCellType()
  116. {
  117. }
  118. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
  119. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  120. return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
  121. };
  122. TipCellType.prototype.processMouseEnter = function (hitInfo){
  123. if (!this._toolTipElement) {
  124. var div = document.createElement("div");
  125. $(div).css("position", "absolute")
  126. .css("border", "1px #C0C0C0 solid")
  127. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  128. .css("font", "9pt Arial")
  129. .css("background", "#fff")
  130. // .css("color", "#fff")
  131. .css("z-index", "1000")
  132. .css("padding", 5);
  133. this._toolTipElement = div;
  134. }
  135. $(this._toolTipElement).text("单位数量:每一单位清单下所需工料消耗量。")
  136. .css("top", hitInfo.y + 15)
  137. .css("left", hitInfo.x - 15);
  138. $(this._toolTipElement).hide();
  139. // document.body.insertBefore(this._toolTipElement, null);
  140. if (hitInfo.sheet.yn === 4) { // 用于区分上下两个工料关联表
  141. $('#material-self-spread-div').append(this._toolTipElement, null);
  142. } else {
  143. $('#material-spread-div').append(this._toolTipElement, null);
  144. }
  145. $(this._toolTipElement).show("fast");
  146. };
  147. TipCellType.prototype.processMouseLeave = function (hitInfo) {
  148. if (this._toolTipElement) {
  149. // document.body.removeChild(this._toolTipElement);
  150. // $('#material-spread-div').removeChild(this._toolTipElement);
  151. this._toolTipElement.remove();
  152. this._toolTipElement = null;
  153. }
  154. };
  155. autoFlashHeight();
  156. // 清单table
  157. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  158. const ledgerSpreadSetting = {
  159. cols: [
  160. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 90, formatter: '@'},
  161. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  162. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
  163. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
  164. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'},
  165. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'},
  166. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'},
  167. {title: '本期完成金额', colSpan: '1', rowSpan: '2', field: 'gather_tp', hAlign: 2, width: 110, type: 'Number'},
  168. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 110, type: 'Number'}
  169. ],
  170. emptyRows: 0,
  171. headRows: 2,
  172. headRowHeight: [25, 25],
  173. defaultRowHeight: 21,
  174. headerFont: '12px 微软雅黑',
  175. font: '12px 微软雅黑',
  176. readOnly: true,
  177. };
  178. // let gclGatherData = gclGatherModel.gatherGclData()
  179. // 获取项目节数据
  180. function loadLeafXmjData(iGclRow) {
  181. const gcl = gclGatherData[iGclRow];
  182. if (gcl) {
  183. for (const [index, xmj] of gcl.leafXmjs.entries()) {
  184. const jiacha = calcOneBQJC(xmj);
  185. gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, materialDecimal.tp) : null;
  186. }
  187. const leafXmjs = gcl.leafXmjs.filter(item => {
  188. return item.qc_qty || item.contract_qty
  189. });
  190. console.log(leafXmjs);
  191. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, leafXmjs);
  192. // 对清单调差工料table的单位数量进行改变
  193. // materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  194. // SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  195. } else {
  196. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  197. }
  198. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  199. }
  200. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  201. // 项目明细table
  202. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  203. const leafXmjSpreadSetting = {
  204. cols: [
  205. {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  206. {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  207. {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  208. {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number'},
  209. {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  210. {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  211. {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
  212. {title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  213. {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 80, type: 'Number'},
  214. {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  215. {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number'},
  216. ],
  217. emptyRows: 0,
  218. headRows: 2,
  219. headRowHeight: [25, 25],
  220. defaultRowHeight: 21,
  221. headerFont: '12px 微软雅黑',
  222. font: '12px 微软雅黑',
  223. readOnly: true,
  224. rowHeader:[
  225. {
  226. rowHeaderType: 'circle',
  227. setting: {
  228. size: 5,
  229. indent: 16,
  230. getColor: function (index, data) {
  231. if (!data) return;
  232. if (_.findIndex(selfList, { gcl_id: data.gcl_id, xmj_id: data.id, mx_id: (data.mx_id ? data.mx_id : '') }) !== -1) {
  233. return '#dc3545';
  234. }
  235. }
  236. },
  237. },
  238. ],
  239. };
  240. const needUpdateArray = ['quantity', 'msg_tp', 'msg_times', 'msg_spread', 'm_spread', 'm_tp', 'm_tax_tp', 'is_summary', 'remark'];
  241. function getGclList() {
  242. if (gclGatherListData) {
  243. return gclGatherListData;
  244. } else {
  245. const newGclGatherListData = [];
  246. for (const [index,s] of ledgerListData.entries()) {
  247. console.log(index, s);
  248. gclGatherModel.loadLedgerData(ledger, s);
  249. gclGatherModel.loadPosData(pos, posListData[index]);
  250. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  251. return item.qc_qty || item.contract_qty
  252. });
  253. newGclGatherListData.push(oneGclGatherData);
  254. }
  255. return newGclGatherListData;
  256. }
  257. }
  258. let first = true;
  259. function setListsData(sid = null, ms_id = null) {
  260. if (first) {
  261. // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  262. postData(window.location.pathname + '/load', {sid}, async function (result) {
  263. ledger = result.ledger;
  264. curLedgerData = result.curLedgerData;
  265. pos = result.pos;
  266. curPosData = result.curPosData;
  267. materialListData = result.materialListData;
  268. gclList = result.gclList;
  269. notJoinList = result.materialNotJoinListData;
  270. notChangeList = result.materialNotChangeListData;
  271. selfList = result.materialSelfListData;
  272. materialChecklistData = result.materialChecklistData;
  273. if (isStageSelf) {
  274. updateBillsData(ms_id);
  275. const newGclGatherListData = [];
  276. for (const [index, s] of result.ledgerListData.entries()) {
  277. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), s);
  278. gclGatherModel.loadPosData(_.cloneDeep(pos), result.posListData[index]);
  279. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  280. return item.qc_qty || item.contract_qty
  281. });
  282. newGclGatherListData.push(oneGclGatherData);
  283. }
  284. gclGatherListData = newGclGatherListData;
  285. }
  286. // 解析清单汇总数据
  287. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  288. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  289. gclGatherData = gclGatherModel.gatherGclData();
  290. console.log(gclGatherData);
  291. if (openMaterialChecklist) {
  292. const hadBillsidList = _.uniq(_.map(gclList, 'gcl_id'));
  293. console.log(hadBillsidList);
  294. // 判断是否有修订影响到本次数据,并有几率修改清单设置页的值
  295. const pushData = [];
  296. const updateData = [];
  297. for (const hb of hadBillsidList) {
  298. const gcl = _.find(gclGatherData, function (item) {
  299. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: hb}) !== -1;
  300. });
  301. if (gcl) {
  302. const mc = _.find(materialChecklistData, {
  303. b_code: gcl.b_code,
  304. name: gcl.name,
  305. unit: gcl.unit,
  306. unit_price: gcl.unit_price
  307. });
  308. // const newOrder = _.indexOf(gclGatherData, gcl);
  309. // console.log(newOrder);
  310. if (!mc && _.findIndex(pushData, {
  311. b_code: gcl.b_code,
  312. name: gcl.name,
  313. unit: gcl.unit,
  314. unit_price: gcl.unit_price
  315. }) === -1) {
  316. pushData.push({
  317. b_code: gcl.b_code,
  318. name: gcl.name,
  319. unit: gcl.unit,
  320. unit_price: gcl.unit_price,
  321. quantity: (gcl.quantity ? gcl.quantity : null),
  322. total_price: (gcl.total_price ? gcl.total_price : null),
  323. had_bills: 1
  324. });
  325. }
  326. }
  327. }
  328. const removeData = [];
  329. for (const mc of materialChecklistData) {
  330. const gcl = _.find(gclGatherData, {
  331. b_code: mc.b_code,
  332. name: mc.name,
  333. unit: mc.unit,
  334. unit_price: mc.unit_price
  335. });
  336. // 判断是否已不存在工料清单,台账修改过后删除之
  337. if (!gcl) {
  338. removeData.push(mc.id);
  339. } else {
  340. // 更新had_bills值
  341. const updateObj = {id: mc.id};
  342. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  343. const jiaoji = _.intersection(gcl_ids, hadBillsidList);
  344. if (mc.had_bills === 1) {
  345. if (jiaoji.length === 0) {
  346. updateObj.mid = materialID;
  347. updateObj.had_bills = 0;
  348. // updateData.push({ id: mc.id, mid: materialID, had_bills: 0 });
  349. }
  350. } else if (mc.had_bills === 0) {
  351. if (jiaoji.length !== 0) {
  352. updateObj.had_bills = 1;
  353. }
  354. }
  355. // 更新工程量及台账金额
  356. if (mc.quantity !== (gcl.quantity ? gcl.quantity : null)) {
  357. updateObj.quantity = gcl.quantity ? gcl.quantity : null;
  358. updateObj.total_price = gcl.total_price ? gcl.total_price : null;
  359. }
  360. if (!_.isEqual(updateObj, {id: mc.id})) updateData.push(updateObj);
  361. }
  362. }
  363. console.log(pushData, removeData, updateData);
  364. if (pushData.length > 0 || removeData.length > 0 || updateData.length > 0) {
  365. // materialChecklistData = await postDataAsync('/tender/'+ tenderID +'/measure/material/'+ stage_order +'/checklist/save', { type: 'resetChecklist', pushData, removeData, updateData })
  366. }
  367. gclGatherData = gclGatherData.filter(item => {
  368. return item.qc_qty || item.contract_qty
  369. });
  370. // 取交集
  371. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  372. gclGatherData = _.filter(gclGatherData, function (item) {
  373. if (_.find(materialChecklistData, {
  374. b_code: item.b_code,
  375. name: item.name,
  376. unit: item.unit,
  377. unit_price: item.unit_price
  378. })) {
  379. return true;
  380. } else {
  381. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  382. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  383. if (jiaoji.length > 0) {
  384. return true;
  385. }
  386. }
  387. });
  388. } else {
  389. gclGatherData = gclGatherData.filter(item => {
  390. return item.qc_qty || item.contract_qty
  391. });
  392. }
  393. calculateJiaCha(gclGatherData);
  394. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  395. // 加载清单数据
  396. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  397. loadLeafXmjData(0);
  398. loadMaterialData(0);
  399. loadXmjMaterialData(0, 0);
  400. const sheet = materialSpread.getActiveSheet();
  401. sheet.suspendPaint();
  402. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  403. sheet.resumePaint();
  404. const selfSheet = materialSelfSpread.getActiveSheet();
  405. selfSheet.suspendPaint();
  406. selfSheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  407. selfSheet.resumePaint();
  408. checkNotJoinMaterialData();
  409. first = false;
  410. });
  411. } else {
  412. // 解析清单汇总数据
  413. // const ms_id = $('#myTab').find('.active').data('msid');
  414. updateBillsData(ms_id);
  415. const i = _.findIndex(materialStageData, { sid });
  416. gclGatherData = gclGatherListData[i];
  417. if (openMaterialChecklist) {
  418. gclGatherData = gclGatherData.filter(item => {
  419. return item.qc_qty || item.contract_qty
  420. });
  421. // 取交集
  422. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  423. gclGatherData = _.filter(gclGatherData, function (item) {
  424. if (_.find(materialChecklistData, {
  425. b_code: item.b_code,
  426. name: item.name,
  427. unit: item.unit,
  428. unit_price: item.unit_price
  429. })) {
  430. return true;
  431. } else {
  432. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  433. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  434. if (jiaoji.length > 0) {
  435. return true;
  436. }
  437. }
  438. });
  439. } else {
  440. gclGatherData = gclGatherData.filter(item => {
  441. return item.qc_qty || item.contract_qty
  442. });
  443. }
  444. if ($('#show_material_gcl').is(':checked')) {
  445. const hadMaterialGclGatherData = [];
  446. const hadGclIdList = [];
  447. for (const ml of materialListData) {
  448. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  449. hadGclIdList.push(ml.gcl_id);
  450. }
  451. }
  452. for (const gcl of gclGatherData) {
  453. for (const index in gcl.leafXmjs) {
  454. const gcl_id = gcl.leafXmjs[index].gcl_id;
  455. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  456. hadMaterialGclGatherData.push(gcl);
  457. break;
  458. }
  459. }
  460. }
  461. gclGatherData = hadMaterialGclGatherData;
  462. }
  463. console.log(gclGatherData);
  464. calculateJiaCha(gclGatherData);
  465. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  466. // 加载清单数据
  467. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  468. loadLeafXmjData(0);
  469. loadMaterialData(0);
  470. loadXmjMaterialData(0, 0);
  471. const sheet = materialSpread.getActiveSheet();
  472. sheet.suspendPaint();
  473. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  474. sheet.resumePaint();
  475. const selfSheet = materialSelfSpread.getActiveSheet();
  476. selfSheet.suspendPaint();
  477. selfSheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  478. selfSheet.resumePaint();
  479. ledgerSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  480. checkNotJoinMaterialData();
  481. }
  482. }
  483. function updateBillsData(ms_id) {
  484. const msbList = _.filter(materialStageBillsData, { ms_id });
  485. for (const mb of materialBillsData) {
  486. mb.ms_id = ms_id;
  487. const msbInfo = _.find(msbList, { mb_id: mb.id });
  488. for (const nu of needUpdateArray) {
  489. mb[nu] = msbInfo[nu];
  490. }
  491. }
  492. }
  493. setListsData(isStageSelf ? materialStageData[0].sid : null, isStageSelf ? materialStageData[0].id : null);
  494. // 期切换
  495. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  496. e.preventDefault();
  497. const ms_id = $('#myTab').find('.active').data('msid');
  498. const msInfo = _.find(materialStageData, { id: ms_id });
  499. showWaitingView();
  500. setTimeout(function () {
  501. setListsData(msInfo.sid, ms_id);
  502. closeWaitingView();
  503. }, 500);
  504. });
  505. // const leafXmjCol = {
  506. // getValue: {
  507. // jiacha: function (data) {
  508. // let sum = 0;
  509. // const sheet = leafXmjSpread.getActiveSheet();
  510. // const select = SpreadJsObj.getSelectObject(sheet);
  511. // const notx = findNotJoinLeafXmj(select);
  512. // if (notx === undefined) {
  513. // for(const ml of materialList) {
  514. // sum = ZhCalc.round(ZhCalc.add(sum, ZhCalc.mul(ZhCalc.mul(data.gather_qty, ml.quantity), getMpSpreadByMBData(ml.mb_id))), 2);
  515. // }
  516. // }
  517. // return sum !== 0 ? sum : null;
  518. // }
  519. // }
  520. // };
  521. // SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  522. // 调差清单工料table
  523. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  524. const materialSpreadSetting = {
  525. cols: [
  526. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  527. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  528. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  529. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  530. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  531. ],
  532. emptyRows: 0,
  533. headRows: 2,
  534. headRowHeight: [25, 25],
  535. defaultRowHeight: 21,
  536. headerFont: '12px 微软雅黑',
  537. font: '12px 微软雅黑',
  538. };
  539. const materialBase = {
  540. isEdit: function (data, type = 'normal') {
  541. // 是否本期添加的工料
  542. // return data.order === stage_order && !openMaterialChecklist;
  543. let flag = true;
  544. if (type === 'del' || !editListPermission) {
  545. flag = data.order === stage_order;
  546. }
  547. return flag && !openMaterialChecklist;
  548. }
  549. };
  550. const materialCol = {
  551. readOnly: {
  552. isEdit: function (data) {
  553. // const sheet = leafXmjSpread.getActiveSheet();
  554. // const select = SpreadJsObj.getSelectObject(sheet);
  555. // const notx = findNotJoinLeafXmj(select);
  556. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  557. return !(!readOnly && materialBase.isEdit(data));
  558. },
  559. },
  560. };
  561. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  562. // 获取项目节数据
  563. let materialList = [];
  564. function loadMaterialData(iGclRow) {
  565. const gcl = gclGatherData[iGclRow];
  566. if (gcl && gcl.leafXmjs) {
  567. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  568. materialList = [];
  569. const newMaterialList = _.uniqBy(_.filter(gclList, function (m) {
  570. return _.indexOf(gcl_ids, m.gcl_id) !== -1;
  571. }), 'mb_id');
  572. for(const m of newMaterialList) {
  573. const bills = _.find(materialBillsData, { id: m.mb_id });
  574. if(bills) {
  575. m.code = bills.code;
  576. m.name = bills.name;
  577. m.unit = bills.unit;
  578. }
  579. }
  580. console.log(newMaterialList);
  581. materialList = newMaterialList;
  582. // 对清单调差工料table的单位数量进行改变
  583. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  584. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  585. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  586. } else {
  587. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '数量 �';
  588. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  589. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  590. }
  591. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  592. }
  593. // 调差清单工料table
  594. const materialSelfSpread = SpreadJsObj.createNewSpread($('#material-self-spread')[0]);
  595. const materialSelfSpreadSetting = {
  596. cols: [
  597. {title: '明细清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  598. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  599. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  600. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  601. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  602. ],
  603. emptyRows: 0,
  604. headRows: 2,
  605. headRowHeight: [25, 25],
  606. defaultRowHeight: 21,
  607. headerFont: '12px 微软雅黑',
  608. font: '12px 微软雅黑',
  609. };
  610. const materialSelfBase = {
  611. isEdit: function (data, type = 'normal') {
  612. // 是否本期添加的工料
  613. // return data.order === stage_order && !openMaterialChecklist;
  614. let flag = true;
  615. if (type === 'del' || !editListPermission) {
  616. flag = data.order === stage_order;
  617. }
  618. return flag;
  619. }
  620. };
  621. const materialSelfCol = {
  622. readOnly: {
  623. isEdit: function (data) {
  624. // const sheet = leafXmjSpread.getActiveSheet();
  625. // const select = SpreadJsObj.getSelectObject(sheet);
  626. // const notx = findNotJoinLeafXmj(select);
  627. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  628. return openMaterialSelf && !(!readOnly && materialSelfBase.isEdit(data));
  629. },
  630. },
  631. };
  632. SpreadJsObj.initSpreadSettingEvents(materialSelfSpreadSetting, materialSelfCol);
  633. let materialListSelf = [];
  634. function loadXmjMaterialData(iGclRow, iLXmjRow) {
  635. // 存在单独设置的才展示,不然隐藏
  636. const gcl = gclGatherData[iGclRow];
  637. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  638. return item.qc_qty || item.contract_qty
  639. }) : null;
  640. if (leafXmjs) {
  641. const xmj = leafXmjs[iLXmjRow];
  642. console.log(xmj, iLXmjRow);
  643. materialListSelf = [];
  644. if (_.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: (xmj.mx_id ? xmj.mx_id : '') }) != -1) {
  645. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  646. for (const m of materialListData) {
  647. if (m.gcl_id === xmj.gcl_id && m.xmj_id === xmj.id && ((xmj.mx_id !==undefined && m.mx_id === xmj.mx_id) || xmj.mx_id === undefined) && (ms_id === null || ms_id === m.ms_id)) {
  648. materialListSelf.push(m);
  649. }
  650. }
  651. $('#material-self-spread-div').addClass('active');
  652. showSelfSideTools(true);
  653. } else {
  654. $('#material-self-spread-div').removeClass('active');
  655. showSelfSideTools(false);
  656. }
  657. // 对清单调差工料table的单位数量进行改变
  658. materialSelfSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  659. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  660. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialListSelf);
  661. } else {
  662. $('#material-self-spread-div').removeClass('active');
  663. showSelfSideTools(false);
  664. materialSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '数量 �';
  665. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  666. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  667. }
  668. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  669. leafXmjSpread.refresh();
  670. materialSelfSpread.refresh();
  671. }
  672. // SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), )
  673. // loadLeafXmjData(0);
  674. // loadMaterialData(0, 0);
  675. // const sheet = materialSpread.getActiveSheet();
  676. // sheet.suspendPaint();
  677. // sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  678. // sheet.resumePaint();
  679. // 不参与调差数据值变灰, 数量变更不参与调差数据值变黄
  680. function checkNotJoinMaterialData() {
  681. const sheet = ledgerSpread.getActiveSheet();
  682. const select = SpreadJsObj.getSelectObject(sheet);
  683. const index = gclGatherData.indexOf(select);
  684. if (index !== -1) {
  685. const xmj = gclGatherData[index].leafXmjs.filter(item => {
  686. return item.qc_qty || item.contract_qty
  687. });
  688. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  689. for (const [iRow,x] of xmj.entries()) {
  690. const notx = findNotJoinLeafXmj(x);
  691. const color = notx === undefined ? '' : '#d6d8db';
  692. // leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
  693. const notx2 = findNotChangeLeafXmj(x);
  694. const color2 = notx2 === undefined ? color : '#FFE699';
  695. leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color2);
  696. }
  697. }
  698. }
  699. // checkNotJoinMaterialData();
  700. // 对添加工料表格赋值
  701. function changeMaterialTable(from = 'all') {
  702. $('#materialBills tr').removeClass('table-secondary');
  703. $('#materialBills').find('input').removeAttr('disabled');
  704. $('#materialBills').find('input').prop('checked', false);
  705. const searchList = from === 'self' ? materialListSelf : materialList;
  706. console.log(searchList);
  707. for (const [index, ml] of searchList.entries()) {
  708. const mbIndex = materialBillsData.findIndex(function (item) {
  709. return item.id === ml.mb_id;
  710. });
  711. if (mbIndex !== -1) {
  712. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  713. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  714. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  715. }
  716. }
  717. }
  718. // 添加调差工料
  719. $('#add_material_bill').click(function () {
  720. // 获取已选工料
  721. $('#materialBills').find('input:disabled').prop('checked', false);
  722. const selectList = $('#materialBills').find('input:checked');
  723. if (selectList.length === 0) {
  724. toastr.warning('请选择调差工料');
  725. $('#materialBills').find('input:disabled').prop('checked', true);
  726. return false;
  727. }
  728. const mb_id = [];
  729. for (let s = 0; s < selectList.length; s++) {
  730. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  731. }
  732. const type = $('#add_type').val();
  733. if (type === 'all') {
  734. // 获取当前项目节或部位明细id
  735. const sheet = ledgerSpread.getActiveSheet();
  736. const select = SpreadJsObj.getSelectObject(sheet);
  737. const index = gclGatherData.indexOf(select);
  738. const gcl = gclGatherData[index].leafXmjs;
  739. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  740. const datas = [];
  741. for (const xmj of gcl) {
  742. const notx = findNotJoinLeafXmj(xmj);
  743. const notx2 = findNotChangeLeafXmj(xmj);
  744. const data = {
  745. xmj_id: xmj.id,
  746. gcl_id: xmj.gcl_id,
  747. mx_id: xmj.mx_id ? xmj.mx_id : '',
  748. gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
  749. is_join: notx === undefined ? 1 : 0,
  750. };
  751. if (ms_id) data.ms_id = ms_id;
  752. datas.push(data);
  753. }
  754. if (isStageSelf) {
  755. // 取所有的gclGatherData才行,然后获取下的值
  756. const gclData = gclGatherData[index];
  757. for (const [index, ms] of materialStageData.entries()) {
  758. if (ms.id !== ms_id) {
  759. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  760. if (gclOther) {
  761. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  762. for (const xmj of leafXmjs) {
  763. const notx = findNotJoinLeafXmj(xmj);
  764. const notx2 = findNotChangeLeafXmj(xmj);
  765. const data = {
  766. xmj_id: xmj.id,
  767. gcl_id: xmj.gcl_id,
  768. mx_id: xmj.mx_id ? xmj.mx_id : '',
  769. gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
  770. is_join: notx === undefined ? 1 : 0,
  771. ms_id: ms.id,
  772. };
  773. datas.push(data);
  774. }
  775. }
  776. }
  777. }
  778. }
  779. console.log(datas, gcl, mb_id);
  780. postData(window.location.pathname + '/save', {type: 'adds', postData: {xmjs: datas, mbIds: mb_id} }, function (result) {
  781. materialListData = result.materialListData;
  782. gclList = result.gclList;
  783. // toastr.success('已成功应用');
  784. calculateJiaCha(gclGatherData);
  785. // const index = gclGatherData.indexOf(ledgerSelect);
  786. loadLeafXmjData(index);
  787. // const xmjSheet = leafXmjSpread.getActiveSheet();
  788. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  789. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  790. loadMaterialData(index);
  791. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  792. $('#addgl').modal('hide');
  793. });
  794. } else if (type === 'self') {
  795. // 获取当前项目节或部位明细id
  796. const sheet = ledgerSpread.getActiveSheet();
  797. const select = SpreadJsObj.getSelectObject(sheet);
  798. const index = gclGatherData.indexOf(select);
  799. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  800. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  801. const gcl = gclGatherData[index].leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  802. const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  803. const xmj = gcl[leafXmjIndex];
  804. const notx = findNotJoinLeafXmj(xmj);
  805. const notx2 = findNotChangeLeafXmj(xmj);
  806. const data = {
  807. xmj_id: xmj.id,
  808. gcl_id: xmj.gcl_id,
  809. mx_id: xmj.mx_id ? xmj.mx_id : '',
  810. mb_id: mb_id,
  811. gather_qty: notx2 === undefined ? xmj.gather_qty : xmj.contract_qty,
  812. is_join: notx === undefined ? 1 : 0,
  813. };
  814. console.log(data);
  815. postData(window.location.pathname + '/save', {type: 'add', postData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  816. // 添加到materialList里
  817. materialListData = result;
  818. loadXmjMaterialData(index, leafXmjIndex);
  819. $('#addgl').modal('hide');
  820. });
  821. }
  822. $('#materialBills').find('input:disabled').prop('checked', true);
  823. });
  824. const leafXmjSpreadObj = {
  825. getSelect : function () {
  826. const sheet = ledgerSpread.getActiveSheet();
  827. const select = SpreadJsObj.getSelectObject(sheet);
  828. const index = gclGatherData.indexOf(select);
  829. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  830. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  831. const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  832. const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  833. return item.qc_qty || item.contract_qty
  834. });
  835. const nRow = leafXmjs.indexOf(leafXmjSelect);
  836. const leafXmjColor = findNotJoinLeafXmj(leafXmjSelect) ? '#d6d8db' : (findNotChangeLeafXmj(leafXmjSelect) ? '#FFE699' : '');
  837. return [index, iRow, nRow, leafXmjSheet, leafXmjSelect, leafXmjColor];
  838. },
  839. checkJoinMaterial: function (type) {
  840. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  841. const color = type === 'join' ? '' : '#d6d8db';
  842. const data = {
  843. type: type,
  844. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  845. gather_qty: select.gather_qty,
  846. ms_id: $('#myTab').find('.active').data('msid') || null,
  847. };
  848. // 添加到
  849. postData(window.location.pathname + '/save', data, function (result) {
  850. if (type === 'join') {
  851. const index = findNotJoinLeafXmj(select, 'index');
  852. notJoinList.splice(index, 1);
  853. } else {
  854. notJoinList.push(result);
  855. const index = findNotChangeLeafXmj(select, 'index');
  856. notChangeList.splice(index, 1);
  857. }
  858. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  859. calculateJiaCha(gclGatherData, iGclRow);
  860. SpreadJsObj.reLoadRowData(sheet, nRow);
  861. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  862. loadMaterialData(iGclRow);
  863. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  864. });
  865. },
  866. checkChangeMaterial: function (type) {
  867. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  868. const color = type === 'change' ? '' : '#FFE699';
  869. const data = {
  870. type: type,
  871. select: type === 'change' ? findNotChangeLeafXmj(select) : select,
  872. gather_qty: type === 'change' ? select.gather_qty : select.contract_qty,
  873. ms_id: $('#myTab').find('.active').data('msid') || null,
  874. };
  875. // 添加到
  876. postData(window.location.pathname + '/save', data, function (result) {
  877. if (type === 'change') {
  878. const index = findNotChangeLeafXmj(select, 'index');
  879. notChangeList.splice(index, 1);
  880. } else {
  881. notChangeList.push(result);
  882. }
  883. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  884. calculateJiaCha(gclGatherData, iGclRow);
  885. SpreadJsObj.reLoadRowData(sheet, nRow);
  886. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  887. loadMaterialData(iGclRow);
  888. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  889. });
  890. },
  891. checkSelfMaterial: function (type) {
  892. const [iGclRow, iRow, nRow, sheet, select, color] = leafXmjSpreadObj.getSelect();
  893. // const color = type === 'self' ? '' : '#d6d8db';
  894. const data = {
  895. type: type,
  896. select: type === 'noself' ? findSelfLeafXmj(select) : select,
  897. ms_id: $('#myTab').find('.active').data('msid') || null,
  898. };
  899. if (type === 'noself') {
  900. if (isStageSelf) {
  901. data.select.gather_qty = {};
  902. const ledgerSheet = ledgerSpread.getActiveSheet();
  903. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  904. const index = gclGatherData.indexOf(ledgerSelect);
  905. // 取所有的gclGatherData才行,然后获取下的值
  906. const gclData = gclGatherData[index];
  907. for (const [index, ms] of materialStageData.entries()) {
  908. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  909. let gather_qty = null;
  910. if (gclOther) {
  911. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  912. const oneXmj = _.find(leafXmjs, function (item) {
  913. return item.gcl_id === select.gcl_id && item.id === select.id && (select.mx_id === undefined || item.mx_id === select.mx_id);
  914. });
  915. if (oneXmj) gather_qty = oneXmj.gather_qty;
  916. }
  917. data.select.gather_qty['ms_id_' + ms.id] = gather_qty;
  918. }
  919. } else {
  920. data.select.gather_qty = select.gather_qty ? select.gather_qty : null;
  921. }
  922. }
  923. console.log(data);
  924. // 添加到
  925. postData(window.location.pathname + '/save', data, function (result) {
  926. if (type === 'noself') {
  927. const index = findSelfLeafXmj(select, 'index');
  928. selfList.splice(index, 1);
  929. materialListData = result;
  930. $('#cancel-self').modal('hide');
  931. } else {
  932. selfList.push(result.info);
  933. materialListData = result.materialListData;
  934. }
  935. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  936. calculateJiaCha(gclGatherData, iGclRow);
  937. SpreadJsObj.reLoadRowData(sheet, nRow);
  938. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  939. loadXmjMaterialData(iGclRow, nRow);
  940. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  941. });
  942. },
  943. }
  944. if (!readOnly) {
  945. // leafXmj右键功能
  946. if (!editForAudit) {
  947. $.contextMenu({
  948. selector: '#leaf-xmj-spread',
  949. build: function ($trigger, e) {
  950. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  951. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  952. },
  953. items: {
  954. 'stop': {
  955. name: '当前节点不参与调差',
  956. icon: 'fa-remove',
  957. callback: function (key, opt) {
  958. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  959. },
  960. visible: function (key, opt) {
  961. const sheet = leafXmjSpread.getActiveSheet();
  962. const select = SpreadJsObj.getSelectObject(sheet);
  963. const sel = sheet.getSelections()[0];
  964. if (!select || sel.rowCount !== 1) {
  965. return false;
  966. }
  967. const notx = findNotJoinLeafXmj(select);
  968. if (!readOnly && select && notx === undefined) {
  969. return true;
  970. } else {
  971. return false;
  972. }
  973. }
  974. },
  975. 'start': {
  976. name: '当前节点参与调差',
  977. icon: 'fa-sign-in',
  978. callback: function (key, opt) {
  979. leafXmjSpreadObj.checkJoinMaterial('join');
  980. },
  981. visible: function (key, opt) {
  982. const sheet = leafXmjSpread.getActiveSheet();
  983. const select = SpreadJsObj.getSelectObject(sheet);
  984. const sel = sheet.getSelections()[0];
  985. if (!select || sel.rowCount !== 1) {
  986. return false;
  987. }
  988. const notx = findNotJoinLeafXmj(select);
  989. if (!readOnly && select && notx === undefined) {
  990. return false;
  991. } else {
  992. return true;
  993. }
  994. },
  995. },
  996. 'stop2': {
  997. name: '数量变更不参与调差',
  998. icon: 'fa-remove',
  999. callback: function (key, opt) {
  1000. leafXmjSpreadObj.checkChangeMaterial('notchange');
  1001. },
  1002. visible: function (key, opt) {
  1003. const sheet = leafXmjSpread.getActiveSheet();
  1004. const select = SpreadJsObj.getSelectObject(sheet);
  1005. const sel = sheet.getSelections()[0];
  1006. if (!select || sel.rowCount !== 1) {
  1007. return false;
  1008. }
  1009. const notx = findNotJoinLeafXmj(select);
  1010. if (!(!readOnly && select && notx === undefined)) {
  1011. return false;
  1012. }
  1013. const notx2 = findNotChangeLeafXmj(select);
  1014. if (!readOnly && select && notx2 === undefined) {
  1015. return true;
  1016. } else {
  1017. return false;
  1018. }
  1019. }
  1020. },
  1021. 'start2': {
  1022. name: '数量变更参与调差',
  1023. icon: 'fa-sign-in',
  1024. callback: function (key, opt) {
  1025. leafXmjSpreadObj.checkChangeMaterial('change');
  1026. },
  1027. visible: function (key, opt) {
  1028. const sheet = leafXmjSpread.getActiveSheet();
  1029. const select = SpreadJsObj.getSelectObject(sheet);
  1030. const sel = sheet.getSelections()[0];
  1031. if (!select || sel.rowCount !== 1) {
  1032. return false;
  1033. }
  1034. const notx = findNotJoinLeafXmj(select);
  1035. if (!(!readOnly && select && notx === undefined)) {
  1036. return false;
  1037. }
  1038. const notx2 = findNotChangeLeafXmj(select);
  1039. if (!readOnly && select && notx2 === undefined) {
  1040. return false;
  1041. } else {
  1042. return true;
  1043. }
  1044. },
  1045. },
  1046. 'self': {
  1047. name: '单独添加工料',
  1048. icon: 'fa-sign-in',
  1049. callback: function (key, opt) {
  1050. leafXmjSpreadObj.checkSelfMaterial('self');
  1051. },
  1052. visible: function (key, opt) {
  1053. if (!openMaterialSelf) {
  1054. return false;
  1055. }
  1056. const sheet = leafXmjSpread.getActiveSheet();
  1057. const select = SpreadJsObj.getSelectObject(sheet);
  1058. const sel = sheet.getSelections()[0];
  1059. if (!select || sel.rowCount !== 1) {
  1060. return false;
  1061. }
  1062. const notx = findSelfLeafXmj(select);
  1063. if (!readOnly && select && notx === undefined) {
  1064. return true;
  1065. } else {
  1066. return false;
  1067. }
  1068. }
  1069. },
  1070. 'noself': {
  1071. name: '取消单独添加工料',
  1072. icon: 'fa-remove',
  1073. callback: function (key, opt) {
  1074. $('#cancel-self').modal('show');
  1075. // leafXmjSpreadObj.checkSelfMaterial('noself');
  1076. },
  1077. visible: function (key, opt) {
  1078. if (!openMaterialSelf) {
  1079. return false;
  1080. }
  1081. const sheet = leafXmjSpread.getActiveSheet();
  1082. const select = SpreadJsObj.getSelectObject(sheet);
  1083. const sel = sheet.getSelections()[0];
  1084. if (!select || sel.rowCount !== 1) {
  1085. return false;
  1086. }
  1087. const notx = findSelfLeafXmj(select);
  1088. if (!readOnly && select && notx === undefined) {
  1089. return false;
  1090. } else {
  1091. return true;
  1092. }
  1093. },
  1094. disabled: function (key, opt) {
  1095. // const sheet = ledgerSpread.getActiveSheet();
  1096. // const select = SpreadJsObj.getSelectObject(sheet);
  1097. // const index = gclGatherData.indexOf(select);
  1098. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  1099. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  1100. // const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  1101. // const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  1102. // return item.qc_qty || item.contract_qty
  1103. // });
  1104. // const nRow = leafXmjs.indexOf(leafXmjSelect);
  1105. // const leafXmjColor = findNotJoinLeafXmj(leafXmjSelect) ? '#d6d8db' : '';
  1106. // return [index, iRow, nRow, leafXmjSheet, leafXmjSelect, leafXmjColor];
  1107. const [iGclRow, iRow, nRow, sheet, select, color] = leafXmjSpreadObj.getSelect();
  1108. const gcl = gclGatherData[iGclRow];
  1109. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  1110. return item.qc_qty || item.contract_qty
  1111. }) : null;
  1112. let flag = false;
  1113. if (leafXmjs) {
  1114. const xmj = leafXmjs[nRow];
  1115. if (_.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: (xmj.mx_id ? xmj.mx_id : '') }) != -1) {
  1116. for (const m of materialListData) {
  1117. if (m.gcl_id === xmj.gcl_id && m.xmj_id === xmj.id && ((xmj.mx_id !==undefined && m.mx_id === xmj.mx_id) || xmj.mx_id === undefined) && m.order !== stage_order) {
  1118. flag = true;
  1119. break;
  1120. }
  1121. }
  1122. }
  1123. }
  1124. return flag;
  1125. },
  1126. },
  1127. }
  1128. });
  1129. $('#cancelSelfBtn').click(function () {
  1130. leafXmjSpreadObj.checkSelfMaterial('noself');
  1131. });
  1132. }
  1133. // material-spread右键功能
  1134. const materialSpreadObj = {
  1135. del: function () {
  1136. const materialSheet = materialSpread.getActiveSheet();
  1137. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  1138. const sheet = ledgerSpread.getActiveSheet();
  1139. const select = SpreadJsObj.getSelectObject(sheet);
  1140. const index = gclGatherData.indexOf(select);
  1141. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  1142. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  1143. const gcl = gclGatherData[index].leafXmjs;
  1144. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  1145. const datas = [];
  1146. for (const xmj of gcl) {
  1147. const data = {
  1148. xmj_id: xmj.id,
  1149. gcl_id: xmj.gcl_id,
  1150. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1151. };
  1152. datas.push(data);
  1153. }
  1154. if (isStageSelf) {
  1155. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1156. // 取所有的gclGatherData才行,然后获取下的值
  1157. const gclData = gclGatherData[index];
  1158. for (const [index, ms] of materialStageData.entries()) {
  1159. if (ms.id !== ms_id) {
  1160. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1161. if (gclOther) {
  1162. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1163. for (const xmj of leafXmjs) {
  1164. const data = {
  1165. xmj_id: xmj.id,
  1166. gcl_id: xmj.gcl_id,
  1167. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1168. };
  1169. if (_.indexOf(datas, data) === -1) {
  1170. datas.push(data);
  1171. }
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. console.log(datas, materialSelect.mb_id);
  1178. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }, ms_id: $('#myTab').find('.active').data('msid') || null}, function (result) {
  1179. materialListData = result.materialListData;
  1180. gclList = result.gclList;
  1181. calculateJiaCha(gclGatherData);
  1182. // const index = gclGatherData.indexOf(ledgerSelect);
  1183. loadLeafXmjData(index);
  1184. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1185. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1186. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1187. loadMaterialData(index);
  1188. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1189. });
  1190. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  1191. // const index = materialList.indexOf(select);
  1192. // materialList.splice(index, 1);
  1193. // sheet.deleteRows(index, 1);
  1194. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1195. // const sel = sheet.getSelections();
  1196. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1197. // const materialListIndex = materialListData.indexOf(select);
  1198. // materialListData.splice(materialListIndex, 1);
  1199. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  1200. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1201. // calculateJiaCha(gclGatherData, iGclRow);
  1202. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  1203. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1204. // });
  1205. },
  1206. deletePress: function (sheet) {
  1207. return;
  1208. },
  1209. editStarting: function (e, info) {
  1210. const col = info.sheet.zh_setting.cols[info.col];
  1211. const select = SpreadJsObj.getSelectObject(info.sheet);
  1212. if (col.field === 'quantity') {
  1213. if (select.expr && select.expr !== '') {
  1214. info.sheet.getCell(info.row, info.col).text(select.expr);
  1215. }
  1216. }
  1217. },
  1218. editEnded: function (e, info) {
  1219. if (info.sheet.zh_setting) {
  1220. const select = SpreadJsObj.getSelectObject(info.sheet);
  1221. const col = info.sheet.zh_setting.cols[info.col];
  1222. // 未改变值则不提交
  1223. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1224. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1225. // let orgValue = select[col.field];
  1226. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1227. let orgValue;
  1228. if (col.field === 'quantity') {
  1229. orgValue = validText && validText !== ''
  1230. ? _.toNumber(validText) ? select.quantity : select.expr
  1231. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1232. } else {
  1233. orgValue = select[col.field];
  1234. }
  1235. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1236. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1237. return;
  1238. }
  1239. const exprQuantity = {
  1240. expr: '',
  1241. quantity: 0,
  1242. };
  1243. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1244. if (!valid) {
  1245. toastr.error(msg);
  1246. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1247. return;
  1248. }
  1249. if (isNaN(exprQuantity.quantity)) {
  1250. toastr.error('不能输入其它非数字类型字符');
  1251. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1252. return;
  1253. }
  1254. const num = parseFloat(exprQuantity.quantity);
  1255. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1256. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1257. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1258. // return;
  1259. toastr.warning('已保留6位小数');
  1260. exprQuantity.quantity = ZhCalc.round(num, 6);
  1261. }
  1262. // 更新至服务器
  1263. const ledgerSheet = ledgerSpread.getActiveSheet();
  1264. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1265. const index = gclGatherData.indexOf(ledgerSelect);
  1266. const gcl = gclGatherData[index].leafXmjs;
  1267. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1268. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1269. // const xmjIndex = gcl.indexOf(xmjSelect);
  1270. const datas = [];
  1271. for (const xmj of gcl) {
  1272. const data = {
  1273. xmj_id: xmj.id,
  1274. gcl_id: xmj.gcl_id,
  1275. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1276. };
  1277. datas.push(data);
  1278. }
  1279. if (isStageSelf) {
  1280. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1281. // 取所有的gclGatherData才行,然后获取下的值
  1282. const gclData = gclGatherData[index];
  1283. for (const [index, ms] of materialStageData.entries()) {
  1284. if (ms.id !== ms_id) {
  1285. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1286. if (gclOther) {
  1287. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1288. for (const xmj of leafXmjs) {
  1289. const data = {
  1290. xmj_id: xmj.id,
  1291. gcl_id: xmj.gcl_id,
  1292. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1293. };
  1294. if (_.indexOf(datas, data) === -1) {
  1295. datas.push(data);
  1296. }
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }
  1302. console.log(exprQuantity, datas, select.mb_id);
  1303. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1304. materialListData = result.materialListData;
  1305. gclList = result.gclList;
  1306. calculateJiaCha(gclGatherData);
  1307. // const index = gclGatherData.indexOf(ledgerSelect);
  1308. loadLeafXmjData(index);
  1309. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1310. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1311. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1312. loadMaterialData(index);
  1313. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1314. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  1315. }, function () {
  1316. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1317. });
  1318. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  1319. // const materialListIndex = materialListData.indexOf(select);
  1320. // const index = materialList.indexOf(select);
  1321. // select[col.field] = validText;
  1322. // materialListData.splice(materialListIndex, 1, select);
  1323. // materialList.indexOf(index, 1, select);
  1324. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1325. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1326. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1327. // calculateJiaCha(gclGatherData, iGclRow)
  1328. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1329. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1330. // }, function () {
  1331. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1332. // });
  1333. }
  1334. },
  1335. clipboardPasted(e, info) {
  1336. const hint = {
  1337. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1338. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1339. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1340. };
  1341. const range = info.cellRange;
  1342. const sortData = info.sheet.zh_data || [];
  1343. if (range.row + range.rowCount > sortData.length) {
  1344. toastMessageUniq(hint.cellError);
  1345. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1346. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1347. return;
  1348. }
  1349. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1350. toastMessageUniq(hint.cellError);
  1351. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1352. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1353. return;
  1354. }
  1355. const data = [];
  1356. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1357. let bPaste = true;
  1358. const curRow = range.row + iRow;
  1359. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  1360. const hintRow = range.rowCount > 1 ? curRow : '';
  1361. let sameCol = 0;
  1362. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1363. const curCol = range.col + iCol;
  1364. const colSetting = info.sheet.zh_setting.cols[curCol];
  1365. if (!colSetting) continue;
  1366. // let validText = info.sheet.getText(curRow, curCol);
  1367. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1368. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1369. const orgValue = sortData[curRow][colSetting.field];
  1370. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1371. sameCol++;
  1372. if (range.colCount === sameCol) {
  1373. bPaste = false;
  1374. }
  1375. continue;
  1376. }
  1377. const exprQuantity = {
  1378. expr: '',
  1379. quantity: 0,
  1380. };
  1381. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1382. if (!valid) {
  1383. toastMessageUniq(getPasteHint(msg, hintRow));
  1384. bPaste = false;
  1385. continue;
  1386. }
  1387. if (isNaN(exprQuantity.quantity)) {
  1388. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1389. bPaste = false;
  1390. continue;
  1391. }
  1392. const num = parseFloat(exprQuantity.quantity);
  1393. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1394. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1395. // bPaste = false;
  1396. // continue;
  1397. exprQuantity.quantity = ZhCalc.round(num, 6);
  1398. }
  1399. // materialData[colSetting.field] = validText;
  1400. materialData.expr = exprQuantity.expr;
  1401. materialData.quantity = exprQuantity.quantity;
  1402. }
  1403. if (bPaste) {
  1404. data.push(materialData);
  1405. // rowData.push(curRow);
  1406. } else {
  1407. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1408. }
  1409. }
  1410. if (data.length === 0) {
  1411. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1412. return;
  1413. }
  1414. const ledgerSheet = ledgerSpread.getActiveSheet();
  1415. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1416. const index = gclGatherData.indexOf(ledgerSelect);
  1417. const gcl = gclGatherData[index].leafXmjs;
  1418. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1419. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1420. // const xmjIndex = gcl.indexOf(xmjSelect);
  1421. const datas = [];
  1422. for (const xmj of gcl) {
  1423. const data2 = {
  1424. xmj_id: xmj.id,
  1425. gcl_id: xmj.gcl_id,
  1426. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1427. };
  1428. datas.push(data2);
  1429. }
  1430. if (isStageSelf) {
  1431. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1432. // 取所有的gclGatherData才行,然后获取下的值
  1433. const gclData = gclGatherData[index];
  1434. for (const [index, ms] of materialStageData.entries()) {
  1435. if (ms.id !== ms_id) {
  1436. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1437. console.log(gclOther);
  1438. if (gclOther) {
  1439. const leafXmjs = gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  1440. for (const xmj of leafXmjs) {
  1441. const data = {
  1442. xmj_id: xmj.id,
  1443. gcl_id: xmj.gcl_id,
  1444. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1445. };
  1446. if (_.indexOf(datas, data) === -1) {
  1447. datas.push(data);
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. }
  1454. console.log(data, datas);
  1455. // 更新至服务器
  1456. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1457. materialListData = result.materialListData;
  1458. gclList = result.gclList;
  1459. calculateJiaCha(gclGatherData);
  1460. // const index = gclGatherData.indexOf(ledgerSelect);
  1461. loadLeafXmjData(index);
  1462. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1463. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1464. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1465. loadMaterialData(index);
  1466. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1467. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1468. }, function () {
  1469. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1470. });
  1471. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1472. // materialListData = result;
  1473. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1474. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1475. // calculateJiaCha(gclGatherData, iGclRow);
  1476. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1477. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1478. // }, function () {
  1479. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1480. // });
  1481. },
  1482. _checkExprValid(expr) {
  1483. if (!expr) return [true, null];
  1484. const param = [];
  1485. let num = '', base = '';
  1486. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1487. if (/^[\d\.%]+/.test(expr[i])) {
  1488. if (base !== '') {
  1489. param.push({type: 'base', value: base});
  1490. base = '';
  1491. }
  1492. num = num + expr[i];
  1493. } else if (expr[i] === '(') {
  1494. if (num !== '') {
  1495. param.push({type: 'num', value: num});
  1496. num = '';
  1497. }
  1498. if (base !== '') {
  1499. param.push({type: 'base', value: base});
  1500. base = '';
  1501. }
  1502. param.push({type: 'left', value: '('});
  1503. } else if (expr[i] === ')') {
  1504. if (num !== '') {
  1505. param.push({type: 'num', value: num});
  1506. num = '';
  1507. }
  1508. if (base !== '') {
  1509. param.push({type: 'base', value: base});
  1510. base = '';
  1511. }
  1512. param.push({type: 'right', value: ')'});
  1513. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1514. if (num !== '') {
  1515. param.push({type: 'num', value: num});
  1516. num = '';
  1517. }
  1518. if (base !== '') {
  1519. param.push({type: 'base', value: base});
  1520. base = '';
  1521. }
  1522. param.push({type: 'calc', value: expr[i]});
  1523. } else {
  1524. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1525. }
  1526. }
  1527. if (num !== '') {
  1528. param.push({type: 'num', value: num});
  1529. num = '';
  1530. }
  1531. if (base !== '') {
  1532. param.push({type: 'base', value: base});
  1533. base = '';
  1534. }
  1535. if (param.length === 0) return true;
  1536. if (param.length > 1) {
  1537. if (param[0].value === '-') {
  1538. param[1].value = '-' + param[1];
  1539. }
  1540. param.unshift();
  1541. }
  1542. const iLen = param.length;
  1543. let iLeftCount = 0, iRightCount = 0;
  1544. for (const [i, p] of param.entries()) {
  1545. if (p.type === 'calc') {
  1546. if (i === 0 || i === iLen - 1)
  1547. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1548. }
  1549. if (p.type === 'num') {
  1550. num = p.value.replace('%', '');
  1551. if (p.value.length - num.length > 1)
  1552. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1553. num = _.toNumber(num);
  1554. if (num === undefined || num === null || _.isNaN(num))
  1555. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1556. if (i > 0) {
  1557. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1558. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1559. } else if (param[i - 1].value === '/' && num === 0) {
  1560. return [false, '输入的表达式非法:请勿除0'];
  1561. }
  1562. }
  1563. }
  1564. if (p.type === 'base') {
  1565. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1566. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1567. }
  1568. if (p.type === 'left') {
  1569. iLeftCount += 1;
  1570. if (i !== 0 && param[i-1].type !== 'calc')
  1571. return [false, '输入的表达式非法:(前应有运算符'];
  1572. }
  1573. if (p.type === 'right') {
  1574. iRightCount += 1;
  1575. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1576. return [false, '输入的表达式非法:)后应有运算符'];
  1577. if (iRightCount > iLeftCount)
  1578. return [false, '输入的表达式非法:")"前无对应的"("'];
  1579. }
  1580. }
  1581. if (iLeftCount > iRightCount)
  1582. return [false, '输入的表达式非法:"("后无对应的")"'];
  1583. return [true, ''];
  1584. },
  1585. _checkExpr: function (text, data) {
  1586. if (text) {
  1587. const num = _.toNumber(text);
  1588. if (num) {
  1589. data.quantity = num;
  1590. data.expr = '';
  1591. } else {
  1592. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1593. const [valid, msg] = this._checkExprValid(expr);
  1594. if (!valid) return [valid, msg];
  1595. data.expr = expr;
  1596. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace('%', '/100'));
  1597. // const ce = new CalcEvalMin();
  1598. // data.quantity = ce.eval(expr);
  1599. // console.log(data.quantity);
  1600. }
  1601. } else {
  1602. data.quantity = 0;
  1603. data.expr = '';
  1604. }
  1605. return [true, ''];
  1606. },
  1607. };
  1608. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  1609. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  1610. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  1611. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  1612. // material-spread右键功能
  1613. if (openMaterialSelf) {
  1614. const materialSelfSpreadObj = {
  1615. del: function () {
  1616. const sheet = materialSelfSpread.getActiveSheet();
  1617. const select = SpreadJsObj.getSelectObject(sheet);
  1618. console.log(select);
  1619. postData(window.location.pathname + '/save', {
  1620. type: 'del',
  1621. id: select.id,
  1622. mb_id: select.mb_id,
  1623. ms_id: $('#myTab').find('.active').data('msid') || null
  1624. }, function (result) {
  1625. const index = materialListSelf.indexOf(select);
  1626. materialListSelf.splice(index, 1);
  1627. sheet.deleteRows(index, 1);
  1628. SpreadJsObj.reLoadSheetData(materialSelfSpread.getActiveSheet());
  1629. const sel = sheet.getSelections();
  1630. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1631. const materialListIndex = materialListData.indexOf(select);
  1632. materialListData.splice(materialListIndex, 1);
  1633. const [iGclRow, iRow, nRow, lsheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1634. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1635. calculateJiaCha(gclGatherData, iGclRow);
  1636. SpreadJsObj.reLoadRowData(lsheet, nRow);
  1637. lsheet.getRange(nRow, -1, 1, -1).backColor(color);
  1638. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1639. });
  1640. },
  1641. deletePress: function (sheet) {
  1642. return;
  1643. },
  1644. editStarting: function (e, info) {
  1645. const col = info.sheet.zh_setting.cols[info.col];
  1646. const select = SpreadJsObj.getSelectObject(info.sheet);
  1647. if (col.field === 'quantity') {
  1648. if (select.expr && select.expr !== '') {
  1649. info.sheet.getCell(info.row, info.col).text(select.expr);
  1650. }
  1651. }
  1652. },
  1653. editEnded: function (e, info) {
  1654. if (info.sheet.zh_setting) {
  1655. const select = SpreadJsObj.getSelectObject(info.sheet);
  1656. const col = info.sheet.zh_setting.cols[info.col];
  1657. // 未改变值则不提交
  1658. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1659. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1660. // let orgValue = select[col.field];
  1661. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1662. let orgValue;
  1663. if (col.field === 'quantity') {
  1664. orgValue = validText && validText !== ''
  1665. ? _.toNumber(validText) ? select.quantity : select.expr
  1666. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1667. } else {
  1668. orgValue = select[col.field];
  1669. }
  1670. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1671. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1672. return;
  1673. }
  1674. const exprQuantity = {
  1675. expr: '',
  1676. quantity: 0,
  1677. };
  1678. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1679. if (!valid) {
  1680. toastr.error(msg);
  1681. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1682. return;
  1683. }
  1684. if (isNaN(exprQuantity.quantity)) {
  1685. toastr.error('不能输入其它非数字类型字符');
  1686. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1687. return;
  1688. }
  1689. const num = parseFloat(exprQuantity.quantity);
  1690. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1691. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1692. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1693. // return;
  1694. toastr.warning('已保留6位小数');
  1695. exprQuantity.quantity = ZhCalc.round(num, 6);
  1696. }
  1697. // 更新至服务器
  1698. console.log(exprQuantity, select.mb_id);
  1699. postData(window.location.pathname + '/save', {
  1700. type: 'update',
  1701. updateData: {
  1702. id: select.id,
  1703. expr: exprQuantity.expr,
  1704. quantity: exprQuantity.quantity,
  1705. mb_id: select.mb_id
  1706. },
  1707. ms_id: $('#myTab').find('.active').data('msid') || null
  1708. }, function (result) {
  1709. const materialListIndex = materialListData.indexOf(select);
  1710. const index = materialList.indexOf(select);
  1711. select.quantity = exprQuantity.quantity;
  1712. select.expr = exprQuantity.expr;
  1713. materialListData.splice(materialListIndex, 1, select);
  1714. materialList.indexOf(index, 1, select);
  1715. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1716. const [iGclRow, iRow, nRow, sheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1717. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1718. calculateJiaCha(gclGatherData, iGclRow);
  1719. SpreadJsObj.reLoadRowData(sheet, nRow);
  1720. console.log(lselect, color);
  1721. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1722. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1723. }, function () {
  1724. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1725. });
  1726. }
  1727. },
  1728. clipboardPasted(e, info) {
  1729. const hint = {
  1730. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1731. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1732. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1733. };
  1734. const range = info.cellRange;
  1735. const sortData = info.sheet.zh_data || [];
  1736. if (range.row + range.rowCount > sortData.length) {
  1737. toastMessageUniq(hint.cellError);
  1738. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1739. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1740. return;
  1741. }
  1742. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1743. toastMessageUniq(hint.cellError);
  1744. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1745. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1746. return;
  1747. }
  1748. const data = [];
  1749. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1750. let bPaste = true;
  1751. const curRow = range.row + iRow;
  1752. const materialData = {id: sortData[curRow].id, mb_id: sortData[curRow].mb_id};
  1753. const hintRow = range.rowCount > 1 ? curRow : '';
  1754. let sameCol = 0;
  1755. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1756. const curCol = range.col + iCol;
  1757. const colSetting = info.sheet.zh_setting.cols[curCol];
  1758. if (!colSetting) continue;
  1759. // let validText = info.sheet.getText(curRow, curCol);
  1760. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1761. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1762. const orgValue = sortData[curRow][colSetting.field];
  1763. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1764. sameCol++;
  1765. if (range.colCount === sameCol) {
  1766. bPaste = false;
  1767. }
  1768. continue;
  1769. }
  1770. const exprQuantity = {
  1771. expr: '',
  1772. quantity: 0,
  1773. };
  1774. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1775. if (!valid) {
  1776. toastMessageUniq(getPasteHint(msg, hintRow));
  1777. bPaste = false;
  1778. continue;
  1779. }
  1780. if (isNaN(exprQuantity.quantity)) {
  1781. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1782. bPaste = false;
  1783. continue;
  1784. }
  1785. const num = parseFloat(exprQuantity.quantity);
  1786. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1787. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1788. // bPaste = false;
  1789. // continue;
  1790. exprQuantity.quantity = ZhCalc.round(num, 6);
  1791. }
  1792. // materialData[colSetting.field] = validText;
  1793. materialData.expr = exprQuantity.expr;
  1794. materialData.quantity = exprQuantity.quantity;
  1795. }
  1796. if (bPaste) {
  1797. data.push(materialData);
  1798. // rowData.push(curRow);
  1799. } else {
  1800. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1801. }
  1802. }
  1803. if (data.length === 0) {
  1804. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1805. return;
  1806. }
  1807. console.log(data);
  1808. postData(window.location.pathname + '/save', {
  1809. type: 'paste',
  1810. updateData: data,
  1811. ms_id: $('#myTab').find('.active').data('msid') || null
  1812. }, function (result) {
  1813. materialListData = result;
  1814. const [iGclRow, iRow, nRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1815. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1816. calculateJiaCha(gclGatherData, iGclRow);
  1817. SpreadJsObj.reLoadRowData(sheet, nRow);
  1818. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1819. loadXmjMaterialData(iGclRow, nRow);
  1820. }, function () {
  1821. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1822. });
  1823. },
  1824. };
  1825. materialSelfSpread.bind(spreadNS.Events.EditStarting, materialSelfSpreadObj.editStarting);
  1826. materialSelfSpread.bind(spreadNS.Events.EditEnded, materialSelfSpreadObj.editEnded);
  1827. materialSelfSpread.bind(spreadNS.Events.ClipboardPasted, materialSelfSpreadObj.clipboardPasted);
  1828. SpreadJsObj.addDeleteBind(materialSelfSpread, materialSelfSpreadObj.deletePress);
  1829. if (!editForAudit) {
  1830. $.contextMenu({
  1831. selector: '#material-self-spread',
  1832. build: function ($trigger, e) {
  1833. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSelfSpread);
  1834. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1835. },
  1836. items: {
  1837. 'create': {
  1838. name: '添加工料',
  1839. icon: 'fa-sign-in',
  1840. callback: function (key, opt) {
  1841. // 获取已选清单
  1842. changeMaterialTable('self');
  1843. $('#add_type').val('self');
  1844. $('#addgl').modal('show');
  1845. },
  1846. disabled: function (key, opt) {
  1847. const sheet = leafXmjSpread.getActiveSheet();
  1848. const select = SpreadJsObj.getSelectObject(sheet);
  1849. // const notx = findNotJoinLeafXmj(select);
  1850. if (!select) {
  1851. return true;
  1852. }
  1853. // if (!readOnly && notx === undefined) {
  1854. // return false;
  1855. // } else {
  1856. // return true;
  1857. // }
  1858. return readOnly;
  1859. },
  1860. },
  1861. 'delete': {
  1862. name: '删除工料',
  1863. icon: 'fa-remove',
  1864. callback: function (key, opt) {
  1865. materialSelfSpreadObj.del(materialSelfSpread.getActiveSheet());
  1866. },
  1867. disabled: function (key, opt) {
  1868. const sheet = materialSelfSpread.getActiveSheet();
  1869. const select = SpreadJsObj.getSelectObject(sheet);
  1870. if (!select) {
  1871. return true;
  1872. }
  1873. if (!readOnly && select && materialSelfBase.isEdit(select, 'del')) {
  1874. return false;
  1875. } else {
  1876. return true;
  1877. }
  1878. }
  1879. },
  1880. }
  1881. });
  1882. }
  1883. }
  1884. if (!openMaterialChecklist && !editForAudit) {
  1885. $.contextMenu({
  1886. selector: '#material-spread',
  1887. build: function ($trigger, e) {
  1888. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1889. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1890. },
  1891. items: {
  1892. 'create': {
  1893. name: '添加工料',
  1894. icon: 'fa-sign-in',
  1895. callback: function (key, opt) {
  1896. // 获取已选清单
  1897. changeMaterialTable();
  1898. $('#add_type').val('all');
  1899. $('#addgl').modal('show');
  1900. },
  1901. disabled: function (key, opt) {
  1902. const sheet = leafXmjSpread.getActiveSheet();
  1903. const select = SpreadJsObj.getSelectObject(sheet);
  1904. // const notx = findNotJoinLeafXmj(select);
  1905. if (!select) {
  1906. return true;
  1907. }
  1908. // if (!readOnly && notx === undefined) {
  1909. // return false;
  1910. // } else {
  1911. // return true;
  1912. // }
  1913. return readOnly;
  1914. }
  1915. },
  1916. 'delete': {
  1917. name: '删除工料',
  1918. icon: 'fa-remove',
  1919. callback: function (key, opt) {
  1920. materialSpreadObj.del(materialSpread.getActiveSheet());
  1921. },
  1922. disabled: function (key, opt) {
  1923. const sheet = materialSpread.getActiveSheet();
  1924. const select = SpreadJsObj.getSelectObject(sheet);
  1925. if (!select) {
  1926. return true;
  1927. }
  1928. if (!readOnly && select && materialBase.isEdit(select, 'del')) {
  1929. return false;
  1930. } else {
  1931. return true;
  1932. }
  1933. }
  1934. },
  1935. }
  1936. });
  1937. }
  1938. }
  1939. // 应用调差工料至其他清单明细
  1940. $('#user_all_material').click(function () {
  1941. const ledgerSheet = ledgerSpread.getActiveSheet();
  1942. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1943. if (ledgerSelect.leafXmjs.length < 2) {
  1944. toastr.warning('没有需要应用调差工料的其它清单明细');
  1945. return false;
  1946. }
  1947. const xmjSheet = leafXmjSpread.getActiveSheet();
  1948. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1949. console.log(ledgerSelect.leafXmjs);
  1950. // 判断需要应用调差工料的清单明细
  1951. const needAddList = [];
  1952. for (const xmj of ledgerSelect.leafXmjs) {
  1953. const notx = findNotJoinLeafXmj(xmj);
  1954. if (notx === undefined && xmjSelect !== xmj && xmj.gather_qty && xmj.jiacha === null && xmjSelect.jiacha !== null) {
  1955. needAddList.push(xmj);
  1956. }
  1957. }
  1958. // if (needAddList.length === 0) {
  1959. // toastr.warning('没有需要应用调差工料的其它清单明细');
  1960. // return false;
  1961. // }
  1962. console.log(needAddList, materialList);
  1963. // 更新至服务器
  1964. postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  1965. materialListData = result.materialListData;
  1966. gclList = result.gclList;
  1967. toastr.success('已成功应用');
  1968. calculateJiaCha(gclGatherData);
  1969. const index = gclGatherData.indexOf(ledgerSelect);
  1970. loadLeafXmjData(index);
  1971. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1972. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1973. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1974. loadMaterialData(index);
  1975. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1976. });
  1977. });
  1978. // 切换清单行,读取所属项目节数据
  1979. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1980. if (info.oldSelections !== undefined) {
  1981. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1982. if (iNewRow !== iOldRow) {
  1983. loadLeafXmjData(iNewRow);
  1984. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  1985. loadMaterialData(iNewRow);
  1986. loadXmjMaterialData(iNewRow, 0);
  1987. checkNotJoinMaterialData();
  1988. }
  1989. }
  1990. });
  1991. // 切换项目节数据清单明细行,读取单独的清单工料数据
  1992. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1993. if (info.oldSelections !== undefined) {
  1994. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  1995. if (iNewRow !== iOldRow) {
  1996. const sheet = ledgerSpread.getActiveSheet();
  1997. const select = SpreadJsObj.getSelectObject(sheet);
  1998. const index = gclGatherData.indexOf(select);
  1999. loadXmjMaterialData(index, iNewRow);
  2000. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  2001. }
  2002. }
  2003. });
  2004. // 显示有调差工料清单
  2005. $('#show_material_gcl').click(function () {
  2006. if ($(this).is(':checked')) {
  2007. const hadMaterialGclGatherData = [];
  2008. const hadGclIdList = [];
  2009. for (const ml of materialListData) {
  2010. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  2011. hadGclIdList.push(ml.gcl_id);
  2012. }
  2013. }
  2014. for (const gcl of gclGatherData) {
  2015. for (const index in gcl.leafXmjs) {
  2016. const gcl_id = gcl.leafXmjs[index].gcl_id;
  2017. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  2018. hadMaterialGclGatherData.push(gcl);
  2019. break;
  2020. }
  2021. }
  2022. }
  2023. gclGatherData = hadMaterialGclGatherData;
  2024. } else {
  2025. if (isStageSelf) {
  2026. const ms_id = parseInt($('#myTab').find('.active').data('msid'));
  2027. updateBillsData(ms_id);
  2028. const i = _.findIndex(materialStageData, { id: ms_id });
  2029. gclGatherData = gclGatherListData[i];
  2030. } else {
  2031. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  2032. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  2033. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  2034. return item.qc_qty || item.contract_qty
  2035. });
  2036. }
  2037. if (openMaterialChecklist) {
  2038. // 取交集
  2039. gclGatherData = _.filter(gclGatherData, function (item) {
  2040. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  2041. });
  2042. }
  2043. }
  2044. calculateJiaCha(gclGatherData);
  2045. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  2046. loadLeafXmjData(0);
  2047. loadMaterialData(0);
  2048. loadXmjMaterialData(0, 0);
  2049. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  2050. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  2051. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  2052. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  2053. checkNotJoinMaterialData();
  2054. });
  2055. $.subMenu({
  2056. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2057. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2058. key: 'menu.1.0.0',
  2059. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2060. callback: function (info) {
  2061. if (info.mini) {
  2062. $('.panel-title').addClass('fluid');
  2063. $('#sub-menu').removeClass('panel-sidebar');
  2064. } else {
  2065. $('.panel-title').removeClass('fluid');
  2066. $('#sub-menu').addClass('panel-sidebar');
  2067. }
  2068. autoFlashHeight();
  2069. ledgerSpread.refresh();
  2070. leafXmjSpread.refresh();
  2071. materialSpread.refresh();
  2072. materialSelfSpread.refresh();
  2073. }
  2074. });
  2075. $(window).resize(function () {
  2076. ledgerSpread.refresh();
  2077. leafXmjSpread.refresh();
  2078. materialSpread.refresh();
  2079. materialSelfSpread.refresh();
  2080. });
  2081. $.divResizer({
  2082. select: '#right-spr',
  2083. callback: function () {
  2084. ledgerSpread.refresh();
  2085. // leafXmjSpread.refresh();
  2086. materialSpread.refresh();
  2087. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  2088. setLocalCache('material_list_' + materialID, width);
  2089. }
  2090. });
  2091. $.divResizer({
  2092. select: '#right-spr2',
  2093. callback: function () {
  2094. leafXmjSpread.refresh();
  2095. materialSelfSpread.refresh();
  2096. // const width = (($('#right-view2').width()/$('#right-view2').parent('div').width())*100).toFixed();
  2097. // setLocalCache('material_list3_' + materialID, width);
  2098. }
  2099. });
  2100. $.divResizer({
  2101. select: '#main-resize',
  2102. callback: function () {
  2103. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2104. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  2105. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2106. $(".sp-wrap").height(bcontent-30);
  2107. materialSpread.refresh();
  2108. ledgerSpread.refresh();
  2109. leafXmjSpread.refresh();
  2110. materialSelfSpread.refresh();
  2111. const height = $('.bcontent-wrap').height();
  2112. setLocalCache('material_list2_' + materialID, height);
  2113. }
  2114. });
  2115. // 展开收起月信息价并浏览器记住本期展开收起
  2116. $('a', '.right-nav').bind('click', function () {
  2117. //const main = $('#main-view'), tool = $('#tools-view');
  2118. const tab = $(this), tabPanel = $(tab.attr('content'));
  2119. if (!tab.hasClass('active')) {
  2120. $('a', '.side-menu').removeClass('active');
  2121. $('.tab-content .tab-select-show').removeClass('active');
  2122. tab.addClass('active');
  2123. tabPanel.addClass('active');
  2124. showSideTools(tab.hasClass('active'));
  2125. if (tab.attr('content') === '#material-tab') {
  2126. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  2127. setLocalCache('material_list_' + materialID, width);
  2128. }
  2129. } else {
  2130. removeLocalCache('material_list_' + materialID);
  2131. tab.removeClass('active');
  2132. tabPanel.removeClass('active');
  2133. showSideTools(tab.hasClass('active'));
  2134. }
  2135. ledgerSpread.refresh();
  2136. // leafXmjSpread.refresh();
  2137. materialSpread.refresh();
  2138. });
  2139. // 根据浏览器记录展开收起
  2140. if (getLocalCache('material_list_' + materialID)) {
  2141. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  2142. $('a', '.side-menu').removeClass('active');
  2143. $('.tab-content .tab-select-show').removeClass('active');
  2144. tab.addClass('active');
  2145. tabPanel.addClass('active');
  2146. $('#right-view').css('width', getLocalCache('material_list_' + materialID) + '%');
  2147. showSideTools(tab.hasClass('active'));
  2148. ledgerSpread.refresh();
  2149. // leafXmjSpread.refresh();
  2150. materialSpread.refresh();
  2151. }
  2152. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  2153. if (getLocalCache('material_list2_' + materialID)) {
  2154. $('.bcontent-wrap').height(getLocalCache('material_list2_' + materialID));
  2155. const cHeader = getObjHeight($(".c-header"));
  2156. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2157. $(".sp-wrap").height(bcontent-30);
  2158. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  2159. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2160. materialSpread.refresh();
  2161. ledgerSpread.refresh();
  2162. leafXmjSpread.refresh();
  2163. materialSelfSpread.refresh();
  2164. } else {
  2165. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2166. ledgerSpread.refresh();
  2167. }
  2168. function getObjHeight(select) {
  2169. return select.length > 0 ? select.height() : 0;
  2170. }
  2171. const showSelfSideTools = function (show) {
  2172. const left = $('#left-view2'), right = $('#right-view2'), parent = left.parent();
  2173. if (show) {
  2174. right.show();
  2175. autoFlashHeight();
  2176. /**
  2177. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  2178. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  2179. * 故需要通过最终的parent.width再计算一次left.width
  2180. *
  2181. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  2182. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  2183. *
  2184. */
  2185. //left.css('width', parent.width() - right.outerWidth());
  2186. //left.css('width', parent.width() - right.outerWidth());
  2187. const percent = 100 - right.outerWidth() /parent.width() * 100;
  2188. left.css('width', percent + '%');
  2189. } else {
  2190. // left.css('width', parent.width());
  2191. left.css('width', '100%');
  2192. right.hide();
  2193. }
  2194. };
  2195. });