equipment_purchase_view.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. let unitOptions = ['m', 'm2', 'm3', 'km', 't', 'kg', '台班', '工日', '昼夜', '元', '项', '处', '个', '件',
  2. '根', '组', '系统', '台', '套', '株', '丛', '缸', '支', '只', '块', '座', '对', '份', '樘', '攒', '榀']
  3. let equipmentPurchaseObj = {
  4. IDMap:{},
  5. parentMap:{},
  6. setting:{
  7. header: [
  8. {headerName: "编码", headerWidth: 160, dataCode: "code", dataType: "String",formatter: "@"},
  9. {headerName: "设备名称", headerWidth: 200, dataCode: "name", dataType: "String"},
  10. {headerName: "单位", headerWidth: 60, dataCode: "unit", dataType: "String",hAlign: "center",cellType:'comboBox',editable:true,options:unitOptions},
  11. {headerName: "数量", headerWidth: 100, dataCode: "quantity", hAlign: "right", dataType: "Number",validator:'number'},
  12. {headerName: "原价", headerWidth: 100, dataCode: "originalPrice", hAlign: "right", dataType: "Number",validator:'number'},
  13. {headerName: "运杂费费率(%)", headerWidth: 100, dataCode: "freightRate", hAlign: "right", dataType: "Number",validator:'number'},
  14. {headerName: "运杂费", headerWidth: 100, dataCode: "freight", hAlign: "right", dataType: "Number",validator:'number'},
  15. {headerName: "备品备件购置费\n费率(%)", headerWidth: 130, dataCode: "sparePartCostRate", hAlign: "right", dataType: "Number",validator:'number'},
  16. {headerName: "备品备件购置费", headerWidth: 100, dataCode: "sparePartCost", hAlign: "right", dataType: "Number",validator:'number'},
  17. {headerName: "单价", headerWidth: 100, dataCode: "unitPrice", hAlign: "right", dataType: "Number",validator:'number'},
  18. {headerName: "合价", headerWidth: 100, dataCode: "totalPrice", hAlign: "right", dataType: "Number"},
  19. {headerName: "备注", headerWidth: 100, dataCode: "remark", dataType: "String"},
  20. ],
  21. view: {
  22. lockColumns: ["totalPrice",'unitPrice','freight','sparePartCost'],
  23. colHeaderHeight:40,
  24. }
  25. },
  26. sheet:null,
  27. initSpread:function () {
  28. if(this.sheet == null){
  29. this.spread = SheetDataHelper.createNewSpread($("#equipmentSpread")[0]);
  30. sheetCommonObj.spreadDefaultStyle(this.spread);
  31. this.sheet = this.spread.getSheet(0);
  32. sheetCommonObj.initSheet(this.sheet, this.setting, 0);
  33. this.sheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onValueChange);
  34. this.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onSheetRangeChange);
  35. this.sheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onEditStarting);
  36. this.sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e,args) {
  37. args.sheet.repaint();
  38. equipmentPurchaseObj.checkBtn();
  39. });
  40. if (projectReadOnly) {
  41. sheetCommonObj.disableSpread(this.spread);
  42. } else {
  43. this.initRightClick();
  44. }
  45. }
  46. },
  47. checkBtn:function(){
  48. let me = equipmentPurchaseObj;
  49. let selected = me.getSelected();
  50. let preNode = me.getPreNode(selected);
  51. let afterNode = me.getAfterNode(selected);
  52. //工具栏按钮的有效性
  53. me.validateBtn($('#equipment_upMove'),preNode);
  54. me.validateBtn($('#equipment_downMove'),afterNode);
  55. me.validateBtn($('#equipment_upLevel'),selected && selected.ParentID !=='-1');
  56. me.validateBtn($('#equipment_downLevel'),preNode);
  57. },
  58. validateBtn:function(btn,validate){
  59. if(validate){
  60. btn.removeClass('disabled');
  61. }else{
  62. btn.addClass('disabled');
  63. }
  64. },
  65. getTreeData:function(){
  66. let treeData = [];
  67. let roots = this.parentMap['-1'];
  68. let me = this;
  69. getChildren(roots,treeData);
  70. return treeData;
  71. function getChildren(nodes,data){
  72. if(nodes){
  73. for(let n of nodes){
  74. data.push(n);
  75. getChildren(me.parentMap[n.ID],data)
  76. }
  77. }
  78. }
  79. },
  80. getSelected:function(){
  81. let sel = this.sheet.getSelections()[0];
  82. let row = sel.row == -1 || sel.row == "" ? 0 : sel.row;
  83. if(this.data && this.data.length>0){
  84. return this.data[row];
  85. }
  86. return null;
  87. },
  88. getParentNode:function(node){
  89. if(node.ParentID === '-1') return null;
  90. return this.IDMap[node.ParentID];
  91. },
  92. //取前兄弟节点
  93. getPreNode:function(node){
  94. if(node){
  95. let nodes = this.parentMap[node.ParentID];
  96. let index = nodes.indexOf(node);
  97. return nodes[index-1]
  98. }
  99. return null;
  100. },
  101. //取后兄弟节点
  102. getAfterNode:function(node){
  103. if(node){
  104. let nodes = this.parentMap[node.ParentID];
  105. let index = nodes.indexOf(node);
  106. return nodes[index+1]
  107. }
  108. return null;
  109. },
  110. //取所有后兄弟节点
  111. getAllAfterNodes:function(node){
  112. let brothers = this.parentMap[node.ParentID];
  113. let index = brothers.indexOf(node);
  114. if(brothers.length >= index + 2){
  115. return brothers.slice(index+1);
  116. }
  117. return [];
  118. },
  119. //插入为最后一个子节点的序号
  120. getLastChildrenSeq:function(node){
  121. let seq = 1;
  122. let children = this.parentMap[node.ID];
  123. if(children && children.length > 0){
  124. return children[children.length-1].seq +1
  125. }
  126. return seq;
  127. },
  128. showData:function(){
  129. let equipment_purchase = projectObj.project.equipment_purchase;
  130. this.sourceData = equipment_purchase.datas;
  131. let data = this.sourceData.equipments;
  132. this.IDMap = {};
  133. this.parentMap = {};
  134. data = _.sortBy(data,'seq');
  135. for(let d of data){
  136. let node = ({...d,collapsed:false})
  137. this.IDMap[node.ID] = node;
  138. this.parentMap[node.ParentID] ?this.parentMap[node.ParentID].push(node):this.parentMap[node.ParentID]=[node];
  139. }
  140. let treeData = this.getTreeData();
  141. this.data = treeData;
  142. console.log(data);
  143. sheetCommonObj.showTreeData(this.sheet, this.setting,treeData);
  144. this.checkBtn();
  145. $('#equipment_total').text(this.sourceData.total);
  146. },
  147. onEditStarting: function (sender, args) {
  148. let me = equipmentPurchaseObj;
  149. let row = args.row;
  150. let col = args.col;
  151. if (me.editChecking(row, col) == false) {
  152. args.cancel = true;
  153. }
  154. },
  155. editChecking:function (row,col) {
  156. let me = equipmentPurchaseObj
  157. let dataCode = me.setting.header[col].dataCode;
  158. let equipment = me.data[row];
  159. let children = me.parentMap[equipment.ID];
  160. if(children && children.length>0){//父节点只有这三列才能编辑
  161. return dataCode === 'unit'||dataCode === 'name'||dataCode === 'code'
  162. }
  163. return true;
  164. },
  165. onValueChange:function (e,info) {
  166. let me = equipmentPurchaseObj,row = info.row, col = info.col;
  167. let dataCode = me.setting.header[col].dataCode;
  168. let value = info.newValue;
  169. let equipment = me.data[row];
  170. if (value&&! sheetCommonObj.checkData(col,me.setting,value)) {
  171. alert('输入的数据类型不对,请重新输入!');
  172. return me.showData();
  173. }
  174. let data = {doc:{},ID:equipment.ID};
  175. if(dataCode == 'quantity' || dataCode == 'originalPrice'|| dataCode == 'freightRate'|| dataCode == 'sparePartCostRate'){
  176. value = me.calcTotalPrice(value,dataCode,data.doc,equipment);
  177. }
  178. if(equipment[dataCode] == value) return me.showData();
  179. data.doc[dataCode] = value;
  180. me.updateEquipments([data]);
  181. },
  182. //计算父节点
  183. calcParent:function(updateData){
  184. let me = this;
  185. let temIDMap = {};
  186. let temParentMap = {};
  187. let deleteMap = {};
  188. for(let d of updateData){
  189. if(d.doc){
  190. temIDMap[d.ID] = d;
  191. if(d.doc.ParentID){
  192. temParentMap[d.doc.ParentID]?temParentMap[d.doc.ParentID].push(d):temParentMap[d.doc.ParentID]=[d];
  193. }
  194. }
  195. if(d.type === 'delete')deleteMap[d.ID] = true
  196. }
  197. for(let d of this.data){
  198. let children = this.parentMap[d.ID];
  199. let newChildren = temParentMap[d.ID];
  200. if((children&&children.length > 0) || (newChildren && newChildren.length > 0)){
  201. let totalPrice = getTotalPrice(d.ID);
  202. if(d.totalPrice !== totalPrice) updateData.push({ID:d.ID,doc: {totalPrice,unitPrice:'',sparePartCost:'',sparePartCostRate:'',freight:'',freightRate:'',originalPrice:'',quantity:''} })
  203. }
  204. }
  205. function getTotalPrice(ID){
  206. let sum = 0;
  207. let children = me.parentMap[ID];
  208. let newChildren = temParentMap[ID];
  209. if((children&&children.length > 0) || (newChildren && newChildren.length > 0)){
  210. if(children&&children.length > 0){
  211. for(let c of children){
  212. let newChild = temIDMap[c.ID];
  213. if(deleteMap[c.ID]) continue;//如果是删除操作,不用计算
  214. if(newChild && newChild.doc){
  215. if(newChild.doc.ParentID && newChild.doc.ParentID!=ID) continue;//升级操作时,子节点可能已经不是它的子节点了
  216. }
  217. let totalPrice = getTotalPrice(c.ID);
  218. sum = scMathUtil.roundForObj(sum + totalPrice,getDecimal('process'));
  219. }
  220. }
  221. if(newChildren && newChildren.length > 0){
  222. for(let c of newChildren){
  223. let totalPrice = getTotalPrice(c.ID);
  224. sum = scMathUtil.roundForObj(sum + totalPrice,getDecimal('process'));
  225. }
  226. }
  227. return scMathUtil.roundForObj(sum,getDecimal('glj.unitPrice'));
  228. }
  229. let tem = temIDMap[ID];
  230. if(tem && tem.doc){
  231. let doc = tem.doc;
  232. if(gljUtil.isDef(doc.totalPrice)) return doc.totalPrice;
  233. }
  234. return me.IDMap[ID].totalPrice?scMathUtil.roundForObj(me.IDMap[ID].totalPrice,getDecimal('glj.unitPrice')):0
  235. }
  236. },
  237. calcTotalPrice:function(newValue = 0,dataCode,doc,equipment){
  238. //设备原价
  239. let originalPrice = equipment.originalPrice?scMathUtil.roundForObj(equipment.originalPrice,getDecimal('glj.unitPrice')):0;
  240. //设备运杂费费率
  241. let freightRate = equipment.freightRate?scMathUtil.roundForObj(equipment.freightRate,getDecimal('feeRate')):0;
  242. //备品备件费费率
  243. let sparePartCostRate = equipment.sparePartCostRate?scMathUtil.roundForObj(equipment.sparePartCostRate,getDecimal('feeRate')):0;
  244. let quantity = equipment.quantity?scMathUtil.roundForObj(equipment.quantity,getDecimal('glj.quantity')):0;
  245. let unitPrice = 0;
  246. let freight = 0;
  247. let sparePartCost = 0;
  248. if(gljUtil.isDef(doc.originalPrice)) originalPrice = doc.originalPrice;
  249. if(gljUtil.isDef(doc.freight)) freight = doc.freight;
  250. if(gljUtil.isDef(doc.sparePartCost)) sparePartCost = doc.sparePartCost;
  251. if(gljUtil.isDef(doc.quantity)) quantity = doc.quantity;
  252. if(dataCode === 'quantity') {
  253. newValue = scMathUtil.roundForObj(newValue,getDecimal('glj.quantity'));
  254. quantity = newValue;
  255. }
  256. if(dataCode === 'originalPrice') {
  257. newValue = scMathUtil.roundForObj(newValue,getDecimal('glj.unitPrice'));
  258. originalPrice = newValue;
  259. }
  260. if(dataCode === 'freightRate') {
  261. newValue = scMathUtil.roundForObj(newValue,getDecimal('feeRate'));
  262. freightRate = newValue;
  263. }
  264. if(dataCode === 'sparePartCostRate') {
  265. newValue = scMathUtil.roundForObj(newValue,getDecimal('feeRate'));
  266. sparePartCostRate = newValue;
  267. }
  268. //运杂费 = 原价*运杂费费率(%)*0.01
  269. freight = scMathUtil.roundForObj(originalPrice * freightRate * 0.01,getDecimal('glj.unitPrice'));
  270. // 备品备件费 = 原价*备品备件购置费费率(%)*0.01
  271. sparePartCost = scMathUtil.roundForObj(originalPrice * sparePartCostRate * 0.01,getDecimal('glj.unitPrice'));
  272. unitPrice = scMathUtil.roundForObj(originalPrice + freight,getDecimal('process'));
  273. unitPrice = scMathUtil.roundForObj(unitPrice + sparePartCost,getDecimal('glj.unitPrice'));
  274. doc.freight = freight;
  275. doc.sparePartCost = sparePartCost;
  276. doc.unitPrice = unitPrice;
  277. doc.totalPrice = scMathUtil.roundForObj(quantity * unitPrice,getDecimal('bills.totalPrice'));
  278. return newValue;
  279. },
  280. //计算序列号,返回要改变的兄弟节点数据
  281. calcSeq:function(ParentID,seq){
  282. let data = [];
  283. let nodes = this.parentMap[ParentID];
  284. let temSeq = seq+1;
  285. if(nodes && nodes.length > 0){
  286. for(let n of nodes){
  287. if(n.seq >= seq){
  288. data.push({doc:{seq:temSeq},ID:n.ID})
  289. temSeq+=1;
  290. }
  291. }
  292. }
  293. return data;
  294. },
  295. onSheetRangeChange:function(e,args){
  296. let updateMap = {};
  297. let updateData = []
  298. let me = equipmentPurchaseObj;
  299. for(let c of args.changedCells){
  300. let dataCode = me.setting.header[c.col].dataCode;
  301. let value= args.sheet.getCell(c.row, c.col).text();
  302. let equipment = me.data[c.row];
  303. if (me.editChecking(c.row, c.col) == false) {
  304. continue
  305. }
  306. if (value&&!sheetCommonObj.checkData(c.col,me.setting,value)) {
  307. alert('输入的数据类型不对,请重新输入!');
  308. me.showData();
  309. return ;
  310. }
  311. let tem = updateMap[equipment.ID]?updateMap[equipment.ID]:{};
  312. if(dataCode == 'quantity' || dataCode == 'originalPrice'|| dataCode == 'freightRate'|| dataCode == 'sparePartCostRate'){
  313. value = me.calcTotalPrice(value,dataCode,tem,equipment);
  314. }
  315. tem[dataCode] = value;
  316. updateMap[equipment.ID] = tem;
  317. }
  318. for(let ID in updateMap){
  319. let data = {doc:updateMap[ID],ID:ID};
  320. updateData.push(data);
  321. }
  322. updateData.length > 0? me.updateEquipments(updateData): me.showData();
  323. },
  324. newEquipment:function(ParentID='-1',seq=0){
  325. return {ID:uuid.v1(),ParentID,seq}
  326. },
  327. sumTotal: function(updateData){
  328. let dataMap = {};
  329. let temParentMap = {};
  330. let total = 0;
  331. let deleteMap = {};
  332. for(let d of updateData){
  333. if(d.doc){
  334. dataMap[d.ID] = d;
  335. if(d.doc.ParentID){
  336. temParentMap[d.doc.ParentID]?temParentMap[d.doc.ParentID].push(d):temParentMap[d.doc.ParentID]=[d];
  337. }
  338. }
  339. if(d.type === 'delete')deleteMap[d.ID] = true
  340. }
  341. for(let d of this.data){
  342. //累加所有底层节点就行
  343. if(!this.parentMap[d.ID] && !temParentMap[d.ID] ){
  344. if(deleteMap[d.ID]) continue;
  345. let totalPrice = d.totalPrice?scMathUtil.roundForObj(d.totalPrice,getDecimal('bills.totalPrice')):0;
  346. let data = dataMap[d.ID];
  347. if(data && gljUtil.isDef(data.doc.totalPrice))totalPrice = data.doc.totalPrice;
  348. total =scMathUtil.roundForObj(total + totalPrice,getDecimal('bills.totalPrice'))
  349. }
  350. }
  351. return total;
  352. },
  353. //上移
  354. moveUp:async function(node){
  355. let preNode = this.getPreNode(node);
  356. if(preNode){
  357. let updateData = [];
  358. updateData.push({doc:{seq:node.seq},ID:preNode.ID});
  359. updateData.push({doc:{seq:preNode.seq},ID:node.ID});
  360. await this.updateEquipments(updateData);
  361. }
  362. },
  363. getDeleteData: function(sourceID){
  364. let data = [];
  365. let me = this;
  366. deleteNode(sourceID);
  367. return data;
  368. function deleteNode(ID){
  369. data.push({ID,type:'delete'});
  370. if(me.parentMap[ID]){
  371. for(let c of me.parentMap[ID]){
  372. deleteNode(c.ID);
  373. }
  374. }
  375. }
  376. },
  377. updateEquipments:async function(updateData){
  378. try {
  379. this.calcParent(updateData);
  380. $.bootstrapLoading.start();
  381. let projectID = projectObj.project.ID();
  382. let total = this.sumTotal(updateData);
  383. await ajaxPost('/equipmentPurchase/updateEquipments', { projectID, updateData,total });
  384. for(let data of updateData){
  385. if(data.type === 'insert'){
  386. this.sourceData.equipments.push(...data.documents);
  387. }else if (data.type === 'delete'){
  388. _.remove( this.sourceData.equipments,{ID:data.ID});
  389. } else{
  390. let equipment = _.find(this.sourceData.equipments,{ID:data.ID});
  391. if(equipment){
  392. Object.assign(equipment,data.doc);
  393. }
  394. }
  395. }
  396. projectObj.project.equipment_purchase.datas.total = total;
  397. } catch (error) {
  398. console.log(error);
  399. alert('更新失败,请重试');
  400. }
  401. this.showData();
  402. $.bootstrapLoading.end();
  403. },
  404. insertEquipments:async function(equipments){
  405. try {
  406. $.bootstrapLoading.start();
  407. let projectID = projectObj.project.ID();
  408. await ajaxPost('/equipmentPurchase/insertData', { projectID, equipments });
  409. this.sourceData.equipments.push(...equipments)
  410. this.showData();
  411. } catch (error) {
  412. alert('插入失败,请重试');
  413. }
  414. $.bootstrapLoading.end();
  415. },
  416. deleteEquipment:async function(ID){
  417. try {
  418. let projectID = projectObj.project.ID();
  419. await ajaxPost('/equipmentPurchase/deleteEquipment', { projectID, ID });
  420. _.remove( this.sourceData.equipments,{ID});
  421. this.showData();
  422. } catch (error) {
  423. alert('删除失败,请重试');
  424. }
  425. },
  426. registerInputContextMenuItem:function(){
  427. const insertEquipmentHtml = `<span>插入&nbsp;&nbsp;<input id='insert-equipment-number' class="menu-input" type="text" value="1" onfocus="this.select()">&nbsp;&nbsp;行</span>`;
  428. let me = this;
  429. return sheetCommonObj.registerInputContextMenuItem('insertEquipment', insertEquipmentHtml, 'fa-sign-in', async function () {
  430. const number = +$('#insert-equipment-number').val();
  431. if (!number) {
  432. return;
  433. }
  434. const newData = [];
  435. let row = me.rightClickTarget.row;
  436. let seq = 0;
  437. let ParentID = '-1';
  438. let brotherNodes = [];
  439. if(row == undefined){//没有选中节点的情况,添加到最后
  440. brotherNodes = me.parentMap['-1'];
  441. if(brotherNodes && brotherNodes.length > 0){
  442. seq = brotherNodes[brotherNodes.length -1].seq;
  443. }
  444. }else{
  445. let node = me.data[row];//选中节点时插入为选中的下一行
  446. seq = node.seq;
  447. ParentID = node.ParentID;
  448. }
  449. for (let i = 0; i < number; i++) {
  450. seq+=1;
  451. newData.push(me.newEquipment(ParentID,seq));
  452. }
  453. let updateData = me.calcSeq(ParentID,seq);
  454. updateData.push({documents:newData,type:'insert'});
  455. me.updateEquipments(updateData)
  456. });
  457. },
  458. initRightClick: function () {
  459. let me = this;
  460. $.contextMenu({
  461. selector: '#equipmentSpread',
  462. build: function ($trigger, e) {
  463. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.spread);
  464. me.checkBtn();
  465. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  466. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  467. },
  468. items: {
  469. "insert": {
  470. type: me.registerInputContextMenuItem(),
  471. disabled: function () {
  472. return false;
  473. },
  474. /* callback: function (key, opt) {
  475. me.insertEquipments([me.newEquipment()])
  476. } */
  477. },
  478. "delete": {
  479. name: "删除",
  480. icon: 'fa-times',
  481. disabled: function () {
  482. return me.rightClickTarget.row === undefined;
  483. },
  484. callback: function (key, opt) {
  485. let row = me.rightClickTarget.row;
  486. me.updateEquipments(me.getDeleteData(me.data[row].ID));
  487. //me.preApplyInfoPrice(row);
  488. }
  489. }
  490. }
  491. });
  492. },
  493. }
  494. $(function () {
  495. $('#tab_equipment_purchase').on('shown.bs.tab', function (e) {
  496. sessionStorage.setItem('mainTab', '#tab_equipment_purchase');
  497. $(e.relatedTarget.hash).removeClass('active');
  498. equipmentPurchaseObj.initSpread();
  499. equipmentPurchaseObj.showData();
  500. })
  501. //降级
  502. $('#equipment_downLevel').click(function(){
  503. let me = equipmentPurchaseObj;
  504. let selected = me.getSelected();
  505. if(selected){
  506. let preNode = me.getPreNode(selected);
  507. if(preNode){
  508. let seq = me.getLastChildrenSeq(preNode);
  509. me.updateEquipments([{doc:{ParentID:preNode.ID,seq},ID:selected.ID}])
  510. }
  511. }
  512. })
  513. //升级 - 后兄弟节点变成子节点
  514. $('#equipment_upLevel').click(function(){
  515. let me = equipmentPurchaseObj;
  516. let selected = me.getSelected();
  517. if(selected){
  518. let parentNode = me.getParentNode(selected);
  519. if(parentNode){
  520. let seq = parentNode.seq+1;
  521. let updateData = me.calcSeq(parentNode.ParentID,seq);
  522. updateData.push({doc:{ParentID:parentNode.ParentID,seq},ID:selected.ID})
  523. let brothers = me.getAllAfterNodes(selected);
  524. let subSeq = 0;
  525. //后兄弟节点变成子节点
  526. for(let b of brothers){
  527. subSeq+=1;
  528. updateData.push({doc:{ParentID:selected.ID,seq:subSeq},ID:b.ID})
  529. }
  530. me.updateEquipments(updateData)
  531. }
  532. }
  533. })
  534. //上移
  535. $('#equipment_upMove').click(async function (){
  536. let me = equipmentPurchaseObj;
  537. let selected = me.getSelected();
  538. if(selected){
  539. let sel = me.sheet.getSelections()[0];
  540. me.sheet.setSelection(sel.row -1 , sel.col, sel.rowCount, sel.colCount);
  541. await me.moveUp(selected);
  542. }
  543. })
  544. //下移
  545. $('#equipment_downMove').click(async function(){
  546. let me = equipmentPurchaseObj;
  547. let selected = me.getSelected();
  548. if(selected){
  549. let sel = me.sheet.getSelections()[0];
  550. let node = me.getAfterNode(selected);
  551. if(node){
  552. me.sheet.setSelection(sel.row +1 , sel.col, sel.rowCount, sel.colCount);
  553. await me.moveUp(node);
  554. }
  555. }
  556. })
  557. })