1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import {
|
8 | isNumber
|
9 | } from 'tinper-sparrow/src/util';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | const removeRowByRowId = function(rowid) {
|
18 | for (var i = 0, count = this.rows.length; i < count; i++) {
|
19 | if (this.rows[i].rowId == rowid) {
|
20 | this.rows.splice(i, 1);
|
21 | count--;
|
22 | this.updateSelectedIndices(i, '-')
|
23 | this.updateFocusIndex(i, '-')
|
24 | }
|
25 | }
|
26 | }
|
27 |
|
28 |
|
29 | const updateSelectedIndices = function(index, type, num) {
|
30 | if (!isNumber(num)) {
|
31 | num = 1
|
32 | }
|
33 | var selectedIndices = this.selectedIndices.slice();
|
34 | if (selectedIndices == null || selectedIndices.length == 0)
|
35 | return
|
36 | for (var i = 0, count = selectedIndices.length; i < count; i++) {
|
37 | if (type == '+') {
|
38 | if (selectedIndices[i] >= index)
|
39 | selectedIndices[i] = parseInt(selectedIndices[i]) + num
|
40 | } else if (type == '-') {
|
41 | if (selectedIndices[i] >= index && selectedIndices[i] <= index + num - 1) {
|
42 | selectedIndices.splice(i, 1)
|
43 | } else if (selectedIndices[i] > index + num - 1)
|
44 | selectedIndices[i] = selectedIndices[i] - num
|
45 | }
|
46 | }
|
47 | this.selectedIndices = selectedIndices
|
48 | }
|
49 |
|
50 |
|
51 | const updateFocusIndex = function(opIndex, opType, num) {
|
52 | if (!isNumber(num)) {
|
53 | num = 1
|
54 | }
|
55 | if (opIndex <= this.focus && this.focus != -1) {
|
56 | if (opType === '+') {
|
57 | this.focus = this.focus + num
|
58 | } else if (opType === '-') {
|
59 | if (this.focus >= opIndex && this.focus <= opIndex + num - 1) {
|
60 | this.focus = this.focus - 1
|
61 | } else if (this.focus > opIndex + num - 1) {
|
62 | this.focus = this.focus - num
|
63 | }
|
64 | }
|
65 | }
|
66 | }
|
67 |
|
68 |
|
69 | export const pageRemoveRowFunObj = {
|
70 | removeRowByRowId: removeRowByRowId,
|
71 | updateSelectedIndices: updateSelectedIndices,
|
72 | updateFocusIndex: updateFocusIndex
|
73 | }
|