components.js 12 KB

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