components.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /**
  2. * Created by Zhong on 2017/8/25.
  3. */
  4. /*
  5. 弹出组成物窗口 组成物表
  6. * */
  7. let componentOprObj = {
  8. treeObj: null,
  9. rootNode: null,//分类树根节点
  10. parentNodeIds: {},
  11. radiosSelected: null,//allGljs, stdGljs, complementaryGljs
  12. workBook: null,
  13. selectedList: [],//选中的组成物
  14. setting: {
  15. owner: "components",
  16. header: [
  17. { headerName: "选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center" },
  18. { headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  19. { headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center" },
  20. { headerName: "规格型号", headerWidth: 80, dataCode: "specs", dataType: "String", hAlign: "center", vAlign: "center" },
  21. { headerName: "单位", headerWidth: 80, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center" },
  22. { headerName: "单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center" },
  23. { headerName: "类型", headerWidth: 80, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center" }
  24. ]
  25. },
  26. //生成列头(多单价)
  27. initHeaders: function (priceProperties) {
  28. let headers = [
  29. { headerName: "选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center" },
  30. { headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  31. { headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center" },
  32. { headerName: "规格型号", headerWidth: 80, dataCode: "specs", dataType: "String", hAlign: "center", vAlign: "center" },
  33. { headerName: "单位", headerWidth: 80, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center" },
  34. { headerName: "类型", headerWidth: 80, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center" }
  35. ];
  36. //生成单价列
  37. if (!priceProperties || priceProperties.length === 0) {
  38. headers.push({ headerName: "定额价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center" });
  39. }
  40. else {
  41. for (let priceProp of priceProperties) {
  42. let colData = {
  43. headerName: priceProp.price.dataName,
  44. headerWidth: 90,
  45. dataCode: priceProp.price.dataCode,
  46. dataType: 'Number',
  47. formatter: '0.00',
  48. hAlign: 'right',
  49. vAlign: 'center'
  50. };
  51. headers.push(colData);
  52. }
  53. }
  54. let tailHeaders = [
  55. ];
  56. headers = headers.concat(tailHeaders);
  57. return headers;
  58. },
  59. buildSheet: function (container) {
  60. let me = componentOprObj;
  61. //生成人材机组成物表格列头
  62. me.setting.header = me.initHeaders(priceProperties);
  63. //生成人材机组成物列映射
  64. sheetCommonObj.initColMapping(me, me.setting.header);
  65. repositoryGljObj.initPriceCols.call(me, priceProperties, me.colMapping);
  66. me.workBook = sheetOpr.buildSheet(container, me.setting, 30);
  67. if (priceProperties && priceProperties.length > 0) {
  68. me.workBook.getSheet(0).frozenColumnCount(6);
  69. }
  70. sheetCommonObj.spreadDefaultStyle(me.workBook);
  71. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  72. me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
  73. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  74. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  75. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  76. me.componentsBtnOpr($('#componentsConf'));
  77. me.radiosChange();
  78. },
  79. onClipboardPasting: function (sender, args) {
  80. args.cancel = true;
  81. },
  82. onCellEditStart: function (sender, args) {
  83. args.cancel = true;
  84. },
  85. onButtonClicked: function (sender, args) {
  86. let me = componentOprObj, re = repositoryGljObj;
  87. let val = args.sheet.getValue(args.row, args.col);
  88. let thisComponent = me.currentCache[args.row];
  89. thisComponent.isChecked = val;
  90. if (args.sheet.isEditing()) {
  91. args.sheet.endEdit(true);
  92. }
  93. else {
  94. //维护选中组成物列表
  95. if (val === true) {
  96. let isExist = false;
  97. for (let i = 0, len = me.selectedList.length; i < len; i++) {
  98. if (me.selectedList[i].ID === thisComponent.ID) {
  99. isExist = true;
  100. break;
  101. }
  102. }
  103. if (!isExist) {
  104. me.selectedList.push(thisComponent);
  105. }
  106. }
  107. else if (val === false) {
  108. for (let i = 0, len = me.selectedList.length; i < len; i++) {
  109. if (me.selectedList[i].ID === thisComponent.ID) {
  110. me.selectedList.splice(i, 1);
  111. break;
  112. }
  113. }
  114. }
  115. }
  116. },
  117. setShowGljList: function (gljList, clearChecked) {
  118. let that = repositoryGljObj, me = componentOprObj;
  119. for (let i = 0; i < gljList.length; i++) {
  120. if (machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljList[i].gljType) ||
  121. materialAllowComponent.includes(that.currentGlj.gljType) && gljList[i].gljType === 201 ||
  122. that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && (!gljList[i].component || gljList[i].component.length === 0) && gljList[i].ID !== that.currentGlj.ID) {
  123. //去除与已添加的组成物重复的条目
  124. let isExist = false;
  125. for (let j = 0; j < that.currentComponent.length; j++) {
  126. if (that.currentComponent[j].ID === gljList[i].ID) {
  127. isExist = true;
  128. break;
  129. }
  130. }
  131. if (!isExist) {
  132. gljList[i].isChecked = false;
  133. }
  134. else {
  135. gljList[i].isChecked = true;
  136. }
  137. me.showGljList.push(gljList[i]);
  138. }
  139. }
  140. },
  141. //初始化分类树
  142. //@param {String}type(标准或补充) {Array}treeData(树数据)
  143. initClassTree: function (type, treeData) {
  144. let me = this;
  145. if (me.treeObj) {
  146. me.treeObj.destroy();
  147. me.parentNodeIds = {};
  148. }
  149. zTreeHelper.createTree(treeData, componentSetting, "componentTree", componentOprObj);
  150. let rootNode = componentOprObj.treeObj.getNodes()[0];
  151. if (rootNode && rootNode.isParent && rootNode.isFirstNode) {
  152. componentOprObj.rootNode = rootNode;
  153. }
  154. if (me.rootNode) {
  155. me.treeObj.selectNode(me.rootNode);
  156. componentTypeTreeOprObj.onClick(null, 'componentTree', me.rootNode);
  157. }
  158. },
  159. //初始默认radio
  160. initRadio: function () {
  161. let that = repositoryGljObj, me = componentOprObj;
  162. $('#gljSearchKeyword').val('');//恢复搜索文本
  163. //初始化组成物列表
  164. me.selectedList = [].concat(that.currentComponent);
  165. //默认radio所有工料机
  166. if (typeof $("input[name='glj']:checked")[0] !== 'undefined') {
  167. $("input[name='glj']:checked")[0].checked = false;
  168. }
  169. $("input[value = 'stdGljs']")[0].checked = true;
  170. me.radiosSelected = 'stdGljs';
  171. //初始为所有工料机,机械类型可添加机械组成物,混凝土,砂浆、配合比可添加普通材料
  172. me.showGljList = [];
  173. if (me.radiosSelected === 'stdGljs') {
  174. me.setShowGljList(that.stdGljList, true);
  175. //me.setShowGljList(that.complementaryGljList, true);
  176. that.sortGlj(me.showGljList);
  177. }
  178. },
  179. filterDatasAndShow: function () {
  180. let me = componentOprObj, re = repositoryGljObj;
  181. let val = $("input[name='glj']:checked").val();
  182. me.radiosSelected = val;
  183. //选择改变,数据重新筛选显示
  184. me.showGljList = [];
  185. if (me.radiosSelected === 'allGljs') {
  186. me.setShowGljList(re.stdGljList);
  187. me.setShowGljList(re.complementaryGljList);
  188. }
  189. else if (me.radiosSelected === 'stdGljs') {
  190. me.setShowGljList(re.stdGljList);
  191. }
  192. else if (me.radiosSelected === 'complementaryGljs') {
  193. me.setShowGljList(re.complementaryGljList);
  194. }
  195. //搜索匹配
  196. let searchStr = $('#gljSearchKeyword').val();
  197. if (searchStr && searchStr.trim() != '') {
  198. let reg = new RegExp(searchStr);
  199. me.showGljList = _.filter(me.showGljList, function (data) {
  200. return reg.test(data.code) || reg.test(data.name);
  201. });
  202. }
  203. re.sortGlj(me.showGljList);
  204. //重新显示
  205. me.showGljItems(me.showGljList, me.gljCurTypeId);
  206. //切换radio后更新cache
  207. if (me.currentOprParent = 1) {
  208. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  209. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  210. }
  211. else {
  212. me.currentCache = [];
  213. }
  214. } else {
  215. me.currentCache = me.getCache();
  216. }
  217. },
  218. //监听radios选择事件
  219. radiosChange: function () {
  220. let me = componentOprObj, gc = gljClassTreeObj;
  221. $('.glj-radio').change(function () {
  222. me.filterDatasAndShow();
  223. if ($(this).val() === 'stdGljs') {
  224. me.initClassTree('std', gc.treeData.std);
  225. } else {
  226. me.initClassTree('comple', gc.treeData.comple);
  227. }
  228. //me.filterDatasAndShow();
  229. });
  230. },
  231. getParentCache: function (nodes) {
  232. let me = componentOprObj, rst = [];
  233. for (let i = 0; i < me.showGljList.length; i++) {
  234. if (nodes.indexOf(me.showGljList[i].gljClass) !== -1) {
  235. rst.push(me.showGljList[i]);
  236. }
  237. }
  238. rst.sort(function (a, b) {
  239. let rst = 0;
  240. if (a.code > b.code) rst = 1;
  241. else if (a.code < b.code) rst = -1;
  242. return rst;
  243. });
  244. return rst;
  245. },
  246. getCache: function () {
  247. let me = componentOprObj, rst = [];
  248. for (let i = 0; i < me.showGljList.length; i++) {
  249. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  250. rst.push(me.showGljList[i]);
  251. }
  252. }
  253. return rst;
  254. },
  255. showGljItems: function (data, type) {
  256. let me = componentOprObj, re = repositoryGljObj;
  257. if (me.workBook) {
  258. let cacheSection = [];
  259. let pArr = me.parentNodeIds["_pNodeId_" + type];
  260. for (let i = 0; i < data.length; i++) {
  261. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  262. cacheSection.push(data[i]);
  263. } else if (type == data[i].gljClass) {
  264. cacheSection.push(data[i]);
  265. }
  266. }
  267. sheetOpr.showData(me, me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
  268. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  269. cacheSection = null;
  270. }
  271. },
  272. //组成物窗口按钮操作
  273. componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
  274. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
  275. conf.click(function () {
  276. //添加选择添加的组成物
  277. let updateArr = [];
  278. let newComponent = [];
  279. //re.currentGlj.component = [];
  280. for (let i = 0, len = me.selectedList.length; i < len; i++) {
  281. let isExist = false;
  282. for (let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++) {
  283. if (me.selectedList[i].ID === re.currentGlj.component[j].ID) {
  284. let newComponentObj = { isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false, ID: me.selectedList[i].ID }
  285. that.copyConsumeAmt(newComponentObj, re.currentGlj.component[j]);
  286. newComponent.push(newComponentObj);
  287. /* newComponent.push({
  288. isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false
  289. , ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt
  290. }); */
  291. isExist = true;
  292. break;
  293. }
  294. }
  295. if (!isExist) {
  296. let newComponentObj = { isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false, ID: me.selectedList[i].ID };
  297. that.initConsumeAmt(newComponentObj);
  298. newComponent.push(newComponentObj);
  299. }
  300. //re.currentGlj.component.push({ID: me.selectedList[i].ID, consumeAmt: 0});
  301. }
  302. re.currentGlj.component = newComponent;
  303. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
  304. if (re.isGljPriceChange(re.currentGlj, gljBasePrc)) {
  305. re.setPrice(re.currentGlj, gljBasePrc);
  306. re.reshowGljBasePrc(re.currentGlj);
  307. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  308. }
  309. updateArr.push(re.currentGlj);
  310. that.updateComponent(updateArr);
  311. $('#componentsCacnel').click();
  312. });
  313. }
  314. };
  315. let componentTypeTreeOprObj = {
  316. onClick: function (event, treeId, treeNode) {
  317. let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
  318. if (me.gljCurTypeId !== treeNode.ID) {
  319. me.gljCurTypeId = treeNode.ID;
  320. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  321. me.currentOprParent = 1;
  322. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  323. } else {
  324. me.currentCache = me.getCache();
  325. }
  326. }
  327. me.showGljItems(me.showGljList, gljTypeId);
  328. }
  329. }
  330. $(document).ready(function () {
  331. $('#gljSearchKeyword').bind('keyup', function () {
  332. componentOprObj.filterDatasAndShow();
  333. });
  334. /*$('#gljSearchKeyword').bind('keypress', function (e) {
  335. if(e.keyCode === 13){
  336. $(this).blur();
  337. return false;
  338. }
  339. });*/
  340. });