454 lines
11 KiB
JavaScript
454 lines
11 KiB
JavaScript
export default {
|
|
data() {
|
|
return {
|
|
title: '收银台',
|
|
type: 'goods',
|
|
goodsData: {},
|
|
orderData: {
|
|
goods_num: 0,
|
|
pay_money: 0,
|
|
goods_list: [],
|
|
remark: '',
|
|
create_time: 0
|
|
},
|
|
remark: '',
|
|
outTradeNo: '',
|
|
orderId: 0,
|
|
searchType: 'mobile',
|
|
searchText: '',
|
|
searchTypeList: [{
|
|
'label': '手机号',
|
|
'value': 'mobile',
|
|
'disabled': false
|
|
},
|
|
// {
|
|
// 'label': '卡号',
|
|
// 'value': 'member_code',
|
|
// 'disabled': false
|
|
// },
|
|
{
|
|
'label': '昵称',
|
|
'value': 'nickname',
|
|
'disabled': false
|
|
},
|
|
|
|
],
|
|
date: '',
|
|
goodsIds: [],
|
|
ordertime: ''
|
|
}
|
|
},
|
|
onShow() {
|
|
this.orderData.create_time = this.$util.timeFormat(parseInt(new Date().getTime() / 1000));
|
|
},
|
|
onLoad() {
|
|
|
|
},
|
|
methods: {
|
|
showMember() {
|
|
this.type = 'member';
|
|
this.$refs.member.type = 'member';
|
|
},
|
|
searchMember() {
|
|
if (!this.searchText) {
|
|
this.$util.showToast({
|
|
title: '请输入会员信息',
|
|
icon: 'error'
|
|
});
|
|
return false;
|
|
}
|
|
this.$refs.member.searchMemberByType(this.searchText, this.searchType);
|
|
},
|
|
switchType(index, item) {
|
|
this.searchType = item.value;
|
|
},
|
|
addmember() {
|
|
this.type = 'member';
|
|
this.$refs.member.type = 'addmember';
|
|
},
|
|
/**
|
|
* 切换会员
|
|
*/
|
|
replaceMember() {
|
|
this.$refs.member.memberId = 0;
|
|
this.$store.commit('setMemberInfo', null);
|
|
this.type = 'member';
|
|
},
|
|
selectGoods(data) {
|
|
let key = 'sku_' + data.sku_id;
|
|
if (this.goodsData[key]) {
|
|
this.goodsData[key].num += 1;
|
|
} else {
|
|
this.goodsData[key] = data;
|
|
this.goodsData[key].num = 1;
|
|
}
|
|
this.calculation();
|
|
},
|
|
selectMemberGoods(arr) {
|
|
arr.forEach((data) => {
|
|
let key = 'sku_' + data.sku_id + 'item_' + data.item_id;
|
|
if (this.goodsData[key]) {
|
|
this.goodsData[key].num += data.num;
|
|
} else {
|
|
this.goodsData[key] = data;
|
|
this.goodsData[key].num = data.num;
|
|
}
|
|
})
|
|
this.calculation();
|
|
},
|
|
deleteGoods(data) {
|
|
if (data.card_item_id) {
|
|
let _data = this.goodsData['sku_' + data.sku_id + 'item_' + data.card_item_id];
|
|
|
|
this.$refs.member.memberCardData.list[_data.card_index].total_use_num -= _data.num;
|
|
this.$refs.member.memberCardData.list[_data.card_index].item_list[_data.index].use_num -= _data.num;
|
|
if (this.$refs.member.memberCardData.index == _data.card_index) {
|
|
if (_data.card_type != 'timecard') this.$refs.member.memberCardData.currData.item_list[_data.index]
|
|
.use_num -= _data.num;
|
|
this.$refs.member.memberCardData.currData.total_use_num -= _data.num;
|
|
}
|
|
|
|
delete this.goodsData['sku_' + data.sku_id + 'item_' + data.card_item_id];
|
|
} else {
|
|
delete this.goodsData['sku_' + data.sku_id];
|
|
}
|
|
this.calculation();
|
|
|
|
if (!Object.keys(this.goodsData).length) {
|
|
this.orderData.goods_list = [];
|
|
this.orderData.goods_num = 0;
|
|
this.orderData.pay_money = 0;
|
|
}
|
|
},
|
|
/**
|
|
* 商品数量增加
|
|
* @param {Object} data
|
|
*/
|
|
inc(data) {
|
|
|
|
if (data.card_item_id) {
|
|
let _data = this.goodsData['sku_' + data.sku_id + 'item_' + data.card_item_id],
|
|
memberCardData = this.$refs.member.memberCardData;
|
|
|
|
if (data.goods_type == '' && _data.num >= data.stock) {
|
|
this.$util.showToast({
|
|
title: '商品库存不足'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// 如果会员卡项中正在变更的和该商品所使用的卡项一致
|
|
if (memberCardData.index == _data.card_index && Object.keys(memberCardData.selected).length) return;
|
|
|
|
if (_data.card_type == 'commoncard') {
|
|
if (memberCardData.list[_data.card_index].total_num == memberCardData.list[_data.card_index]
|
|
.total_use_num) return;
|
|
} else if (_data.card_type != 'timecard') {
|
|
if (memberCardData.list[_data.card_index].item_list[_data.index].num == memberCardData.list[_data
|
|
.card_index].item_list[_data.index].use_num) return;
|
|
}
|
|
|
|
memberCardData.list[_data.card_index].total_use_num += 1;
|
|
memberCardData.list[_data.card_index].item_list[_data.index].use_num += 1;
|
|
|
|
if (memberCardData.index == _data.card_index) {
|
|
memberCardData.currData.total_use_num += 1;
|
|
if (_data.card_type != 'timecard') {
|
|
memberCardData.currData.item_list[_data.index].use_num += 1;
|
|
}
|
|
}
|
|
|
|
this.goodsData['sku_' + data.sku_id + 'item_' + data.card_item_id].num += 1;
|
|
} else {
|
|
let _data = this.goodsData['sku_' + data.sku_id];
|
|
if (data.goods_type == '' && _data.num >= data.stock) {
|
|
this.$util.showToast({
|
|
title: '商品库存不足'
|
|
});
|
|
return;
|
|
}
|
|
this.goodsData['sku_' + data.sku_id].num += 1;
|
|
}
|
|
this.calculation();
|
|
},
|
|
/**
|
|
* 商品数量减少
|
|
* @param {Object} data
|
|
*/
|
|
dec(data) {
|
|
if (data.card_item_id) {
|
|
let _data = this.goodsData['sku_' + data.sku_id + 'item_' + data.card_item_id];
|
|
if (_data.num == 1) return;
|
|
|
|
this.$refs.member.memberCardData.list[_data.card_index].total_use_num -= 1;
|
|
this.$refs.member.memberCardData.list[_data.card_index].item_list[_data.index].use_num -= 1;
|
|
if (this.$refs.member.memberCardData.index == _data.card_index) {
|
|
this.$refs.member.memberCardData.currData.item_list[_data.index].use_num -= 1;
|
|
this.$refs.member.memberCardData.currData.total_use_num -= 1;
|
|
}
|
|
this.goodsData['sku_' + data.sku_id + 'item_' + data.card_item_id].num -= 1;
|
|
this.calculation();
|
|
} else {
|
|
if (this.goodsData['sku_' + data.sku_id].num == 1) return;
|
|
|
|
this.goodsData['sku_' + data.sku_id].num -= 1;
|
|
this.calculation();
|
|
}
|
|
},
|
|
/**
|
|
* 计算
|
|
*/
|
|
calculation() {
|
|
this.goodsIds = [];
|
|
if (!Object.keys(this.goodsData).length) {
|
|
this.orderData.goods_num = 0;
|
|
return;
|
|
}
|
|
|
|
let sku_array = [],
|
|
goodsIds = [];
|
|
|
|
Object.keys(this.goodsData).forEach(key => {
|
|
let item = this.goodsData[key];
|
|
sku_array.push({
|
|
sku_id: item.sku_id,
|
|
num: item.num,
|
|
card_item_id: item.item_id ? item.item_id : 0
|
|
})
|
|
if (!item.item_id) goodsIds.push(item.goods_id);
|
|
})
|
|
this.goodsIds = goodsIds;
|
|
let data = {
|
|
sku_array: JSON.stringify(sku_array),
|
|
create_time: this.orderData.create_time
|
|
};
|
|
if (this.memberInfo) data.member_id = this.memberInfo.member_id;
|
|
|
|
this.$api.sendRequest({
|
|
url: '/cashier/storeapi/cashierordercreate/calculate',
|
|
data: data,
|
|
success: res => {
|
|
if (res.code == 0) {
|
|
Object.assign(this.orderData, res.data);
|
|
uni.setStorageSync('orderData', this.orderData);
|
|
this.$forceUpdate();
|
|
} else {
|
|
this.$util.showToast({
|
|
title: res.message
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 返回
|
|
*/
|
|
goreturn() {
|
|
uni.navigateBack({
|
|
delta: 1
|
|
})
|
|
},
|
|
/**
|
|
* 挂单
|
|
*/
|
|
hangingOrder() {
|
|
if (Object.keys(this.goodsData).length) {
|
|
let data = {
|
|
goods: [],
|
|
order_id: this.orderData.order_id,
|
|
remark: this.orderData.remark
|
|
};
|
|
if (this.memberInfo) data.member_id = this.memberInfo.member_id;
|
|
Object.keys(this.goodsData).forEach(key => {
|
|
let item = this.goodsData[key];
|
|
data.goods.push({
|
|
goods_id: item.goods_id,
|
|
sku_id: item.sku_id,
|
|
num: item.num
|
|
})
|
|
})
|
|
data.goods = JSON.stringify(data.goods);
|
|
|
|
this.$api.sendRequest({
|
|
url: this.orderData.order_id ? '/cashier/storeapi/pendorder/edit' :
|
|
'/cashier/storeapi/pendorder/add',
|
|
data: data,
|
|
success: res => {
|
|
if (res.code == 0) {
|
|
this.orderData.order_id = 0;
|
|
this.wholeOrderCancel();
|
|
this.$refs.order.orderData.page = 0;
|
|
this.$refs.order.getOrder();
|
|
} else {
|
|
this.$util.showToast({
|
|
title: res.message
|
|
})
|
|
}
|
|
}
|
|
})
|
|
} else if (this.orderNum) {
|
|
this.type = 'order';
|
|
} else {
|
|
this.$util.showToast({
|
|
title: '当前没有挂单'
|
|
})
|
|
}
|
|
},
|
|
/**
|
|
* 取单
|
|
* @param {Object} data
|
|
*/
|
|
takeorder(data) {
|
|
this.$refs.member.memberId = data.member_id;
|
|
if (data.member_id) {
|
|
this.$refs.member.getMemberInfo();
|
|
} else {
|
|
this.$store.commit('setMemberInfo', null);
|
|
}
|
|
|
|
let goodsData = {};
|
|
data.order_goods.forEach(item => {
|
|
goodsData['sku_' + item.sku_id] = item;
|
|
})
|
|
this.goodsData = goodsData;
|
|
this.orderData.order_id = data.order_id;
|
|
this.orderData.goods_list = [];
|
|
this.orderData.remark = data.remark;
|
|
this.calculation();
|
|
},
|
|
/**
|
|
* 整单取消
|
|
*/
|
|
wholeOrderCancel() {
|
|
if (Object.keys(this.goodsData).length) {
|
|
// 清除当前会员
|
|
this.$refs.member.memberId = 0;
|
|
this.$refs.member.memberCardData.page = 0;
|
|
this.$store.commit('setMemberInfo', null);
|
|
// 清除商品数据
|
|
this.goodsData = {};
|
|
this.calculation();
|
|
if (this.orderData.order_id) {
|
|
this.$refs.order.deleteOrder(this.orderData);
|
|
this.orderData.order_id = 0;
|
|
}
|
|
// 清除订单数据
|
|
this.orderData = {
|
|
goods_num: 0,
|
|
pay_money: 0,
|
|
goods_list: [],
|
|
remark: '',
|
|
create_time: this.$util.timeFormat(parseInt(new Date().getTime() / 1000))
|
|
}
|
|
this.outTradeNo = '';
|
|
this.orderId = 0;
|
|
} else {
|
|
this.$util.showToast({
|
|
title: '当前没有订单'
|
|
})
|
|
}
|
|
},
|
|
remarkConfirm() {
|
|
this.orderData.remark = this.remark;
|
|
this.$refs.remarkPopup.close();
|
|
},
|
|
remarkSeting() {
|
|
this.remark = this.orderData.remark;
|
|
this.$refs.remarkPopup.open();
|
|
},
|
|
/**
|
|
* 支付
|
|
*/
|
|
pay(type = '') {
|
|
if (!Object.keys(this.goodsData).length || this.isRepeat) return;
|
|
this.isRepeat = true;
|
|
|
|
if (this.outTradeNo) {
|
|
this.type = 'pay';
|
|
if (type) this.$refs.payment.type = type;
|
|
return;
|
|
}
|
|
|
|
let sku_array = [];
|
|
Object.keys(this.goodsData).forEach(key => {
|
|
let item = this.goodsData[key];
|
|
sku_array.push({
|
|
sku_id: item.sku_id,
|
|
num: item.num,
|
|
card_item_id: item.item_id ? item.item_id : 0
|
|
})
|
|
})
|
|
let data = {
|
|
sku_array: JSON.stringify(sku_array),
|
|
remark: this.orderData.remark,
|
|
create_time: this.orderData.create_time
|
|
};
|
|
if (this.memberInfo) data.member_id = this.memberInfo.member_id;
|
|
|
|
this.$api.sendRequest({
|
|
url: '/cashier/storeapi/cashierordercreate/create',
|
|
data: data,
|
|
success: res => {
|
|
this.isRepeat = false;
|
|
if (res.code == 0) {
|
|
this.outTradeNo = res.data.out_trade_no;
|
|
this.orderId = res.data.order_id;
|
|
this.type = 'pay';
|
|
if (type) this.$refs.payment.type = type;
|
|
} else {
|
|
this.$util.showToast({
|
|
title: res.message,
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
cancelPayment() {
|
|
this.$api.sendRequest({
|
|
url: '/cashier/storeapi/cashierorder/deleteorder',
|
|
data: {
|
|
order_id: this.orderId
|
|
},
|
|
success: res => {
|
|
if (res.code == 0) {
|
|
this.outTradeNo = '';
|
|
this.orderId = 0;
|
|
this.type = 'goods';
|
|
} else {
|
|
this.$util.showToast({
|
|
title: res.message,
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
paySuccess() {
|
|
this.type = 'goods';
|
|
this.wholeOrderCancel();
|
|
this.searchText = '';
|
|
}
|
|
|
|
},
|
|
computed: {
|
|
orderNum() {
|
|
return this.$store.state.pendOrderNum;
|
|
}
|
|
},
|
|
watch: {
|
|
type: function(nVal) {
|
|
if (nVal != 'member') {
|
|
this.$refs.member.search = false;
|
|
}
|
|
},
|
|
orderNum: function(nVal) {
|
|
if (nVal == 0) this.type = 'goods';
|
|
},
|
|
memberInfo: function(nVal, oVal) {
|
|
if ((nVal && oVal && nVal.member_id != oVal.member_id) || !nVal) {
|
|
this.goodsData = {};
|
|
}
|
|
this.calculation();
|
|
}
|
|
}
|
|
}
|