|
@@ -2,6 +2,7 @@ import { getProductDataApi,getStockInItem } from "@/api/product";
|
|
|
import { mapGetters, mapActions } from "vuex";
|
|
import { mapGetters, mapActions } from "vuex";
|
|
|
import { copyObject } from "@/utils/util"
|
|
import { copyObject } from "@/utils/util"
|
|
|
import { allProduct } from '@/api/product'
|
|
import { allProduct } from '@/api/product'
|
|
|
|
|
+import { getLimitBuyInfo } from "@/api/purchase"
|
|
|
export default {
|
|
export default {
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
@@ -37,14 +38,20 @@ export default {
|
|
|
this.selectJobType = selectJobType;
|
|
this.selectJobType = selectJobType;
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- onUnload() {},
|
|
|
|
|
computed: {
|
|
computed: {
|
|
|
- ...mapGetters(["getSelectInfo"]),
|
|
|
|
|
|
|
+ ...mapGetters(["getSelectInfo", "getLimitBuyInfo"]),
|
|
|
//当前页面选中的商品列表
|
|
//当前页面选中的商品列表
|
|
|
selectList() {
|
|
selectList() {
|
|
|
let selectInfo = this.getSelectInfo;
|
|
let selectInfo = this.getSelectInfo;
|
|
|
return selectInfo[this.selectJobType+'_'+this.selectJobId] || []
|
|
return selectInfo[this.selectJobType+'_'+this.selectJobId] || []
|
|
|
},
|
|
},
|
|
|
|
|
+ limitBuyList() {
|
|
|
|
|
+ if (!this.option || this.option.limitBuy != 1) {
|
|
|
|
|
+ return []
|
|
|
|
|
+ }
|
|
|
|
|
+ let limitBuyInfo = this.getLimitBuyInfo || {};
|
|
|
|
|
+ return limitBuyInfo[this.selectJobType+'_'+this.selectJobId] || []
|
|
|
|
|
+ },
|
|
|
scrollClassId() {
|
|
scrollClassId() {
|
|
|
const curClass = this.productInfoList[this.classIndex];
|
|
const curClass = this.productInfoList[this.classIndex];
|
|
|
if (curClass) {
|
|
if (curClass) {
|
|
@@ -54,26 +61,10 @@ export default {
|
|
|
},
|
|
},
|
|
|
allPrice() {
|
|
allPrice() {
|
|
|
let price = 0;
|
|
let price = 0;
|
|
|
|
|
+ const isQuickBill = this.isTrueValue(this.isQuickBill)
|
|
|
if (this.selectList) {
|
|
if (this.selectList) {
|
|
|
for (const item of this.selectList) {
|
|
for (const item of this.selectList) {
|
|
|
- const itemInfo = this.getSelectItemById(item.id, item.classId);
|
|
|
|
|
- if (itemInfo && !this.$util.isEmpty(itemInfo.bigPrice) && !this.$util.isEmpty(itemInfo.smallPrice)) {
|
|
|
|
|
- if(item.userPrice>0){
|
|
|
|
|
- if(Number(item.bigCount) > 0){
|
|
|
|
|
- price += Number(item.bigCount) * Number(itemInfo.userPrice);
|
|
|
|
|
- }
|
|
|
|
|
- if(Number(item.smallCount) > 0){
|
|
|
|
|
- price += Number(item.smallCount) * Number(itemInfo.userPrice);
|
|
|
|
|
- }
|
|
|
|
|
- }else{
|
|
|
|
|
- if(Number(item.bigCount) > 0){
|
|
|
|
|
- price += Number(item.bigCount) * Number(itemInfo.bigPrice);
|
|
|
|
|
- }
|
|
|
|
|
- if(Number(item.smallCount) > 0){
|
|
|
|
|
- price += Number(item.smallCount) * Number(itemInfo.smallPrice);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ price += this.getSelectItemTotalPrice(item, isQuickBill)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return Math.round(price * 100) / 100;
|
|
return Math.round(price * 100) / 100;
|
|
@@ -128,12 +119,9 @@ export default {
|
|
|
}
|
|
}
|
|
|
return has;
|
|
return has;
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- onShow(){
|
|
|
|
|
-
|
|
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
- ...mapActions(["setSelectInfo", "reSetSelectInfo"]),
|
|
|
|
|
|
|
+ ...mapActions(["setSelectInfo", "reSetSelectInfo", "setLimitBuyInfo", "reSetLimitBuyInfo"]),
|
|
|
init(){
|
|
init(){
|
|
|
if (this.autoLoad) {
|
|
if (this.autoLoad) {
|
|
|
this.initData();
|
|
this.initData();
|
|
@@ -141,7 +129,7 @@ export default {
|
|
|
},
|
|
},
|
|
|
//放到仓库
|
|
//放到仓库
|
|
|
pushToSave(selectData){
|
|
pushToSave(selectData){
|
|
|
- this.setSelectInfo({ selectJobType: this.selectJobType, info: selectData,selectJobId:this.selectJobId })
|
|
|
|
|
|
|
+ this.setSelectInfo({ selectJobType: this.selectJobType, info: selectData, selectJobId:this.selectJobId })
|
|
|
uni.setStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId, selectData)
|
|
uni.setStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId, selectData)
|
|
|
},
|
|
},
|
|
|
//询问是否删除缓存
|
|
//询问是否删除缓存
|
|
@@ -158,6 +146,7 @@ export default {
|
|
|
|
|
|
|
|
uni.removeStorageSync('selectList_'+that.selectJobType+'_target_'+that.selectJobId)
|
|
uni.removeStorageSync('selectList_'+that.selectJobType+'_target_'+that.selectJobId)
|
|
|
that.reSetSelectInfo({selectJobType:that.selectJobType,selectJobId:that.selectJobId})
|
|
that.reSetSelectInfo({selectJobType:that.selectJobType,selectJobId:that.selectJobId})
|
|
|
|
|
+ that.reSetLimitBuyInfo({selectJobType:that.selectJobType,selectJobId:that.selectJobId})
|
|
|
|
|
|
|
|
//删除多颜色
|
|
//删除多颜色
|
|
|
//console.log(that.selectJobType+that.selectJobId)
|
|
//console.log(that.selectJobType+that.selectJobId)
|
|
@@ -192,7 +181,6 @@ export default {
|
|
|
let currentItemList = data.itemList ? data.itemList : []
|
|
let currentItemList = data.itemList ? data.itemList : []
|
|
|
|
|
|
|
|
this.globalItemList = currentItemList
|
|
this.globalItemList = currentItemList
|
|
|
-
|
|
|
|
|
this.productInfoList = currentClassItem
|
|
this.productInfoList = currentClassItem
|
|
|
|
|
|
|
|
let currentInfo = uni.getStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId)
|
|
let currentInfo = uni.getStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId)
|
|
@@ -205,7 +193,6 @@ export default {
|
|
|
},
|
|
},
|
|
|
//滚动或切换分类 获取更多数据
|
|
//滚动或切换分类 获取更多数据
|
|
|
scrollPushList(){
|
|
scrollPushList(){
|
|
|
-
|
|
|
|
|
//涉及记住花材的代码和流程,请全项目搜索关键词remember_item
|
|
//涉及记住花材的代码和流程,请全项目搜索关键词remember_item
|
|
|
//将已选的花材按classId_productId键名组合
|
|
//将已选的花材按classId_productId键名组合
|
|
|
let selectListData = []
|
|
let selectListData = []
|
|
@@ -379,12 +366,158 @@ export default {
|
|
|
price = Math.round(sum * 100) / 100;
|
|
price = Math.round(sum * 100) / 100;
|
|
|
return price;
|
|
return price;
|
|
|
},
|
|
},
|
|
|
|
|
+ toSafeNumber(value) {
|
|
|
|
|
+ const num = Number(value)
|
|
|
|
|
+ return isNaN(num) ? 0 : num
|
|
|
|
|
+ },
|
|
|
|
|
+ isTrueValue(value) {
|
|
|
|
|
+ return value === true || value === 1 || value === "1" || value === "true"
|
|
|
|
|
+ },
|
|
|
|
|
+ getLimitBuyItemById(id) {
|
|
|
|
|
+ if (!Array.isArray(this.limitBuyList)) {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.limitBuyList.find(item => String(item.id) === String(id)) || null
|
|
|
|
|
+ },
|
|
|
|
|
+ isLimitSpecialItem(item) {
|
|
|
|
|
+ const limitItem = this.getLimitBuyItemById(item.id)
|
|
|
|
|
+ return !!(limitItem && this.isTrueValue(limitItem.isLimit) && this.isTrueValue(limitItem.specialPrice))
|
|
|
|
|
+ },
|
|
|
|
|
+ getLimitBuyPriceInfo(item, isQuickBill) {
|
|
|
|
|
+ const isQuickBillValue = this.isTrueValue(isQuickBill)
|
|
|
|
|
+ const itemInfo = this.getSelectItemById(item.id, item.classId)
|
|
|
|
|
+ const limitItem = this.getLimitBuyItemById(item.id)
|
|
|
|
|
+
|
|
|
|
|
+ if (isQuickBillValue) { //快捷开单
|
|
|
|
|
+ const result = {
|
|
|
|
|
+ total: 0,
|
|
|
|
|
+ unitPrice: 0,
|
|
|
|
|
+ specialPrice: 0,
|
|
|
|
|
+ originalPrice: 0
|
|
|
|
|
+ }
|
|
|
|
|
+ const price = Number(itemInfo.price) //后端处理好了是零售价还是批发价
|
|
|
|
|
+
|
|
|
|
|
+ result.unitPrice = price
|
|
|
|
|
+ result.total = itemInfo.bigCount * price + (itemInfo.smallCount/itemInfo.ratio * price)
|
|
|
|
|
+ return result
|
|
|
|
|
+ } else { //非快捷开单
|
|
|
|
|
+ const specialPrice = Number(itemInfo.price)//对应优惠价格
|
|
|
|
|
+ const originalPrice = Number(itemInfo.originPrice) //原始价
|
|
|
|
|
+ const result = {
|
|
|
|
|
+ total: 0,
|
|
|
|
|
+ unitPrice: 0,
|
|
|
|
|
+ specialPrice: specialPrice,
|
|
|
|
|
+ originalPrice: originalPrice,
|
|
|
|
|
+ exceedNum: 0,
|
|
|
|
|
+ limitBuy: 0,
|
|
|
|
|
+ hasBuyNum: 0,
|
|
|
|
|
+ currentBuyNum: 0,
|
|
|
|
|
+ specialNum: 0,
|
|
|
|
|
+ originalNum: 0,
|
|
|
|
|
+ isLimitSpecial: false,
|
|
|
|
|
+ reachLimitBuyNum: false
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!limitItem || !this.isLimitSpecialItem(item)) {
|
|
|
|
|
+ result.total = itemInfo.bigCount * specialPrice + (itemInfo.smallCount/itemInfo.ratio * specialPrice)
|
|
|
|
|
+ return result
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const exceedNum = this.toSafeNumber(limitItem.exceedNum) + this.toSafeNumber(limitItem.currentBuyNum) //超出限价的数量
|
|
|
|
|
+ result.exceedNum = exceedNum
|
|
|
|
|
+ result.limitBuy = this.toSafeNumber(limitItem.limitBuy)
|
|
|
|
|
+ result.hasBuyNum = this.toSafeNumber(limitItem.hasBuyNum)
|
|
|
|
|
+ result.currentBuyNum = this.toSafeNumber(limitItem.currentBuyNum)
|
|
|
|
|
+ result.isLimitSpecial = true
|
|
|
|
|
+ result.reachLimitBuyNum = this.isTrueValue(limitItem.reachLimitBuyNum)
|
|
|
|
|
+
|
|
|
|
|
+ if (exceedNum <= 0) {
|
|
|
|
|
+ result.specialNum = result.currentBuyNum
|
|
|
|
|
+ result.originalNum = 0
|
|
|
|
|
+ result.total = result.currentBuyNum * specialPrice
|
|
|
|
|
+ } else if (exceedNum > 0 && result.hasBuyNum > result.limitBuy) {
|
|
|
|
|
+ result.specialNum = 0
|
|
|
|
|
+ result.originalNum = result.currentBuyNum
|
|
|
|
|
+ result.total = result.currentBuyNum * originalPrice
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result.specialNum = result.currentBuyNum - exceedNum
|
|
|
|
|
+ result.originalNum = exceedNum
|
|
|
|
|
+ result.total = result.specialNum * specialPrice + result.originalNum * originalPrice
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ result.total = Math.round(result.total * 100) / 100
|
|
|
|
|
+ const priceCount = Number(itemInfo.smallCount) > 0 ? Number(itemInfo.smallCount) : Number(itemInfo.bigCount)
|
|
|
|
|
+ result.unitPrice = priceCount > 0 ? Math.round((result.total / priceCount) * 100) / 100 : specialPrice
|
|
|
|
|
+
|
|
|
|
|
+ return result
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ getSelectItemTotalPrice(item, isQuickBill) {
|
|
|
|
|
+ return this.getLimitBuyPriceInfo(item, isQuickBill).total
|
|
|
|
|
+ },
|
|
|
|
|
+ getSubmitItemPrice(item, isQuickBill) {
|
|
|
|
|
+ const isQuickBillValue = this.isTrueValue(isQuickBill)
|
|
|
|
|
+ const priceInfo = this.getLimitBuyPriceInfo(item, isQuickBill)
|
|
|
|
|
+ if (!isQuickBillValue) {
|
|
|
|
|
+ return priceInfo.unitPrice
|
|
|
|
|
+ }
|
|
|
|
|
+ return item.userPrice
|
|
|
|
|
+ },
|
|
|
|
|
+ getLimitBuyPriceTip(item, isQuickBill) {
|
|
|
|
|
+ if (this.isTrueValue(isQuickBill)) {
|
|
|
|
|
+ return ''
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const priceInfo = this.getLimitBuyPriceInfo(item, isQuickBill)
|
|
|
|
|
+ if (!priceInfo.isLimitSpecial || !priceInfo.reachLimitBuyNum) {
|
|
|
|
|
+ return ''
|
|
|
|
|
+ }
|
|
|
|
|
+ const unitName = item.bigUnit || '份'
|
|
|
|
|
+ const limitBuy = parseFloat(priceInfo.limitBuy)
|
|
|
|
|
+ const originalNum = parseFloat(priceInfo.originalNum)
|
|
|
|
|
+ const specialNum = parseFloat(priceInfo.specialNum)
|
|
|
|
|
+ if (priceInfo.specialNum <= 0) {
|
|
|
|
|
+ return `限购 ${limitBuy}${unitName},已超出,按原价计算`
|
|
|
|
|
+ }
|
|
|
|
|
+ return `限购${limitBuy}${unitName},${specialNum}${unitName}按特价,超出${originalNum}${unitName}按原价`
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ refreshLimitBuyInfoIfNeeded() {
|
|
|
|
|
+ if (!Array.isArray(this.limitBuyList) || this.limitBuyList.length <= 0) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ let curPage = getCurrentPages()
|
|
|
|
|
+ let route = curPage && curPage.length > 0 ? curPage[curPage.length - 1].route : ''
|
|
|
|
|
+ if (route != 'admin/billing/affirm' || this.$util.isEmpty(this.option.customId)) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ const limitBuyList = this.selectList
|
|
|
|
|
+ .filter(item => Number(item.limitBuy) > 0)
|
|
|
|
|
+ .map(item => {
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: item.id,
|
|
|
|
|
+ bigCount: item.bigCount,
|
|
|
|
|
+ smallCount: item.smallCount
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ if (limitBuyList.length <= 0) {
|
|
|
|
|
+ this.reSetLimitBuyInfo({selectJobType:this.selectJobType,selectJobId:this.selectJobId})
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ getLimitBuyInfo({ customId: this.option.customId, list: limitBuyList }).then(res => {
|
|
|
|
|
+ const limitBuyInfo = Array.isArray(res.data) ? res.data : []
|
|
|
|
|
+ this.setLimitBuyInfo({ selectJobType: this.selectJobType, info: limitBuyInfo, selectJobId: this.selectJobId })
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
//通过id获取当前选中的商品信息
|
|
//通过id获取当前选中的商品信息
|
|
|
getSelectItemById(id, classId) {
|
|
getSelectItemById(id, classId) {
|
|
|
let info = { bigCount: null, smallCount: null, autoPrice: null, itemPrice: null }
|
|
let info = { bigCount: null, smallCount: null, autoPrice: null, itemPrice: null }
|
|
|
const item = this.selectList && this.selectList.find(ele => { return ele.id == id && ele.classId == classId })
|
|
const item = this.selectList && this.selectList.find(ele => { return ele.id == id && ele.classId == classId })
|
|
|
if (item) {
|
|
if (item) {
|
|
|
- info = { ...item, bigCount: Number(item.bigCount), smallCount: Number(item.smallCount), autoPrice: Number(item.autoPrice), itemPrice: Number(item.itemPrice)}
|
|
|
|
|
|
|
+ info = { ...item,
|
|
|
|
|
+ bigCount: Number(item.bigCount),
|
|
|
|
|
+ smallCount: Number(item.smallCount),
|
|
|
|
|
+ autoPrice: Number(item.autoPrice),
|
|
|
|
|
+ itemPrice: Number(item.itemPrice)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return info;
|
|
return info;
|
|
|
},
|
|
},
|
|
@@ -412,7 +545,6 @@ export default {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const list = this.selectList
|
|
const list = this.selectList
|
|
|
-
|
|
|
|
|
let index = list.findIndex(element => element.id == item.id)
|
|
let index = list.findIndex(element => element.id == item.id)
|
|
|
|
|
|
|
|
//扫码数量累加
|
|
//扫码数量累加
|
|
@@ -466,10 +598,9 @@ export default {
|
|
|
|
|
|
|
|
//数据放到仓库永久存放
|
|
//数据放到仓库永久存放
|
|
|
this.pushToSave(list)
|
|
this.pushToSave(list)
|
|
|
|
|
+ this.refreshLimitBuyInfoIfNeeded()
|
|
|
|
|
|
|
|
this.itemNumPriceRefresh()
|
|
this.itemNumPriceRefresh()
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
},
|
|
},
|
|
|
delSelectedItem(product){
|
|
delSelectedItem(product){
|
|
|
let item = copyObject(product)
|
|
let item = copyObject(product)
|
|
@@ -751,4 +882,4 @@ export default {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|