| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- 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();
- }
- }
- }
|