components.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /**
  2. * Created by Zhong on 2017/10/16.
  3. */
  4. /*
  5. 弹出组成物窗口 组成物表
  6. * */
  7. let componentOprObj = {
  8. treeObj:null,
  9. rootNode: null,//分类树根节点
  10. workBook: null,
  11. selectedList: [],//选中的组成物
  12. setting: {
  13. owner: "components",
  14. header: [
  15. {headerName:"选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center"},
  16. {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  17. {headerName:"名称",headerWidth:120,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
  18. {headerName:"规格型号",headerWidth:80,dataCode:"specs", dataType: "String", hAlign: "center", vAlign: "center"},
  19. {headerName:"单位",headerWidth:80,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
  20. {headerName:"单价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  21. {headerName:"类型",headerWidth:80,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
  22. ]
  23. },
  24. buildSheet: function (container) {
  25. let me = componentOprObj;
  26. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  27. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  28. me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
  29. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  30. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  31. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  32. me.workBook.getSheet(0).getRange(-1, 0, -1, 1).cellType(new GC.Spread.Sheets.CellTypes.CheckBox());
  33. me.componentsBtnOpr($('#componentsConf'));
  34. },
  35. onClipboardPasting: function (sender, args) {
  36. args.cancel = true;
  37. },
  38. onCellEditStart: function (sender, args) {
  39. args.cancel = true;
  40. },
  41. onButtonClicked: function (sender, args) {
  42. let me = componentOprObj, re = repositoryGljObj;
  43. let val = args.sheet.getValue(args.row, args.col);
  44. let thisComponent = me.currentCache[args.row];
  45. thisComponent.isChecked = val;
  46. if(args.sheet.isEditing()){
  47. args.sheet.endEdit(true);
  48. }
  49. else{
  50. //维护选中组成物列表
  51. if(val === true){
  52. let isExist = false;
  53. for(let i = 0, len = me.selectedList.length; i < len; i++){
  54. if(me.selectedList[i].ID === thisComponent.ID){
  55. isExist = true;
  56. break;
  57. }
  58. }
  59. if(!isExist){
  60. me.selectedList.push(thisComponent);
  61. }
  62. }
  63. else if(val === false){
  64. for(let i = 0, len = me.selectedList.length; i < len; i++){
  65. if(me.selectedList[i].ID === thisComponent.ID){
  66. me.selectedList.splice(i, 1);
  67. break;
  68. }
  69. }
  70. }
  71. }
  72. },
  73. setShowGljList: function (gljList, clearChecked) {
  74. let that = repositoryGljObj, me = componentOprObj;
  75. for(let i = 0; i < gljList.length; i++){
  76. if(machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljList[i].gljType) ||
  77. materialAllowComponent.includes(that.currentGlj.gljType) && gljList[i].gljType === 201||
  78. that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && (!gljList[i].component || gljList[i].component.length === 0) && gljList[i].ID !== that.currentGlj.ID){
  79. let isExist = false;
  80. for(let j = 0; j < that.currentComponent.length; j++){
  81. if(that.currentComponent[j].ID === gljList[i].ID){
  82. isExist = true;
  83. break;
  84. }
  85. }
  86. if(!isExist){
  87. if(clearChecked){
  88. gljList[i].isChecked = false;
  89. }
  90. }
  91. else {
  92. gljList[i].isChecked = true;
  93. }
  94. me.showGljList.push(gljList[i]);
  95. }
  96. }
  97. },
  98. //初始默认radio
  99. initRadio: function () {
  100. let that = repositoryGljObj, me = componentOprObj;
  101. //初始化组成物列表
  102. me.selectedList = [].concat(that.currentComponent);
  103. //初始为所有工料机,机械类型可添加机械组成物,混凝土,砂浆、配合比可添加普通材料
  104. me.showGljList = [];
  105. me.setShowGljList(that.gljList, true);
  106. that.sortGlj(me.showGljList);
  107. },
  108. getParentCache: function (nodes) {
  109. let me = componentOprObj, rst = [];
  110. for(let i = 0; i < me.showGljList.length; i++){
  111. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  112. rst.push(me.showGljList[i]);
  113. }
  114. }
  115. rst.sort(function (a, b) {
  116. let rst = 0;
  117. if(a.code > b.code) rst = 1;
  118. else if(a.code < b.code)rst = -1;
  119. return rst;
  120. });
  121. return rst;
  122. },
  123. getCache: function() {
  124. let me = componentOprObj, rst = [];
  125. for (let i = 0; i < me.showGljList.length; i++) {
  126. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  127. rst.push(me.showGljList[i]);
  128. }
  129. }
  130. return rst;
  131. },
  132. showGljItems: function(data, type) {
  133. let me = componentOprObj, re = repositoryGljObj;
  134. if (me.workBook) {
  135. let cacheSection = data;
  136. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  137. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
  138. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  139. cacheSection = null;
  140. }
  141. },
  142. //组成物窗口按钮操作
  143. componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
  144. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
  145. conf.click(function () {
  146. //添加选择添加的组成物
  147. let updateArr = [];
  148. let newComponent = [];
  149. for(let i = 0, len = me.selectedList.length; i < len; i++){
  150. let isExist = false;
  151. for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
  152. if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
  153. newComponent.push({ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
  154. isExist = true;
  155. break;
  156. }
  157. }
  158. if(!isExist){
  159. newComponent.push({ID: me.selectedList[i].ID, consumeAmt: 0});
  160. }
  161. }
  162. re.currentGlj.component = newComponent;
  163. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
  164. if(gljBasePrc !== re.currentGlj.basePrice){
  165. re.currentGlj.basePrice = gljBasePrc;
  166. re.reshowGljBasePrc(re.currentGlj);
  167. }
  168. updateArr.push(re.currentGlj);
  169. that.updateComponent(updateArr);
  170. $('#componentsCacnel').click();
  171. });
  172. }
  173. };
  174. let componentTypeTreeOprObj = {
  175. onClick: function(event,treeId,treeNode) {
  176. let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
  177. if(me.gljCurTypeId !== treeNode.ID){
  178. me.gljCurTypeId = treeNode.ID;
  179. if (re.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  180. me.currentOprParent = 1;
  181. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + treeNode.ID]);
  182. } else {
  183. me.currentCache = me.getCache();
  184. }
  185. }
  186. //me.showGljItems(me.showGljList, gljTypeId);
  187. me.showGljItems(me.currentCache, gljTypeId);
  188. }
  189. }