components.js 12 KB

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