筛选优化

This commit is contained in:
邓皓元 2019-03-11 14:37:07 +08:00
parent 7e8377254d
commit fcf5818d7e
6 changed files with 128 additions and 72 deletions

View File

@ -116,6 +116,6 @@ class OrderService extends Service
}
});
return $cards->sortBy('sim')->values();
return $cards->sortBy('sim')->sortBy('order_id')->values();
}
}

View File

@ -193,8 +193,7 @@ class OrderService extends Service
try {
$table = $this->tables[$node['type']];
$cards = array_pluck($attributes['selected'], 'cards');
$cards = array_collapse($cards);
$cards = $attributes['selected'];
$data = [];
@ -221,9 +220,8 @@ class OrderService extends Service
$simArray = implode(',', array_pluck($value, 'sim'));
DB::statement("select fix_timelines('{{$simArray}}'::INT8[]);");
RealOrderCardPartition::whereIn('order_id', array_pluck($attributes['selected'], 'id'))
->whereIn('sim', array_pluck($value, 'sim'))->update(['virtual_order_id' => $node['id']]);
RealOrderCardPartition::whereIn('order_id', array_pluck($attributes['selected'], 'order_id'))
->whereIn('sim', array_pluck($value, 'sim'))->update(['virtual_order_id' => $node['id']]);
}
}
@ -231,7 +229,7 @@ class OrderService extends Service
$this->orderCardPartitionRepository->forgetCached();
app(RealOrderCardPartitionRepository::class)->forgetCached();
CreateRealVirtualRelation::dispatch($node->id, array_pluck($attributes['selected'], 'id'));
CreateRealVirtualRelation::dispatch($node->id, array_pluck($attributes['selected'], 'order_id'));
} catch (\Exception $e) {
DB::rollBack();
throw new HttpException('操作失败');

View File

@ -28,7 +28,13 @@ const getters = {
return state.real_orders.find(item => item.id === id);
},
getSelectedByOrderId: (state) => (order_id) => {
return state.selected.filter(item => item.order_id === order_id);
if (typeof order_id !== 'object') {
order_id = [order_id];
}
return state.selected.filter(item => {
return order_id.includes(item.order_id);
});
},
getCardByOderIdAndSim: (state) => (order_id, sim) => {
return state.selected.find(item => {
@ -60,29 +66,51 @@ const mutations = {
SET_SELECTED(state, data) {
state.selected = data;
},
PUSH_SELECTED(state, { order_id, sim, counts }) {
let index = state.selected.findIndex(item => {
return item.order_id === order_id && item.sim === sim;
PUSH_SELECTED(state, array) {
let selected = state.selected.map(item => {
return { order_id: item.order_id, sim: item.sim, counts: item.counts };
});
if (index !== -1) {
state.selected.splice(index, 1);
}
for (let index = 0; index < array.length; index++) {
const element = array[index];
let obj = { order_id, sim, counts };
state.selected.push(obj);
},
REMOVE_SELECTED(state, { order_id, sim }) {
let index = 0;
while (index !== -1) {
index = state.selected.findIndex(item => {
return sim ? (item.order_id === order_id && item.sim === sim) : (item.order_id === order_id);
let i = selected.findIndex(item => {
return item.order_id === element.order_id && item.sim === element.sim;
});
if (index !== -1) {
state.selected.splice(index, 1);
if (i !== -1) {
selected.splice(i, 1);
}
let obj = { order_id: element.order_id, sim: element.sim, counts: element.counts };
selected.push(obj);
}
state.selected = selected;
},
REMOVE_SELECTED(state, array) {
let selected = state.selected.map(item => {
return { order_id: item.order_id, sim: item.sim, counts: item.counts };
});
for (let index = 0; index < array.length; index++) {
const element = array[index];
let i = 0;
while (i !== -1) {
i = selected.findIndex(item => {
return element.sim ? (item.order_id === element.order_id && item.sim === element.sim) : (item.order_id === element.order_id);
});
if (i !== -1) {
selected.splice(i, 1);
}
}
}
state.selected = selected;
}
};

View File

@ -126,12 +126,13 @@
<Page
:current="Number(page.page)"
:page-size="Number(page.limit)"
:page-size-opts="[10, 20, 100, Infinity]"
:page-size-opts="[10, 20, 50, 100]"
:total="Number(page.total)"
@on-change="changePage"
@on-page-size-change="changeLimit"
show-elevator
show-total
show-sizer
></Page>
</div>
</Col>
@ -141,8 +142,7 @@
size="small"
:loading="cardLoading"
:columns="cardColumns"
:data="cards ? cards : []"
:row-class-name="rowClassName"
:data="showCards ? showCards : []"
stripe
border
:height="449"
@ -172,6 +172,10 @@
}
>>> .ivu-table .bg-yellow td {
background-color: yellow !important;
background-color: #ffffdd !important;
}
>>> .ivu-table .bg-yellow-2n td {
background-color: #ffff88 !important;
}
</style>

View File

@ -27,7 +27,6 @@ export default {
loading: false,
orderLoading: false,
cardLoading: false,
order_id: 0,
search: {
show: true
},
@ -48,34 +47,42 @@ export default {
sim: ''
},
showOrders: [],
showCards: [],
orderColumns: [
{
width: 60,
align: "center",
renderHeader: (h, context) => {
let value = !!this.selected.length;
let value = false;
let indeterminate = false;
if (this.orders.data) {
let total = this.orders.reduce((acc, cur) => {
return acc + cur.counts;
}, 0);
let total = this.showOrders.reduce((acc, cur) => {
return acc + cur.counts;
}, 0);
let counts = this.selected.reduce((acc, cur) => {
return acc + cur.counts;
}, 0);
indeterminate = total !== counts;
}
let select = this.getSelectedByOrderId(this.showOrders.map(el => {
return el.id;
}));
let counts = select.reduce((acc, cur) => {
return acc + cur.counts;
}, 0);
value = !!counts;
indeterminate = total !== counts;
return h("Checkbox", {
props: {
indeterminate: value && indeterminate,
value: value,
disabled: !value
value: value
},
on: {
input: () => {
this.$store.commit('SET_SELECTED', []);
input: value => {
let order_id = this.showOrders.map(item => {
return item.id;
});
this.handleSelectOrder(order_id, value);
}
}
});
@ -171,7 +178,8 @@ export default {
},
on: {
input: value => {
this.handleSelectOrder(context.row.id, true, value);
let bool = !!value;
this.handleSelectOrder(context.row.id, bool, value);
}
}
});
@ -188,7 +196,7 @@ export default {
value = !!this.selected.length;
indeterminate = this.selected.length && this.selected.length !== this.cards.length;
indeterminate = this.selected.length && this.selected.length !== this.showCards.length;
return h("Checkbox", {
props: {
@ -198,14 +206,19 @@ export default {
on: {
input: value => {
if (value) {
let cards = this.getFilterUsedCards(this.cards);
let cards = this.getFilterUsedCards(this.showCards);
cards.map(item => {
let obj = { order_id: item.order_id, sim: item.sim, counts: item.counts };
this.$store.commit('PUSH_SELECTED', obj);
let array = cards.map(item => {
return { order_id: item.order_id, sim: item.sim, counts: item.counts };
});
this.$store.commit('PUSH_SELECTED', array);
} else {
this.$store.commit('SET_SELECTED', []);
let array = this.showCards.map(item => {
return { order_id: item.order_id, sim: item.sim };
});
this.$store.commit('REMOVE_SELECTED', array);
}
}
}
@ -282,19 +295,17 @@ export default {
}
},
methods: {
rowClassName(row, index) {
if (row.order_id === this.order_id) {
return 'bg-yellow';
}
return '';
},
ok() {
this.my_show = false;
},
index(force = 0) {
let params = this.parseParams(this.params);
params.type = this.type;
if (params.type !== this.type) {
params.type = this.type;
this.$store.commit('SET_SELECTED', []);
}
this.orderLoading = true;
if (force) {
@ -318,12 +329,7 @@ export default {
this.showOrders = this.orders.slice((page - 1) * this.page.limit, page * this.page.limit);
},
handleOrderRowDblclick(row) {
window.t = this;
this.order_id = this.order_id === row.id ? 0 : row.id;
this.getCards(row.id).then(() => {
let index = this.cards.findIndex(el => { return el.order_id === row.id; });
this.$refs.cardSelection.scrollToRow(index);
});
this.getCards(row.id);
},
visibleChange(bool) {
if (!bool) {
@ -353,6 +359,15 @@ export default {
let params = { order_id: order_id, type: this.type };
this.$store.dispatch('getCards', params).then((cards) => {
this.cardLoading = false;
this.showCards = cards;
// 跳转到选择的行
this.$nextTick(() => {
if (typeof order_id !== 'object') {
let index = this.showCards.findIndex(el => { return el.order_id === order_id; });
let toIndex = index - 5 > 0 ? index - 5 : 0;
this.$refs.cardSelection.scrollToRow(toIndex);
}
});
resolve(cards);
}).catch((err) => {
this.cardLoading = false;
@ -361,8 +376,18 @@ export default {
});
},
handleSelectOrder(order_id, value, counts = null) {
if (!value || counts === 0) {
return this.$store.commit('REMOVE_SELECTED', { order_id });
if (typeof order_id !== 'object') {
order_id = [order_id];
}
let remove = order_id.map(el => {
return { order_id: el };
});
this.$store.commit('REMOVE_SELECTED', remove);
if (!value) {
return;
}
this.getCards(order_id).then((cards) => {
@ -389,22 +414,20 @@ export default {
});
}
this.$store.commit('REMOVE_SELECTED', { order_id });
arr.map(item => {
this.$store.commit('PUSH_SELECTED', item);
});
this.$store.commit('PUSH_SELECTED', arr);
});
},
handleSelectCards(row, value) {
let action = value ? 'PUSH_SELECTED' : 'REMOVE_SELECTED';
this.$store.commit(action, { order_id: row.order_id, sim: row.sim, counts: row.counts });
this.$store.commit(action, [{ order_id: row.order_id, sim: row.sim, counts: row.counts }]);
},
order() {
this.$emit('create-order');
},
store() {},
sort() {
this.showCards = this.cards;
let mapped = this.orders.map((el, i) => { return { index: i, id: el.id }; });
mapped.sort((a, b) => {

View File

@ -8,6 +8,9 @@ module.exports = {
outputDir: '../public',
indexPath: process.env.NODE_ENV === 'production' ? '../resources/views/index.blade.php' : 'index.html',
lintOnSave: true,
configureWebpack: {
devtool: 'source-map'
},
chainWebpack: config => {
config.resolve.alias
.set('node_modules', resolve('node_modules'))