gljSelect.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /**
  2. * Created by Zhong on 2017/8/25.
  3. */
  4. let gljSelOprObj = {
  5. parentNodeIds: {},
  6. treeObj:null,
  7. rootNode: null,//分类树根节点
  8. radiosSelected: null,//allGljs, stdGljs, complementaryGljs
  9. workBook: null,
  10. selectedList: [],//选中的工料机
  11. setting: {
  12. header: [
  13. {headerName:"选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center"},
  14. {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  15. {headerName:"名称",headerWidth:120,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
  16. {headerName:"规格型号",headerWidth:80,dataCode:"specs", dataType: "String", hAlign: "center", vAlign: "center"},
  17. {headerName:"单位",headerWidth:80,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
  18. {headerName:"单价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  19. {headerName:"类型",headerWidth:80,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
  20. ]
  21. },
  22. setProp: function (prop, value, gljList) {
  23. for(let i = 0, len = gljList.length; i < len; i++){
  24. gljList[i][prop] = value;
  25. }
  26. },
  27. sortGlj: function(gljList) {
  28. gljList.sort(function(a, b){
  29. let rst = 0;
  30. if (a.code > b.code) rst = 1
  31. else if (a.code < b.code) rst = -1;
  32. return rst;
  33. });
  34. },
  35. switchToGljId: function (gljList) {
  36. for(let glj of gljList){
  37. glj.gljId = glj.ID;
  38. delete glj.ID;
  39. }
  40. },
  41. getSelGljItems: function(gljData) {
  42. this.stdGljList = gljData.stdGljs;
  43. //兼容多单价,计算补充定额价格时,套多单价人材机的时候,默认取第一个价格
  44. for(let sGlj of this.stdGljList){
  45. if(sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined'){
  46. sGlj.basePrice = sGlj.priceProperty.price1;
  47. }
  48. }
  49. this.complementaryGljList = gljData.complementaryGljs;
  50. this.switchToGljId(this.stdGljList);
  51. this.switchToGljId(this.complementaryGljList);
  52. this.setProp('type', 'std', this.stdGljList);
  53. this.setProp('type', 'complementary', this.complementaryGljList);
  54. this.sortGlj(this.stdGljList);
  55. this.sortGlj(this.complementaryGljList);
  56. gljAdjOprObj.gljList = this.stdGljList.concat(this.complementaryGljList);
  57. },
  58. initClassTree: function (type, treeData) {
  59. let me = this;
  60. if (me.treeObj) {
  61. me.treeObj.destroy();
  62. me.parentNodeIds = {};
  63. }
  64. zTreeHelper.createTree(treeData, gljSelTreeOprObj.setting, "selGljTree", me);
  65. let rootNode = me.treeObj.getNodes()[0];
  66. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  67. me.rootNode = rootNode;
  68. }
  69. if(me.rootNode){
  70. me.treeObj.selectNode(me.rootNode);
  71. if ((me.stdGljList && me.stdGljList.length > 0) ||
  72. (me.complementaryGljList && me.complementaryGljList.length > 0)) {
  73. gljSelTreeOprObj.setting.callback.onClick(null, 'selGljTree', me.rootNode);
  74. }
  75. }
  76. },
  77. getGljClassTree: function (mixedTreeData) {
  78. this.treeData = mixedTreeData;
  79. this.initClassTree('std', this.treeData.std);
  80. gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
  81. },
  82. buildSheet: function (container) {
  83. let me = gljSelOprObj;
  84. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  85. sheetCommonObj.spreadDefaultStyle(me.workBook);
  86. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  87. me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
  88. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  89. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  90. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  91. me.bindBtnOpr($('#gljSelY'));
  92. me.radiosChange();
  93. },
  94. onClipboardPasting: function (sender, args) {
  95. args.cancel = true;
  96. },
  97. onCellEditStart: function (sender, args) {
  98. args.cancel = true;
  99. },
  100. onButtonClicked: function (sender, args) {
  101. let me = gljSelOprObj;
  102. let val = args.sheet.getValue(args.row, args.col);
  103. let thisGlj = me.currentCache[args.row];
  104. thisGlj.isChecked = val;
  105. if(args.sheet.isEditing()){
  106. args.sheet.endEdit(true);
  107. }
  108. else{
  109. //设置选中
  110. if(val === true){
  111. let isExist = false;
  112. for(let i = 0, len = me.selectedList.length; i < len; i++){
  113. if(me.selectedList[i].gljId === thisGlj.gljId){
  114. isExist = true;
  115. break;
  116. }
  117. }
  118. if(!isExist){
  119. thisGlj.consumeAmt = 0;
  120. me.selectedList.push(_.cloneDeep(thisGlj));
  121. }
  122. }
  123. else if(val === false){
  124. for(let i = 0, len = me.selectedList.length; i < len; i++){
  125. if(me.selectedList[i].gljId === thisGlj.gljId){
  126. me.selectedList.splice(i, 1);
  127. break;
  128. }
  129. }
  130. }
  131. }
  132. },
  133. setShowGljList: function (gljList, clearChecked) {
  134. //初始为所有工料机
  135. let me = this;
  136. let curRationGlj = rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID];
  137. for(let i = 0; i < gljList.length; i++){
  138. //去除与已添加的组成物重复的条目
  139. let isExist = false;
  140. for(let j = 0; j < curRationGlj.length; j++){
  141. if(curRationGlj[j].gljId === gljList[i].gljId){
  142. isExist = true;
  143. break;
  144. }
  145. }
  146. if(!isExist){
  147. if(clearChecked){
  148. gljList[i].isChecked = false;
  149. }
  150. }
  151. else {
  152. gljList[i].isChecked = true;
  153. }
  154. me.showGljList.push(gljList[i]);
  155. }
  156. },
  157. //初始默认radio
  158. initRadio: function () {
  159. let me = gljSelOprObj;
  160. $('#gljSearchKeyword').val('');//恢复搜索文本
  161. me.selectedList = [].concat(rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID]);
  162. //默认radio所有工料机
  163. if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
  164. $("input[name='glj']:checked")[0].checked = false;
  165. }
  166. $("input[value = 'stdGljs']")[0].checked = true;
  167. me.radiosSelected = 'stdGljs';
  168. //初始为标准工料机
  169. me.showGljList = [];
  170. if(me.radiosSelected === 'stdGljs'){
  171. me.setShowGljList(me.stdGljList, true);
  172. //me.setShowGljList(me.complementaryGljList, true);
  173. me.sortGlj(me.showGljList);
  174. }
  175. },
  176. filterDatasAndShow: function () {
  177. let me = gljSelOprObj;
  178. let val = $("input[name='glj']:checked").val();
  179. me.radiosSelected = val;
  180. //选择改变,数据重新筛选显示
  181. me.showGljList = [];
  182. if(me.radiosSelected === 'allGljs'){
  183. me.setShowGljList(me.stdGljList);
  184. me.setShowGljList(me.complementaryGljList);
  185. }
  186. else if(me.radiosSelected === 'stdGljs'){
  187. me.setShowGljList(me.stdGljList);
  188. }
  189. else if(me.radiosSelected === 'complementaryGljs'){
  190. me.setShowGljList(me.complementaryGljList);
  191. }
  192. //搜索匹配
  193. let searchStr = $('#gljSearchKeyword').val();
  194. if(searchStr && searchStr.trim() != ''){
  195. let reg = new RegExp(searchStr);
  196. me.showGljList = _.filter(me.showGljList, function (data) {
  197. return reg.test(data.code) || reg.test(data.name);
  198. });
  199. }
  200. me.sortGlj(me.showGljList);
  201. //重新显示
  202. me.showGljItems(me.showGljList, me.gljCurTypeId);
  203. //切换radio后更新cache
  204. if (me.currentOprParent = 1) {
  205. if(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  206. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  207. }
  208. else{
  209. me.currentCache = [];
  210. }
  211. } else {
  212. me.currentCache = me.getCache();
  213. }
  214. },
  215. //监听radios选择事件
  216. radiosChange: function () {
  217. let me = gljSelOprObj;
  218. $('.glj-radio').change(function () {
  219. if($(this).val() === 'stdGljs') {
  220. me.initClassTree('std', me.treeData.std);
  221. } else {
  222. me.initClassTree('comple', me.treeData.comple);
  223. }
  224. me.filterDatasAndShow();
  225. });
  226. },
  227. getParentCache: function (nodes) {
  228. let me = gljSelOprObj, rst = [];
  229. for(let i = 0; i < me.showGljList.length; i++){
  230. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  231. rst.push(me.showGljList[i]);
  232. }
  233. }
  234. rst.sort(function (a, b) {
  235. let rst = 0;
  236. if(a.code > b.code) rst = 1;
  237. else if(a.code < b.code)rst = -1;
  238. return rst;
  239. });
  240. return rst;
  241. },
  242. getCache: function() {
  243. let me = gljSelOprObj, rst = [];
  244. for (let i = 0; i < me.showGljList.length; i++) {
  245. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  246. rst.push(me.showGljList[i]);
  247. }
  248. }
  249. return rst;
  250. },
  251. showGljItems: function(data, type) {
  252. let me = gljSelOprObj;
  253. if (me.workBook) {
  254. let cacheSection = [];
  255. let pArr = me.parentNodeIds["_pNodeId_" + type];
  256. for (let i = 0; i < data.length; i++) {
  257. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  258. cacheSection.push(data[i]);
  259. } else if (type == data[i].gljClass) {
  260. cacheSection.push(data[i]);
  261. }
  262. }
  263. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  264. sheetsOprObj.showDataForGljSel(me.workBook.getSheet(0), me.setting, cacheSection, rationGLJOprObj.distTypeTree);
  265. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  266. cacheSection = null;
  267. }
  268. },
  269. //组成物窗口按钮操作
  270. bindBtnOpr: function (conf) {//确定、取消、关闭按钮
  271. let me = gljSelOprObj, that = rationGLJOprObj;
  272. conf.click(function () {
  273. that.cache['_GLJ_' + that.currentRationItem.ID] = me.selectedList;
  274. that.updateRationItem(function () {
  275. that.sheet.getParent().focus();
  276. sheetCommonObj.cleanData(that.sheet, that.setting, -1);
  277. that.showGljItems(that.currentRationItem.ID);
  278. $('#selGlj').modal('hide');
  279. });
  280. });
  281. }
  282. };
  283. let gljSelTreeOprObj = {
  284. setting: {
  285. view: {
  286. expandSpeed: "",
  287. selectedMulti: false
  288. },
  289. edit: {
  290. enable: false,
  291. editNameSelectAll: true,
  292. showRemoveBtn: true,
  293. showRenameBtn: true,
  294. removeTitle: "删除节点",
  295. renameTitle: "更改名称"
  296. },
  297. data: {
  298. keep: {
  299. parent:true,
  300. leaf:true
  301. },
  302. key: {
  303. children: "items",
  304. name: "Name"
  305. },
  306. simpleData: {
  307. enable: false,
  308. idKey: "ID",
  309. pIdKey: "ParentID",
  310. rootPId: -1
  311. }
  312. },
  313. callback:{
  314. onClick: function(event,treeId,treeNode) {
  315. let me = gljSelOprObj, gljTypeId = treeNode.ID;
  316. if(me.gljCurTypeId !== treeNode.ID){
  317. me.gljCurTypeId = treeNode.ID;
  318. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  319. me.currentOprParent = 1;
  320. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  321. } else {
  322. me.currentCache = me.getCache();
  323. }
  324. }
  325. me.showGljItems(me.showGljList, gljTypeId);
  326. }
  327. }
  328. }
  329. };
  330. $(document).ready(function () {
  331. $('#gljSearchKeyword').change(function () {
  332. gljSelOprObj.filterDatasAndShow();
  333. });
  334. $('#gljSearchKeyword').bind('keypress', function (e) {
  335. if(e.keyCode === 13){
  336. $(this).blur();
  337. return false;
  338. }
  339. });
  340. $('#selGlj').on('shown.bs.modal', function () {
  341. if (gljSelOprObj.workBook) {
  342. gljSelOprObj.workBook.refresh();
  343. }
  344. });
  345. });