gljSelect.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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 (gljLibId, callback) {
  78. let me = this;
  79. let url = '/complementartGlj/api/getMixedTree';
  80. let postData = {gljLibId: gljLibId};
  81. let sucFunc = function (rstData) {
  82. me.treeData = rstData;
  83. me.initClassTree('std', me.treeData.std);
  84. gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
  85. if(callback){
  86. callback();
  87. }
  88. };
  89. let errFunc = function () {
  90. };
  91. CommonAjax.post(url, postData, sucFunc, errFunc);
  92. },
  93. getGljClassTree: function (mixedTreeData) {
  94. this.treeData = mixedTreeData;
  95. this.initClassTree('std', this.treeData.std);
  96. gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
  97. },
  98. buildSheet: function (container) {
  99. let me = gljSelOprObj;
  100. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  101. sheetCommonObj.spreadDefaultStyle(me.workBook);
  102. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  103. me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
  104. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  105. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  106. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  107. me.bindBtnOpr($('#gljSelY'));
  108. me.radiosChange();
  109. },
  110. onClipboardPasting: function (sender, args) {
  111. args.cancel = true;
  112. },
  113. onCellEditStart: function (sender, args) {
  114. args.cancel = true;
  115. },
  116. onButtonClicked: function (sender, args) {
  117. let me = gljSelOprObj;
  118. let val = args.sheet.getValue(args.row, args.col);
  119. let thisGlj = me.currentCache[args.row];
  120. thisGlj.isChecked = val;
  121. if(args.sheet.isEditing()){
  122. args.sheet.endEdit(true);
  123. }
  124. else{
  125. //设置选中
  126. if(val === true){
  127. let isExist = false;
  128. for(let i = 0, len = me.selectedList.length; i < len; i++){
  129. if(me.selectedList[i].gljId === thisGlj.gljId){
  130. isExist = true;
  131. break;
  132. }
  133. }
  134. if(!isExist){
  135. thisGlj.consumeAmt = 0;
  136. me.selectedList.push(_.cloneDeep(thisGlj));
  137. }
  138. }
  139. else if(val === false){
  140. for(let i = 0, len = me.selectedList.length; i < len; i++){
  141. if(me.selectedList[i].gljId === thisGlj.gljId){
  142. me.selectedList.splice(i, 1);
  143. break;
  144. }
  145. }
  146. }
  147. }
  148. },
  149. setShowGljList: function (gljList, clearChecked) {
  150. //初始为所有工料机
  151. let me = this;
  152. let curRationGlj = rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID];
  153. for(let i = 0; i < gljList.length; i++){
  154. //去除与已添加的组成物重复的条目
  155. let isExist = false;
  156. for(let j = 0; j < curRationGlj.length; j++){
  157. if(curRationGlj[j].gljId === gljList[i].gljId){
  158. isExist = true;
  159. break;
  160. }
  161. }
  162. if(!isExist){
  163. if(clearChecked){
  164. gljList[i].isChecked = false;
  165. }
  166. }
  167. else {
  168. gljList[i].isChecked = true;
  169. }
  170. me.showGljList.push(gljList[i]);
  171. }
  172. },
  173. //初始默认radio
  174. initRadio: function () {
  175. let me = gljSelOprObj;
  176. $('#gljSearchKeyword').val('');//恢复搜索文本
  177. me.selectedList = [].concat(rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID]);
  178. //默认radio所有工料机
  179. if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
  180. $("input[name='glj']:checked")[0].checked = false;
  181. }
  182. $("input[value = 'stdGljs']")[0].checked = true;
  183. me.radiosSelected = 'stdGljs';
  184. //初始为标准工料机
  185. me.showGljList = [];
  186. if(me.radiosSelected === 'stdGljs'){
  187. me.setShowGljList(me.stdGljList, true);
  188. //me.setShowGljList(me.complementaryGljList, true);
  189. me.sortGlj(me.showGljList);
  190. }
  191. },
  192. filterDatasAndShow: function () {
  193. let me = gljSelOprObj;
  194. let val = $("input[name='glj']:checked").val();
  195. me.radiosSelected = val;
  196. //选择改变,数据重新筛选显示
  197. me.showGljList = [];
  198. if(me.radiosSelected === 'allGljs'){
  199. me.setShowGljList(me.stdGljList);
  200. me.setShowGljList(me.complementaryGljList);
  201. }
  202. else if(me.radiosSelected === 'stdGljs'){
  203. me.setShowGljList(me.stdGljList);
  204. }
  205. else if(me.radiosSelected === 'complementaryGljs'){
  206. me.setShowGljList(me.complementaryGljList);
  207. }
  208. //搜索匹配
  209. let searchStr = $('#gljSearchKeyword').val();
  210. if(searchStr && searchStr.trim() != ''){
  211. let reg = new RegExp(searchStr);
  212. me.showGljList = _.filter(me.showGljList, function (data) {
  213. return reg.test(data.code) || reg.test(data.name);
  214. });
  215. }
  216. me.sortGlj(me.showGljList);
  217. //重新显示
  218. me.showGljItems(me.showGljList, me.gljCurTypeId);
  219. //切换radio后更新cache
  220. if (me.currentOprParent = 1) {
  221. if(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
  222. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  223. }
  224. else{
  225. me.currentCache = [];
  226. }
  227. } else {
  228. me.currentCache = me.getCache();
  229. }
  230. },
  231. //监听radios选择事件
  232. radiosChange: function () {
  233. let me = gljSelOprObj;
  234. $('.glj-radio').change(function () {
  235. if($(this).val() === 'stdGljs') {
  236. me.initClassTree('std', me.treeData.std);
  237. } else {
  238. me.initClassTree('comple', me.treeData.comple);
  239. }
  240. me.filterDatasAndShow();
  241. });
  242. },
  243. getParentCache: function (nodes) {
  244. let me = gljSelOprObj, rst = [];
  245. for(let i = 0; i < me.showGljList.length; i++){
  246. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  247. rst.push(me.showGljList[i]);
  248. }
  249. }
  250. rst.sort(function (a, b) {
  251. let rst = 0;
  252. if(a.code > b.code) rst = 1;
  253. else if(a.code < b.code)rst = -1;
  254. return rst;
  255. });
  256. return rst;
  257. },
  258. getCache: function() {
  259. let me = gljSelOprObj, rst = [];
  260. for (let i = 0; i < me.showGljList.length; i++) {
  261. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  262. rst.push(me.showGljList[i]);
  263. }
  264. }
  265. return rst;
  266. },
  267. showGljItems: function(data, type) {
  268. let me = gljSelOprObj;
  269. if (me.workBook) {
  270. let cacheSection = [];
  271. let pArr = me.parentNodeIds["_pNodeId_" + type];
  272. for (let i = 0; i < data.length; i++) {
  273. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  274. cacheSection.push(data[i]);
  275. } else if (type == data[i].gljClass) {
  276. cacheSection.push(data[i]);
  277. }
  278. }
  279. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  280. sheetsOprObj.showDataForGljSel(me.workBook.getSheet(0), me.setting, cacheSection, rationGLJOprObj.distTypeTree);
  281. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  282. cacheSection = null;
  283. }
  284. },
  285. //组成物窗口按钮操作
  286. bindBtnOpr: function (conf) {//确定、取消、关闭按钮
  287. let me = gljSelOprObj, that = rationGLJOprObj;
  288. conf.click(function () {
  289. that.cache['_GLJ_' + that.currentRationItem.ID] = me.selectedList;
  290. that.updateRationItem(function () {
  291. that.sheet.getParent().focus();
  292. sheetCommonObj.cleanData(that.sheet, that.setting, -1);
  293. that.showGljItems(that.currentRationItem.ID);
  294. $('#selGlj').modal('hide');
  295. });
  296. });
  297. }
  298. };
  299. let gljSelTreeOprObj = {
  300. setting: {
  301. view: {
  302. expandSpeed: "",
  303. selectedMulti: false
  304. },
  305. edit: {
  306. enable: false,
  307. editNameSelectAll: true,
  308. showRemoveBtn: true,
  309. showRenameBtn: true,
  310. removeTitle: "删除节点",
  311. renameTitle: "更改名称"
  312. },
  313. data: {
  314. keep: {
  315. parent:true,
  316. leaf:true
  317. },
  318. key: {
  319. children: "items",
  320. name: "Name"
  321. },
  322. simpleData: {
  323. enable: false,
  324. idKey: "ID",
  325. pIdKey: "ParentID",
  326. rootPId: -1
  327. }
  328. },
  329. callback:{
  330. onClick: function(event,treeId,treeNode) {
  331. let me = gljSelOprObj, gljTypeId = treeNode.ID;
  332. if(me.gljCurTypeId !== treeNode.ID){
  333. me.gljCurTypeId = treeNode.ID;
  334. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  335. me.currentOprParent = 1;
  336. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  337. } else {
  338. me.currentCache = me.getCache();
  339. }
  340. }
  341. me.showGljItems(me.showGljList, gljTypeId);
  342. }
  343. }
  344. }
  345. };
  346. $(document).ready(function () {
  347. $('#gljSearchKeyword').change(function () {
  348. gljSelOprObj.filterDatasAndShow();
  349. });
  350. $('#gljSearchKeyword').bind('keypress', function (e) {
  351. if(e.keyCode === 13){
  352. $(this).blur();
  353. return false;
  354. }
  355. });
  356. });