gljSelect.js 12 KB

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