equipment_purchase_view.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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. insertEquipment:async function(number){
  328. let me = this;
  329. const newData = [];
  330. let seq = 0;
  331. let ParentID = '-1';
  332. let brotherNodes = [];
  333. let selected = me.getSelected();
  334. if(!selected){//没有选中节点的情况,添加到最后
  335. brotherNodes = me.parentMap['-1'];
  336. if(brotherNodes && brotherNodes.length > 0){
  337. seq = brotherNodes[brotherNodes.length -1].seq;
  338. }
  339. }else{
  340. let node = selected;//选中节点时插入为选中的下一行
  341. seq = node.seq;
  342. ParentID = node.ParentID;
  343. }
  344. for (let i = 0; i < number; i++) {
  345. seq+=1;
  346. newData.push(me.newEquipment(ParentID,seq));
  347. }
  348. let updateData = me.calcSeq(ParentID,seq);
  349. updateData.push({documents:newData,type:'insert'});
  350. me.updateEquipments(updateData)
  351. },
  352. sumTotal: function(updateData){
  353. let dataMap = {};
  354. let temParentMap = {};
  355. let total = 0;
  356. let deleteMap = {};
  357. for(let d of updateData){
  358. if(d.doc){
  359. dataMap[d.ID] = d;
  360. if(d.doc.ParentID){
  361. temParentMap[d.doc.ParentID]?temParentMap[d.doc.ParentID].push(d):temParentMap[d.doc.ParentID]=[d];
  362. }
  363. }
  364. if(d.type === 'delete')deleteMap[d.ID] = true
  365. }
  366. for(let d of this.data){
  367. //累加所有底层节点就行
  368. if(!this.parentMap[d.ID] && !temParentMap[d.ID] ){
  369. if(deleteMap[d.ID]) continue;
  370. let totalPrice = d.totalPrice?scMathUtil.roundForObj(d.totalPrice,getDecimal('bills.totalPrice')):0;
  371. let data = dataMap[d.ID];
  372. if(data && gljUtil.isDef(data.doc.totalPrice))totalPrice = data.doc.totalPrice;
  373. total =scMathUtil.roundForObj(total + totalPrice,getDecimal('bills.totalPrice'))
  374. }
  375. }
  376. return total;
  377. },
  378. //上移
  379. moveUp:async function(node){
  380. let preNode = this.getPreNode(node);
  381. if(preNode){
  382. let updateData = [];
  383. updateData.push({doc:{seq:node.seq},ID:preNode.ID});
  384. updateData.push({doc:{seq:preNode.seq},ID:node.ID});
  385. await this.updateEquipments(updateData);
  386. }
  387. },
  388. getDeleteData: function(sourceID){
  389. let data = [];
  390. let me = this;
  391. deleteNode(sourceID);
  392. return data;
  393. function deleteNode(ID){
  394. data.push({ID,type:'delete'});
  395. if(me.parentMap[ID]){
  396. for(let c of me.parentMap[ID]){
  397. deleteNode(c.ID);
  398. }
  399. }
  400. }
  401. },
  402. updateEquipments:async function(updateData){
  403. try {
  404. this.calcParent(updateData);
  405. $.bootstrapLoading.start();
  406. let projectID = projectObj.project.ID();
  407. let total = this.sumTotal(updateData);
  408. await ajaxPost('/equipmentPurchase/updateEquipments', { projectID, updateData,total });
  409. for(let data of updateData){
  410. if(data.type === 'insert'){
  411. this.sourceData.equipments.push(...data.documents);
  412. }else if (data.type === 'delete'){
  413. _.remove( this.sourceData.equipments,{ID:data.ID});
  414. } else{
  415. let equipment = _.find(this.sourceData.equipments,{ID:data.ID});
  416. if(equipment){
  417. Object.assign(equipment,data.doc);
  418. }
  419. }
  420. }
  421. projectObj.project.equipment_purchase.datas.total = total;
  422. } catch (error) {
  423. console.log(error);
  424. alert('更新失败,请重试');
  425. }
  426. this.showData();
  427. $.bootstrapLoading.end();
  428. },
  429. /* insertEquipments:async function(equipments){
  430. try {
  431. $.bootstrapLoading.start();
  432. let projectID = projectObj.project.ID();
  433. await ajaxPost('/equipmentPurchase/insertData', { projectID, equipments });
  434. this.sourceData.equipments.push(...equipments)
  435. this.showData();
  436. } catch (error) {
  437. alert('插入失败,请重试');
  438. }
  439. $.bootstrapLoading.end();
  440. }, */
  441. deleteEquipment:async function(ID){
  442. try {
  443. let projectID = projectObj.project.ID();
  444. await ajaxPost('/equipmentPurchase/deleteEquipment', { projectID, ID });
  445. _.remove( this.sourceData.equipments,{ID});
  446. this.showData();
  447. } catch (error) {
  448. alert('删除失败,请重试');
  449. }
  450. },
  451. registerInputContextMenuItem:function(){
  452. const insertEquipmentHtml = `<span>插入&nbsp;&nbsp;<input id='insert-equipment-number' class="menu-input" type="text" value="1" onfocus="this.select()">&nbsp;&nbsp;行</span>`;
  453. let me = this;
  454. return sheetCommonObj.registerInputContextMenuItem('insertEquipment', insertEquipmentHtml, 'fa-sign-in', async function () {
  455. const number = +$('#insert-equipment-number').val();
  456. if (!number) {
  457. return;
  458. }
  459. me.insertEquipment(number);
  460. });
  461. },
  462. initRightClick: function () {
  463. let me = this;
  464. $.contextMenu({
  465. selector: '#equipmentSpread',
  466. build: function ($trigger, e) {
  467. me.rightClickTarget = SheetDataHelper.safeRightClickSelection($trigger, e, me.spread);
  468. me.checkBtn();
  469. return me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.viewport ||
  470. me.rightClickTarget.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  471. },
  472. items: {
  473. "insert": {
  474. type: me.registerInputContextMenuItem(),
  475. disabled: function () {
  476. return false;
  477. },
  478. /* callback: function (key, opt) {
  479. me.insertEquipments([me.newEquipment()])
  480. } */
  481. },
  482. "delete": {
  483. name: "删除",
  484. icon: 'fa-times',
  485. disabled: function () {
  486. return me.rightClickTarget.row === undefined;
  487. },
  488. callback: function (key, opt) {
  489. let row = me.rightClickTarget.row;
  490. me.updateEquipments(me.getDeleteData(me.data[row].ID));
  491. //me.preApplyInfoPrice(row);
  492. }
  493. }
  494. }
  495. });
  496. },
  497. }
  498. $(function () {
  499. $('#tab_equipment_purchase').on('shown.bs.tab', function (e) {
  500. sessionStorage.setItem('mainTab', '#tab_equipment_purchase');
  501. $(e.relatedTarget.hash).removeClass('active');
  502. equipmentPurchaseObj.initSpread();
  503. equipmentPurchaseObj.showData();
  504. })
  505. //插入
  506. $('#equipment_insert').click(function(){
  507. let me = equipmentPurchaseObj;
  508. me.insertEquipment(1);
  509. })
  510. //降级
  511. $('#equipment_downLevel').click(function(){
  512. let me = equipmentPurchaseObj;
  513. let selected = me.getSelected();
  514. if(selected){
  515. let preNode = me.getPreNode(selected);
  516. if(preNode){
  517. let seq = me.getLastChildrenSeq(preNode);
  518. me.updateEquipments([{doc:{ParentID:preNode.ID,seq},ID:selected.ID}])
  519. }
  520. }
  521. })
  522. //升级 - 后兄弟节点变成子节点
  523. $('#equipment_upLevel').click(function(){
  524. let me = equipmentPurchaseObj;
  525. let selected = me.getSelected();
  526. if(selected){
  527. let parentNode = me.getParentNode(selected);
  528. if(parentNode){
  529. let seq = parentNode.seq+1;
  530. let updateData = me.calcSeq(parentNode.ParentID,seq);
  531. updateData.push({doc:{ParentID:parentNode.ParentID,seq},ID:selected.ID})
  532. let brothers = me.getAllAfterNodes(selected);
  533. let subSeq = 0;
  534. //后兄弟节点变成子节点
  535. for(let b of brothers){
  536. subSeq+=1;
  537. updateData.push({doc:{ParentID:selected.ID,seq:subSeq},ID:b.ID})
  538. }
  539. me.updateEquipments(updateData)
  540. }
  541. }
  542. })
  543. //上移
  544. $('#equipment_upMove').click(async function (){
  545. let me = equipmentPurchaseObj;
  546. let selected = me.getSelected();
  547. if(selected){
  548. let sel = me.sheet.getSelections()[0];
  549. me.sheet.setSelection(sel.row -1 , sel.col, sel.rowCount, sel.colCount);
  550. await me.moveUp(selected);
  551. }
  552. })
  553. //下移
  554. $('#equipment_downMove').click(async function(){
  555. let me = equipmentPurchaseObj;
  556. let selected = me.getSelected();
  557. if(selected){
  558. let sel = me.sheet.getSelections()[0];
  559. let node = me.getAfterNode(selected);
  560. if(node){
  561. me.sheet.setSelection(sel.row +1 , sel.col, sel.rowCount, sel.colCount);
  562. await me.moveUp(node);
  563. }
  564. }
  565. })
  566. })