components.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**
  2. * Created by Zhong on 2017/8/25.
  3. */
  4. /*
  5. 弹出组成物窗口 组成物表
  6. * */
  7. let componentOprObj = {
  8. treeObj:null,
  9. rootNode: null,//分类树根节点
  10. radiosSelected: null,//allGljs, stdGljs, complementaryGljs
  11. workBook: null,
  12. selectedList: [],//选中的组成物
  13. setting: {
  14. owner: "components",
  15. header: [
  16. {headerName:"选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center"},
  17. {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  18. {headerName:"名称",headerWidth:120,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
  19. {headerName:"规格型号",headerWidth:80,dataCode:"specs", dataType: "String", hAlign: "center", vAlign: "center"},
  20. {headerName:"单位",headerWidth:80,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
  21. {headerName:"单价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  22. {headerName:"类型",headerWidth:80,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
  23. ]
  24. },
  25. buildSheet: function (container) {
  26. let me = componentOprObj;
  27. me.workBook = sheetOpr.buildSheet(container, me.setting, 30);
  28. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  29. me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
  30. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  31. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  32. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  33. me.componentsBtnOpr($('#componentsConf'));
  34. me.radiosChange();
  35. },
  36. onClipboardPasting: function (sender, args) {
  37. args.cancel = true;
  38. },
  39. onCellEditStart: function (sender, args) {
  40. args.cancel = true;
  41. },
  42. onButtonClicked: function (sender, args) {
  43. let me = componentOprObj, re = repositoryGljObj;
  44. let val = args.sheet.getValue(args.row, args.col);
  45. let thisComponent = me.currentCache[args.row];
  46. thisComponent.isChecked = val;
  47. if(args.sheet.isEditing()){
  48. args.sheet.endEdit(true);
  49. }
  50. else{
  51. //维护选中组成物列表
  52. if(val === true){
  53. let isExist = false;
  54. for(let i = 0, len = me.selectedList.length; i < len; i++){
  55. if(me.selectedList[i].ID === thisComponent.ID){
  56. isExist = true;
  57. break;
  58. }
  59. }
  60. if(!isExist){
  61. me.selectedList.push(thisComponent);
  62. }
  63. }
  64. else if(val === false){
  65. for(let i = 0, len = me.selectedList.length; i < len; i++){
  66. if(me.selectedList[i].ID === thisComponent.ID){
  67. me.selectedList.splice(i, 1);
  68. break;
  69. }
  70. }
  71. }
  72. }
  73. },
  74. setShowGljList: function (gljList, clearChecked) {
  75. //初始为所有工料机,机械类型可添加机械组成物、机上人工,混凝土,砂浆、配合比可添加普通材料
  76. let machineArr = [302, 303];
  77. let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
  78. let that = repositoryGljObj, me = componentOprObj;
  79. for(let i = 0; i < gljList.length; i++){
  80. if(that.currentGlj.gljType === 301 && machineArr.indexOf(gljList[i].gljType) !== -1 ||
  81. materialArr.indexOf(that.currentGlj.gljType) !== -1 && gljList[i].gljType === 201 ||
  82. that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && (!gljList[i].component || gljList[i].component.length === 0) && gljList[i].ID !== that.currentGlj.ID){
  83. //去除与已添加的组成物重复的条目
  84. let isExist = false;
  85. for(let j = 0; j < that.currentComponent.length; j++){
  86. if(that.currentComponent[j].ID === gljList[i].ID){
  87. isExist = true;
  88. break;
  89. }
  90. }
  91. if(!isExist){
  92. if(clearChecked){
  93. gljList[i].isChecked = false;
  94. }
  95. }
  96. else {
  97. gljList[i].isChecked = true;
  98. }
  99. me.showGljList.push(gljList[i]);
  100. }
  101. }
  102. },
  103. //初始默认radio
  104. initRadio: function () {
  105. let that = repositoryGljObj, me = componentOprObj;
  106. //$('#searchGlj').val('');//恢复搜索文本
  107. //初始化组成物列表
  108. me.selectedList = [].concat(that.currentComponent);
  109. //默认radio所有工料机
  110. if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
  111. $("input[name='glj']:checked")[0].checked = false;
  112. }
  113. $("input[value = 'allGljs']")[0].checked = true;
  114. me.radiosSelected = 'allGljs';
  115. //初始为所有工料机,机械类型可添加机械组成物,混凝土,砂浆、配合比可添加普通材料
  116. me.showGljList = [];
  117. if(me.radiosSelected === 'allGljs'){
  118. me.setShowGljList(that.stdGljList, true);
  119. me.setShowGljList(that.complementaryGljList, true);
  120. that.sortGlj(me.showGljList);
  121. }
  122. },
  123. //监听radios选择事件
  124. radiosChange: function () {
  125. let me = componentOprObj, re = repositoryGljObj;
  126. let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
  127. $('.glj-radio').change(function () {
  128. let val = $("input[name='glj']:checked").val();
  129. me.radiosSelected = val;
  130. //选择改变,数据重新筛选显示
  131. me.showGljList = [];
  132. if(me.radiosSelected === 'allGljs'){
  133. me.setShowGljList(re.stdGljList);
  134. me.setShowGljList(re.complementaryGljList);
  135. }
  136. else if(me.radiosSelected === 'stdGljs'){
  137. me.setShowGljList(re.stdGljList);
  138. }
  139. else if(me.radiosSelected === 'complementaryGljs'){
  140. me.setShowGljList(re.complementaryGljList);
  141. }
  142. re.sortGlj(me.showGljList);
  143. //重新显示
  144. me.showGljItems(me.showGljList, me.gljCurTypeId);
  145. //切换radio后更新cache
  146. if (me.currentOprParent = 1) {
  147. if(re.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  148. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  149. }
  150. else{
  151. me.currentCache = [];
  152. }
  153. } else {
  154. me.currentCache = me.getCache();
  155. }
  156. });
  157. },
  158. //获得选择的组成物
  159. getComponents: function () {
  160. let rst = [];
  161. let me = componentOprObj;
  162. for(let i = 0; i < me.showGljList.length; i++){
  163. }
  164. },
  165. getParentCache: function (nodes) {
  166. let me = componentOprObj, rst = [];
  167. for(let i = 0; i < me.showGljList.length; i++){
  168. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  169. rst.push(me.showGljList[i]);
  170. }
  171. }
  172. rst.sort(function (a, b) {
  173. let rst = 0;
  174. if(a.code > b.code) rst = 1;
  175. else if(a.code < b.code)rst = -1;
  176. return rst;
  177. });
  178. return rst;
  179. },
  180. getCache: function() {
  181. let me = componentOprObj, rst = [];
  182. for (let i = 0; i < me.showGljList.length; i++) {
  183. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  184. rst.push(me.showGljList[i]);
  185. }
  186. }
  187. return rst;
  188. },
  189. showGljItems: function(data, type) {
  190. let me = componentOprObj, re = repositoryGljObj;
  191. if (me.workBook) {
  192. let cacheSection = [];
  193. let pArr = re.parentNodeIds["_pNodeId_" + type];
  194. for (let i = 0; i < data.length; i++) {
  195. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  196. cacheSection.push(data[i]);
  197. } else if (type == data[i].gljClass) {
  198. cacheSection.push(data[i]);
  199. }
  200. }
  201. sheetOpr.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  202. sheetOpr.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
  203. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  204. cacheSection = null;
  205. }
  206. },
  207. //组成物窗口按钮操作
  208. componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
  209. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
  210. conf.click(function () {
  211. //添加选择添加的组成物
  212. let updateArr = [];
  213. let newComponent = [];
  214. //re.currentGlj.component = [];
  215. for(let i = 0, len = me.selectedList.length; i < len; i++){
  216. let isExist = false;
  217. for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
  218. if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
  219. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false
  220. , ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
  221. isExist = true;
  222. break;
  223. }
  224. }
  225. if(!isExist){
  226. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false, ID: me.selectedList[i].ID, consumeAmt: 0});
  227. }
  228. //re.currentGlj.component.push({ID: me.selectedList[i].ID, consumeAmt: 0});
  229. }
  230. re.currentGlj.component = newComponent;
  231. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
  232. if(gljBasePrc !== re.currentGlj.basePrice){
  233. re.currentGlj.basePrice = gljBasePrc;
  234. re.reshowGljBasePrc(re.currentGlj);
  235. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  236. }
  237. updateArr.push(re.currentGlj);
  238. that.updateComponent(updateArr);
  239. $('#componentsCacnel').click();
  240. });
  241. }
  242. };
  243. let componentTypeTreeOprObj = {
  244. onClick: function(event,treeId,treeNode) {
  245. let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
  246. if(me.gljCurTypeId !== treeNode.ID){
  247. me.gljCurTypeId = treeNode.ID;
  248. if (re.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  249. me.currentOprParent = 1;
  250. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + treeNode.ID]);
  251. } else {
  252. me.currentCache = me.getCache();
  253. }
  254. }
  255. me.showGljItems(me.showGljList, gljTypeId);
  256. }
  257. }