gljSelect.js 12 KB

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