locate_view.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /**
  2. * Created by zhang on 2018/11/16.
  3. */
  4. let locateObject={
  5. bills_setting:{
  6. header:[
  7. {headerName: "编码", headerWidth: 120, dataCode: "code", dataType: "String"},
  8. {headerName: "项目名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  9. {headerName: "单位", headerWidth: 50, dataCode: "unit", dataType: "String",hAlign: "center"},
  10. {headerName: "工程量", headerWidth: 65, dataCode: "quantity", dataType: "Number", hAlign: "right"},
  11. {headerName: "综合单价", headerWidth: 65, dataCode: "unitPrice", dataType: "Number", hAlign: "right"},
  12. {headerName: "综合合价", headerWidth: 65, dataCode: "totalPrice", dataType: "Number", hAlign: "right"}
  13. ],
  14. view: {
  15. lockColumns: [0,1,2,3,4,5],
  16. colHeaderHeight:30
  17. }
  18. },
  19. ration_setting:{
  20. header:[
  21. {headerName: "定额编码", headerWidth: 100, dataCode: "code", dataType: "String"},
  22. {headerName: "定额名称", headerWidth: 180, dataCode: "name", dataType: "String"},
  23. {headerName: "单位", headerWidth: 50, dataCode: "unit", dataType: "String",hAlign: "center"},
  24. {headerName: "工程量", headerWidth: 65, dataCode: "quantity", dataType: "Number", hAlign: "right",decimalField: "ration.quantity"}
  25. ],
  26. view: {
  27. lockColumns: [0,1,2,3],
  28. colHeaderHeight:30
  29. }
  30. },
  31. ration_glj_setting:{
  32. header:[
  33. {headerName: "编码", headerWidth: 120, dataCode: "code", dataType: "String"},
  34. {headerName: "名称", headerWidth: 80, dataCode: "name", dataType: "String"},
  35. {headerName: "规格型号", headerWidth: 80, dataCode: "specs", dataType: "String"},
  36. {headerName: "单位", headerWidth: 50, dataCode: "unit", dataType: "String",hAlign: "center"},
  37. {headerName: "市场价", headerWidth: 65, dataCode: "marketPrice", dataType: "Number", hAlign: "right"}
  38. ],
  39. view: {
  40. lockColumns: [0,1,2,3,4],
  41. colHeaderHeight:30
  42. }
  43. },
  44. datas:[],
  45. bookMarkSetting:{
  46. header:[
  47. {headerName: "编码", headerWidth: 120, dataCode: "code", dataType: "String"},
  48. {headerName: "书签名称", headerWidth: 200, dataCode: "name", dataType: "String"},
  49. ],
  50. view: {
  51. lockColumns: [0,1],
  52. colHeaderHeight:30
  53. }
  54. },
  55. //为了兼容旧项目,这里给个默认值
  56. bookmarkPropertySetting:{
  57. settingList :[
  58. {background:"E2F2C5",describe:""},
  59. {background:"F9E2CF",describe:""},
  60. {background:"F2EFD9",describe:"hehe"},
  61. {background:"F5D1DA",describe:""},
  62. {background:"E3E3E3",describe:""},
  63. {background:"B6F3F2",describe:""},
  64. {background:"ECE0F5",describe:""}
  65. ],
  66. selected:"E2F2C5"
  67. },
  68. initMainSpread:function(){
  69. if(!this.mainSpread){
  70. this.mainSpread = SheetDataHelper.createNewSpread($("#locate_result")[0],3);
  71. sheetCommonObj.spreadDefaultStyle(this.mainSpread);
  72. this.initMainSheet();
  73. }else {
  74. this.mainSpread.refresh();
  75. }
  76. },
  77. initMainSheet:function () {
  78. //初始化清单表格
  79. sheetCommonObj.initSheet(this.mainSpread .getSheet(0),this.bills_setting);
  80. this.mainSpread .getSheet(0).setRowCount(0);
  81. //初始化定额表格
  82. sheetCommonObj.initSheet(this.mainSpread .getSheet(1),this.ration_setting);
  83. this.mainSpread .getSheet(1).setRowCount(0);
  84. //初始化人材机表格
  85. sheetCommonObj.initSheet(this.mainSpread.getSheet(2),this.ration_glj_setting);
  86. this.mainSpread .getSheet(2).setRowCount(0);
  87. this.mainSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick,this.onSheetDoubleClick);
  88. this.mainSpread .getSheet(2).bind(GC.Spread.Sheets.Events.SelectionChanged,this.gljSelectionChange);
  89. },
  90. initSubSpread:function () {
  91. if(!this.subSpread){
  92. this.subSpread = SheetDataHelper.createNewSpread($("#locate_sub")[0]);
  93. sheetCommonObj.spreadDefaultStyle(this.subSpread);
  94. this.initSubSheet();
  95. this.subSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick,this.onSheetDoubleClick);
  96. }else {
  97. this.subSpread.refresh();
  98. }
  99. },
  100. initBookmarkSpread:function(){
  101. if(!this.bookmarkSpread){
  102. this.bookmarkSpread = SheetDataHelper.createNewSpread($("#bookmarkSpread")[0]);
  103. sheetCommonObj.spreadDefaultStyle(this.bookmarkSpread);
  104. this.initBookmarkSheet();
  105. // this.subSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick,this.onSheetDoubleClick);
  106. }else {
  107. this.bookmarkSpread.refresh();
  108. }
  109. },
  110. refreshWorkBook: function () {
  111. if (this.mainSpread) this.mainSpread.refresh();
  112. if (this.subSpread) this.subSpread.refresh();
  113. if (this.bookmarkSpread) this.bookmarkSpread.refresh();
  114. },
  115. initSubSheet:function () {
  116. this.subSheet = this.subSpread .getSheet(0);
  117. sheetCommonObj.initSheet( this.subSheet, this.ration_setting);
  118. this.subSheet.setRowCount(0);
  119. this.subSheet.name('locate_sub');
  120. },
  121. initBookmarkSheet:function () {
  122. this.bookmarkSheet = this.bookmarkSpread .getSheet(0);
  123. sheetCommonObj.initSheet( this.bookmarkSheet, this.bookMarkSetting);
  124. this.bookmarkSheet.setRowCount(0);
  125. this.bookmarkSheet.name('bookmark');
  126. },
  127. initOutstanding:function () {
  128. if(!projectObj.project.property.locateSetting) return;
  129. let outstd = projectObj.project.property.locateSetting;
  130. $("#outstanding").prop("checked",outstd.outstanding);
  131. $("#outInp").val(parseFloat(outstd.outInp));
  132. },
  133. initBookmarkSetting:function () {
  134. $("#bookmarkSettingList").empty();
  135. let setting = projectObj.project.property.bookmarkSetting?projectObj.project.property.bookmarkSetting:this.bookmarkPropertySetting;
  136. for(let s of setting.settingList){
  137. let b = `<div class="input-group input-group-sm mb-2" style="width:200px">
  138. <div class="input-group-prepend">
  139. <span class="input-group-text " style="background: #${s.background}">&nbsp;&nbsp;&nbsp;&nbsp;</span>
  140. </div>
  141. <input type="text" class="form-control" id="${s.background}" placeholder="描述" value="${s.describe}">
  142. </div>`;
  143. $("#bookmarkSettingList").append(b);
  144. $("#"+s.background).bind('focus', bookmarkSelected);
  145. }
  146. },
  147. showMainData:function (datas,setting) {
  148. sheetCommonObj.showData(this.mainSpread.getActiveSheet(),setting,datas);
  149. this.mainSpread.getActiveSheet().setRowCount(datas.length);
  150. },
  151. showSubRateDatas:function () {
  152. this.subRationDatas = this.getSubRationDatas();
  153. sheetCommonObj.showData(this.subSheet,this.ration_setting,this.subRationDatas);
  154. this.subSheet.setRowCount(this.subRationDatas.length);
  155. },
  156. getSubRationDatas:function () {
  157. let datas = [];
  158. let sheet = this.mainSpread.getActiveSheet();
  159. let oldSel = sheet.getSelections()[0];
  160. if(this.gljDatas && this.gljDatas.length > 0){
  161. let glj = this.gljDatas[oldSel.row];
  162. if(!glj) return datas;
  163. let nodes = projectObj.project.projectGLJ.getImpactRationNodes([glj.reference]);
  164. for(let n of nodes){
  165. datas.push(this.getShowRationDatas(n.data));
  166. }
  167. }
  168. return datas;
  169. },
  170. refreshView: function (options, refreshWorkBook) {
  171. let me = this;
  172. let mainHeight = $(window).height()-$(".header").height()-$(".toolsbar").height()-$("#searchPanel").height();
  173. let subHeight = 0;
  174. if(options == "bookmark"){
  175. let bookMarkLibResize = getBookmarkResize();
  176. loadHeight(bookMarkLibResize);
  177. }else {
  178. $('#locateTopDiv').height(mainHeight);
  179. $('#locate_result').height(mainHeight);
  180. $('#locateBottomDiv').height(subHeight);
  181. $('#locate_sub').height(subHeight - 7);
  182. if(options == "ration_glj"){
  183. let locateLibResize = getLocateLibResize();
  184. loadHeight(locateLibResize);
  185. }
  186. }
  187. function loadHeight(libResize) {
  188. SlideResize.loadVerticalHeight(libResize.eleObj.module, libResize.eleObj, libResize.limit, function () {
  189. locateObject.refreshWorkBook();
  190. });
  191. }
  192. if (refreshWorkBook) {
  193. me.refreshWorkBook();
  194. }
  195. },
  196. init:function () {
  197. let me = this;
  198. let options = $("input[name='content_type']:checked").val();
  199. let callback = function () {
  200. me.refreshView(options, false);
  201. me.initMainSpread();
  202. me.initSubSpread();
  203. me.initBookmarkSpread();
  204. };
  205. if(options == 'bookmark'){
  206. $("#aboutLocateDiv").hide();
  207. $("#outstandingOptions").hide();
  208. me.initBookmarkSetting();
  209. $("#aboutBookmarkDiv").show(0,callback);
  210. }else {
  211. $("#aboutBookmarkDiv").hide();
  212. $("#aboutLocateDiv").show(0,function () {
  213. if(options == "bills") me.initOutstanding();
  214. options == "bills"?$("#outstandingOptions").show(0,callback):$("#outstandingOptions").hide(0,callback);
  215. });
  216. }
  217. },
  218. findRecodes:function () {
  219. let options = $("input[name='content_type']:checked").val();
  220. let keyword = $("#locateInput").val();
  221. switch (options){
  222. case "bills":
  223. this.billsDatas = this.findBills(keyword);
  224. this.showMainData(this.billsDatas,this.bills_setting);
  225. break;
  226. case "ration":
  227. this.rationDatas = this.findRations(keyword);
  228. this.showMainData(this.rationDatas,this.ration_setting);
  229. break;
  230. case "ration_glj":
  231. this.gljDatas = this.findGLJs(keyword);
  232. this.showMainData(this.gljDatas,this.ration_glj_setting);
  233. this.showSubRateDatas();
  234. break;
  235. }
  236. },
  237. onshow:function () {
  238. locateObject.init();
  239. },
  240. matchItem:function (keyword,i) {//true 匹配上,false匹配失败
  241. let match = false;
  242. if(keyword && keyword !="") {//如果keyword为空,匹配所有
  243. if (i.code && i.code.indexOf(keyword) != -1) match = true;
  244. if (i.name && i.name.indexOf(keyword) != -1) match = true;
  245. if(match == false) return false
  246. }
  247. return true;
  248. },
  249. findGLJs:function(keyword){
  250. let datas = [];
  251. let gljList = projectObj.project.projectGLJ.datas.gljList;
  252. gljList = sortProjectGLJ(gljList);
  253. for(let glj of gljList){
  254. // if(glj.quantity == 0 || glj.quantity == '0') continue; 2019-07-01 需求改成消耗量为0也显示
  255. let match = this.matchItem(keyword,glj);
  256. if(match == false) continue;
  257. let data = getGLJDatas(glj);
  258. gljOprObj.setGLJPrice(data,glj);
  259. datas.push(data);
  260. }
  261. return datas;
  262. function getGLJDatas(tem) {
  263. return{
  264. ID:tem.id,
  265. name:tem.name,
  266. code:tem.code,
  267. unit:tem.unit,
  268. specs:tem.specs,
  269. reference:tem
  270. }
  271. }
  272. },
  273. findRations:function (keyword) {
  274. let datas = [];
  275. let items = projectObj.project.mainTree.items;
  276. for(let i of items){
  277. if(i.sourceType == ModuleNames.ration){
  278. let match = this.matchItem(keyword,i.data);
  279. if(match == false) continue;
  280. let bills = this.getShowRationDatas(i.data);
  281. datas.push(bills);
  282. }
  283. }
  284. return datas;
  285. },
  286. getShowRationDatas:function(data){
  287. return{
  288. ID:data.ID,
  289. name:data.name,
  290. code:data.code,
  291. unit:data.unit,
  292. quantity:data.quantity
  293. }
  294. },
  295. findBills:function(keyword){
  296. let datas = [],priceMap={};
  297. let items = projectObj.project.mainTree.items;
  298. for(let i of items){
  299. if(i.sourceType == ModuleNames.bills){
  300. let match = this.matchItem(keyword,i.data);
  301. if(match == false) continue;
  302. let bills = getBillData(i.data);
  303. priceMap = setPriceMap(bills,priceMap);
  304. datas.push(bills);
  305. }
  306. }
  307. setBgColour(datas,priceMap);
  308. datas = _.sortByAll(datas,['code']);
  309. return datas;
  310. function setBgColour(bills,map) {
  311. let outStd = $("#outstanding").prop("checked");
  312. let outInp = $("#outInp").val();
  313. if(outStd == true && outInp && outInp!=""){
  314. for(let b of bills){
  315. if(b.code && b.code.length >= 9){
  316. let key = b.code.substr(0,9);
  317. if(map[key] && map[key].count > 1){
  318. let avg = map[key].total/map[key].count;
  319. let unitPrice = b.unitPrice?parseFloat(b.unitPrice):0;
  320. if(unitPrice ==0 ) continue;
  321. if(Math.abs(unitPrice - avg)/avg * 100 >= parseFloat(outInp)) b.bgColour = "#FFFACD"
  322. }
  323. }
  324. }
  325. }
  326. }
  327. function setPriceMap (bills,map) {
  328. if(bills.code && bills.code.length >= 9){
  329. let key = bills.code.substr(0,9);
  330. let unitPrice = bills.unitPrice?parseFloat(bills.unitPrice):0;
  331. if(map[key]){
  332. map[key].total += unitPrice;
  333. map[key].count ++;
  334. }else {
  335. map[key] = {total:unitPrice,count:1}
  336. }
  337. }
  338. return map;
  339. }
  340. function getBillData(data) {
  341. return{
  342. ID:data.ID,
  343. name:data.name,
  344. code:data.code,
  345. unit:data.unit,
  346. quantity:data.quantity,
  347. unitPrice:data.feesIndex&&data.feesIndex.common?data.feesIndex.common.unitFee:"",
  348. totalPrice:data.feesIndex&&data.feesIndex.common?data.feesIndex.common.totalFee:"",
  349. bgColour:"white"
  350. }
  351. }
  352. },
  353. onSheetDoubleClick:function (e,args) {
  354. let me = locateObject;
  355. let options = $("input[name='content_type']:checked").val();
  356. let sheetName = args.sheet.name()
  357. if(options == "ration_glj"&&sheetName != "locate_sub" ) return;
  358. let datas = options == "bills"? me.billsDatas:me.rationDatas;
  359. if( args.sheet.name() == "locate_sub") datas = me.subRationDatas;
  360. me.locateNode(datas[args.row].ID);
  361. },
  362. gljSelectionChange:function (e,args) {
  363. let me = locateObject;
  364. let newSel = args.newSelections[0];
  365. let oldSel = args.oldSelections?args.oldSelections[0]:{};
  366. if(newSel.row != oldSel.row){
  367. me.showSubRateDatas();
  368. }
  369. },
  370. locateNode:function (ID) {
  371. let node = projectObj.project.mainTree.findNode(ID);
  372. if(node) projectObj.loadFocusLocation(node.serialNo(),1);
  373. },
  374. updateOutStanding:function (outstanding,outInp) {
  375. let outstd = {outstanding:outstanding,outInp:outInp};
  376. let updateData = {type:ModuleNames.project,data:{'ID' : projectObj.project.ID(),'property.locateSetting':outstd}};
  377. projectObj.project.updateNodes([updateData],function () {
  378. projectObj.project.property.locateSetting = outstd;
  379. });
  380. }
  381. };
  382. $("#locate_btn").click(function () {
  383. locateObject.findRecodes();
  384. });
  385. //回车键搜索
  386. $('#locateInput').bind('keypress', function (event) {
  387. if(event.keyCode === 13){
  388. $(this).blur();
  389. locateObject.findRecodes();
  390. }
  391. });
  392. $("input[name='content_type']").each(function(){
  393. $(this).click(function(){
  394. let options = $(this).val();
  395. switch (options){
  396. case "bills":
  397. locateObject.mainSpread.setActiveSheetIndex(0);
  398. break;
  399. case "ration":
  400. locateObject.mainSpread.setActiveSheetIndex(1);
  401. break;
  402. case "ration_glj":
  403. locateObject.mainSpread.setActiveSheetIndex(2);
  404. break;
  405. }
  406. locateObject.init();
  407. });
  408. });
  409. $('#outInp').change(function(){
  410. let me = locateObject;
  411. let process = getDecimal('process');
  412. var newVal = $(this).val();
  413. let outInp = scMathUtil.roundForObj(newVal,process);
  414. let outStd = $("#outstanding").prop("checked");
  415. me.updateOutStanding(outStd,outInp);
  416. });
  417. $('#outstanding').change(function(){
  418. let me = locateObject;
  419. let outInp = $("#outInp").val();
  420. let outStd = $("#outstanding").prop("checked");
  421. me.updateOutStanding(outStd,scMathUtil.roundForObj(outInp,getDecimal('process')));
  422. });
  423. $('#bookmarkSettingDropdown').on('shown.bs.dropdown', function showDropdown() {
  424. let setting = projectObj.project.property.bookmarkSetting?projectObj.project.property.bookmarkSetting:locateObject.bookmarkPropertySetting;
  425. $("#"+setting.selected).focus();
  426. });
  427. function bookmarkSelected() {
  428. console.log("hehe");
  429. $("#bookmarkSelected").val($(this)[0].id);
  430. }