components.js 12 KB

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