shish 2 rokov pred
rodič
commit
e8a3875b13

+ 497 - 0
ghs/src/mixins/product2.js

@@ -0,0 +1,497 @@
+import { mapGetters, mapActions } from "vuex";
+import { copyObject } from "@/utils/util"
+export default {
+	data() {
+		return {
+			selectJobType: "bill",//业务类型,开单、采购、损耗、盘点
+			selectJobId:0,//业务类型对应的主体ID等
+			isCut:false,
+			productInfoList: [], //商品信息
+			globalClassIndex: 0, //当前商品类别下标
+			py: "", //拼音搜索条件
+			type: "", //库存预警时,固定为waring,其他情况不传或者传空
+			autoLoad: true, //自动获取商品信息
+			allFilterProductInfo:'',
+			top_list:'',
+			scroll_into_view:"",
+			timeFun:"",
+			kdType:'HIT',//点击和扫码开单,HIT SCAN
+			globalCheckStock:true,// 考虑库存,盘点不需要考虑库存
+			isAddModel:false,
+			isAddInputFocus:false,
+			customData: { bigCount: 0, smallCount: 0, userPrice: 0 },
+			globalItemList:[],
+			globalUnitType:0,
+			globalAllProduct:[],
+			calc:'add',
+			globalRequestType:'kd',
+			globalCustomId:0,
+			globalClassData:[],
+			globalClassId:0,
+			globalFinishGetItem:0,
+			globalPage:1,
+			globalPy:'',
+			globalItemData:[],
+			globalScrollTopPlace:0,
+			globalScrollTopOldPlace:0,
+			globalIsRequesting:false
+		};
+	},
+	onLoad(options) {
+		const { selectJobType } = options;
+		if (selectJobType) {
+			this.selectJobType = selectJobType;
+		}
+	},
+	onUnload() {},
+	computed: {
+		...mapGetters(["getSelectInfo"]),
+		selectList() {
+			let selectInfo = this.getSelectInfo;
+			return selectInfo[this.selectJobType+'_'+this.selectJobId] || []
+		},
+		scrollClassId() {
+			const curClass = this.productInfoList[this.globalClassIndex];
+			if (curClass) {
+				return `class_${curClass.classId}`;
+			}
+			return "";
+		},
+		allPrice() {
+			let price = 0;
+			if (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);	
+							}
+						}
+					}
+				}
+			}
+			return Math.round(price * 100) / 100;
+		},
+		allCount() {
+			let bigLength = 0;
+			let smallLength = 0;
+			let weight = 0
+			if (this.selectList) {
+				for (const item of this.selectList) {
+					bigLength += Number(item.bigCount)
+					smallLength += Number(item.smallCount)
+					let thisWeight = item.weight ? item.weight : 0
+					let currentWeight = Number(thisWeight)*Number(item.bigCount)
+					weight = Number(weight) + Number(currentWeight)
+				}
+				weight = weight.toFixed(2)
+				weight = parseFloat(weight)
+			}
+			return {bigLength:bigLength,smallLength:smallLength,weight:weight};
+		},
+		hasNoStock() {
+			let has = false;
+			if (this.selectList) {
+				for (const item of this.selectList) {
+					const {
+						bigCount,
+						smallCount,
+						bigNum,
+						smallNum,
+						ratio
+					} = item;
+					const ratioNum = Number(ratio);
+					if (
+						Number(bigCount) * ratioNum + Number(smallCount) >
+						Number(bigNum) * ratioNum + Number(smallNum)
+					) {
+						has = true;
+						break;
+					}
+				}
+			}
+			return has;
+		}
+	},
+	onShow(){
+
+	},
+	methods: {
+		...mapActions(["setSelectInfo", "reSetSelectInfo"]),
+		init(){
+			if (this.autoLoad) {
+				this.initData();
+			}
+		},
+		initData() {
+			let that = this
+			// getMenu().then(res=>{
+			// 	if(res.code == 1){
+			// 		that.globalClassData = res.data.class ? res.data.class : []
+			// 		if(that.globalClassData[0]){
+			// 			that.globalClassId = that.globalClassData[0].id
+			// 			//保存到仓库
+			// 			let currentInfo = uni.getStorageSync('selectList_'+that.selectJobType+'_target_'+that.selectJobId)
+			// 			if(!that.$util.isEmpty(currentInfo)){
+			// 				that.setSelectInfo({ selectJobType: that.selectJobType, info: currentInfo,selectJobId:that.selectJobId })
+			// 			}
+			// 			that.getGlobalProductList()
+			// 		}
+			// 	}
+			// })
+		},
+		reGetGlobalProductList(){
+			this.globalGoToTop()
+            this.globalPage = 1
+			this.globalFinishGetItem = 0
+			this.getGlobalProductList()
+		},
+        getGlobalProductList(){
+            if(this.globalFinishGetItem == 1){
+                return false
+            }
+            let that = this
+			// getItemList({classId:this.globalClassId,requestType:this.globalRequestType,page:this.globalPage,search:this.globalPy,customId:this.globalCustomId}).then(res=>{
+			// 	if(res.code == 1){
+			// 		that.globalItemData = that.globalPage == 1 ? res.data.list : that.globalItemData.concat(res.data.list)
+            //         if(res.data.moreData == 1){
+            //             that.globalPage++
+            //         }else{
+            //             that.globalFinishGetItem = 1
+            //         }
+			// 		that.globalIsRequesting = false
+			// 		that.globalRememberRefresh()
+			// 	}
+			// })
+        },
+		globalRememberRefresh(){
+			let that = this
+			if(that.$util.isEmpty(that.globalItemData)){
+				return false
+			}
+			let selectListData = []
+			if(!that.$util.isEmpty(that.selectList)){
+				that.selectList.forEach((i)=>{
+					selectListData[i.id] = i
+				})
+			}
+			//修改数据需要复制一份,否则不会生效
+			that.globalItemData = copyObject(that.globalItemData);
+			for (let i=0;i<that.globalItemData.length;i++){
+				let currentProduct = that.globalItemData[i]
+				let currentPId = currentProduct.id
+				let selectProduct = selectListData[currentPId] || []
+				if(!that.$util.isEmpty(selectProduct)){
+					that.globalItemData[i].bigCount = selectProduct.bigCount || 0
+					that.globalItemData[i].userPrice = selectProduct.userPrice || 0
+					that.globalItemData[i].smallCount = selectProduct.smallCount || 0
+				}else{
+					that.globalItemData[i].bigCount = 0
+					that.globalItemData[i].userPrice = 0
+					that.globalItemData[i].smallCount = 0
+				}
+			}
+		},
+		globalSwitchClass(cur,item) {
+			this.globalGoToTop()
+			this.globalClassIndex = cur
+            this.globalPage = 1
+			this.globalPy = ''
+			this.$refs.globalSearchRef.search = ''
+            this.globalClassId = item.id
+            this.globalFinishGetItem = 0
+            this.getGlobalProductList()
+		},
+		pushToSave(selectData){
+			this.setSelectInfo({ selectJobType: this.selectJobType, info: selectData,selectJobId:this.selectJobId })
+			uni.setStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId, selectData)
+		},
+		globalChangeClass(index,item){
+			this.$refs.globalClassImgRef.close()
+			this.globalSwitchClass(index,item)
+		},
+		removeFromSave(){
+			let that = this
+			that.$util.confirmModal({content:'确认清除花材?'},() => {
+				that.removeFromSaveDirect()
+				that.$msg('已清除')
+            })
+		},
+		removeFromSaveDirect(){
+			let that = this
+			//删除仓库
+			uni.removeStorageSync('selectList_'+that.selectJobType+'_target_'+that.selectJobId)
+			that.reSetSelectInfo({selectJobType:that.selectJobType,selectJobId:that.selectJobId})
+			//删除多颜色
+			//console.log(that.selectJobType+that.selectJobId)
+			if(that.selectJobType == 'bill'){
+				uni.removeStorageSync("xj"+that.selectJobId)
+			}
+			//删除显示
+			if(!this.$util.isEmpty(this.globalItemData)){
+				this.globalItemData.forEach((item,index,arr) =>{
+					arr[index].bigCount = 0;
+					arr[index].smallCount = 0;
+					arr[index].userPrice = 0;
+				})
+				this.$forceUpdate()
+			}
+		},
+        globalSearch(){
+			this.globalPage = 1
+            if(!this.$util.isEmpty(this.globalPy)){
+				this.globalGoToTop()
+                this.globalClassIndex = -1
+                this.globalFinishGetItem = 0
+                this.getGlobalProductList()
+            }
+        },
+		globalGoToTop(){
+			let that = this
+			this.globalScrollTopPlace = this.globalScrollTopOldPlace
+			this.$nextTick(()=>{
+				that.globalScrollTopPlace = 0
+			})
+		},
+		globalGetScroll(event){
+			this.globalScrollTopOldPlace = event.detail.scrollTop
+		},
+		globalScrollBottom(){
+			if(this.globalIsRequesting == true){
+				return false
+			}
+			this.globalIsRequesting = true
+			this.getGlobalProductList()
+        },
+		getSelectItemById(id, classId) {
+			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 })
+			if (item) {
+				info = { ...item, bigCount: Number(item.bigCount), smallCount: Number(item.smallCount), autoPrice: Number(item.autoPrice), itemPrice: Number(item.itemPrice)}
+			}
+			return info;
+		},
+		//添加删除和修改花材
+		//multiple 0一个一个加减 1弹框方式,多个加减
+		//calc 当multiple=0时,add表示加,sub表示减
+		replaceItemFn(product,multiple=0,calc='add',scan=0) {
+			let item = copyObject(product)
+			if(multiple == 0){
+				if(Number(item.smallCount)>0){
+					if(calc == 'add'){
+						item.smallCount++
+					}
+					if(calc == 'sub'){
+						item.smallCount--
+					}
+				}else{
+					if(calc == 'add'){
+						item.bigCount++
+					}
+					if(calc == 'sub'){
+						item.bigCount--
+					}					
+				}
+			}
+
+			const list = this.selectList
+
+			let index = list.findIndex(element => element.id == item.id)
+
+			//扫码数量累加
+			if(index != -1 && scan == 1){
+				item.bigCount = parseInt(Number(item.bigCount)+Number(list[index].bigCount))
+				item.smallCount = parseInt(Number(item.smallCount)+Number(list[index].smallCount))
+			}
+
+			//扫码会出现负数
+			if(Number(item.bigCount)<0 || Number(item.smallCount)<0){
+				return false
+			}
+
+			if(this.globalCheckStock){
+				let currentCount = Number(item.bigCount) * item.ratio + Number(item.smallCount)
+				currentCount = currentCount.toFixed(2)
+				let currentNum = Number(item.bigNum) * item.ratio + Number(item.smallNum)
+				currentNum = currentNum.toFixed(2)
+				console.log(currentCount+' '+currentNum)
+				if (Number(currentCount) > Number(currentNum)) {
+					console.log('库存不足。。。')
+					this.$util.noStockRemind()
+					this.$msg("库存不足哦")
+					return
+				}
+			}
+
+			if(index == -1){
+				if(this.$util.isEmpty(item.userPrice) || Number(item.userPrice) == 0){
+					item.userPrice = item.bigPrice
+				}
+				list.push(item)			
+			}else{
+				if(item.bigCount <= 0 && item.smallCount <= 0){
+					//删除花材
+					list.splice(index,1)
+				}else{
+					list[index].bigCount = item.bigCount
+					list[index].smallCount = item.smallCount
+					list[index].userPrice = item.userPrice
+				}
+			}
+			//点击要响声
+			if(this.kdType == 'HIT' && multiple ==0){
+				this.$util.hitRemind()
+			}
+			//扫码要响声
+			if(scan == 1){
+				this.$util.hitRemind()
+			}
+			//数据放到仓库
+			this.pushToSave(list)
+			this.globalRememberRefresh()
+		},
+		delSelectedItem(product){
+			let item = copyObject(product)
+			const list = this.selectList
+			let index = list.findIndex(element => element.id == item.id)
+			if(index != -1){
+				list.splice(index,1)
+			}
+		},
+		listenScanItem(){
+
+    	},
+		takeItem(code){
+			if(this.$util.isEmpty(code)){
+				return false
+			}
+			let current = null
+			let unitPrice = 0
+			let unitName = ''
+			//花材
+			current = this.globalAllProduct.find(function(val){
+				return Number(val.itemId) == Number(code)
+			})
+			if(current == undefined){
+				return false
+			}
+			if(this.$util.isEmpty(current)){
+				return false
+			}
+			unitName = current.bigUnit
+			unitPrice = current.bigPrice
+			let num = this.calc == 'add' ? 1 : -1
+			let params = {...current,unitName:unitName,userPrice:unitPrice,bigCount:num,smallCount:0}
+			this.replaceItemFn(params,1,'add',1)
+		},
+		//大小单位切换
+		switchGlobalUnitType(){
+			if(this.globalUnitType == 0){
+				this.globalUnitType = 1
+				this.customData.userPrice = parseFloat(this.customData.smallPrice)
+				this.customData.bigCount = null
+			}else{
+				this.globalUnitType = 0
+				this.customData.userPrice = parseFloat(this.customData.bigPrice)
+				this.customData.smallCount = null
+			}
+		},
+		//显示可以修改花材的弹框
+		showAddModelFn(info) {
+
+			if(info && info.variety == 1 && this.selectJobType == 'bill'){
+				let curPage = getCurrentPages();
+				let route = curPage[curPage.length - 1].route;
+				if(route == 'admin/billing/affirm'){
+					this.$msg('多颜色花材,请返回修改')
+					return false
+				}
+			}
+
+			if(info.bigNum <= 0 && info.smallNum <= 0){
+				if(this.globalCheckStock){
+					this.$util.noStockRemind()
+					this.$msg('库存不足哦..')
+					return false
+				}
+			}
+
+			//弹框时默认显示的单位
+			if(Number(info.smallCount)>0){
+				this.globalUnitType = 1
+			}else{
+				this.globalUnitType = 0
+			}
+
+			this.isAddModel = true;
+			this.customData = copyObject(info)
+			this.isAddInputFocus = false;
+			this.$nextTick(()=>{
+				this.customData.smallCount = this.customData.smallCount==0?null:this.customData.smallCount;
+				this.customData.bigCount = this.customData.bigCount==0?null:this.customData.bigCount;
+				if(this.selectJobType == 'bill'){
+					if(this.customData.userPrice == null || this.customData.userPrice == 0){
+						this.customData.userPrice =	parseFloat(this.customData.bigPrice)
+					}
+				}else{
+					this.customData.userPrice = this.customData.userPrice==0 ? null : parseFloat(this.customData.userPrice)
+				}
+				this.isAddInputFocus = true;
+			})
+		},
+		confirmAddItemModel(val) {
+			if (val.index === 0) {
+				this.addItemModelHidden();
+				return false
+			}
+
+			//二个都不是数值
+			if(/(^[1-9]\d*$)/.test(this.customData.bigCount) == false && /(^[1-9]\d*$)/.test(this.customData.smallCount) == false){
+				uni.showToast({title:"请填写数值",icon:"none"})
+				return;
+			}
+
+			if(/(^[1-9]\d*$)/.test(this.customData.bigCount)){
+				if(this.customData.bigCount<=0){
+					uni.showToast({title:"数量要大于0",icon:"none"})
+					return;
+				}
+			}
+
+			if(/(^[1-9]\d*$)/.test(this.customData.smallCount)){
+				if(this.customData.smallCount<=0){
+					uni.showToast({title:"数量要大于0",icon:"none"})
+					return;
+				}
+			}
+			//只有开单和采购需要使用价格
+			if(this.selectJobType == 'bill' || this.selectJobType == 'purchase'){
+				if(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(this.customData.userPrice) == false){
+					uni.showToast({title:"金额错误",icon:"none"})
+					return;
+				}
+				if(this.customData.userPrice <=0){
+					uni.showToast({title:"金额要大于0",icon:"none"})
+					return;
+				}
+			}
+			this.replaceItemFn(this.customData,1)
+			this.addItemModelHidden()			
+		},
+		addItemModelHidden() {
+			this.isAddModel = false;
+			this.customData = {};
+		}
+	}
+}

