components.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. //去除与已添加的组成物重复的条目
  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. if(clearChecked){
  92. gljList[i].isChecked = false;
  93. }
  94. }
  95. else {
  96. gljList[i].isChecked = true;
  97. }
  98. me.showGljList.push(gljList[i]);
  99. }
  100. }
  101. },
  102. //初始默认radio
  103. initRadio: function () {
  104. let that = repositoryGljObj, me = componentOprObj;
  105. //$('#searchGlj').val('');//恢复搜索文本
  106. //初始化组成物列表
  107. me.selectedList = [].concat(that.currentComponent);
  108. //默认radio所有工料机
  109. if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
  110. $("input[name='glj']:checked")[0].checked = false;
  111. }
  112. $("input[value = 'allGljs']")[0].checked = true;
  113. me.radiosSelected = 'allGljs';
  114. //初始为所有工料机,机械类型可添加机械组成物,混凝土,砂浆、配合比可添加普通材料
  115. me.showGljList = [];
  116. if(me.radiosSelected === 'allGljs'){
  117. me.setShowGljList(that.stdGljList, true);
  118. me.setShowGljList(that.complementaryGljList, true);
  119. that.sortGlj(me.showGljList);
  120. }
  121. },
  122. //监听radios选择事件
  123. radiosChange: function () {
  124. let me = componentOprObj, re = repositoryGljObj;
  125. let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
  126. $('.glj-radio').change(function () {
  127. let val = $("input[name='glj']:checked").val();
  128. me.radiosSelected = val;
  129. //选择改变,数据重新筛选显示
  130. me.showGljList = [];
  131. if(me.radiosSelected === 'allGljs'){
  132. me.setShowGljList(re.stdGljList);
  133. me.setShowGljList(re.complementaryGljList);
  134. }
  135. else if(me.radiosSelected === 'stdGljs'){
  136. me.setShowGljList(re.stdGljList);
  137. }
  138. else if(me.radiosSelected === 'complementaryGljs'){
  139. me.setShowGljList(re.complementaryGljList);
  140. }
  141. re.sortGlj(me.showGljList);
  142. //重新显示
  143. me.showGljItems(me.showGljList, me.gljCurTypeId);
  144. //切换radio后更新cache
  145. if (me.currentOprParent = 1) {
  146. if(re.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  147. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  148. }
  149. else{
  150. me.currentCache = [];
  151. }
  152. } else {
  153. me.currentCache = me.getCache();
  154. }
  155. });
  156. },
  157. //获得选择的组成物
  158. getComponents: function () {
  159. let rst = [];
  160. let me = componentOprObj;
  161. for(let i = 0; i < me.showGljList.length; i++){
  162. }
  163. },
  164. getParentCache: function (nodes) {
  165. let me = componentOprObj, rst = [];
  166. for(let i = 0; i < me.showGljList.length; i++){
  167. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  168. rst.push(me.showGljList[i]);
  169. }
  170. }
  171. rst.sort(function (a, b) {
  172. let rst = 0;
  173. if(a.code > b.code) rst = 1;
  174. else if(a.code < b.code)rst = -1;
  175. return rst;
  176. });
  177. return rst;
  178. },
  179. getCache: function() {
  180. let me = componentOprObj, rst = [];
  181. for (let i = 0; i < me.showGljList.length; i++) {
  182. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  183. rst.push(me.showGljList[i]);
  184. }
  185. }
  186. return rst;
  187. },
  188. showGljItems: function(data, type) {
  189. let me = componentOprObj, re = repositoryGljObj;
  190. if (me.workBook) {
  191. let cacheSection = [];
  192. let pArr = re.parentNodeIds["_pNodeId_" + type];
  193. for (let i = 0; i < data.length; i++) {
  194. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  195. cacheSection.push(data[i]);
  196. } else if (type == data[i].gljClass) {
  197. cacheSection.push(data[i]);
  198. }
  199. }
  200. sheetOpr.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  201. sheetOpr.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
  202. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  203. cacheSection = null;
  204. }
  205. },
  206. //组成物窗口按钮操作
  207. componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
  208. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
  209. conf.click(function () {
  210. //添加选择添加的组成物
  211. let updateArr = [];
  212. let newComponent = [];
  213. //re.currentGlj.component = [];
  214. for(let i = 0, len = me.selectedList.length; i < len; i++){
  215. let isExist = false;
  216. for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
  217. if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
  218. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false
  219. , ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
  220. isExist = true;
  221. break;
  222. }
  223. }
  224. if(!isExist){
  225. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false, ID: me.selectedList[i].ID, consumeAmt: 0});
  226. }
  227. //re.currentGlj.component.push({ID: me.selectedList[i].ID, consumeAmt: 0});
  228. }
  229. re.currentGlj.component = newComponent;
  230. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
  231. if(gljBasePrc !== re.currentGlj.basePrice){
  232. re.currentGlj.basePrice = gljBasePrc;
  233. re.reshowGljBasePrc(re.currentGlj);
  234. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  235. }
  236. updateArr.push(re.currentGlj);
  237. that.updateComponent(updateArr);
  238. $('#componentsCacnel').click();
  239. });
  240. }
  241. };
  242. let componentTypeTreeOprObj = {
  243. onClick: function(event,treeId,treeNode) {
  244. let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
  245. if(me.gljCurTypeId !== treeNode.ID){
  246. me.gljCurTypeId = treeNode.ID;
  247. if (re.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  248. me.currentOprParent = 1;
  249. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + treeNode.ID]);
  250. } else {
  251. me.currentCache = me.getCache();
  252. }
  253. }
  254. me.showGljItems(me.showGljList, gljTypeId);
  255. }
  256. }