gljSelect.js 13 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. 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. getGljClassTree: function (gljLibId, callback) {
  65. console.log('enter2');
  66. let me = this;
  67. let url = '/complementartGlj/api/getGljTree';
  68. let postData = {gljLibId: gljLibId};
  69. let sucFunc = function (rstData) {
  70. zTreeHelper.createTree(rstData, gljSelTreeOprObj.setting, "selGljTree", gljSelOprObj);
  71. let rootNode = gljSelOprObj.treeObj.getNodes()[0];
  72. if(rootNode && rootNode.isParent && rootNode.isFirstNode){
  73. gljSelOprObj.rootNode = rootNode;
  74. }
  75. gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
  76. if(callback){
  77. callback();
  78. }
  79. };
  80. let errFunc = function () {
  81. };
  82. CommonAjax.post(url, postData, sucFunc, errFunc);
  83. },
  84. buildSheet: function (container) {
  85. let me = gljSelOprObj;
  86. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  87. sheetCommonObj.spreadDefaultStyle(me.workBook);
  88. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  89. me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
  90. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  91. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  92. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  93. me.bindBtnOpr($('#gljSelY'));
  94. me.radiosChange();
  95. },
  96. onClipboardPasting: function (sender, args) {
  97. args.cancel = true;
  98. },
  99. onCellEditStart: function (sender, args) {
  100. args.cancel = true;
  101. },
  102. onButtonClicked: function (sender, args) {
  103. let me = gljSelOprObj;
  104. let val = args.sheet.getValue(args.row, args.col);
  105. let thisGlj = me.currentCache[args.row];
  106. thisGlj.isChecked = val;
  107. if(args.sheet.isEditing()){
  108. args.sheet.endEdit(true);
  109. }
  110. else{
  111. //设置选中
  112. if(val === true){
  113. let isExist = false;
  114. for(let i = 0, len = me.selectedList.length; i < len; i++){
  115. if(me.selectedList[i].gljId === thisGlj.gljId){
  116. isExist = true;
  117. break;
  118. }
  119. }
  120. if(!isExist){
  121. thisGlj.consumeAmt = 0;
  122. me.selectedList.push(thisGlj);
  123. }
  124. }
  125. else if(val === false){
  126. for(let i = 0, len = me.selectedList.length; i < len; i++){
  127. if(me.selectedList[i].gljId === thisGlj.gljId){
  128. me.selectedList.splice(i, 1);
  129. break;
  130. }
  131. }
  132. }
  133. }
  134. },
  135. setShowGljList: function (gljList, clearChecked) {
  136. //初始为所有工料机
  137. let me = this;
  138. let curRationGlj = rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID];
  139. for(let i = 0; i < gljList.length; i++){
  140. //去除与已添加的组成物重复的条目
  141. let isExist = false;
  142. for(let j = 0; j < curRationGlj.length; j++){
  143. if(curRationGlj[j].gljId === gljList[i].gljId){
  144. isExist = true;
  145. break;
  146. }
  147. }
  148. if(!isExist){
  149. if(clearChecked){
  150. gljList[i].isChecked = false;
  151. }
  152. }
  153. else {
  154. gljList[i].isChecked = true;
  155. }
  156. me.showGljList.push(gljList[i]);
  157. }
  158. },
  159. //初始默认radio
  160. initRadio: function () {
  161. let me = gljSelOprObj;
  162. $('#gljSearchKeyword').val('');//恢复搜索文本
  163. me.selectedList = [].concat(rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID]);
  164. //默认radio所有工料机
  165. if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
  166. $("input[name='glj']:checked")[0].checked = false;
  167. }
  168. $("input[value = 'allGljs']")[0].checked = true;
  169. me.radiosSelected = 'allGljs';
  170. //初始为所有工料机
  171. me.showGljList = [];
  172. if(me.radiosSelected === 'allGljs'){
  173. me.setShowGljList(me.stdGljList, true);
  174. me.setShowGljList(me.complementaryGljList, true);
  175. me.sortGlj(me.showGljList);
  176. }
  177. },
  178. filterDatasAndShow: function () {
  179. let me = gljSelOprObj;
  180. let val = $("input[name='glj']:checked").val();
  181. me.radiosSelected = val;
  182. //选择改变,数据重新筛选显示
  183. me.showGljList = [];
  184. if(me.radiosSelected === 'allGljs'){
  185. me.setShowGljList(me.stdGljList);
  186. me.setShowGljList(me.complementaryGljList);
  187. }
  188. else if(me.radiosSelected === 'stdGljs'){
  189. me.setShowGljList(me.stdGljList);
  190. }
  191. else if(me.radiosSelected === 'complementaryGljs'){
  192. me.setShowGljList(me.complementaryGljList);
  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. });