|
|
@@ -11,6 +11,7 @@ export default {
|
|
|
currentJobId:0,//业务类型对应的主体ID等
|
|
|
currentBackJobId:1,
|
|
|
globalHasHand:0,
|
|
|
+ globalHandOrderList:[],
|
|
|
isCut:false,
|
|
|
productInfoList: [], //商品信息
|
|
|
classIndex: 0, //当前商品类别下标
|
|
|
@@ -46,6 +47,9 @@ export default {
|
|
|
let selectInfo = this.getSelectInfo;
|
|
|
return selectInfo[this.currentJobType+'_'+this.currentJobId] || []
|
|
|
},
|
|
|
+ handOrderCount() {
|
|
|
+ return Array.isArray(this.globalHandOrderList) ? this.globalHandOrderList.length : 0
|
|
|
+ },
|
|
|
allPrice() {
|
|
|
let price = 0;
|
|
|
if(!this.$util.isEmpty(this.selectList)){
|
|
|
@@ -96,61 +100,184 @@ export default {
|
|
|
this.setSelectInfo({ currentJobType: this.currentJobType, info: selectData,currentJobId:this.currentJobId })
|
|
|
uni.setStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentJobId, selectData)
|
|
|
},
|
|
|
+ getHandOrderStorageKey(){
|
|
|
+ return 'handOrderList_'+this.currentJobType
|
|
|
+ },
|
|
|
+ cloneHandOrderData(data){
|
|
|
+ if(this.$util.isEmpty(data)){
|
|
|
+ return Array.isArray(data) ? [] : {}
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ return JSON.parse(JSON.stringify(data))
|
|
|
+ }catch(e){
|
|
|
+ return data
|
|
|
+ }
|
|
|
+ },
|
|
|
+ createHandOrderId(){
|
|
|
+ return Date.now()+'_'+Math.floor(Math.random()*100000)
|
|
|
+ },
|
|
|
+ normalizeHandOrderList(list){
|
|
|
+ if(!Array.isArray(list)){
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ return list.filter(order => {
|
|
|
+ return order && !this.$util.isEmpty(order.selectList)
|
|
|
+ }).map(order => {
|
|
|
+ return {
|
|
|
+ ...order,
|
|
|
+ id: order.id || this.createHandOrderId(),
|
|
|
+ createTime: order.createTime || Date.now(),
|
|
|
+ selectList: Array.isArray(order.selectList) ? order.selectList : [],
|
|
|
+ xj: Array.isArray(order.xj) ? order.xj : []
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ refreshHandOrderList(){
|
|
|
+ let list = this.normalizeHandOrderList(uni.getStorageSync(this.getHandOrderStorageKey()))
|
|
|
+ let legacyInfo = uni.getStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentBackJobId)
|
|
|
+ if(!this.$util.isEmpty(legacyInfo)){
|
|
|
+ let legacyXj = uni.getStorageSync("xj_hand_"+this.currentBackJobId)
|
|
|
+ list.unshift({
|
|
|
+ id: this.createHandOrderId(),
|
|
|
+ createTime: Date.now(),
|
|
|
+ selectList: this.cloneHandOrderData(legacyInfo),
|
|
|
+ xj: this.$util.isEmpty(legacyXj) ? [] : this.cloneHandOrderData(legacyXj),
|
|
|
+ customId: this.customId || 0,
|
|
|
+ customName: this.customName || ''
|
|
|
+ })
|
|
|
+ uni.removeStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentBackJobId)
|
|
|
+ uni.removeStorageSync("xj_hand_"+this.currentBackJobId)
|
|
|
+ }
|
|
|
+ return this.saveHandOrderList(list)
|
|
|
+ },
|
|
|
+ saveHandOrderList(list){
|
|
|
+ let saveList = this.normalizeHandOrderList(list)
|
|
|
+ uni.setStorageSync(this.getHandOrderStorageKey(), saveList)
|
|
|
+ this.globalHandOrderList = saveList
|
|
|
+ this.globalHasHand = saveList.length > 0 ? 1 : 0
|
|
|
+ return saveList
|
|
|
+ },
|
|
|
+ getHandOrderTotalNum(order){
|
|
|
+ if(!order || this.$util.isEmpty(order.selectList)){
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ return order.selectList.reduce((total,item) => {
|
|
|
+ return Number(total)+Number(item.currentNum || 0)
|
|
|
+ },0)
|
|
|
+ },
|
|
|
+ getHandOrderTotalPrice(order){
|
|
|
+ if(!order || this.$util.isEmpty(order.selectList)){
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ let price = order.selectList.reduce((total,item) => {
|
|
|
+ return Number(total)+Number(item.currentNum || 0)*Number(item.unitPrice || 0)
|
|
|
+ },0)
|
|
|
+ return parseFloat(price.toFixed(2))
|
|
|
+ },
|
|
|
+ formatHandOrderTime(order){
|
|
|
+ let time = order && order.createTime ? Number(order.createTime) : Date.now()
|
|
|
+ if(isNaN(time)){
|
|
|
+ time = Date.now()
|
|
|
+ }
|
|
|
+ let date = new Date(time)
|
|
|
+ let pad = num => Number(num) < 10 ? '0'+Number(num) : String(num)
|
|
|
+ return pad(date.getMonth()+1)+'-'+pad(date.getDate())+' '+pad(date.getHours())+':'+pad(date.getMinutes())
|
|
|
+ },
|
|
|
+ getHandOrderTitle(order,index){
|
|
|
+ let customName = order.customName || '快捷开单'
|
|
|
+ let itemCount = order.selectList ? order.selectList.length : 0
|
|
|
+ return (index+1)+'. '+customName+' '+itemCount+'项 ¥'+this.getHandOrderTotalPrice(order)
|
|
|
+ },
|
|
|
handOrder(){
|
|
|
- let that = this
|
|
|
this.$util.hitVoice()
|
|
|
- let has = uni.getStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentBackJobId)
|
|
|
- if(!this.$util.isEmpty(has)){
|
|
|
- this.$msg('已挂了一单')
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
let currentInfo = uni.getStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentJobId)
|
|
|
if(this.$util.isEmpty(currentInfo)){
|
|
|
this.$msg('没有花材要挂单')
|
|
|
return false
|
|
|
}
|
|
|
- uni.setStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentBackJobId, currentInfo)
|
|
|
-
|
|
|
- //多颜色也要挂单
|
|
|
+ let list = this.refreshHandOrderList()
|
|
|
+ let custom = this.custom ? this.cloneHandOrderData(this.custom) : {}
|
|
|
let xjInfo = uni.getStorageSync("xj")
|
|
|
- if (!this.$util.isEmpty(xjInfo)) {
|
|
|
- uni.setStorageSync("xj_hand_"+this.currentBackJobId, xjInfo)
|
|
|
- uni.removeStorageSync("xj")
|
|
|
- }
|
|
|
-
|
|
|
- uni.removeStorageSync('selectList_'+that.currentJobType+'_target_'+that.currentJobId)
|
|
|
- that.reSetSelectInfo({currentJobType:that.currentJobType,currentJobId:that.currentJobId})
|
|
|
-
|
|
|
- this.globalHasHand = 1
|
|
|
+ list.unshift({
|
|
|
+ id: this.createHandOrderId(),
|
|
|
+ createTime: Date.now(),
|
|
|
+ selectList: this.cloneHandOrderData(currentInfo),
|
|
|
+ xj: this.$util.isEmpty(xjInfo) ? [] : this.cloneHandOrderData(xjInfo),
|
|
|
+ customId: this.customId || 0,
|
|
|
+ customName: this.customName || custom.name || '',
|
|
|
+ custom
|
|
|
+ })
|
|
|
+ this.saveHandOrderList(list)
|
|
|
+ this.removeFromSaveDirect()
|
|
|
+ this.$msg('已挂单')
|
|
|
+ return true
|
|
|
},
|
|
|
getHandOrder(){
|
|
|
- let that = this
|
|
|
this.$util.hitVoice()
|
|
|
- let currentInfo = uni.getStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentBackJobId)
|
|
|
- if(this.$util.isEmpty(currentInfo)){
|
|
|
+ let list = this.refreshHandOrderList()
|
|
|
+ if(this.$util.isEmpty(list)){
|
|
|
this.$msg('没有挂单')
|
|
|
return false
|
|
|
}
|
|
|
- uni.removeStorageSync('selectList_'+that.currentJobType+'_target_'+that.currentJobId)
|
|
|
- that.reSetSelectInfo({currentJobType:that.currentJobType,currentJobId:that.currentJobId})
|
|
|
-
|
|
|
- uni.setStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentJobId, currentInfo)
|
|
|
- if(!this.$util.isEmpty(currentInfo)){
|
|
|
- this.setSelectInfo({ currentJobType: this.currentJobType, info: currentInfo,currentJobId:this.currentJobId })
|
|
|
+ if(list.length == 1){
|
|
|
+ return this.takeHandOrder(list[0].id)
|
|
|
}
|
|
|
-
|
|
|
- //清除挂单
|
|
|
- uni.removeStorageSync('selectList_'+that.currentJobType+'_target_'+that.currentBackJobId)
|
|
|
-
|
|
|
- //多颜色的处理
|
|
|
- let xjInfo = uni.getStorageSync("xj_hand_"+this.currentBackJobId)
|
|
|
- if (!this.$util.isEmpty(xjInfo)) {
|
|
|
- uni.setStorageSync("xj", xjInfo)
|
|
|
- uni.removeStorageSync("xj_hand_"+this.currentBackJobId)
|
|
|
+ uni.showActionSheet({
|
|
|
+ itemList: list.map((order,index) => this.getHandOrderTitle(order,index)),
|
|
|
+ success: res => {
|
|
|
+ let order = this.globalHandOrderList[res.tapIndex]
|
|
|
+ if(order){
|
|
|
+ this.takeHandOrder(order.id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return true
|
|
|
+ },
|
|
|
+ takeHandOrder(id){
|
|
|
+ let list = this.refreshHandOrderList()
|
|
|
+ let index = list.findIndex(order => String(order.id) === String(id))
|
|
|
+ if(index == -1){
|
|
|
+ this.$msg('挂单不存在')
|
|
|
+ return false
|
|
|
}
|
|
|
-
|
|
|
- this.globalHasHand = 0
|
|
|
+ let currentInfo = uni.getStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentJobId)
|
|
|
+ if(!this.$util.isEmpty(currentInfo) || !this.$util.isEmpty(this.selectList)){
|
|
|
+ this.$msg('请先挂单或清空当前花材')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ let order = list[index]
|
|
|
+ let currentInfoList = this.cloneHandOrderData(order.selectList)
|
|
|
+ uni.setStorageSync('selectList_'+this.currentJobType+'_target_'+this.currentJobId, currentInfoList)
|
|
|
+ this.setSelectInfo({ currentJobType: this.currentJobType, info: currentInfoList,currentJobId:this.currentJobId })
|
|
|
+ uni.removeStorageSync('xj')
|
|
|
+ if(!this.$util.isEmpty(order.xj)){
|
|
|
+ uni.setStorageSync("xj", this.cloneHandOrderData(order.xj))
|
|
|
+ }
|
|
|
+ if(order.customId !== undefined){
|
|
|
+ this.$emit('update:customId', Number(order.customId) || 0)
|
|
|
+ }
|
|
|
+ if(order.customName !== undefined){
|
|
|
+ this.$emit('update:customName', order.customName || '')
|
|
|
+ }
|
|
|
+ if(order.custom !== undefined){
|
|
|
+ this.$emit('update:custom', this.cloneHandOrderData(order.custom || {}))
|
|
|
+ }
|
|
|
+ list.splice(index,1)
|
|
|
+ this.saveHandOrderList(list)
|
|
|
+ this.$msg('已取单')
|
|
|
+ return true
|
|
|
+ },
|
|
|
+ deleteHandOrder(id){
|
|
|
+ let list = this.refreshHandOrderList()
|
|
|
+ let index = list.findIndex(order => String(order.id) === String(id))
|
|
|
+ if(index == -1){
|
|
|
+ this.$msg('挂单不存在')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ list.splice(index,1)
|
|
|
+ this.saveHandOrderList(list)
|
|
|
+ this.$msg('已删除')
|
|
|
+ return true
|
|
|
},
|
|
|
removeFromSave(){
|
|
|
let that = this
|
|
|
@@ -494,4 +621,4 @@ export default {
|
|
|
this.globalShowCatItem()
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|