material_list.js 108 KB

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