432 lines
10 KiB
JavaScript
432 lines
10 KiB
JavaScript
export default {
|
|
components: {
|
|
BTable: resolve => require(['components/table'], resolve)
|
|
},
|
|
props: {
|
|
show: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
source: {
|
|
type: Number,
|
|
default: 0
|
|
},
|
|
type: {
|
|
type: Number,
|
|
default: 0
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
my_show: false,
|
|
loading: false,
|
|
orderLoading: false,
|
|
cardLoading: false,
|
|
order_id: 0,
|
|
search: {
|
|
show: true
|
|
},
|
|
params: {
|
|
company_id: '',
|
|
package_id: '',
|
|
carrier_operator: '',
|
|
time: [
|
|
this.moment().subtract('2', 'months').startOf('month').format('YYYY-MM-DD'),
|
|
this.moment().subtract('2', 'months').endOf('month').format('YYYY-MM-DD')
|
|
],
|
|
used: '',
|
|
sim: ''
|
|
},
|
|
orderColumns: [
|
|
{
|
|
width: 60,
|
|
align: "center",
|
|
renderHeader: (h, context) => {
|
|
let value = false;
|
|
let indeterminate = false;
|
|
|
|
if (this.orders.data) {
|
|
this.orders.data.map(item => {
|
|
let select = this.selected.find(v => {
|
|
return v.id === item.id;
|
|
});
|
|
|
|
if (select) {
|
|
value = true;
|
|
}
|
|
|
|
if (!select) {
|
|
indeterminate = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
return h("Checkbox", {
|
|
props: {
|
|
indeterminate: value && indeterminate,
|
|
value: value,
|
|
disabled: !value
|
|
},
|
|
on: {
|
|
input: () => {
|
|
this.selected = [];
|
|
}
|
|
}
|
|
});
|
|
},
|
|
render: (h, context) => {
|
|
let value = false;
|
|
|
|
let select = this.selected.find(item => {
|
|
return item.id === context.row.id;
|
|
});
|
|
|
|
if (select) {
|
|
value = true;
|
|
}
|
|
|
|
let indeterminate =
|
|
select &&
|
|
select.cards &&
|
|
context.row.counts !== select.cards.reduce((acc, cur) => {
|
|
return acc + cur.counts;
|
|
}, 0);
|
|
|
|
return h("Checkbox", {
|
|
props: {
|
|
indeterminate: value && indeterminate,
|
|
value: value,
|
|
disabled: context.row.counts === context.row.cards_count
|
|
},
|
|
on: {
|
|
input: value => {
|
|
this.handleSelectOrder(context.row.id, value);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
{
|
|
title: "订单编号",
|
|
key: "sn",
|
|
width: 220
|
|
},
|
|
|
|
{
|
|
title: "企业名称",
|
|
key: "company_name",
|
|
width: 210
|
|
},
|
|
{
|
|
title: "运营商",
|
|
key: "carrier_operator_name",
|
|
width: 75
|
|
},
|
|
{
|
|
title: "套餐名称",
|
|
key: "package_name",
|
|
width: 150
|
|
},
|
|
{
|
|
title: "支付方式",
|
|
key: "pay_channel_name",
|
|
width: 90
|
|
},
|
|
{
|
|
title: "数量",
|
|
key: "counts",
|
|
width: 90
|
|
},
|
|
{
|
|
title: "已用数量",
|
|
key: "cards_count",
|
|
width: 90
|
|
},
|
|
{
|
|
title: "订单金额",
|
|
key: "total_price",
|
|
width: 100
|
|
},
|
|
|
|
{
|
|
title: "订单时间",
|
|
key: "order_at",
|
|
width: 150
|
|
},
|
|
{
|
|
title: "所需卡量",
|
|
key: "",
|
|
width: 150,
|
|
fixed: 'right',
|
|
render: (h, context) => {
|
|
let select = this.selected.find(item => {
|
|
return item.id === context.row.id;
|
|
});
|
|
|
|
let value = select ? select.cards.reduce((acc, cur) => {
|
|
return acc + cur.counts;
|
|
}, 0) : 0;
|
|
|
|
return h("InputNumber", {
|
|
props: {
|
|
max: context.row.counts - context.row.cards_count,
|
|
min: 0,
|
|
value: value,
|
|
precision: 0
|
|
},
|
|
on: {
|
|
input: value => {
|
|
this.handleSelectOrder(context.row.id, true, value);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
],
|
|
cardColumns: [
|
|
{
|
|
width: 60,
|
|
align: "center",
|
|
renderHeader: (h, context) => {
|
|
let value = false;
|
|
let indeterminate = false;
|
|
|
|
let select = this.selected.find(item => {
|
|
return item.id === this.order_id;
|
|
});
|
|
|
|
value = !!select;
|
|
|
|
indeterminate =
|
|
select &&
|
|
select.cards &&
|
|
select.cards.length !== this.cards.length;
|
|
|
|
return h("Checkbox", {
|
|
props: {
|
|
indeterminate: value && indeterminate,
|
|
value: value
|
|
},
|
|
on: {
|
|
input: value => {
|
|
this.handleSelectOrder(this.order_id, value);
|
|
}
|
|
}
|
|
});
|
|
},
|
|
render: (h, context) => {
|
|
let value = false;
|
|
|
|
let select = this.selected.find(item => {
|
|
return item.id == this.order_id;
|
|
});
|
|
|
|
if (select) {
|
|
let card = select.cards.find(item => {
|
|
return item.sim == context.row.sim;
|
|
});
|
|
|
|
if (card) {
|
|
value = true;
|
|
}
|
|
}
|
|
|
|
return h("Checkbox", {
|
|
props: {
|
|
value: value,
|
|
disabled: !!context.row.virtual_order_id
|
|
},
|
|
on: {
|
|
input: value => {
|
|
this.handleSelectCards(context.row, value);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
{
|
|
title: "SIM",
|
|
key: "sim",
|
|
width: 135
|
|
},
|
|
{
|
|
title: "数量",
|
|
key: "counts",
|
|
width: 60
|
|
},
|
|
{
|
|
title: "状态",
|
|
key: "",
|
|
width: 100,
|
|
align: 'center',
|
|
render: (h, { row, column, index }) => {
|
|
return h(
|
|
"Tag", {
|
|
props: {
|
|
color: row.virtual_order_id ? "error" : "primary"
|
|
}
|
|
},
|
|
row.virtual_order_id ? "已使用" : "未使用"
|
|
);
|
|
}
|
|
},
|
|
{
|
|
title: "VD企业",
|
|
key: "company_name",
|
|
width: 210
|
|
},
|
|
{
|
|
title: "VD套餐",
|
|
key: "package_name",
|
|
width: 150
|
|
}
|
|
]
|
|
};
|
|
},
|
|
computed: {
|
|
orders() {
|
|
return this.$store.state.order.real_orders;
|
|
},
|
|
cards: {
|
|
get() {
|
|
return this.$store.state.order.cards;
|
|
},
|
|
set(value) {
|
|
this.$store.commit("SET_CARDS", value);
|
|
}
|
|
},
|
|
selected: {
|
|
get() {
|
|
return this.$store.state.order.selected;
|
|
},
|
|
set(value) {
|
|
this.$store.commit("SET_REAL_ORDER_SELECTED", value);
|
|
}
|
|
},
|
|
counts() {
|
|
let selected = this.$store.state.order.selected;
|
|
|
|
if (!selected.length) {
|
|
return 0;
|
|
}
|
|
|
|
return selected.reduce((acc, cur) => {
|
|
return acc + cur.cards.reduce((a, c) => {
|
|
return a + c.counts;
|
|
}, 0);
|
|
}, 0);
|
|
}
|
|
},
|
|
watch: {
|
|
show(bool) {
|
|
this.my_show = bool;
|
|
this.$store.commit('SET_CARDS', []);
|
|
if (bool) {
|
|
this.index(1);
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
ok() {
|
|
this.my_show = false;
|
|
},
|
|
index(page, limit = 10) {
|
|
let params = this.searchDataHandle({}, { page, limit }, this.params);
|
|
params.type = this.type;
|
|
this.orderLoading = true;
|
|
this.$store.dispatch("getOrders", params).then(() => {
|
|
this.orderLoading = false;
|
|
}).catch(() => {
|
|
this.orderLoading = false;
|
|
});
|
|
},
|
|
getCards(order_id) {
|
|
this.order_id = order_id;
|
|
this.cardLoading = true;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
let params = { order_id: order_id, type: this.type };
|
|
this.$store.dispatch("getCards", params).then(cards => {
|
|
this.cardLoading = false;
|
|
resolve(cards);
|
|
}).catch(() => {
|
|
this.cardLoading = false;
|
|
this.$Message.error("服务器出错,请稍后再试");
|
|
});
|
|
});
|
|
},
|
|
handleOrderRowDblclick(row) {
|
|
this.getCards(row.id);
|
|
},
|
|
visibleChange(bool) {
|
|
if (!bool) {
|
|
this.$emit("update:show", false);
|
|
}
|
|
},
|
|
clear() {
|
|
this.$store.commit('SET_REAL_ORDER_SELECTED', []);
|
|
this.my_show = false;
|
|
},
|
|
resetSearch() {
|
|
for (let k in this.params) {
|
|
if (k === 'time') {
|
|
this.params[k] = [
|
|
this.moment().subtract('2', 'months').startOf('month').format('YYYY-MM-DD'),
|
|
this.moment().subtract('2', 'months').endOf('month').format('YYYY-MM-DD')
|
|
];
|
|
} else {
|
|
this.params[k] = '';
|
|
}
|
|
}
|
|
this.index(1);
|
|
},
|
|
handleSelectOrder(order_id, value, counts = null) {
|
|
if (value) {
|
|
this.getCards(order_id).then(cards => {
|
|
cards = this.filterUsed(cards);
|
|
|
|
if (cards.length) {
|
|
cards.sort((a, b) => {
|
|
return a.counts < b.counts ? -1 : (a.counts > b.counts ? 1 : 0);
|
|
});
|
|
|
|
let arr = [];
|
|
|
|
counts = counts === null ? cards.length : counts;
|
|
|
|
cards.map(item => {
|
|
if (counts > 0) {
|
|
arr.push({ sim: item.sim, counts: item.counts });
|
|
counts -= item.counts;
|
|
}
|
|
});
|
|
|
|
if (arr.length) {
|
|
this.$store.commit('PUSH_REAL_ORDER_SELECTED', { order_id, cards: arr });
|
|
} else {
|
|
this.$store.commit('REMOVE_REAL_ORDER_SELECTED', order_id);
|
|
}
|
|
} else {
|
|
this.$Message.error('选中零张卡');
|
|
}
|
|
});
|
|
} else {
|
|
this.$store.commit('REMOVE_REAL_ORDER_SELECTED', order_id);
|
|
}
|
|
},
|
|
handleSelectCards(row, value) {
|
|
let action = value ? 'PUSH_CARD_SELECTED' : 'REMOVE_CARD_SELECTED';
|
|
this.$store.commit(action, { order_id: row.order_id, sim: row.sim, counts: row.counts });
|
|
},
|
|
filterUsed(cards) {
|
|
return cards.filter(item => {
|
|
return item.virtual_order_id === 0;
|
|
});
|
|
},
|
|
order() {
|
|
this.$emit('create-order');
|
|
},
|
|
store() {}
|
|
}
|
|
};
|