筛选优化

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

View File

@ -28,7 +28,13 @@ const getters = {
return state.real_orders.find(item => item.id === id); return state.real_orders.find(item => item.id === id);
}, },
getSelectedByOrderId: (state) => (order_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) => { getCardByOderIdAndSim: (state) => (order_id, sim) => {
return state.selected.find(item => { return state.selected.find(item => {
@ -60,30 +66,52 @@ const mutations = {
SET_SELECTED(state, data) { SET_SELECTED(state, data) {
state.selected = data; state.selected = data;
}, },
PUSH_SELECTED(state, { order_id, sim, counts }) { PUSH_SELECTED(state, array) {
let index = state.selected.findIndex(item => { let selected = state.selected.map(item => {
return item.order_id === order_id && item.sim === sim; return { order_id: item.order_id, sim: item.sim, counts: item.counts };
}); });
if (index !== -1) { for (let index = 0; index < array.length; index++) {
state.selected.splice(index, 1); const element = array[index];
let i = selected.findIndex(item => {
return item.order_id === element.order_id && item.sim === element.sim;
});
if (i !== -1) {
selected.splice(i, 1);
} }
let obj = { order_id, sim, counts }; let obj = { order_id: element.order_id, sim: element.sim, counts: element.counts };
state.selected.push(obj);
selected.push(obj);
}
state.selected = selected;
}, },
REMOVE_SELECTED(state, { order_id, sim }) { REMOVE_SELECTED(state, array) {
let index = 0; let selected = state.selected.map(item => {
while (index !== -1) { return { order_id: item.order_id, sim: item.sim, counts: item.counts };
index = state.selected.findIndex(item => {
return sim ? (item.order_id === order_id && item.sim === sim) : (item.order_id === order_id);
}); });
if (index !== -1) { for (let index = 0; index < array.length; index++) {
state.selected.splice(index, 1); 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;
}
}; };
const actions = { const actions = {

View File

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

View File

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

View File

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