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. $.ajax({
  44. type:"POST",
  45. url:"/stdGljRepository/api/getGljItems",
  46. data:{"repositoryId": stdGljLibId},
  47. dataType:"json",
  48. cache:false,
  49. timeout:20000,
  50. success:function(result){
  51. if(!result.error) {
  52. me.stdGljList = result.data;
  53. me.switchToGljId(me.stdGljList);
  54. me.sortGlj(me.stdGljList);
  55. if(callback){
  56. callback();
  57. }
  58. }
  59. },
  60. error:function(err){
  61. alert(err.responseJSON.error);
  62. }
  63. });
  64. },
  65. getGljClassTree: function (gljLibId, callback) {
  66. let me = this;
  67. let url = '/stdGljRepository/api/getGljTree';
  68. let postData = {gljLibId: gljLibId};
  69. let sucFunc = function (rstData) {
  70. zTreeHelper.createTree(rstData, gljSelTreeOprObj.setting, "selGljTree", gljSelOprObj);
  71. let rootNode = gljSelOprObj.treeObj.getNodes()[0];
  72. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  73. gljSelOprObj.rootNode = rootNode;
  74. }
  75. gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
  76. if(callback){
  77. callback();
  78. }
  79. };
  80. let errFunc = function () {
  81. };
  82. CommonAjax.post(url, postData, sucFunc, errFunc);
  83. },
  84. buildSheet: function (container) {
  85. let me = gljSelOprObj;
  86. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  87. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  88. me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
  89. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  90. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  91. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  92. me.bindBtnOpr($('#gljSelY'));
  93. me.radiosChange();
  94. },
  95. onClipboardPasting: function (sender, args) {
  96. args.cancel = true;
  97. },
  98. onCellEditStart: function (sender, args) {
  99. args.cancel = true;
  100. },
  101. onButtonClicked: function (sender, args) {
  102. let me = gljSelOprObj;
  103. let val = args.sheet.getValue(args.row, args.col);
  104. let thisGlj = me.currentCache[args.row];
  105. thisGlj.isChecked = val;
  106. if(args.sheet.isEditing()){
  107. args.sheet.endEdit(true);
  108. }
  109. else{
  110. //设置选中
  111. if(val === true){
  112. let isExist = false;
  113. for(let i = 0, len = me.selectedList.length; i < len; i++){
  114. if(me.selectedList[i].gljId === thisGlj.gljId){
  115. isExist = true;
  116. break;
  117. }
  118. }
  119. if(!isExist){
  120. thisGlj.consumeAmt = 0;
  121. me.selectedList.push(thisGlj);
  122. }
  123. }
  124. else if(val === false){
  125. for(let i = 0, len = me.selectedList.length; i < len; i++){
  126. if(me.selectedList[i].gljId === thisGlj.gljId){
  127. me.selectedList.splice(i, 1);
  128. break;
  129. }
  130. }
  131. }
  132. }
  133. },
  134. setShowGljList: function (gljList, clearChecked) {
  135. //初始为所有工料机
  136. let me = this;
  137. let curRationGlj = rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID];
  138. for(let i = 0; i < gljList.length; i++){
  139. //去除与已添加的组成物重复的条目
  140. let isExist = false;
  141. for(let j = 0; j < curRationGlj.length; j++){
  142. if(curRationGlj[j].gljId === gljList[i].gljId){
  143. isExist = true;
  144. break;
  145. }
  146. }
  147. if(!isExist){
  148. if(clearChecked){
  149. gljList[i].isChecked = false;
  150. }
  151. }
  152. else {
  153. gljList[i].isChecked = true;
  154. }
  155. me.showGljList.push(gljList[i]);
  156. }
  157. },
  158. //初始默认radio
  159. initRadio: function () {
  160. let me = gljSelOprObj;
  161. $('#gljSearchKeyword').val('');//恢复搜索文本
  162. me.selectedList = [].concat(rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID]);
  163. //默认radio所有工料机
  164. if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
  165. $("input[name='glj']:checked")[0].checked = false;
  166. }
  167. $("input[value = 'allGljs']")[0].checked = true;
  168. me.radiosSelected = 'allGljs';
  169. //初始为所有工料机
  170. me.showGljList = [];
  171. if(me.radiosSelected === 'allGljs'){
  172. me.setShowGljList(me.stdGljList, 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. }
  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. });