|
|
@@ -0,0 +1,456 @@
|
|
|
+import { getProductDataApi } from "@/api/product/index";
|
|
|
+import { mapGetters, mapActions } from "vuex";
|
|
|
+import { copyObject } from "@/utils/util";
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ selectJobType: "bill",//业务类型,开单、采购、报损、盘点
|
|
|
+ selectJobId:0,//业务类型对应的主体ID等
|
|
|
+ isCut:false,
|
|
|
+ productInfoList: [], //商品信息
|
|
|
+ classIndex: 0, //当前商品类别下标
|
|
|
+ py: "", //拼音搜索条件
|
|
|
+ type: "", //库存预警时,固定为waring,其他情况不传或者传空
|
|
|
+ autoLoad: true, //自动获取商品信息
|
|
|
+ allFilterProductInfo:'',
|
|
|
+ globalClassItemList:'',
|
|
|
+ top_list:'',
|
|
|
+ //id动态切换
|
|
|
+ scroll_into_view:"",
|
|
|
+ timeFun:"",
|
|
|
+ kdType:'HIT',//点击和扫码开单,HIT SCAN
|
|
|
+ checkStock:true,// 考虑库存,盘点不需要考虑库存
|
|
|
+ isAddModel:false,
|
|
|
+ isAddInputFocus:false,
|
|
|
+ customData: { bigCount: 0, smallCount: 0, userPrice: 0 },
|
|
|
+ globalItemList:[],
|
|
|
+ //当前页面默认使用的单位 0大单位 1小单位
|
|
|
+ globalUnitType:0
|
|
|
+ };
|
|
|
+ },
|
|
|
+ onLoad(options) {
|
|
|
+ const { selectJobType } = options;
|
|
|
+ if (selectJobType) {
|
|
|
+ this.selectJobType = selectJobType;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onUnload() {},
|
|
|
+ computed: {
|
|
|
+ ...mapGetters(["getSelectInfo"]),
|
|
|
+ //当前页面选中的商品列表
|
|
|
+ selectList() {
|
|
|
+ let selectInfo = this.getSelectInfo;
|
|
|
+ let currentList = selectInfo[this.selectJobType+'_'+this.selectJobId] || []
|
|
|
+
|
|
|
+ let has = [];
|
|
|
+ if (!this.$util.isEmpty(currentList)){
|
|
|
+ currentList.forEach((currentItem,currentIndex,currentArray)=>{
|
|
|
+ let id = currentItem.id
|
|
|
+ has[id]= currentItem
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (this.list && this.list.data && !this.$util.isEmpty(this.list.data)){
|
|
|
+ this.list.data.forEach((currentItem,currentIndex,currentArray)=>{
|
|
|
+ let id = currentItem.id
|
|
|
+ if(has[id]){
|
|
|
+ currentItem.bigCount = has[id].bigCount || 0
|
|
|
+ currentItem.userPrice = has[id].userPrice || 0
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.$forceUpdate()
|
|
|
+ }
|
|
|
+
|
|
|
+ return currentList
|
|
|
+ },
|
|
|
+ scrollClassId() {
|
|
|
+ const curClass = this.productInfoList[this.classIndex];
|
|
|
+ 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)
|
|
|
+ price += Number(item.bigCount) * Number(itemInfo.userPrice)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Math.round(price * 100) / 100;
|
|
|
+ },
|
|
|
+ //选择商品总数
|
|
|
+ allCount() {
|
|
|
+ let bigLength = 0;
|
|
|
+ let smallLength = 0;
|
|
|
+ if (this.selectList) {
|
|
|
+ for (const item of this.selectList) {
|
|
|
+ bigLength += Number(item.bigCount)
|
|
|
+ smallLength += Number(item.smallCount)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {bigLength:bigLength,smallLength:smallLength,};
|
|
|
+ },
|
|
|
+ //当前选中商品列表中是否有没有库存的商品
|
|
|
+ hasNoStock() {
|
|
|
+ let has = false;
|
|
|
+ if (this.selectList) {
|
|
|
+ for (const item of this.selectList) {
|
|
|
+ const { bigCount, smallCount, bigNum, bigUnit, smallNum, smallUnit, 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(){
|
|
|
+ this.initData();
|
|
|
+ },
|
|
|
+ //放到仓库
|
|
|
+ pushToSave(selectData){
|
|
|
+ this.setSelectInfo({ selectJobType: this.selectJobType, info: selectData,selectJobId:this.selectJobId })
|
|
|
+ uni.setStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId, selectData)
|
|
|
+ },
|
|
|
+ //询问是否删除缓存
|
|
|
+ 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})
|
|
|
+
|
|
|
+ if(!this.$util.isEmpty(this.globalClassItemList)){
|
|
|
+ this.globalClassItemList.forEach((item,index,arr) =>{
|
|
|
+ if(!this.$util.isEmpty(arr[index].child)){
|
|
|
+ arr[index].child.forEach((ele,i,son)=>{
|
|
|
+ arr[index].child[i].bigCount = 0;
|
|
|
+ arr[index].child[i].smallCount = 0;
|
|
|
+ arr[index].child[i].userPrice = 0;
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.$forceUpdate()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //请求商品数据
|
|
|
+ async initData(extendInfo) {
|
|
|
+
|
|
|
+ let currentInfo = uni.getStorageSync('selectList_'+this.selectJobType+'_target_'+this.selectJobId)
|
|
|
+ if(!this.$util.isEmpty(currentInfo)){
|
|
|
+ currentInfo.forEach((currentItem,currentIndex,currentArray)=>{
|
|
|
+ let currentId = currentItem.id
|
|
|
+ if(this.globalItemList[currentId]){
|
|
|
+ currentArray[currentIndex].bigPrice = this.globalItemList[currentId].bigPrice
|
|
|
+ currentArray[currentIndex].smallPrice = this.globalItemList[currentId].smallPrice
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setSelectInfo({ selectJobType: this.selectJobType, info: currentInfo,selectJobId:this.selectJobId })
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ //滚动或切换分类 获取更多数据
|
|
|
+ scrollPushList(){
|
|
|
+
|
|
|
+ //涉及记住花材的代码和流程,请全项目搜索关键词remember_item
|
|
|
+ //将已选的花材按classId_productId键名组合
|
|
|
+ let selectListData = []
|
|
|
+ if(!this.$util.isEmpty(this.selectList)){
|
|
|
+ this.selectList.forEach((i)=>{
|
|
|
+ selectListData[i.id] = i
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ let list = copyObject(this.productInfoList);
|
|
|
+ let classList = [];
|
|
|
+ for (let i=0;i<list.length;i++){
|
|
|
+
|
|
|
+ //将已选的花材数量和价格组合到总列表里
|
|
|
+ if(!this.$util.isEmpty(list[i].child)){
|
|
|
+ let currentChildren = list[i].child
|
|
|
+ for(let x=0;x<currentChildren.length;x++){
|
|
|
+ let currentProduct = currentChildren[x]
|
|
|
+ let currentPId = currentProduct.id
|
|
|
+ let selectProduct = selectListData[currentPId] || []
|
|
|
+ if(!this.$util.isEmpty(selectProduct)){
|
|
|
+ list[i].child[x].bigCount = selectProduct.bigCount || 0
|
|
|
+ list[i].child[x].userPrice = selectProduct.userPrice || 0
|
|
|
+ list[i].child[x].smallCount = selectProduct.smallCount || 0
|
|
|
+ }else{
|
|
|
+ list[i].child[x].bigCount = 0
|
|
|
+ list[i].child[x].userPrice = 0
|
|
|
+ list[i].child[x].smallCount = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(i<2){
|
|
|
+ classList.push({...list[i],isActive:true});
|
|
|
+ }else{
|
|
|
+ classList.push({...list[i],isActive:false});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.globalClassItemList = classList
|
|
|
+ },
|
|
|
+ //搜索对应花材
|
|
|
+ searchFn() {
|
|
|
+ let list = this.globalItemList
|
|
|
+ if(this.$util.isEmpty(this.py)){
|
|
|
+ this.globalClassItemList = '';
|
|
|
+ this.classIndex = 0;
|
|
|
+ this.scroll_into_view = 'class_'+0;
|
|
|
+ this.scrollPushList();
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //大于等于2个字符才开始搜索 shish 20210622
|
|
|
+ if(this.py.length <=1){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //红色粉色花材太多,搜索时会卡住,所以设置输入第三个字母时才搜索
|
|
|
+ if(this.py.indexOf('fs') == 0 && this.py.length <= 2){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(this.py.indexOf('hs') == 0 && this.py.length <= 2){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(this.py.indexOf('zs') == 0 && this.py.length <= 2){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(this.py.indexOf('ls') == 0 && this.py.length <= 2){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(this.py.indexOf('bs') == 0 && this.py.length <= 2){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(this.py.indexOf('yj') == 0 && this.py.length <= 2){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //涉及记住花材的代码和流程,请全项目搜索关键词remember_item
|
|
|
+ //将已选的花材按productId键名组合
|
|
|
+ let selectListData = []
|
|
|
+ if(!this.$util.isEmpty(this.selectList)){
|
|
|
+ this.selectList.forEach((i)=>{
|
|
|
+ selectListData[i.id] = i
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ let filterItemData = [];
|
|
|
+ list.forEach(currentItem => {
|
|
|
+
|
|
|
+ //组合已记忆已选择的花材
|
|
|
+ let currentPId = currentItem.id
|
|
|
+ let selectProduct = selectListData[currentPId] || []
|
|
|
+ if(!this.$util.isEmpty(selectProduct)){
|
|
|
+ currentItem.bigCount = selectProduct.bigCount || 0
|
|
|
+ currentItem.userPrice = selectProduct.userPrice || 0
|
|
|
+ currentItem.smallCount = selectProduct.smallCount || 0
|
|
|
+ }else{
|
|
|
+ currentItem.bigCount = 0
|
|
|
+ currentItem.userPrice = 0
|
|
|
+ currentItem.smallCount = 0
|
|
|
+ }
|
|
|
+ let elePy = (currentItem.py && currentItem.py.toLocaleUpperCase()) || "";
|
|
|
+ let hasPy = elePy.indexOf(this.py.toLocaleUpperCase()) >= 0;
|
|
|
+ if (hasPy) {
|
|
|
+ if(this.$util.isEmpty(filterItemData)){
|
|
|
+ filterItemData = [{classId: currentItem.classId, className: currentItem.className,isActive:true,child:[currentItem]}]
|
|
|
+ }else{
|
|
|
+ filterItemData.forEach(res => {
|
|
|
+ if(res.classId==currentItem.classId){
|
|
|
+ res.child.push(currentItem)
|
|
|
+ }else{
|
|
|
+ filterItemData.push({classId: currentItem.classId, className: currentItem.className,isActive:true,child:[currentItem]})
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ let searchList = this.$util.unique(filterItemData)
|
|
|
+ this.globalClassItemList = searchList;
|
|
|
+ this.classIndex = 0;
|
|
|
+ this.scroll_into_view = 'class_'+0;
|
|
|
+ },
|
|
|
+ //获取当前选中商品总价
|
|
|
+ getSelectItemPrice(item) {
|
|
|
+ let price = 0;
|
|
|
+ const { bigCount, smallCount, bigPrice, smallPrice } = item;
|
|
|
+ let sum =
|
|
|
+ Number(bigCount) * Number(bigPrice) +
|
|
|
+ Number(smallCount) * Number(smallPrice);
|
|
|
+ price = Math.round(sum * 100) / 100;
|
|
|
+ return price;
|
|
|
+ },
|
|
|
+ //通过id获取当前选中的商品信息
|
|
|
+ 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') {
|
|
|
+ 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--
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log('........replace_item......')
|
|
|
+ console.log(item)
|
|
|
+ const list = this.selectList
|
|
|
+ if(this.checkStock){
|
|
|
+ if ((Number(item.bigCount) * item.ratio + Number(item.smallCount)) > (Number(item.bigNum) * item.ratio + Number(item.smallNum))) {
|
|
|
+ this.$util.noStockRemind()
|
|
|
+ this.$msg("库存不足哦")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let index = list.findIndex(element => element.id == item.id)
|
|
|
+ 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()
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据放到仓库永久存放
|
|
|
+ this.pushToSave(list)
|
|
|
+
|
|
|
+ },
|
|
|
+ //大小单位切换
|
|
|
+ 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.bigNum <= 0 && info.smallNum <= 0){
|
|
|
+ if(this.checkStock){
|
|
|
+ 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 = this.customData.bigPrice;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ this.customData.userPrice = this.customData.userPrice==0?null: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' || this.selectJobType == 'cgPlant'){
|
|
|
+ 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 = {};
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|