+ 2 - 1
ghs/src/store/getters.js

@@ -12,6 +12,7 @@ const getters = {
 	level: state => state.config.level,
 	category: state => state.config.category,
 	festival: state => state.config.festival,
-	usage: state => state.config.usage
+	usage: state => state.config.usage,
+	getSelectInfo: state => state.product.selectInfo
 };
 export default getters;

+ 2 - 0
ghs/src/store/index.js

@@ -5,6 +5,7 @@ import process from './modules/process';
 import menu from './modules/menu';
 import user from './modules/user';
 import config from './modules/config';
+import product from './modules/product';
 
 Vue.use(Vuex);
 
@@ -14,6 +15,7 @@ const store = new Vuex.Store({
 		menu,
 		user,
 		config,
+		product,
 		main: {
 			actions: {
 				appLoad() {

+ 21 - 0
ghs/src/store/modules/product.js

@@ -0,0 +1,21 @@
+import store from '@/utils/store';
+export default {
+	state: {
+		selectInfo: store.get('selectInfo') || {}
+	},
+	actions: {
+		//保存已选花材列表
+		setSelectInfo({ commit }, { selectJobType, info,selectJobId }) {
+			commit("SET_SELECTED_ITEM", { selectJobType, info,selectJobId });
+		},
+		//清空已选花材信息
+		reSetSelectInfo({ commit }, {selectJobType,selectJobId}) {
+			commit("SET_SELECTED_ITEM", { selectJobType, info: [],selectJobId });
+		}
+	},
+	mutations: {
+		SET_SELECTED_ITEM(state, { selectJobType, info,selectJobId }) {
+			state.selectInfo = { ...state.selectInfo, [selectJobType+'_'+selectJobId]: info }
+		}
+	}
+};

+ 1 - 1
ghs/src/views/item/list.vue

@@ -629,7 +629,7 @@ export default {
               label: '名称',
               align: 'center',
 			  fixed: 'left',
-              'min-width': 100
+              'min-width': 140
             },
 			{
 				prop: 'cover',

+ 2 - 2
ghs/src/views/member/list.vue

@@ -189,13 +189,13 @@ export default {
 							prop: 'growth',
 							label: '成长值',
 							align: 'center',
-							width: 130
+							width: 100
 						},
 						{
 							prop: 'visitTime',
 							label: '最近访问',
 							align: 'center',
-							width: 130
+							width: 160
 						}
 					],
 					// 操作列