components.js 12 KB

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