gljSelect.js 12 KB

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