gljSelect.js 13 KB

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