glj_view.js 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  1. /**
  2. * Created by CSL on 2017-05-12.
  3. */
  4. var gljOprObj = {
  5. sheet: null,
  6. libID: null,
  7. ration: null,
  8. sheetData: [],
  9. coeSheetData: [],
  10. checkb: null,
  11. coeSheet: null,
  12. assSheet: null,
  13. assSheetData: [],
  14. detailSheet: null,
  15. detailData: [],
  16. GLJSelection: [],
  17. selectedGLJClass: null,
  18. parentNodeIds: {},
  19. activeTab: '#linkGLJ',
  20. setting: {
  21. header: [
  22. {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
  23. {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
  24. {headerName: "规格型号", headerWidth: 90, dataCode: "specs", dataType: "String", hAlign: "left"},
  25. {headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center"},
  26. {headerName: "类型", headerWidth: 45, dataCode: "shortName", dataType: "String", hAlign: "center"},
  27. {
  28. headerName: "定额消耗",
  29. headerWidth: 80,
  30. dataCode: "rationItemQuantity",
  31. dataType: "Number",
  32. hAlign: "right",
  33. decimalField: "glj.quantity"
  34. }, // dataType: "Number", formatter: "0.00"
  35. {
  36. headerName: "自定消耗",
  37. headerWidth: 80,
  38. dataCode: "customQuantity",
  39. dataType: "Number",
  40. hAlign: "right",
  41. decimalField: "glj.quantity"
  42. },
  43. {
  44. headerName: "消耗量",
  45. headerWidth: 80,
  46. dataCode: "quantity",
  47. dataType: "Number",
  48. hAlign: "right",
  49. decimalField: "glj.quantity"
  50. },
  51. {
  52. headerName: "总消耗量",
  53. headerWidth: 80,
  54. dataCode: "totalQuantity",
  55. dataType: "Number",
  56. hAlign: "right",
  57. decimalField: "glj.quantity"
  58. },
  59. {
  60. headerName: "定额价",
  61. headerWidth: 80,
  62. dataCode: "basePrice",
  63. dataType: "Number",
  64. hAlign: "right",
  65. decimalField: "glj.unitPrice"
  66. },
  67. {
  68. headerName: "调整价",
  69. headerWidth: 80,
  70. dataCode: "adjustPrice",
  71. dataType: "Number",
  72. hAlign: "right",
  73. decimalField: "glj.unitPrice"
  74. },
  75. {
  76. headerName: "市场价",
  77. headerWidth: 80,
  78. dataCode: "marketPrice",
  79. dataType: "Number",
  80. hAlign: "right",
  81. decimalField: "glj.unitPrice"
  82. },
  83. {
  84. headerName: "是否暂估",
  85. headerWidth: 65,
  86. dataCode: "isEstimate",
  87. dataType: "String",
  88. hAlign: "center",
  89. vAlign: "center",
  90. cellType: "checkBox"
  91. }
  92. ],
  93. view: {
  94. comboBox: [{row: -1, col: 12, rowCount: -1, colCount: 1}],
  95. lockedCells: [{row: -1, col: 3, rowCount: -1, colCount: 1}],
  96. lockColumns: [0, 4, 5, 7, 8, 10, 12]
  97. },
  98. // 工料机类型是混凝土、砂浆、配合比、机械台班时,价格不可编辑。
  99. editedTyep:[GLJTypeConst.MAIN_MATERIAL,GLJTypeConst.EQUIPMENT]//主材设备
  100. },
  101. coeSetting: {
  102. header: [
  103. {headerName: "调整", headerWidth: 100, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"},
  104. {headerName: "条件", headerWidth: 120, dataCode: "name", dataType: "String", cellType: "button"},
  105. {headerName: "内容", headerWidth: 350, dataCode: "content", dataType: "String", hAlign: "left"}
  106. ],
  107. view: {
  108. lockColumns: [0, 1, 2]
  109. }
  110. },
  111. assSetting: {
  112. header: [
  113. {headerName: "调整名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  114. {headerName: "定额值", headerWidth: 120, dataCode: "stdValue", hAlign: "right", dataType: "String"},
  115. {headerName: "实际值", headerWidth: 120, dataCode: "actualValue", hAlign: "right", dataType: "String"}
  116. ],
  117. view: {
  118. lockColumns: [0, 1]
  119. }
  120. },
  121. detailSetting: {
  122. header: [
  123. {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  124. {headerName: "计算式", headerWidth: 120, dataCode: "regex", dataType: "String"},
  125. {
  126. headerName: "结果(C)",
  127. headerWidth: 120,
  128. dataCode: "result",
  129. dataType: "Number",
  130. decimalField: "quantity_detail"
  131. },
  132. {headerName: "累加", headerWidth: 120, dataCode: "isSummation", dataType: "String", cellType: "checkBox"}
  133. ],
  134. view: {
  135. lockColumns: [2, 3]
  136. }
  137. },
  138. gljTreeSetting: {
  139. view: {
  140. //addHoverDom: gljTypeTreeOprObj.addHoverDom,
  141. //removeHoverDom: gljTypeTreeOprObj.removeHoverDom,
  142. expandSpeed: "",
  143. selectedMulti: false
  144. },
  145. edit: {
  146. enable: false,
  147. editNameSelectAll: true,
  148. showRemoveBtn: true,
  149. showRenameBtn: true,
  150. removeTitle: "删除节点",
  151. renameTitle: "更改名称"
  152. },
  153. data: {
  154. keep: {
  155. parent: true,
  156. leaf: true
  157. },
  158. key: {
  159. children: "items",
  160. name: "Name"
  161. },
  162. simpleData: {
  163. enable: false,
  164. idKey: "ID",
  165. pIdKey: "ParentID",
  166. rootPId: -1
  167. }
  168. },
  169. callback: {
  170. onClick: function (event, treeId, treeNode) {
  171. if (treeId == 'gljTree') {
  172. let me = gljOprObj, gljTypeId = treeNode.ID;
  173. if (treeNode.ID) {
  174. me.gljCurTypeId = treeNode.ID;
  175. me.filterLibGLJSheetData();
  176. me.showLibGLJSheetData();
  177. }
  178. } else {
  179. if (treeNode.isParent) {
  180. $('#class_selected_conf').attr("disabled", "disabled");
  181. $('#selected_class').val("");
  182. } else {
  183. $('#class_selected_conf').removeAttr("disabled");
  184. $('#selected_class').val(treeNode.ID);
  185. }
  186. }
  187. }
  188. }
  189. },
  190. gljLibSheetSetting: {
  191. owner: 'gljTree',
  192. header: [
  193. {
  194. headerName: "选择",
  195. headerWidth: 40,
  196. dataCode: "select",
  197. hAlign: "center",
  198. vAlign: "center",
  199. cellType: "checkBox"
  200. },
  201. {
  202. headerName: "编码",
  203. headerWidth: 80,
  204. dataCode: "code",
  205. dataType: "String",
  206. formatter: "@",
  207. hAlign: "left",
  208. vAlign: "center"
  209. },
  210. {
  211. headerName: "名称",
  212. headerWidth: 120,
  213. dataCode: "name",
  214. dataType: "String",
  215. hAlign: "left",
  216. vAlign: "center"
  217. },
  218. {
  219. headerName: "规格型号",
  220. headerWidth: 80,
  221. dataCode: "specs",
  222. dataType: "String",
  223. hAlign: "center",
  224. vAlign: "center"
  225. },
  226. {
  227. headerName: "单位",
  228. headerWidth: 40,
  229. dataCode: "unit",
  230. dataType: "String",
  231. hAlign: "center",
  232. vAlign: "center"
  233. },
  234. {
  235. headerName: "单价",
  236. headerWidth: 80,
  237. dataCode: "basePrice",
  238. dataType: "Number",
  239. formatter: "0.00",
  240. hAlign: "right",
  241. vAlign: "center"
  242. },
  243. {
  244. headerName: "类型",
  245. headerWidth: 80,
  246. dataCode: "gljType",
  247. dataType: "String",
  248. hAlign: "center",
  249. vAlign: "center"
  250. },
  251. {
  252. headerName: "是否新增",
  253. headerWidth: 80,
  254. dataCode: "isComplementary",
  255. dataType: "String",
  256. hAlign: "center",
  257. vAlign: "center",
  258. cellType: "checkBox"
  259. }
  260. ],
  261. view: {
  262. lockColumns: [0, 1, 2, 3, 4, 5, 6]
  263. }
  264. },
  265. gljLibSheet: null,
  266. initSheet: function (sheet) {
  267. var me = this;
  268. me.sheet = sheet;
  269. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  270. sheet.name('ration_glj');
  271. me.bindSheetEvent(sheet);
  272. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  273. sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
  274. sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);
  275. gljContextMenu.loadGLJSpreadContextMenu();
  276. },
  277. initCoeSheet: function (sheet) {
  278. var me = this;
  279. me.coeSheet = sheet;
  280. sheetCommonObj.initSheet(me.coeSheet, me.coeSetting, 30);
  281. sheet.name('ration_coe');
  282. me.bindSheetEvent(sheet);
  283. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCoeCellClick);
  284. subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
  285. },
  286. initAssSheet: function (sheet) {
  287. var me = this;
  288. me.assSheet = sheet;
  289. sheetCommonObj.initSheet(me.assSheet, me.assSetting, 30);
  290. sheet.name('ration_ass');
  291. me.bindSheetEvent(sheet);
  292. },
  293. initDetailSheet: function (sheet) {
  294. var me = this;
  295. me.detailSheet = sheet;
  296. sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
  297. // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
  298. sheet.name('quantity_detail');
  299. me.bindSheetEvent(sheet);
  300. sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
  301. let selected = projectObj.project.mainTree.selected;
  302. if(selected&&selected.sourceType == ModuleNames.ration_glj){//是主材或者是设备时只读
  303. args.cancel = true;
  304. }else {
  305. if(args.sheet.getValue(args.row,args.col)==null){//这里是为了解决当单元格里的值是null的时候,在单元格里输入数据,按键盘箭头移动光标的时候,会直接结束编辑,跳到另外的单元格。
  306. args.sheet.setValue(args.row,args.col,"");
  307. }
  308. }
  309. });
  310. },
  311. showCoeData: function (sheet, setting, datas) {
  312. sheet.floatingObjects.remove("customerCoe");
  313. sheetCommonObj.showData(sheet, setting, datas);
  314. if (datas.length > 0) {
  315. var cus_index = _.findIndex(datas, function (item) {
  316. return item.coeID == -1;
  317. })
  318. if (cus_index != -1) {
  319. this.addDropDownList();
  320. this.addCusButton(cus_index, 1, datas[cus_index].name);
  321. }
  322. }
  323. },
  324. bindSheetEvent: function (sheet) {
  325. var me = this;
  326. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  327. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  328. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  329. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  330. // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  331. },
  332. onClipboardPasting: function (sender, args) {
  333. var me = gljOprObj;
  334. if (!me.ration) {
  335. args.cancel = true;
  336. }
  337. },
  338. onClipboardPasted: function (e, info) {
  339. var me = gljOprObj;
  340. console.log('past');
  341. // if (!me.ration) {return;};
  342. // your code...
  343. },
  344. onEditEnded: function (sender, args) {
  345. var me = gljOprObj;
  346. if (args.sheetName == 'ration_glj') {
  347. me.onEditGLJSheet(args)
  348. }
  349. if (args.sheetName == 'ration_ass') {
  350. me.onEditAssSheet(args);
  351. }
  352. if (args.sheetName == 'quantity_detail') {
  353. me.onEditDetailSheet(args);
  354. }
  355. },
  356. onEditDetailSheet: function (args) {
  357. var me = gljOprObj;
  358. if (args.row > me.detailData.length) {
  359. return;
  360. }
  361. if (args.row == me.detailData.length && args.editingText == null) {
  362. return;
  363. }
  364. var selected = projectObj.project.mainTree.selected;//因为使用了延时方法,所以要先取得选中行;
  365. var detailList = me.detailData;
  366. args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
  367. args.editingText = args.editingText.replace(/)/g, ")");
  368. setTimeout(function () {//这里须用延时执行的办法,不然的弹窗确认窗口会和spreadjs 的事件有冲突,造成定额工料机数据不会根据树结点更新的问题
  369. if (args.row == detailList.length) {
  370. projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected);
  371. }
  372. if (args.row < detailList.length) {
  373. projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected);
  374. }
  375. }, 100);
  376. },
  377. onEditGLJSheet: function (args) {
  378. var me = gljOprObj;
  379. if (args.row >= me.sheetData.length) {
  380. me.sheet.getCell(args.row, args.col).value(null);
  381. return;
  382. }
  383. me.updateRationGLJ(args);
  384. },
  385. onEditAssSheet: function (args) {
  386. var me = gljOprObj;
  387. if (args.row >= me.assSheetData.length) {
  388. me.assSheet.getCell(args.row, args.col).value(null);
  389. return;
  390. }
  391. if (me.assSetting.header[args.col].dataCode == 'actualValue') {//自定义消耗量
  392. me.updateRationAss(args);
  393. }
  394. },
  395. onButtonClick: function (sender, args) {
  396. if(args.sheet.isEditing()){
  397. args.sheet.endEdit();
  398. }
  399. var me = gljOprObj;
  400. var sheet = args.sheet, row = args.row, col = args.col;
  401. var cellType = sheet.getCellType(row, col);
  402. if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
  403. if(args.sheetName == 'ration_coe'){
  404. me.onCusButtonClick(sender, args);
  405. }else if(args.sheetName == 'rationInstallSheet'){
  406. installationFeeObj.onPositionButtonClick(sender,args);
  407. }
  408. } else {
  409. me.onCheckBoxClick(sender, args)
  410. }
  411. },
  412. onCheckBoxClick: function (sender, args) {
  413. let selected = projectObj.project.mainTree.selected;
  414. if(selected.sourceType == ModuleNames.ration_glj){//选中的是工料机时不可编辑
  415. return ;
  416. }
  417. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  418. if(args.sheetName == 'rationInstallSheet' && checkboxValue){
  419. return;
  420. }
  421. let newval = 0;
  422. if (checkboxValue) {
  423. newval = 0;
  424. args.sheet.getCell(args.row, args.col).value(newval);
  425. } else {
  426. newval = 1;
  427. args.sheet.getCell(args.row, args.col).value(newval);
  428. }
  429. if (args.sheetName == 'ration_glj') {
  430. gljOprObj.updateIsEstimate(args,newval);
  431. } else if (args.sheetName == 'ration_coe') {
  432. gljOprObj.updateRationCoe(args, newval)
  433. } else if (args.sheetName == 'quantity_detail') {
  434. projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
  435. } else if (args.sheetName == 'glj_lib') {
  436. gljOprObj.setGLJSelection(args, newval);
  437. }else if(args.sheetName == 'rationInstallSheet'){
  438. args.newValue = newval;
  439. installationFeeObj.onRationInstallValueChange(sender,args);
  440. }
  441. },
  442. onCusButtonClick: function (sender, args) {
  443. var me = gljOprObj;
  444. var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
  445. var isVisable = floatingObject.isVisible();
  446. if (!isVisable) {
  447. me.coeSheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  448. me.showFloationObject(floatingObject, me.coeSheetData[args.row]);
  449. } else {
  450. var result = me.checkIfNeedUpdate();
  451. if (result.isNeed) {
  452. projectObj.project.ration_coe.updateCustomerCoe(result);
  453. }
  454. floatingObject.isVisible(false);
  455. }
  456. },
  457. onCellClick: function (sender, args) {
  458. var me = gljOprObj;
  459. if (args.row >= me.sheetData.length) {
  460. return;
  461. }
  462. me.editChecking(args);
  463. },
  464. onCellDoubleClick:function (sender, args) {
  465. var me = gljOprObj;
  466. var header = me.setting.header;
  467. if (args.row >= me.sheetData.length) {
  468. return;
  469. }
  470. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  471. if(me.hasComposition(me.sheetData[args.row])){
  472. alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
  473. }
  474. }
  475. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  476. var isAdd = me.sheetData[args.row].isAdd;
  477. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  478. if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
  479. alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
  480. }
  481. }
  482. }
  483. },
  484. onClipboardChanged: function (sender, info) {
  485. let cDatas = sheetCommonObj.getTableData(info.sheet, null);
  486. sheetCommonObj.copyTextToClipboard(cDatas);
  487. return;
  488. },
  489. onCoeCellClick: function (sender, args) {
  490. var me = gljOprObj;
  491. var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
  492. var isVisable = floatingObject.isVisible();
  493. /* if($('#dropdown').css("display") == 'none'){
  494. if(args.col==1&&me.coeSheetData.length>args.row&&me.coeSheetData[args.row].coeID==-1){
  495. me.showFloationObject(floatingObject,me.coeSheetData[args.row]);
  496. }
  497. }*/
  498. if (isVisable) {
  499. var result = me.checkIfNeedUpdate();
  500. if (result.isNeed) {
  501. projectObj.project.ration_coe.updateCustomerCoe(result);
  502. }
  503. floatingObject.isVisible(false);
  504. // $('#dropdown').hide();
  505. }
  506. },
  507. showFloationObject(floatingObject, data){
  508. floatingObject.isVisible(true);
  509. var sheet = this.coeSheet;
  510. var startRow = this.coeSheetData.length;
  511. var endRow = startRow + 7;
  512. floatingObject.startRow(startRow);
  513. floatingObject.startColumn(1);
  514. floatingObject.endColumn(2);
  515. floatingObject.endRow(endRow);
  516. this.bindFloadingObjectValue(data);
  517. sheet.repaint();
  518. // var editPosition = $("#edit").offset();
  519. //$('#dropdown').show();
  520. //var top =editPosition.top>=825?825:editPosition.top
  521. //$('#dropdown').offset({left:editPosition.left,top:top});//top: 791px; left:70px;
  522. },
  523. bindFloadingObjectValue(data){
  524. $('#coe_ration').val(data.coes[0].amount);
  525. $('#manual').val(data.coes[1].amount);
  526. $('#material').val(data.coes[2].amount);
  527. $('#manchine').val(data.coes[3].amount);
  528. $('#mainM').val(data.coes[4].amount);
  529. $('#equipment').val(data.coes[5].amount);
  530. },
  531. onInputChange(id, name){
  532. var coe = _.find(gljOprObj.coeSheetData, function (c) {
  533. return c.coeID == -1;
  534. });
  535. var newValue = gljOprObj.numberValueChecking($('#' + id).val());
  536. if (newValue) {
  537. newValue = _.round(newValue, 2);
  538. if (newValue == coe.coes[name].amount) return;
  539. if (id == 'coe_ration') {
  540. $('#coe_ration').val(newValue);
  541. $('#manual').val(newValue);
  542. $('#material').val(newValue);
  543. $('#manchine').val(newValue);
  544. $('#mainM').val(newValue);
  545. $('#equipment').val(newValue);
  546. } else {
  547. $('#' + id).val(newValue);
  548. }
  549. } else {
  550. $('#' + id).val(coe.coes[name].amount);
  551. }
  552. },
  553. checkIfNeedUpdate(){
  554. var data = _.find(gljOprObj.coeSheetData, function (c) {
  555. return c.coeID == -1;
  556. });
  557. var result = {
  558. isNeed: false
  559. }
  560. var coe_ration = $('#coe_ration').val();
  561. var manual = $('#manual').val();
  562. var material = $('#material').val();
  563. var manchine = $('#manchine').val();
  564. var mainM = $('#mainM').val();
  565. var equipment = $('#equipment').val();
  566. if (coe_ration != data.coes[0].amount) {
  567. result.isNeed = true;
  568. data.coes[0].amount = coe_ration;
  569. }
  570. if (manual != data.coes[1].amount) {
  571. result.isNeed = true;
  572. data.coes[1].amount = manual;
  573. }
  574. if (material != data.coes[2].amount) {
  575. result.isNeed = true;
  576. data.coes[2].amount = material;
  577. }
  578. if (manchine != data.coes[3].amount) {
  579. result.isNeed = true;
  580. data.coes[3].amount = manchine;
  581. }
  582. if (mainM != data.coes[4].amount) {
  583. result.isNeed = true;
  584. data.coes[4].amount = mainM;
  585. }
  586. if (equipment != data.coes[5].amount) {
  587. result.isNeed = true;
  588. data.coes[5].amount = equipment;
  589. }
  590. if (result.isNeed) {
  591. result.doc = {
  592. coes: data.coes
  593. };
  594. result.query = {
  595. projectID: data.projectID,
  596. ID: data.ID,
  597. rationID: data.rationID
  598. };
  599. }
  600. return result;
  601. },
  602. editChecking: function (args) {
  603. var me = gljOprObj;
  604. var header = me.setting.header;
  605. var disable = null;
  606. if (me.sheetData[args.row] != undefined) {
  607. if (me.sheetData[args.row].isMixRatio) {
  608. disable = true;
  609. }else {
  610. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  611. if(me.marketPriceReadOnly({data:me.sheetData[args.row]})){
  612. disable = true;
  613. }else {
  614. disable = false;
  615. }
  616. }
  617. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  618. var isAdd = me.sheetData[args.row].isAdd;
  619. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  620. if(me.marketPriceReadOnly({data:me.sheetData[args.row]})){//如果有组成物,不可修改
  621. disable = true;
  622. }else {
  623. disable = false;
  624. }
  625. } else {
  626. disable = true;
  627. }
  628. }
  629. }
  630. }
  631. if (disable != null) {
  632. me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(disable);
  633. }
  634. },
  635. hasComposition:function (ration_glj,isRationType) {//判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
  636. let type = isRationType==true? ration_glj.subType:ration_glj.type;
  637. if(notEditType.indexOf(type)!=-1||type==gljType.MAIN_MATERIAL){
  638. let keyArray = isRationType==true? rationKeyArray:gljKeyArray;
  639. let con_key = this.getIndex(ration_glj,keyArray);
  640. var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  641. if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
  642. return true;
  643. }
  644. }
  645. return false;
  646. },
  647. addDropDownList: function () {
  648. var sheet = this.coeSheet;
  649. sheet.suspendPaint();
  650. var customFloatingObject = new GC.Spread.Sheets.FloatingObjects.FloatingObject("customerCoe");
  651. var div = document.createElement('div');
  652. div.innerHTML = this.generateHtmlString();
  653. customFloatingObject.startRow(1);
  654. customFloatingObject.startColumn(1);
  655. customFloatingObject.endColumn(2);
  656. customFloatingObject.endRow(2);
  657. $(div).css('background', 'white');
  658. customFloatingObject.content(div);
  659. sheet.floatingObjects.add(customFloatingObject);
  660. customFloatingObject.isVisible(false);
  661. sheet.resumePaint();
  662. },
  663. addCusButton: function (row, col, text) {
  664. var cus_button = new GC.Spread.Sheets.CellTypes.Button();
  665. gljOprObj.coeSheet.setCellType(row, col, cus_button, GC.Spread.Sheets.SheetArea.viewport);
  666. cus_button.marginLeft(0);
  667. cus_button.marginTop(0);
  668. cus_button.marginRight(0);
  669. cus_button.marginBottom(0);
  670. cus_button.text(text);
  671. cus_button.buttonBackColor('white');
  672. gljOprObj.coeSheet.repaint();
  673. },
  674. onRangeChanged: function (sender, args) {
  675. var me = gljOprObj;
  676. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  677. args.editingText = null;
  678. if (args.sheetName == 'ration_glj') {
  679. me.onEditGLJSheet(args);
  680. }
  681. if (args.sheetName == 'ration_ass') {
  682. me.updateRationAss(args);
  683. }
  684. }
  685. },
  686. generateHtmlString: function () {
  687. // return "<div id='edit'><div>";
  688. var newString = "<form ><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;>";
  689. //newString +="<tr><td style='height:15px' colspan='2'>自定义系数</td></tr>"
  690. newString += this.getOneRow('定额', 0, 'coe_ration');
  691. newString += this.getOneRow('人工', 1, 'manual');
  692. newString += this.getOneRow('材料', 2, 'material');
  693. newString += this.getOneRow('机械', 3, 'manchine');
  694. newString += this.getOneRow('主材', 4, 'mainM');
  695. newString += this.getOneRow('设备', 5, 'equipment');
  696. newString += "</table></form>";
  697. return newString;
  698. //"<form id='edit'><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;><tr style='height:10px'><td style='width: 50px'>定额:</td><td style='width: 70px' align='right'><input type='text'value='1' name='ration' style='width:30px;border:0;height:14px' align='right'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr ><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr></table></form>";
  699. },
  700. getOneRow: function (text, name, id) {
  701. var rowstr = "<tr style='height:10px'><td style='width: 50px'>" + text
  702. + ":</td><td style='width: 70px' align='right'><input type='text'value='1' name=" + name
  703. + " style='width:30px;border:0;height:14px' align='right' id=" + id + " onchange='gljOprObj.onInputChange(this.id,this.name)'></td></tr>";
  704. return rowstr;
  705. },
  706. showDataIfRationSelect: function (node) {
  707. var isShow = false;
  708. if (node) {
  709. if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
  710. return;
  711. } else {
  712. this.selectedNodeId = node.getID();
  713. }
  714. if (node.sourceType == "ration") {
  715. if(node.data.type==rationType.gljRation){
  716. this.showMixRatio(node);
  717. }else {
  718. this.showRationGLJData(node);
  719. this.showRationCoeData(node);
  720. this.showRationAssData(node);
  721. installationFeeObj.showRationInstallationData(node);
  722. }
  723. isShow = true;
  724. }
  725. if(node.sourceType == ModuleNames.ration_glj){
  726. this.showMixRatio(node);
  727. isShow = true;
  728. }
  729. this.showQuantityDetailData(node);
  730. } else {
  731. this.selectedNodeId = null;
  732. }
  733. if (!isShow) {
  734. this.clearSheetData();
  735. }
  736. //hide floatingObject
  737. var floatingObject = this.coeSheet.floatingObjects.get('customerCoe');
  738. if (floatingObject) {
  739. floatingObject.isVisible(false);
  740. }
  741. // $('#dropdown').hide();
  742. },
  743. showMixRatio:function (node) {//显示组成物到定额工料机
  744. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  745. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  746. let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
  747. let connect_index = this.getIndex(node.data,indexArray);
  748. let gljList=[];
  749. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  750. gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  751. }
  752. if(gljList.length>0){//计算总消耗量
  753. if(node.sourceType==ModuleNames.ration){
  754. this.calcMixRationTotalQuantity(gljList,node.data.quantity);
  755. }else {
  756. let totalQuantity = this.getTotalQuantity(node.data);
  757. this.calcMixRationTotalQuantity(gljList,totalQuantity)
  758. }
  759. }
  760. this.sheetData = gljList;
  761. this.sheet.setRowCount(0);
  762. this.sheetData = sortRationGLJ(this.sheetData);
  763. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
  764. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  765. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  766. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  767. sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
  768. sheetCommonObj.showData(this.assSheet, this.assSetting, []);
  769. this.coeSheetData = [];
  770. this.assSheetData = [];
  771. },
  772. showRationGLJData: function (node) {
  773. var gljList = [];
  774. var ration_glj = projectObj.project.ration_glj;
  775. node = node ? node : projectObj.project.mainTree.selected;
  776. if (node.sourceType == ModuleNames.ration) {
  777. if(node.data.type==rationType.gljRation){
  778. this.showMixRatio(node);
  779. }else {
  780. let ration = node.data;
  781. gljList = this.filterGljByRation(ration, ration_glj.datas);
  782. this.showInSheet(gljList);
  783. }
  784. }else if(node.sourceType == ModuleNames.ration_glj){
  785. this.showMixRatio(node);
  786. }
  787. },
  788. showRationGLJSheetData: function (init) {
  789. let selected = this.sheet.getSelections();
  790. this.combineWithProjectGlj(this.sheetData);
  791. this.sheet.setRowCount(0);
  792. //console.log(+new Date())
  793. //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
  794. this.sheetData = sortRationGLJ(this.sheetData);
  795. this.sumQuantity();//计算总消耗量
  796. this.addMixRatioToShow();//显示组成物信息
  797. this.initRationTree(init);
  798. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  799. if(selected){//定位光标到之前的位置
  800. this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
  801. }
  802. },
  803. initRationTree: function (init) {
  804. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
  805. for (var i = 0; i < this.sheetData.length; i++) {
  806. if (this.sheetData[i].hasOwnProperty('subList')) {
  807. /* var collapsed = false;
  808. if (init) {
  809. this.sheetData[i].collapsed = true;
  810. collapsed = true;
  811. } else {
  812. collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  813. }*/
  814. var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  815. if (collapsed == true) {
  816. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  817. }
  818. //this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).visible(!collapsed);// this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).locked(true);
  819. //这个方法导致加载缓慢
  820. }
  821. }
  822. },
  823. filterGljByRation: function (ration, datas) {
  824. var gljList = [];
  825. if (datas && datas.length > 0) {
  826. gljList = _.filter(datas, {'rationID': ration.ID})
  827. }
  828. return gljList;
  829. },
  830. showInSheet: function (gljList) {
  831. this.sheetData = gljList;
  832. this.showRationGLJSheetData(true);
  833. },
  834. sumQuantity: function (node) {
  835. if (this.sheetData.length > 0) {
  836. node = node ? node : projectObj.project.mainTree.selected;
  837. let ration = node.data;
  838. let quantity = ration.quantity;
  839. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  840. for (let glj of this.sheetData) {
  841. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  842. }
  843. }
  844. },
  845. getTotalQuantity:function(glj,ration){
  846. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  847. if(ration){
  848. let quantity = ration.quantity;
  849. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  850. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  851. return;
  852. }
  853. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  854. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  855. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  856. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  857. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  858. }
  859. return glj.totalQuantity;
  860. }
  861. },
  862. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  863. for (let subG of mList) {
  864. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  865. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  866. }
  867. },
  868. addMixRatioToShow: function () {
  869. var newList = [];
  870. _.remove(this.sheetData, {'isMixRatio': true});
  871. for (var i = 0; i < this.sheetData.length; i++) {
  872. newList.push(this.sheetData[i]);
  873. if (this.sheetData[i].hasOwnProperty('subList')) {
  874. newList = newList.concat(this.sheetData[i].subList);
  875. }
  876. }
  877. this.sheetData = newList;
  878. },
  879. combineWithProjectGlj: function (ration_gljs) {
  880. var projectGLJData = projectObj.project.projectGLJ.datas;
  881. var projectGljs = projectGLJData.gljList;
  882. var mixRatioMap = projectGLJData.mixRatioMap;
  883. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  884. for (var i = 0; i < ration_gljs.length; i++) {
  885. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  886. if (glj) {
  887. let typeString = ration_gljs[i].type + "";
  888. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
  889. ration_gljs[i].isEstimate = glj.is_evaluate;
  890. }
  891. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  892. ration_gljs[i].isAdd = glj.unit_price.is_add;
  893. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  894. var connect_index = this.getIndex(glj, gljKeyArray);
  895. if (mixRatioMap.hasOwnProperty(connect_index)) {
  896. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  897. ration_gljs[i].subList = mixRatios;
  898. }
  899. }
  900. }
  901. }
  902. return ration_gljs;
  903. },
  904. setGLJPrice:function (data,glj) {
  905. let proGLJ = projectObj.project.projectGLJ;
  906. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  907. if(this.calcPriceDiff(glj)==true) {//计取价差
  908. data.basePrice = proGLJ.getBasePrice(glj);
  909. data.marketPrice = proGLJ.getMarketPrice(glj);
  910. data.adjustPrice = proGLJ.getAdjustPrice(glj);
  911. }else {//不计价差
  912. data.basePrice = proGLJ.getMarketPrice(glj);
  913. data.marketPrice = proGLJ.getMarketPrice(glj);
  914. data.adjustPrice = proGLJ.getMarketPrice(glj);
  915. }
  916. return data;
  917. },
  918. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  919. let proGLJ = projectObj.project.projectGLJ;
  920. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  921. if(this.calcPriceDiff(glj)==true){
  922. return proGLJ.getBasePrice(glj);
  923. }else {
  924. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  925. }
  926. },
  927. calcPriceDiff:function (glj) {
  928. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  929. if(glj.is_evaluate==1){//先按是否暂估判断
  930. return calcOptions.calc_est;
  931. }
  932. if(glj.type==gljType.MAIN_MATERIAL||glj.type==gljType.EQUIPMENT){//再判断是否是主材和设备
  933. return calcOptions.calc_main;
  934. }
  935. if(glj.unit_price.is_add==1){//再判断是否新增
  936. return calcOptions.calc_add;
  937. }
  938. return true;
  939. },
  940. getIndex(obj, pops){
  941. let t_index = '';
  942. let k_arr = [];
  943. for (let p of pops) {
  944. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  945. k_arr.push(tmpK);
  946. }
  947. t_index = k_arr.join("|-|");
  948. return t_index;
  949. },
  950. getConditionByKey(conKey){//将连接字符串转换成对象
  951. let valueArray = conKey.split("|-|");
  952. let obj ={};
  953. for(let i = 0;i<valueArray.length;i++){
  954. if(valueArray[i]!='null'){
  955. if(gljKeyArray[i]=='type'){
  956. valueArray[i] = parseInt(valueArray[i]);
  957. }
  958. obj[gljKeyArray[i]]=valueArray[i];
  959. }
  960. }
  961. return obj;
  962. },
  963. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  964. var temRationGLJs = [];
  965. for (var i = 0; i < mixRatioList.length; i++) {
  966. var pg = _.find(projectGljs, {
  967. 'code': mixRatioList[i].code,
  968. 'name': mixRatioList[i].name,
  969. 'specs': mixRatioList[i].specs,
  970. 'type': mixRatioList[i].type,
  971. 'unit': mixRatioList[i].unit
  972. });//改关联关系
  973. var tem = {
  974. projectGLJID: pg.id,
  975. code: pg.code,
  976. name: pg.name,
  977. specs: pg.specs,
  978. unit: pg.unit,
  979. type:mixRatioList[i].type,
  980. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  981. consumption:mixRatioList[i].consumption,
  982. rationItemQuantity: mixRatioList[i].consumption,
  983. // quantity:mixRatioList[i].consumption,
  984. /* basePrice: pg.unit_price.base_price,
  985. marketPrice: pg.unit_price.market_price,
  986. adjustPrice: pg.adjust_price,*/
  987. //isEstimate: pg.is_evaluate,
  988. isMixRatio: true,
  989. isAdd: pg.unit_price.is_add,
  990. GLJID: pg.glj_id
  991. };
  992. let typeString = pg.type + "";
  993. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
  994. tem.isEstimate = pg.is_evaluate;
  995. }
  996. this.setGLJPrice(tem,pg);
  997. temRationGLJs.push(tem);
  998. }
  999. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  1000. return temRationGLJs;
  1001. },
  1002. showRationCoeData: function (node) {
  1003. var coeList = [];
  1004. var ration_coe = projectObj.project.ration_coe;
  1005. var ration = node.data;
  1006. if (ration_coe.datas && ration_coe.datas.length > 0) {
  1007. coeList = _.filter(ration_coe.datas, {'projectID': ration.projectID, 'rationID': ration.ID})
  1008. }
  1009. this.showCoeData(this.coeSheet, this.coeSetting, coeList);
  1010. this.coeSheetData = coeList;
  1011. },
  1012. showRationAssData: function (node) {
  1013. var assList = node.data.rationAssList ? node.data.rationAssList : [];
  1014. sheetCommonObj.showData(this.assSheet, this.assSetting, assList);
  1015. this.assSheetData = assList;
  1016. },
  1017. showQuantityDetailData: function (node) {
  1018. var details = [];
  1019. node = node ? node : projectObj.project.mainTree.selected;
  1020. var quantity_detail = projectObj.project.quantity_detail;
  1021. if (node.sourceType == ModuleNames.ration) {
  1022. details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
  1023. } else if (node.sourceType == ModuleNames.bills) {
  1024. details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
  1025. }
  1026. details = _.sortBy(details, 'seq');
  1027. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  1028. this.detailData = details;
  1029. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  1030. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  1031. }
  1032. },
  1033. clearSheetData: function () {
  1034. sheetCommonObj.showData(this.sheet, this.setting, []);
  1035. sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
  1036. sheetCommonObj.showData(this.assSheet, this.assSetting, []);
  1037. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  1038. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  1039. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  1040. this.sheetData = [];
  1041. this.coeSheetData = [];
  1042. this.assSheetData = [];
  1043. installationFeeObj.rationInstallData = [];
  1044. //this.detailData=[];
  1045. },
  1046. /* lockRationGLJCell:function(){
  1047. sheetCommonObj.lockCells(this.sheet,this.setting);
  1048. },
  1049. lockRationCoeCell:function () {
  1050. sheetCommonObj.lockCells(this.coeSheet,this.coeSetting);
  1051. /!* if(this.coeSheetData){
  1052. for(var i =0;i<this.coeSheetData.length;i++){
  1053. if(this.coeSheetData[i].coeID==-1){
  1054. this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  1055. }
  1056. }
  1057. }*!/
  1058. },
  1059. lockRationGLJCell:function(){
  1060. sheetCommonObj.lockCells(this.sheet,this.setting);
  1061. },*/
  1062. updateRationGLJ: function (args) {
  1063. var me = this;
  1064. var updateField = me.setting.header[args.col].dataCode;
  1065. var recode = me.sheetData[args.row];
  1066. var newval;
  1067. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  1068. if (args.editingText == null) {
  1069. updateField == 'marketPrice' ? newval = 0 : newval = "";
  1070. } else {
  1071. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
  1072. newval = number_util.checkNumberValue(args.editingText, decimal);
  1073. if (newval == null) {
  1074. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1075. return;
  1076. }
  1077. }
  1078. } else {
  1079. if (updateField == 'name' || updateField == 'unit') {
  1080. if (args.editingText === null) {
  1081. alert(me.setting.header[args.col].headerName + '不能为空!');
  1082. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1083. return;
  1084. }
  1085. }
  1086. newval = args.editingText == null ? "" : args.editingText;
  1087. }
  1088. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  1089. return
  1090. }
  1091. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  1092. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  1093. } else {
  1094. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  1095. }
  1096. },
  1097. updateRationTypeGLJ: function (value, node, fieldName) {
  1098. let newval;
  1099. let updatePrice = false;
  1100. if (fieldName == "marketUnitFee") {
  1101. updatePrice = true;
  1102. if (value == null) {
  1103. newval = 0;
  1104. } else {
  1105. var decimal = getDecimal("glj.unitPrice");
  1106. newval = number_util.checkNumberValue(value, decimal);
  1107. }
  1108. } else {
  1109. if (value != null) {
  1110. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value)
  1111. return;
  1112. //update
  1113. }
  1114. }
  1115. if (newval && updatePrice == true) {
  1116. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  1117. return
  1118. }
  1119. projectObj.mainController.refreshTreeNode([node]);
  1120. },
  1121. updateRationAss: function (args) {
  1122. var me = gljOprObj;
  1123. var newval;
  1124. newval = me.numberValueChecking(args.editingText);
  1125. var recode = me.assSheetData[args.row];
  1126. if (args.editingText === null) {
  1127. newval = parseFloat(recode.stdValue);
  1128. }
  1129. var isValidate = false;
  1130. if (newval) {
  1131. isValidate = me.checkingActualValue(recode, newval)
  1132. }
  1133. if (isValidate) {
  1134. newval = scMathUtil.roundTo(newval, -2);
  1135. projectObj.project.ration_ass.updateActualValue(me.assSheetData, args.row, newval)
  1136. } else {
  1137. newval = recode.actualValue;
  1138. me.assSheet.getCell(args.row, args.col).value(newval);
  1139. }
  1140. },
  1141. updateRationCoe: function (args, newval) {
  1142. var me = gljOprObj;
  1143. var recode = me.coeSheetData[args.row];
  1144. projectObj.project.ration_coe.adjustCoeClick(recode, newval);
  1145. },
  1146. updateIsEstimate:function (args, newval) {
  1147. var me = gljOprObj;
  1148. if(me.setting.header[args.col].dataCode=="isEstimate"){
  1149. var pspread= new ProjectGLJSpread();
  1150. var recode = me.sheetData[args.row];
  1151. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  1152. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  1153. if(glj){
  1154. glj["is_evaluate"]=newval;
  1155. args.fromRG=true;
  1156. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  1157. }
  1158. }
  1159. },
  1160. numberValueChecking: function (val) {
  1161. var newval = Number(val);
  1162. if (number_util.isNumber(newval)) {
  1163. return newval;
  1164. } else {
  1165. if (val) {
  1166. alert('您输入的数据类型不正确,请重新输入。');
  1167. }
  1168. newval = null;
  1169. }
  1170. return newval;
  1171. },
  1172. checkingActualValue(record, newval){
  1173. var minExist = record.minValue && record.minValue != '0' ? true : false;
  1174. var maxExist = record.maxValue && record.maxValue != '0' ? true : false;
  1175. var minValue = parseFloat(record.minValue);
  1176. var maxValue = parseFloat(record.maxValue);
  1177. var stdVale = parseFloat(record.stdValue);
  1178. if (!maxExist && minExist) {
  1179. if (newval < minValue) {
  1180. alert('实际值应≥' + minValue);
  1181. return false;
  1182. }
  1183. }
  1184. if (maxExist && !minExist) {
  1185. if (newval > maxValue) {
  1186. alert('实际值应≤' + maxValue);
  1187. return false;
  1188. }
  1189. }
  1190. if (maxExist && minExist) {
  1191. if (newval < minValue || newval > maxValue) {
  1192. alert('实际值应介于' + minValue + '~' + maxValue + '之间');
  1193. return false;
  1194. }
  1195. }
  1196. return true;
  1197. },
  1198. showLibGLJSheetData: function () {
  1199. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  1200. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  1201. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  1202. },
  1203. filterLibGLJSheetData: function () {
  1204. let me = this;
  1205. let val = $("input[name='glj']:checked").val();
  1206. if (val == 'allGljs') {
  1207. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  1208. } else {
  1209. me.gljLibSheetData = me[val];
  1210. }
  1211. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  1212. me.filterLibGLJByType();
  1213. }
  1214. //文本筛选
  1215. let searchStr = $('#gljSearchKeyword').val();
  1216. if(searchStr && searchStr.trim() != ''){
  1217. let reg = new RegExp(searchStr);
  1218. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  1219. return reg.test(data.code) || reg.test(data.name);
  1220. });
  1221. }
  1222. if (me.gljCurTypeId == undefined) {
  1223. return;
  1224. }
  1225. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1226. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  1227. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  1228. });
  1229. } else {
  1230. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  1231. }
  1232. },
  1233. setGLJSelection: function (args, newVal) {
  1234. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1235. this.addGLJsSelection(args, newVal);
  1236. } else {
  1237. this.replaceGLJSelection(args, newVal);
  1238. }
  1239. },
  1240. addGLJsSelection: function (args, newVal) {
  1241. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  1242. if (newVal == 1) {
  1243. this.GLJSelection.push(con_key);
  1244. this.gljLibSheetData[args.row].select = 1;
  1245. } else if (newVal == 0) {
  1246. _.pull(this.GLJSelection, con_key);
  1247. this.gljLibSheetData[args.row].select = 0;
  1248. }
  1249. },
  1250. replaceGLJSelection: function (args, newVal) {
  1251. var me = this;
  1252. var oldSelection = this.GLJSelection[0];
  1253. if (newVal == 0) {
  1254. args.sheet.getCell(args.row, args.col).value(1);
  1255. return;
  1256. }
  1257. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  1258. this.gljLibSheetData[args.row].select = 1;
  1259. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  1260. var i_key = me.getIndex(item, gljLibKeyArray);
  1261. return oldSelection == i_key;
  1262. });
  1263. if (oindex != -1) {
  1264. args.sheet.getCell(oindex, args.col).value(0);
  1265. this.gljLibSheetData[oindex].select = 0;
  1266. } else {
  1267. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  1268. var i_key = me.getIndex(item, gljLibKeyArray);
  1269. return oldSelection == i_key;
  1270. });
  1271. oldData ? oldData.select = 0 : "";
  1272. }
  1273. },
  1274. filterLibGLJByType: function () {
  1275. var me = this;
  1276. var selected = me.sheetData[gljContextMenu.selectedRow];
  1277. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  1278. },
  1279. getComboData: function (gljDistType) {
  1280. let me = this;
  1281. let distType;
  1282. let distTypeTree = {
  1283. prefix: 'gljType',
  1284. distTypes: {},
  1285. comboDatas: [],
  1286. distTypesArr: []
  1287. };
  1288. gljDistType.forEach(function (typeData) {
  1289. let typeObj = {
  1290. data: typeData,
  1291. children: [],
  1292. parent: null
  1293. }
  1294. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1295. distTypeTree.distTypesArr.push(typeObj);
  1296. });
  1297. gljDistType.forEach(function (typeData) {
  1298. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1299. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1300. if (parent) {
  1301. distType.parent = parent;
  1302. parent.children.push(distType);
  1303. }
  1304. });
  1305. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1306. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1307. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1308. }
  1309. });
  1310. return distTypeTree;
  1311. },
  1312. doInsertGLJ: function () {
  1313. var me = this;
  1314. var selected = projectObj.project.mainTree.selected;
  1315. var project = projectObj.project;
  1316. if (me.GLJSelection.length <= 0) {
  1317. return;
  1318. }
  1319. $("#glj_tree_div").modal('hide');
  1320. $.bootstrapLoading.start();
  1321. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1322. project.projectGLJ.loadData(function () {
  1323. let newNode=null;
  1324. for (let r_glj of data) {
  1325. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1326. r_glj.marketUnitFee = r_glj.marketPrice;
  1327. r_glj.quantity = r_glj.quantity + "";
  1328. project.Ration.datas.push(r_glj);
  1329. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1330. newNode.source = r_glj;
  1331. newNode.sourceType = project.Ration.getSourceType();
  1332. newNode.data = r_glj;
  1333. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1334. }
  1335. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1336. projectObj.mainController.refreshTreeNode([newNode]);
  1337. if(me.hasComposition(newNode.data,true)){
  1338. me.showMixRatio(newNode);
  1339. }else {
  1340. me.showRationGLJSheetData();
  1341. }
  1342. $.bootstrapLoading.end();
  1343. });
  1344. })
  1345. },
  1346. doAddGLJ: function () {
  1347. var selected = projectObj.project.mainTree.selected;
  1348. var project = projectObj.project;
  1349. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1350. var rg = _.find(gljOprObj.sheetData, function (item) {
  1351. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1352. return n == i_key
  1353. })
  1354. return rg ? false : true;
  1355. })
  1356. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1357. $("#glj_tree_div").modal('hide');
  1358. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1359. if (result) {
  1360. selected.data.adjustState = result.adjustState;
  1361. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1362. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1363. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1364. project.ration_glj.addToMainTree(result.showData);
  1365. project.projectGLJ.loadData(function () {
  1366. gljOprObj.showRationGLJSheetData();
  1367. project.calcProgram.calcAndSave(selected);
  1368. projectObj.mainController.refreshTreeNode([selected]);
  1369. $.bootstrapLoading.end();
  1370. });
  1371. }
  1372. });//doc.rationID=selected.data.ID;
  1373. } else {
  1374. $("#glj_tree_div").modal('hide');
  1375. }
  1376. },
  1377. doReplaceGLJ: function () {
  1378. var me = this;
  1379. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1380. var project = projectObj.project;
  1381. var selectCode = gljOprObj.GLJSelection[0];
  1382. var selected = projectObj.project.mainTree.selected;
  1383. $("#glj_tree_div").modal('hide');
  1384. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1385. if (result) {
  1386. //result.adjustState;
  1387. var glj_list = projectObj.project.ration_glj.datas;
  1388. var data = result.data;
  1389. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1390. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1391. var nodes = [selected];
  1392. gljOprObj.sheetData[index] = data;
  1393. glj_list[list_index] = data;
  1394. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1395. gljOprObj.showRationGLJSheetData();
  1396. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1397. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1398. if (node) {
  1399. project.ration_glj.transferToNodeData(data);
  1400. node.source = data;
  1401. node.data = data;
  1402. }
  1403. node ? nodes.push(node) : "";
  1404. }
  1405. //project.ration_glj.addToMainTree(data);
  1406. selected.data.adjustState = result.adjustState;
  1407. projectObj.mainController.refreshTreeNode(nodes);
  1408. project.calcProgram.calcAndSave(selected);
  1409. $.bootstrapLoading.end();
  1410. });
  1411. }
  1412. })
  1413. },
  1414. doMReplaceGLJ: function () {
  1415. var me = this;
  1416. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1417. var project = projectObj.project;
  1418. var selectCode = me.GLJSelection[0];
  1419. $("#glj_tree_div").modal('hide');
  1420. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result) {
  1421. var data = result.data;
  1422. var stateList = result.stateList;
  1423. var n_index = me.getIndex(data.query, gljKeyArray);
  1424. var nodes = [];
  1425. _.forEach(project.ration_glj.datas, function (t) {
  1426. var t_index = me.getIndex(t, gljKeyArray);
  1427. if (n_index == t_index) {
  1428. me.updateProperty(t, data.doc);
  1429. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1430. project.ration_glj.transferToNodeData(t);
  1431. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1432. nodes.push(node);
  1433. }
  1434. }
  1435. })
  1436. project.projectGLJ.loadData(function () {
  1437. me.showRationGLJSheetData();
  1438. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1439. project.calcProgram.calcRationsAndSave(rationNodes);
  1440. $.bootstrapLoading.end();
  1441. });
  1442. })
  1443. },
  1444. updateProperty: function (obj, doc) {
  1445. _.forEach(doc, function (n, key) {
  1446. obj[key] = n;
  1447. });
  1448. },
  1449. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1450. var nodes = [];
  1451. var rationNodes = [];
  1452. _.forEach(stateList, function (s) {
  1453. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1454. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1455. })
  1456. if (node) {
  1457. node.data.adjustState = s.adjustState;
  1458. nodes.push(node);
  1459. rationNodes.push(node);
  1460. }
  1461. });
  1462. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1463. projectObj.mainController.refreshTreeNode(nodes);
  1464. return rationNodes;
  1465. },
  1466. refreshView: function () {
  1467. this.showRationGLJData();
  1468. },
  1469. //
  1470. refreshTreeNode: function (obj) {
  1471. if (!obj) {
  1472. return;
  1473. }
  1474. var objectArray = [];
  1475. var nodes = [];
  1476. if (obj instanceof Array) {
  1477. objectArray.concat(obj);
  1478. } else {
  1479. objectArray.push(obj);
  1480. }
  1481. for (let o of objectArray) {
  1482. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1483. return n.sourceType == o.type && n.data.ID == o.ID;
  1484. })
  1485. if (node) {
  1486. for (var k in o.data) {
  1487. node.data[k] = o.data[k];
  1488. }
  1489. nodes.push(node);
  1490. }
  1491. }
  1492. projectObj.mainController.refreshTreeNode(nodes);
  1493. return nodes;
  1494. },
  1495. getTreeNodeCellType: function (data) {
  1496. var ns = GC.Spread.Sheets;
  1497. var rectW = 10;
  1498. var rectH = 10;
  1499. var margin = 3;
  1500. function TreeNodeCellType() {
  1501. }
  1502. function drowRect(ctx, x, y, w, h) {
  1503. ctx.save();
  1504. ctx.strokeStyle = "gray";
  1505. ctx.translate(0.5, 0.5);
  1506. ctx.beginPath();
  1507. var rectX = x + margin;
  1508. var rectY = y + Math.round(h / 2) - rectH / 2;
  1509. ctx.moveTo(rectX, rectY);
  1510. ctx.lineTo(rectX, rectY + rectH);
  1511. ctx.lineTo(rectX + rectW, rectY + rectH);
  1512. ctx.lineTo(rectX + rectW, rectY);
  1513. ctx.lineTo(rectX, rectY);
  1514. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1515. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1516. ctx.stroke();
  1517. ctx.restore();
  1518. }
  1519. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1520. ctx.save();
  1521. ctx.strokeStyle = "#000000";
  1522. ctx.translate(0.5, 0.5);
  1523. ctx.beginPath();
  1524. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1525. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1526. var rectY = y + Math.round(h / 2) - rectH / 2;
  1527. if (collapsed) {
  1528. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1529. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1530. }
  1531. ctx.stroke();
  1532. ctx.restore();
  1533. }
  1534. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1535. offset += 6;
  1536. ctx.save();
  1537. ctx.strokeStyle = "gray";
  1538. ctx.translate(0.5, 0.5);
  1539. ctx.beginPath();
  1540. ctx.moveTo(x + offset, y);
  1541. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1542. offset += 9;
  1543. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1544. if (nextItem && nextItem.isMixRatio) {
  1545. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1546. ctx.lineTo(x + offset - 9, y + h);
  1547. }
  1548. ctx.stroke();
  1549. ctx.restore();
  1550. return offset;
  1551. }
  1552. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  1553. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1554. if (value != null) {
  1555. var offset = margin + rectW + 6;
  1556. var recode = data[options.row];
  1557. if (recode && recode.hasOwnProperty('subList')) {
  1558. drowRect(ctx, x, y, w, h);
  1559. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1560. drowSymbol(ctx, x, y, w, h, collapsed);
  1561. } else if (recode && recode.isMixRatio) {
  1562. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1563. offset += 1;
  1564. }
  1565. ctx.fillText(value, x + offset + ctx.measureText(value).width, y + h - 5);
  1566. }
  1567. };
  1568. // override getHitInfo to allow cell type get mouse messages
  1569. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1570. return {
  1571. x: x,
  1572. y: y,
  1573. row: context.row,
  1574. col: context.col,
  1575. cellStyle: cellStyle,
  1576. cellRect: cellRect,
  1577. sheetArea: context.sheetArea
  1578. };
  1579. }
  1580. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1581. var recode = data[hitinfo.row];
  1582. if (recode && recode.hasOwnProperty('subList')) {
  1583. var hoffset = hitinfo.cellRect.x + 3;
  1584. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1585. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1586. collapsed = !collapsed
  1587. recode.collapsed = collapsed;
  1588. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1589. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1590. hitinfo.sheet.invalidateLayout();
  1591. hitinfo.sheet.repaint();
  1592. }
  1593. }
  1594. };
  1595. return new TreeNodeCellType()
  1596. },
  1597. marketPriceReadOnly: function (node) {
  1598. let hasCom = false;
  1599. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1600. hasCom = this.hasComposition(node.data,true);
  1601. }else {
  1602. hasCom = this.hasComposition(node.data);
  1603. }
  1604. return hasCom|| node.data.isEstimate == 1;
  1605. }
  1606. }
  1607. $(function () {
  1608. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1609. if (gljOprObj.gljLibSpresd == undefined) {
  1610. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1611. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1612. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1613. gljOprObj.gljLibSheet.options.isProtected = true;
  1614. gljOprObj.gljLibSheet.name('glj_lib');
  1615. }
  1616. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1617. var selected = null;
  1618. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1619. gljOprObj.GLJSelection = [];
  1620. } else {
  1621. selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1622. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1623. gljOprObj.GLJSelection = [connect_key];
  1624. gljOprObj.filterLibGLJByType();
  1625. }
  1626. if (selected != null) {
  1627. var s_key = gljOprObj.getIndex(selected, gljLibKeyArray);
  1628. var r = _.find(gljOprObj.gljLibSheetData, function (item) {
  1629. var item_key = gljOprObj.getIndex(item, gljKeyArray);
  1630. return s_key == item_key;
  1631. });
  1632. r ? r.select = 1 : "";
  1633. }
  1634. gljOprObj.showLibGLJSheetData();
  1635. });
  1636. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1637. $('#gljSearchKeyword').val('');
  1638. });
  1639. $('.glj-radio').change(function () {
  1640. let val = $("input[name='glj']:checked").val();
  1641. if (val == 'allGljs') {
  1642. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1643. gljOprObj.filterLibGLJSheetData();
  1644. gljOprObj.showLibGLJSheetData();
  1645. } else {
  1646. gljOprObj.gljLibSheetData = gljOprObj[val];
  1647. gljOprObj.filterLibGLJSheetData();
  1648. gljOprObj.showLibGLJSheetData();
  1649. }
  1650. })
  1651. //工料机搜索
  1652. $('#gljSearchKeyword').change(function () {
  1653. gljOprObj.filterLibGLJSheetData();
  1654. gljOprObj.showLibGLJSheetData();
  1655. });
  1656. $('#gljSearchKeyword').bind('keypress', function (e) {
  1657. if(e.keyCode === 13){
  1658. $(this).blur();
  1659. return false;
  1660. }
  1661. });
  1662. $('#glj_selected_conf').click(function () {
  1663. if (gljOprObj.GLJSelection.length < 1) {
  1664. return;
  1665. }
  1666. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1667. gljOprObj.doInsertGLJ();
  1668. } else if ($('#actionType').val() == 'add') { //添加工料机
  1669. gljOprObj.doAddGLJ();
  1670. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1671. gljOprObj.doReplaceGLJ();
  1672. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1673. gljOprObj.doMReplaceGLJ();
  1674. }
  1675. })
  1676. $('#class_selected_conf').click(function () {
  1677. var gljClass = $('#selected_class').val();
  1678. var glj = gljOprObj.selectedGLJClass;
  1679. if (glj && gljClass && gljClass != "") {
  1680. //保存到我的工料机库
  1681. /*1 检查是否有组成物
  1682. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1683. * 3 保存
  1684. * */
  1685. var newItem = {
  1686. code: glj.code,
  1687. name: glj.name,
  1688. specs: glj.specs,
  1689. unit: glj.unit,
  1690. basePrice: glj.basePrice,
  1691. gljType: glj.type,
  1692. shortName: glj.shortName,
  1693. component: [],
  1694. gljClass: gljClass
  1695. };
  1696. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1697. for (var i = 0; i < glj.subList.length; i++) {
  1698. let tem = {
  1699. ID: glj.subList[i].GLJID,
  1700. consumeAmt: glj.rationItemQuantity,
  1701. isStd: true
  1702. }
  1703. newItem.component.push(tem);
  1704. }
  1705. }
  1706. var data = getcmpUpdateData([newItem]);
  1707. $.bootstrapLoading.start();
  1708. var callback = function (data) {
  1709. $("#glj_class_div").modal('hide');
  1710. $.bootstrapLoading.end();
  1711. }
  1712. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1713. $.bootstrapLoading.end();
  1714. });
  1715. }
  1716. })
  1717. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1718. gljOprObj.selectedGLJClass = null;
  1719. $('#class_selected_conf').attr("disabled", "disabled");
  1720. $('#selected_class').val("");
  1721. })
  1722. function getcmpUpdateData(items) {
  1723. var data = {
  1724. "updateItems": [],
  1725. "removeIds": []
  1726. }
  1727. data.addItems = items;
  1728. return data;
  1729. }
  1730. })
  1731. function operationWithRound(value1,value2,field,symble) {
  1732. let decimal = getDecimal(field);
  1733. value1 = scMathUtil.roundForObj(value1,decimal);
  1734. value2 = scMathUtil.roundForObj(value2,decimal);
  1735. let result;
  1736. switch (symble){
  1737. case "+" :
  1738. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1739. break;
  1740. case "-":
  1741. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1742. break;
  1743. case "*":
  1744. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1745. break;
  1746. case "/":
  1747. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1748. break
  1749. }
  1750. return result;
  1751. }
  1752. function getDecimal(fieldID, node) {
  1753. if (node) {
  1754. return decimalObj.decimal(fieldID, node);
  1755. } else if (fieldID.indexOf(".") != -1) {
  1756. var keyArray = fieldID.split(".");
  1757. return decimalObj[keyArray[0]][keyArray[1]];
  1758. } else {
  1759. return decimalObj.decimal(fieldID);
  1760. }
  1761. }
  1762. function getFormatter(decimal) {
  1763. var pre = "0.";
  1764. if (decimal <= 0) {
  1765. return "0";
  1766. }
  1767. for (i = 0; i < decimal; i++) {
  1768. pre += "0"
  1769. }
  1770. return pre;
  1771. }
  1772. function sortRationGLJ(list) {
  1773. list = _.sortByAll(list, [function (item) {
  1774. return item.type + "";
  1775. }, "code"])
  1776. return list;
  1777. }
  1778. function compareRationGLJ(a, b) {
  1779. if ((a.type + "") < (b.type + "")) {
  1780. return true
  1781. }
  1782. if ((a.type + "") == (b.type + "")) {
  1783. if (a.code < b.code) {
  1784. return true
  1785. }
  1786. }
  1787. return false;
  1788. }