gljSelect.js 13 KB

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