components.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. $('#gljSearchKeyword').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. filterDatasAndShow: function () {
  124. let me = componentOprObj, re = repositoryGljObj;
  125. let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
  126. let val = $("input[name='glj']:checked").val();
  127. me.radiosSelected = val;
  128. //选择改变,数据重新筛选显示
  129. me.showGljList = [];
  130. if(me.radiosSelected === 'allGljs'){
  131. me.setShowGljList(re.stdGljList);
  132. me.setShowGljList(re.complementaryGljList);
  133. }
  134. else if(me.radiosSelected === 'stdGljs'){
  135. me.setShowGljList(re.stdGljList);
  136. }
  137. else if(me.radiosSelected === 'complementaryGljs'){
  138. me.setShowGljList(re.complementaryGljList);
  139. }
  140. //搜索匹配
  141. let searchStr = $('#gljSearchKeyword').val();
  142. if(searchStr && searchStr.trim() != ''){
  143. let reg = new RegExp(searchStr);
  144. me.showGljList = _.filter(me.showGljList, function (data) {
  145. return reg.test(data.code) || reg.test(data.name);
  146. });
  147. }
  148. re.sortGlj(me.showGljList);
  149. //重新显示
  150. me.showGljItems(me.showGljList, me.gljCurTypeId);
  151. //切换radio后更新cache
  152. if (me.currentOprParent = 1) {
  153. if(re.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  154. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  155. }
  156. else{
  157. me.currentCache = [];
  158. }
  159. } else {
  160. me.currentCache = me.getCache();
  161. }
  162. },
  163. //监听radios选择事件
  164. radiosChange: function () {
  165. let me = componentOprObj, re = repositoryGljObj;
  166. let materialArr = [202, 203, 204];//混凝土、砂浆、配合比, 201普通材料
  167. $('.glj-radio').change(function () {
  168. me.filterDatasAndShow();
  169. });
  170. },
  171. //获得选择的组成物
  172. getComponents: function () {
  173. let rst = [];
  174. let me = componentOprObj;
  175. for(let i = 0; i < me.showGljList.length; i++){
  176. }
  177. },
  178. getParentCache: function (nodes) {
  179. let me = componentOprObj, rst = [];
  180. for(let i = 0; i < me.showGljList.length; i++){
  181. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  182. rst.push(me.showGljList[i]);
  183. }
  184. }
  185. rst.sort(function (a, b) {
  186. let rst = 0;
  187. if(a.code > b.code) rst = 1;
  188. else if(a.code < b.code)rst = -1;
  189. return rst;
  190. });
  191. return rst;
  192. },
  193. getCache: function() {
  194. let me = componentOprObj, rst = [];
  195. for (let i = 0; i < me.showGljList.length; i++) {
  196. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  197. rst.push(me.showGljList[i]);
  198. }
  199. }
  200. return rst;
  201. },
  202. showGljItems: function(data, type) {
  203. let me = componentOprObj, re = repositoryGljObj;
  204. if (me.workBook) {
  205. let cacheSection = [];
  206. let pArr = re.parentNodeIds["_pNodeId_" + type];
  207. for (let i = 0; i < data.length; i++) {
  208. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  209. cacheSection.push(data[i]);
  210. } else if (type == data[i].gljClass) {
  211. cacheSection.push(data[i]);
  212. }
  213. }
  214. sheetOpr.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  215. sheetOpr.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
  216. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  217. cacheSection = null;
  218. }
  219. },
  220. //组成物窗口按钮操作
  221. componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
  222. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
  223. conf.click(function () {
  224. //添加选择添加的组成物
  225. let updateArr = [];
  226. let newComponent = [];
  227. //re.currentGlj.component = [];
  228. for(let i = 0, len = me.selectedList.length; i < len; i++){
  229. let isExist = false;
  230. for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
  231. if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
  232. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false
  233. , ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
  234. isExist = true;
  235. break;
  236. }
  237. }
  238. if(!isExist){
  239. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false, ID: me.selectedList[i].ID, consumeAmt: 0});
  240. }
  241. //re.currentGlj.component.push({ID: me.selectedList[i].ID, consumeAmt: 0});
  242. }
  243. re.currentGlj.component = newComponent;
  244. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
  245. if(gljBasePrc !== re.currentGlj.basePrice){
  246. re.currentGlj.basePrice = gljBasePrc;
  247. re.reshowGljBasePrc(re.currentGlj);
  248. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  249. }
  250. updateArr.push(re.currentGlj);
  251. that.updateComponent(updateArr);
  252. $('#componentsCacnel').click();
  253. });
  254. }
  255. };
  256. let componentTypeTreeOprObj = {
  257. onClick: function(event,treeId,treeNode) {
  258. let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
  259. if(me.gljCurTypeId !== treeNode.ID){
  260. me.gljCurTypeId = treeNode.ID;
  261. if (re.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  262. me.currentOprParent = 1;
  263. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + treeNode.ID]);
  264. } else {
  265. me.currentCache = me.getCache();
  266. }
  267. }
  268. me.showGljItems(me.showGljList, gljTypeId);
  269. }
  270. }
  271. $(document).ready(function () {
  272. $('#gljSearchKeyword').change(function () {
  273. componentOprObj.filterDatasAndShow();
  274. });
  275. $('#gljSearchKeyword').bind('keypress', function (e) {
  276. if(e.keyCode === 13){
  277. $(this).blur();
  278. return false;
  279. }
  280. });
  281. });