locate_view.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. initMainSpread:function(){
  46. if(!this.mainSpread){
  47. this.mainSpread = SheetDataHelper.createNewSpread($("#locate_result")[0],3);
  48. sheetCommonObj.spreadDefaultStyle(this.mainSpread);
  49. this.initMainSheet();
  50. }else {
  51. this.mainSpread.refresh();
  52. }
  53. },
  54. initMainSheet:function () {
  55. //初始化清单表格
  56. sheetCommonObj.initSheet(this.mainSpread .getSheet(0),this.bills_setting);
  57. this.mainSpread .getSheet(0).setRowCount(0);
  58. //初始化定额表格
  59. sheetCommonObj.initSheet(this.mainSpread .getSheet(1),this.ration_setting);
  60. this.mainSpread .getSheet(1).setRowCount(0);
  61. //初始化人材机表格
  62. sheetCommonObj.initSheet(this.mainSpread.getSheet(2),this.ration_glj_setting);
  63. this.mainSpread .getSheet(2).setRowCount(0);
  64. this.mainSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick,this.onSheetDoubleClick);
  65. this.mainSpread .getSheet(2).bind(GC.Spread.Sheets.Events.SelectionChanged,this.gljSelectionChange);
  66. },
  67. initSubSpread:function () {
  68. if(!this.subSpread){
  69. this.subSpread = SheetDataHelper.createNewSpread($("#locate_sub")[0]);
  70. sheetCommonObj.spreadDefaultStyle(this.subSpread);
  71. this.initSubSheet();
  72. this.subSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick,this.onSheetDoubleClick);
  73. }else {
  74. this.subSpread.refresh();
  75. }
  76. },
  77. refreshWorkBook: function () {
  78. if (this.mainSpread) {
  79. this.mainSpread.refresh();
  80. }
  81. if (this.subSpread) {
  82. this.subSpread.refresh();
  83. }
  84. },
  85. initSubSheet:function () {
  86. this.subSheet = this.subSpread .getSheet(0);
  87. sheetCommonObj.initSheet( this.subSheet, this.ration_setting);
  88. this.subSheet.setRowCount(0);
  89. this.subSheet.name('locate_sub');
  90. },
  91. initOutstanding:function () {
  92. if(!projectObj.project.property.locateSetting) return;
  93. let outstd = projectObj.project.property.locateSetting;
  94. $("#outstanding").prop("checked",outstd.outstanding);
  95. $("#outInp").val(parseFloat(outstd.outInp));
  96. },
  97. showMainData:function (datas,setting) {
  98. sheetCommonObj.showData(this.mainSpread.getActiveSheet(),setting,datas);
  99. this.mainSpread.getActiveSheet().setRowCount(datas.length);
  100. },
  101. showSubRateDatas:function () {
  102. this.subRationDatas = this.getSubRationDatas();
  103. sheetCommonObj.showData(this.subSheet,this.ration_setting,this.subRationDatas);
  104. this.subSheet.setRowCount(this.subRationDatas.length);
  105. },
  106. getSubRationDatas:function () {
  107. let datas = [];
  108. let sheet = this.mainSpread.getActiveSheet();
  109. let oldSel = sheet.getSelections()[0];
  110. if(this.gljDatas && this.gljDatas.length > 0){
  111. let glj = this.gljDatas[oldSel.row];
  112. if(!glj) return datas;
  113. let nodes = projectObj.project.projectGLJ.getImpactRationNodes([glj.reference]);
  114. for(let n of nodes){
  115. datas.push(this.getShowRationDatas(n.data));
  116. }
  117. }
  118. return datas;
  119. },
  120. refreshView: function (options, refreshWorkBook) {
  121. let me = this;
  122. let mainHeight = $(window).height()-$(".header").height()-$(".toolsbar").height()-$("#searchPanel").height();
  123. let subHeight = 0;
  124. $('#locateTopDiv').height(mainHeight);
  125. $('#locate_result').height(mainHeight);
  126. $('#locateBottomDiv').height(subHeight);
  127. $('#locate_sub').height(subHeight - 7);
  128. if(options == "ration_glj"){
  129. let locateLibResize = getLocateLibResize();
  130. SlideResize.loadVerticalHeight(locateLibResize.eleObj.module, locateLibResize.eleObj, locateLibResize.limit, function () {
  131. locateObject.refreshWorkBook();
  132. });
  133. }
  134. if (refreshWorkBook) {
  135. me.refreshWorkBook();
  136. }
  137. },
  138. init:function () {
  139. let me = this;
  140. let options = $("input[name='content_type']:checked").val();
  141. let callback = function () {
  142. me.refreshView(options, false);
  143. me.initMainSpread();
  144. me.initSubSpread();
  145. };
  146. if(options == "bills") me.initOutstanding();
  147. options == "bills"?$("#outstandingOptions").show(0,callback):$("#outstandingOptions").hide(0,callback);
  148. },
  149. findRecodes:function () {
  150. let options = $("input[name='content_type']:checked").val();
  151. let keyword = $("#locateInput").val();
  152. switch (options){
  153. case "bills":
  154. this.billsDatas = this.findBills(keyword);
  155. this.showMainData(this.billsDatas,this.bills_setting);
  156. break;
  157. case "ration":
  158. this.rationDatas = this.findRations(keyword);
  159. this.showMainData(this.rationDatas,this.ration_setting);
  160. break;
  161. case "ration_glj":
  162. this.gljDatas = this.findGLJs(keyword);
  163. this.showMainData(this.gljDatas,this.ration_glj_setting);
  164. this.showSubRateDatas();
  165. break;
  166. }
  167. },
  168. onshow:function () {
  169. locateObject.init();
  170. },
  171. matchItem:function (keyword,i) {//true 匹配上,false匹配失败
  172. let match = false;
  173. if(keyword && keyword !="") {//如果keyword为空,匹配所有
  174. if (i.code && i.code.indexOf(keyword) != -1) match = true;
  175. if (i.name && i.name.indexOf(keyword) != -1) match = true;
  176. if(match == false) return false
  177. }
  178. return true;
  179. },
  180. findGLJs:function(keyword){
  181. let datas = [];
  182. let gljList = projectObj.project.projectGLJ.datas.gljList;
  183. gljList = sortProjectGLJ(gljList);
  184. for(let glj of gljList){
  185. // if(glj.quantity == 0 || glj.quantity == '0') continue; 2019-07-01 需求改成消耗量为0也显示
  186. let match = this.matchItem(keyword,glj);
  187. if(match == false) continue;
  188. let data = getGLJDatas(glj);
  189. gljOprObj.setGLJPrice(data,glj);
  190. datas.push(data);
  191. }
  192. return datas;
  193. function getGLJDatas(tem) {
  194. return{
  195. ID:tem.id,
  196. name:tem.name,
  197. code:tem.code,
  198. unit:tem.unit,
  199. specs:tem.specs,
  200. reference:tem
  201. }
  202. }
  203. },
  204. findRations:function (keyword) {
  205. let datas = [];
  206. let items = projectObj.project.mainTree.items;
  207. for(let i of items){
  208. if(i.sourceType == ModuleNames.ration){
  209. let match = this.matchItem(keyword,i.data);
  210. if(match == false) continue;
  211. let bills = this.getShowRationDatas(i.data);
  212. datas.push(bills);
  213. }
  214. }
  215. return datas;
  216. },
  217. getShowRationDatas:function(data){
  218. return{
  219. ID:data.ID,
  220. name:data.name,
  221. code:data.code,
  222. unit:data.unit,
  223. quantity:data.quantity
  224. }
  225. },
  226. findBills:function(keyword){
  227. let datas = [],priceMap={};
  228. let items = projectObj.project.mainTree.items;
  229. for(let i of items){
  230. if(i.sourceType == ModuleNames.bills){
  231. let match = this.matchItem(keyword,i.data);
  232. if(match == false) continue;
  233. let bills = getBillData(i.data);
  234. priceMap = setPriceMap(bills,priceMap);
  235. datas.push(bills);
  236. }
  237. }
  238. setBgColour(datas,priceMap);
  239. datas = _.sortByAll(datas,['code']);
  240. return datas;
  241. function setBgColour(bills,map) {
  242. let outStd = $("#outstanding").prop("checked");
  243. let outInp = $("#outInp").val();
  244. if(outStd == true && outInp && outInp!=""){
  245. for(let b of bills){
  246. if(b.code && b.code.length >= 9){
  247. let key = b.code.substr(0,9);
  248. if(map[key] && map[key].count > 1){
  249. let avg = map[key].total/map[key].count;
  250. let unitPrice = b.unitPrice?parseFloat(b.unitPrice):0;
  251. if(unitPrice ==0 ) continue;
  252. if(Math.abs(unitPrice - avg)/avg * 100 >= parseFloat(outInp)) b.bgColour = "#FFFACD"
  253. }
  254. }
  255. }
  256. }
  257. }
  258. function setPriceMap (bills,map) {
  259. if(bills.code && bills.code.length >= 9){
  260. let key = bills.code.substr(0,9);
  261. let unitPrice = bills.unitPrice?parseFloat(bills.unitPrice):0;
  262. if(map[key]){
  263. map[key].total += unitPrice;
  264. map[key].count ++;
  265. }else {
  266. map[key] = {total:unitPrice,count:1}
  267. }
  268. }
  269. return map;
  270. }
  271. function getBillData(data) {
  272. return{
  273. ID:data.ID,
  274. name:data.name,
  275. code:data.code,
  276. unit:data.unit,
  277. quantity:data.quantity,
  278. unitPrice:data.feesIndex&&data.feesIndex.common?data.feesIndex.common.unitFee:"",
  279. totalPrice:data.feesIndex&&data.feesIndex.common?data.feesIndex.common.totalFee:"",
  280. bgColour:"white"
  281. }
  282. }
  283. },
  284. onSheetDoubleClick:function (e,args) {
  285. let me = locateObject;
  286. let options = $("input[name='content_type']:checked").val();
  287. let sheetName = args.sheet.name()
  288. if(options == "ration_glj"&&sheetName != "locate_sub" ) return;
  289. let datas = options == "bills"? me.billsDatas:me.rationDatas;
  290. if( args.sheet.name() == "locate_sub") datas = me.subRationDatas;
  291. me.locateNode(datas[args.row].ID);
  292. },
  293. gljSelectionChange:function (e,args) {
  294. let me = locateObject;
  295. let newSel = args.newSelections[0];
  296. let oldSel = args.oldSelections?args.oldSelections[0]:{};
  297. if(newSel.row != oldSel.row){
  298. me.showSubRateDatas();
  299. }
  300. },
  301. locateNode:function (ID) {
  302. let node = projectObj.project.mainTree.findNode(ID);
  303. if(node) projectObj.loadFocusLocation(node.serialNo(),1);
  304. },
  305. updateOutStanding:function (outstanding,outInp) {
  306. let outstd = {outstanding:outstanding,outInp:outInp};
  307. let updateData = {type:ModuleNames.project,data:{'ID' : projectObj.project.ID(),'property.locateSetting':outstd}};
  308. projectObj.project.updateNodes([updateData],function () {
  309. projectObj.project.property.locateSetting = outstd;
  310. });
  311. }
  312. };
  313. $("#locate_btn").click(function () {
  314. locateObject.findRecodes();
  315. });
  316. //回车键搜索
  317. $('#locateInput').bind('keypress', function (event) {
  318. if(event.keyCode === 13){
  319. $(this).blur();
  320. locateObject.findRecodes();
  321. }
  322. });
  323. $("input[name='content_type']").each(function(){
  324. $(this).click(function(){
  325. let options = $(this).val();
  326. switch (options){
  327. case "bills":
  328. locateObject.mainSpread.setActiveSheetIndex(0);
  329. break;
  330. case "ration":
  331. locateObject.mainSpread.setActiveSheetIndex(1);
  332. break;
  333. case "ration_glj":
  334. locateObject.mainSpread.setActiveSheetIndex(2);
  335. break;
  336. }
  337. locateObject.init();
  338. });
  339. });
  340. $('#outInp').change(function(){
  341. let me = locateObject;
  342. let process = getDecimal('process');
  343. var newVal = $(this).val();
  344. let outInp = scMathUtil.roundForObj(newVal,process);
  345. let outStd = $("#outstanding").prop("checked");
  346. me.updateOutStanding(outStd,outInp);
  347. });
  348. $('#outstanding').change(function(){
  349. let me = locateObject;
  350. let outInp = $("#outInp").val();
  351. let outStd = $("#outstanding").prop("checked");
  352. me.updateOutStanding(outStd,scMathUtil.roundForObj(outInp,getDecimal('process')));
  353. });