gljSelect.js 12 KB

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