components.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /**
  2. * Created by Zhong on 2017/10/16.
  3. */
  4. /*
  5. 弹出组成物窗口 组成物表
  6. * */
  7. let componentOprObj = {
  8. treeObj:null,
  9. rootNode: null,//分类树根节点
  10. workBook: null,
  11. selectedList: [],//选中的组成物
  12. setting: {
  13. owner: "components",
  14. header: [
  15. {headerName:"选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center"},
  16. {headerName:"编码",headerWidth:80,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  17. {headerName:"名称",headerWidth:120,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
  18. {headerName:"规格型号",headerWidth:80,dataCode:"specs", dataType: "String", hAlign: "center", vAlign: "center"},
  19. {headerName:"单位",headerWidth:80,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
  20. {headerName:"单价",headerWidth:80,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  21. {headerName:"类型",headerWidth:80,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
  22. ]
  23. },
  24. buildSheet: function (container) {
  25. let me = componentOprObj;
  26. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  27. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  28. me.workBook.getSheet(0).setFormatter(-1, 1, "@", GC.Spread.Sheets.SheetArea.viewport);
  29. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  30. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  31. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  32. me.workBook.getSheet(0).getRange(-1, 0, -1, 1).cellType(new GC.Spread.Sheets.CellTypes.CheckBox());
  33. me.componentsBtnOpr($('#componentsConf'));
  34. },
  35. onClipboardPasting: function (sender, args) {
  36. args.cancel = true;
  37. },
  38. onCellEditStart: function (sender, args) {
  39. args.cancel = true;
  40. },
  41. onButtonClicked: function (sender, args) {
  42. let me = componentOprObj, re = repositoryGljObj;
  43. let val = args.sheet.getValue(args.row, args.col);
  44. let thisComponent = me.currentCache[args.row];
  45. thisComponent.isChecked = val;
  46. if(args.sheet.isEditing()){
  47. args.sheet.endEdit(true);
  48. }
  49. else{
  50. //维护选中组成物列表
  51. if(val === true){
  52. let isExist = false;
  53. for(let i = 0, len = me.selectedList.length; i < len; i++){
  54. if(me.selectedList[i].ID === thisComponent.ID){
  55. isExist = true;
  56. break;
  57. }
  58. }
  59. if(!isExist){
  60. me.selectedList.push(thisComponent);
  61. }
  62. }
  63. else if(val === false){
  64. for(let i = 0, len = me.selectedList.length; i < len; i++){
  65. if(me.selectedList[i].ID === thisComponent.ID){
  66. me.selectedList.splice(i, 1);
  67. break;
  68. }
  69. }
  70. }
  71. }
  72. },
  73. setShowGljList: function (gljList, clearChecked) {
  74. let that = repositoryGljObj, me = componentOprObj;
  75. for(let i = 0; i < gljList.length; i++){
  76. if(machineAllowComponent.includes(that.currentGlj.gljType) && machineComponent.includes(gljList[i].gljType) ||
  77. materialAllowComponent.includes(that.currentGlj.gljType) && gljList[i].gljType === 201||
  78. that.currentGlj.gljType === 4 && gljList[i].gljType === 4 && (!gljList[i].component || gljList[i].component.length === 0) && gljList[i].ID !== that.currentGlj.ID){
  79. let isExist = false;
  80. for(let j = 0; j < that.currentComponent.length; j++){
  81. if(that.currentComponent[j].ID === gljList[i].ID){
  82. isExist = true;
  83. break;
  84. }
  85. }
  86. if(!isExist){
  87. if(clearChecked){
  88. gljList[i].isChecked = false;
  89. }
  90. }
  91. else {
  92. gljList[i].isChecked = true;
  93. }
  94. me.showGljList.push(gljList[i]);
  95. }
  96. }
  97. },
  98. //初始默认radio
  99. initRadio: function () {
  100. let that = repositoryGljObj, me = componentOprObj;
  101. //初始化组成物列表
  102. me.selectedList = [].concat(that.currentComponent);
  103. //初始为所有工料机,机械类型可添加机械组成物,混凝土,砂浆、配合比可添加普通材料
  104. me.showGljList = [];
  105. me.setShowGljList(that.gljList, true);
  106. that.sortGlj(me.showGljList);
  107. },
  108. getParentCache: function (nodes) {
  109. let me = componentOprObj, rst = [];
  110. for(let i = 0; i < me.showGljList.length; i++){
  111. if(nodes.indexOf(me.showGljList[i].gljClass) !== -1){
  112. rst.push(me.showGljList[i]);
  113. }
  114. }
  115. rst.sort(function (a, b) {
  116. let rst = 0;
  117. if(a.code > b.code) rst = 1;
  118. else if(a.code < b.code)rst = -1;
  119. return rst;
  120. });
  121. return rst;
  122. },
  123. getCache: function() {
  124. let me = componentOprObj, rst = [];
  125. for (let i = 0; i < me.showGljList.length; i++) {
  126. if (me.showGljList[i].gljClass == me.gljCurTypeId) {
  127. rst.push(me.showGljList[i]);
  128. }
  129. }
  130. return rst;
  131. },
  132. showGljItems: function(data, type) {
  133. let me = componentOprObj, re = repositoryGljObj;
  134. if (me.workBook) {
  135. let cacheSection = data;
  136. sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
  137. sheetsOprObj.showData(me.workBook.getSheet(0), me.setting, cacheSection, re.distTypeTree);
  138. me.workBook.getSheet(0).setRowCount(cacheSection.length);
  139. cacheSection = null;
  140. }
  141. },
  142. //批量插入组成物
  143. batchUpdateComponent: function () {
  144. $.bootstrapLoading.start();
  145. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj,
  146. updateArr = [],
  147. updateBasePrc = [],
  148. IDMapping = {};
  149. let formData = new FormData();
  150. //当前工料机的工料机类型
  151. let currentGljType = re.currentGlj.gljType;
  152. let thisTypeGljList = _.filter(re.gljList, function (data) {
  153. return data.gljType == currentGljType;
  154. });
  155. for(let glj of thisTypeGljList){
  156. let gljComponent = glj.component ? glj.component : [];
  157. let newComponent = [];
  158. if(me.insertType === 'batch'){
  159. for(let selectedComponent of me.selectedList){
  160. let isExist = false;
  161. for(let gljPerComponent of gljComponent){
  162. if(selectedComponent.ID === gljPerComponent.ID){
  163. //newComponent.push({ID: selectedComponent.ID, consumeAmt: gljPerComponent.consumeAmt});
  164. isExist = true;
  165. break;
  166. }
  167. }
  168. if(!isExist){
  169. newComponent.push({ID: selectedComponent.ID, consumeAmt: 0});
  170. }
  171. }
  172. newComponent = newComponent.concat(gljComponent);
  173. }
  174. else if(me.insertType === 'batchClear'){//去除消耗量为0的组成物
  175. for(let gljPerComponent of gljComponent){
  176. if(gljPerComponent.consumeAmt && gljPerComponent.consumeAmt != 0){
  177. newComponent.push({ID: gljPerComponent.ID, consumeAmt: gljPerComponent.consumeAmt});
  178. }
  179. }
  180. }
  181. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(newComponent));
  182. if(gljBasePrc != glj.basePrice){
  183. updateBasePrc.push({gljId: glj.ID, gljType: currentGljType, basePrice: gljBasePrc});
  184. }
  185. IDMapping[glj.ID] = {component : newComponent, basePrice: gljBasePrc};
  186. updateArr.push({ID: glj.ID, component: newComponent, basePrice: gljBasePrc});
  187. }
  188. formData.append('compressData', LZString.compressToUTF16(JSON.stringify(updateArr)));
  189. $.ajax({
  190. url: 'api/batchUpdateComponent',
  191. type: 'POST',
  192. data: formData,
  193. cache: false,
  194. contentType: false,
  195. processData: false,
  196. success: function(response){
  197. if (response.err === 0) {
  198. //更新缓存数据
  199. for(let glj of thisTypeGljList){
  200. if(glj.ID === re.currentGlj.ID){
  201. re.currentComponent = re.getCurrentComponent(IDMapping[glj.ID]['component']);
  202. sheetCommonObj.cleanData(that.workBook.getSheet(0), that.setting, -1);
  203. sheetsOprObj.showData(that.workBook.getSheet(0), that.setting, re.currentComponent);
  204. }
  205. glj.component = IDMapping[glj.ID]['component'];
  206. glj.basePrice = IDMapping[glj.ID]['basePrice'];
  207. }
  208. re.reSetGljBasePrc(thisTypeGljList);
  209. if($('#component').is(':visible')){
  210. $('#component').modal('hide');
  211. }
  212. $.bootstrapLoading.end();
  213. //更新定额
  214. if(updateBasePrc.length > 0){
  215. re.updateRationBasePrcRq(updateBasePrc, that.workBook);
  216. }
  217. } else {
  218. if($('#component').is(':visible')){
  219. $('#component').modal('hide');
  220. }
  221. $.bootstrapLoading.end();
  222. }
  223. },
  224. error: function(jqXHR){
  225. alert(`与服务器通信发生错误${jqXHR.status} ${jqXHR.statusText}`);
  226. $('#component').modal('hide');
  227. $.bootstrapLoading.end();
  228. }
  229. });
  230. },
  231. //组成物窗口按钮操作
  232. componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
  233. let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
  234. conf.click(function () {
  235. if(me.insertType === 'single'){
  236. let updateBasePrc = [];
  237. //添加选择添加的组成物
  238. let updateArr = [];
  239. let newComponent = [];
  240. for(let i = 0, len = me.selectedList.length; i < len; i++){
  241. let isExist = false;
  242. for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
  243. if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
  244. newComponent.push({ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
  245. isExist = true;
  246. break;
  247. }
  248. }
  249. if(!isExist){
  250. newComponent.push({ID: me.selectedList[i].ID, consumeAmt: 0});
  251. }
  252. }
  253. re.currentGlj.component = newComponent;
  254. let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
  255. if(gljBasePrc !== re.currentGlj.basePrice){
  256. re.currentGlj.basePrice = gljBasePrc;
  257. re.reshowGljBasePrc(re.currentGlj);
  258. updateBasePrc.push({gljId: re.currentGlj.ID, gljType: re.currentGlj.gljType, basePrice: gljBasePrc});
  259. re.updateRationBasePrcRq(updateBasePrc, that.workBook);
  260. }
  261. updateArr.push(re.currentGlj);
  262. that.updateComponent(updateArr);
  263. $('#component').modal('hide');
  264. //$('#componentsCacnel').click();
  265. }
  266. else {
  267. me.batchUpdateComponent();
  268. }
  269. });
  270. }
  271. };
  272. let componentTypeTreeOprObj = {
  273. onClick: function(event,treeId,treeNode) {
  274. let me = componentOprObj, re = repositoryGljObj, that = gljComponentOprObj, gljTypeId = treeNode.ID;
  275. if(me.gljCurTypeId !== treeNode.ID){
  276. me.gljCurTypeId = treeNode.ID;
  277. if (re.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  278. me.currentOprParent = 1;
  279. me.currentCache = me.getParentCache(re.parentNodeIds["_pNodeId_" + treeNode.ID]);
  280. } else {
  281. me.currentCache = me.getCache();
  282. }
  283. }
  284. //me.showGljItems(me.showGljList, gljTypeId);
  285. me.showGljItems(me.currentCache, gljTypeId);
  286. }
  287. }