glj_view.js 75 KB

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