components.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. //初始为所有工料机,机械类型可添加机械组成物、机上人工,混凝土,砂浆、配合比可添加普通材料
  77. let machineArr = [302, 303];
  78. let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
  79. let that = repositoryGljObj, me = componentOprObj;
  80. for(let i = 0; i < gljList.length; i++){
  81. if(that.currentGlj.gljType === 301 && machineArr.indexOf(gljList[i].gljType) !== -1 ||
  82. materialArr.indexOf(that.currentGlj.gljType) !== -1 && gljList[i].gljType === 201 ||
  83. that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && (!gljList[i].component || gljList[i].component.length === 0) && gljList[i].ID !== that.currentGlj.ID){
  84. //去除与已添加的组成物重复的条目
  85. let isExist = false;
  86. for(let j = 0; j < that.currentComponent.length; j++){
  87. if(that.currentComponent[j].ID === gljList[i].ID){
  88. isExist = true;
  89. break;
  90. }
  91. }
  92. if(!isExist){
  93. if(clearChecked){
  94. gljList[i].isChecked = false;
  95. }
  96. }
  97. else {
  98. gljList[i].isChecked = true;
  99. }
  100. me.showGljList.push(gljList[i]);
  101. }
  102. }
  103. },
  104. //初始默认radio
  105. initRadio: function () {
  106. let that = repositoryGljObj, me = componentOprObj;
  107. $('#gljSearchKeyword').val('');//恢复搜索文本
  108. //初始化组成物列表
  109. me.selectedList = [].concat(that.currentComponent);
  110. //默认radio所有工料机
  111. if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
  112. $("input[name='glj']:checked")[0].checked = false;
  113. }
  114. $("input[value = 'allGljs']")[0].checked = true;
  115. me.radiosSelected = 'allGljs';
  116. //初始为所有工料机,机械类型可添加机械组成物,混凝土,砂浆、配合比可添加普通材料
  117. me.showGljList = [];
  118. if(me.radiosSelected === 'allGljs'){
  119. me.setShowGljList(that.stdGljList, true);
  120. me.setShowGljList(that.complementaryGljList, true);
  121. that.sortGlj(me.showGljList);
  122. }
  123. },
  124. filterDatasAndShow: function () {
  125. let me = componentOprObj, re = repositoryGljObj;
  126. let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
  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. //搜索匹配
  142. let searchStr = $('#gljSearchKeyword').val();
  143. if(searchStr && searchStr.trim() != ''){
  144. let reg = new RegExp(searchStr);
  145. me.showGljList = _.filter(me.showGljList, function (data) {
  146. return reg.test(data.code) || reg.test(data.name);
  147. });
  148. }
  149. re.sortGlj(me.showGljList);
  150. //重新显示
  151. me.showGljItems(me.showGljList, me.gljCurTypeId);
  152. //切换radio后更新cache
  153. if (me.currentOprParent = 1) {
  154. if(re.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  155. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  156. }
  157. else{
  158. me.currentCache = [];
  159. }
  160. } else {
  161. me.currentCache = me.getCache();
  162. }
  163. },
  164. //监听radios选择事件
  165. radiosChange: function () {
  166. let me = componentOprObj, re = repositoryGljObj;
  167. let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
  168. $('.glj-radio').change(function () {
  169. me.filterDatasAndShow();
  170. });
  171. },
  172. //获得选择的组成物
  173. getComponents: function () {
  174. let rst = [];
  175. let me = componentOprObj;
  176. for(let i = 0; i < me.showGljList.length; i++){
  177. }
  178. },
  179. getParentCache: function (nodes) {
  180. let me = componentOprObj, rst = [];
  181. for(let i = 0; i < me.showGljList.length; i++){
  182. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  183. rst.push(me.showGljList[i]);
  184. }
  185. }
  186. rst.sort(function (a, b) {
  187. let rst = 0;
  188. if(a.code > b.code) rst = 1;
  189. else if(a.code < b.code)rst = -1;
  190. return rst;
  191. });
  192. return rst;
  193. },
  194. getCache: function() {
  195. let me = componentOprObj, rst = [];
  196. for (let i = 0; i < me.showGljList.length; i++) {
  197. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  198. rst.push(me.showGljList[i]);
  199. }
  200. }
  201. return rst;
  202. },
  203. showGljItems: function(data, type) {
  204. let me = componentOprObj, re = repositoryGljObj;
  205. if (me.workBook) {
  206. let cacheSection = [];
  207. let pArr = re.parentNodeIds["_pNodeId_" + type];
  208. for (let i = 0; i < data.length; i++) {
  209. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  210. cacheSection.push(data[i]);
  211. } else if (type == data[i].gljClass) {
  212. cacheSection.push(data[i]);
  213. }
  214. }
  215. sheetOpr.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  216. sheetOpr.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
  217. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  218. cacheSection = null;
  219. }
  220. },
  221. //组成物窗口按钮操作
  222. componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
  223. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
  224. conf.click(function () {
  225. //添加选择添加的组成物
  226. let updateArr = [];
  227. let newComponent = [];
  228. //re.currentGlj.component = [];
  229. for(let i = 0, len = me.selectedList.length; i < len; i++){
  230. let isExist = false;
  231. for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
  232. if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
  233. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false
  234. , ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
  235. isExist = true;
  236. break;
  237. }
  238. }
  239. if(!isExist){
  240. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false, ID: me.selectedList[i].ID, consumeAmt: 0});
  241. }
  242. //re.currentGlj.component.push({ID: me.selectedList[i].ID, consumeAmt: 0});
  243. }
  244. re.currentGlj.component = newComponent;
  245. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
  246. if(gljBasePrc !== re.currentGlj.basePrice){
  247. re.currentGlj.basePrice = gljBasePrc;
  248. re.reshowGljBasePrc(re.currentGlj);
  249. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  250. }
  251. updateArr.push(re.currentGlj);
  252. that.updateComponent(updateArr);
  253. $('#componentsCacnel').click();
  254. });
  255. }
  256. };
  257. let componentTypeTreeOprObj = {
  258. onClick: function(event,treeId,treeNode) {
  259. let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
  260. if(me.gljCurTypeId !== treeNode.ID){
  261. me.gljCurTypeId = treeNode.ID;
  262. if (re.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  263. me.currentOprParent = 1;
  264. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + treeNode.ID]);
  265. } else {
  266. me.currentCache = me.getCache();
  267. }
  268. }
  269. me.showGljItems(me.showGljList, gljTypeId);
  270. }
  271. }
  272. $(document).ready(function () {
  273. $('#gljSearchKeyword').change(function () {
  274. componentOprObj.filterDatasAndShow();
  275. });
  276. $('#gljSearchKeyword').bind('keypress', function (e) {
  277. if(e.keyCode === 13){
  278. $(this).blur();
  279. return false;
  280. }
  281. });
  282. });