gljSelect.js 11 KB

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