components.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && (!gljList[i].component || gljList[i].component.length === 0) && gljList[i].ID !== that.currentGlj.ID){
  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. //初始化分类树
  103. //@param {String}type(标准或补充) {Array}treeData(树数据)
  104. initClassTree: function (type, treeData) {
  105. let me = this;
  106. if (me.treeObj) {
  107. me.treeObj.destroy();
  108. me.parentNodeIds = {};
  109. }
  110. zTreeHelper.createTree(treeData, componentSetting, "componentTree", componentOprObj);
  111. let rootNode = componentOprObj.treeObj.getNodes()[0];
  112. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  113. componentOprObj.rootNode = rootNode;
  114. }
  115. if(me.rootNode){
  116. me.treeObj.selectNode(me.rootNode);
  117. componentTypeTreeOprObj.onClick(null, 'componentTree', me.rootNode);
  118. }
  119. },
  120. //初始默认radio
  121. initRadio: function () {
  122. let that = repositoryGljObj, me = componentOprObj;
  123. $('#gljSearchKeyword').val('');//恢复搜索文本
  124. //初始化组成物列表
  125. me.selectedList = [].concat(that.currentComponent);
  126. //默认radio所有工料机
  127. if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
  128. $("input[name='glj']:checked")[0].checked = false;
  129. }
  130. $("input[value = 'stdGljs']")[0].checked = true;
  131. me.radiosSelected = 'stdGljs';
  132. //初始为所有工料机,机械类型可添加机械组成物,混凝土,砂浆、配合比可添加普通材料
  133. me.showGljList = [];
  134. if(me.radiosSelected === 'stdGljs'){
  135. me.setShowGljList(that.stdGljList, true);
  136. //me.setShowGljList(that.complementaryGljList, true);
  137. that.sortGlj(me.showGljList);
  138. }
  139. },
  140. filterDatasAndShow: function () {
  141. let me = componentOprObj, re = repositoryGljObj;
  142. let val = $("input[name='glj']:checked").val();
  143. me.radiosSelected = val;
  144. //选择改变,数据重新筛选显示
  145. me.showGljList = [];
  146. if(me.radiosSelected === 'allGljs'){
  147. me.setShowGljList(re.stdGljList);
  148. me.setShowGljList(re.complementaryGljList);
  149. }
  150. else if(me.radiosSelected === 'stdGljs'){
  151. me.setShowGljList(re.stdGljList);
  152. }
  153. else if(me.radiosSelected === 'complementaryGljs'){
  154. me.setShowGljList(re.complementaryGljList);
  155. }
  156. //搜索匹配
  157. let searchStr = $('#gljSearchKeyword').val();
  158. if(searchStr && searchStr.trim() != ''){
  159. let reg = new RegExp(searchStr);
  160. me.showGljList = _.filter(me.showGljList, function (data) {
  161. return reg.test(data.code) || reg.test(data.name);
  162. });
  163. }
  164. re.sortGlj(me.showGljList);
  165. //重新显示
  166. me.showGljItems(me.showGljList, me.gljCurTypeId);
  167. //切换radio后更新cache
  168. if (me.currentOprParent = 1) {
  169. if(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  170. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  171. }
  172. else{
  173. me.currentCache = [];
  174. }
  175. } else {
  176. me.currentCache = me.getCache();
  177. }
  178. },
  179. //监听radios选择事件
  180. radiosChange: function () {
  181. let me = componentOprObj, gc = gljClassTreeObj;
  182. $('.glj-radio').change(function () {
  183. if($(this).val() === 'stdGljs') {
  184. me.initClassTree('std', gc.treeData.std);
  185. } else {
  186. me.initClassTree('comple', gc.treeData.comple);
  187. }
  188. me.filterDatasAndShow();
  189. });
  190. },
  191. getParentCache: function (nodes) {
  192. let me = componentOprObj, rst = [];
  193. for(let i = 0; i < me.showGljList.length; i++){
  194. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  195. rst.push(me.showGljList[i]);
  196. }
  197. }
  198. rst.sort(function (a, b) {
  199. let rst = 0;
  200. if(a.code > b.code) rst = 1;
  201. else if(a.code < b.code)rst = -1;
  202. return rst;
  203. });
  204. return rst;
  205. },
  206. getCache: function() {
  207. let me = componentOprObj, rst = [];
  208. for (let i = 0; i < me.showGljList.length; i++) {
  209. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  210. rst.push(me.showGljList[i]);
  211. }
  212. }
  213. return rst;
  214. },
  215. showGljItems: function(data, type) {
  216. let me = componentOprObj, re = repositoryGljObj;
  217. if (me.workBook) {
  218. let cacheSection = [];
  219. let pArr = me.parentNodeIds["_pNodeId_" + type];
  220. for (let i = 0; i < data.length; i++) {
  221. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  222. cacheSection.push(data[i]);
  223. } else if (type == data[i].gljClass) {
  224. cacheSection.push(data[i]);
  225. }
  226. }
  227. sheetOpr.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  228. sheetOpr.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
  229. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  230. cacheSection = null;
  231. }
  232. },
  233. //组成物窗口按钮操作
  234. componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
  235. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
  236. conf.click(function () {
  237. //添加选择添加的组成物
  238. let updateArr = [];
  239. let newComponent = [];
  240. //re.currentGlj.component = [];
  241. for(let i = 0, len = me.selectedList.length; i < len; i++){
  242. let isExist = false;
  243. for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
  244. if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
  245. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false
  246. , ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
  247. isExist = true;
  248. break;
  249. }
  250. }
  251. if(!isExist){
  252. newComponent.push({isStd: typeof me.selectedList[i].isStd !== 'undefined' ? me.selectedList[i].isStd : false, ID: me.selectedList[i].ID, consumeAmt: 0});
  253. }
  254. //re.currentGlj.component.push({ID: me.selectedList[i].ID, consumeAmt: 0});
  255. }
  256. re.currentGlj.component = newComponent;
  257. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
  258. if(gljBasePrc !== re.currentGlj.basePrice){
  259. re.currentGlj.basePrice = gljBasePrc;
  260. re.reshowGljBasePrc(re.currentGlj);
  261. //updateBasePrc.push({gljId: that.currentGlj.ID, gljType: that.currentGlj.gljType, basePrice: that.currentGlj.basePrice});
  262. }
  263. updateArr.push(re.currentGlj);
  264. that.updateComponent(updateArr);
  265. $('#componentsCacnel').click();
  266. });
  267. }
  268. };
  269. let componentTypeTreeOprObj = {
  270. onClick: function(event,treeId,treeNode) {
  271. let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
  272. if(me.gljCurTypeId !== treeNode.ID){
  273. me.gljCurTypeId = treeNode.ID;
  274. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  275. me.currentOprParent = 1;
  276. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  277. } else {
  278. me.currentCache = me.getCache();
  279. }
  280. }
  281. me.showGljItems(me.showGljList, gljTypeId);
  282. }
  283. }
  284. $(document).ready(function () {
  285. $('#gljSearchKeyword').change(function () {
  286. componentOprObj.filterDatasAndShow();
  287. });
  288. $('#gljSearchKeyword').bind('keypress', function (e) {
  289. if(e.keyCode === 13){
  290. $(this).blur();
  291. return false;
  292. }
  293. });
  294. });