gljSelect.js 13 KB

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