gljSelect.js 13 KB

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