export const carousel = { computed: { isIE () { return /(MSIE)|(Trident)/.test(this.$store.state.option.userAgent) }, effect () { return this.isIE ? 'slide' : 'fade' } } } export const sayPriceReplace = { data () { return { showSimilarCodeList: false, showSimilarBrandList: false, similarCode: [], similarBrand: [] } }, methods: { clearSimilar: function () { this.showSimilarCodeList = false this.showSimilarBrandList = false }, checkBrand: function () { let nullStrFlag = this.baseUtils.checkNullStr(this.sayPriceObj.replaceBrand) this.validSayPrice.replaceBrand = this.sayPriceObj.replaceBrand && this.sayPriceObj.replaceBrand !== '' && nullStrFlag if (!this.validSayPrice.replaceBrand) { if (!nullStrFlag) { this.$message.error('品牌输入不合法') } else { this.$message.error('品牌不能为空') } } return this.validSayPrice.brand }, checkCode: function () { let code = this.sayPriceObj.replaceCmpCode.trim() let nullStrFlag = this.baseUtils.checkNullStr(code) this.validSayPrice.replaceCmpCode = code && code !== '' && nullStrFlag if (!this.validSayPrice.replaceCmpCode) { if (!nullStrFlag) { this.$message.error('型号输入不合法') } else { this.$message.error('型号不能为空') } } return this.validSayPrice.replaceCmpCode }, onBrandChange: function () { this.sayPriceObj.replaceBrand = this.sayPriceObj.replaceBrand.trim() if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceBrand)) { let chineseIndex = -1 for (let i = 0; i < this.sayPriceObj.replaceBrand.length; i++) { if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceBrand.charAt(i)) && !(/[\u4e00-\u9fa5]/).test(this.sayPriceObj.replaceBrand.charAt(i))) { chineseIndex = i break } } if (chineseIndex > -1) { this.sayPriceObj.replaceBrand = this.sayPriceObj.replaceBrand.substring(0, chineseIndex) } } else if (this.sayPriceObj.replaceBrand && this.baseUtils.getRealLen(this.sayPriceObj.replaceBrand) > 50) { this.sayPriceObj.replaceBrand = this.baseUtils.cutOutString(this.sayPriceObj.replaceBrand, 50) } else { this.getSimilarBrand() } }, onCodeChange: function () { if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceCmpCode)) { let chineseIndex = -1 for (let i = 0; i < this.sayPriceObj.replaceCmpCode.length; i++) { if ((/[^\x00-\xff]/g).test(this.sayPriceObj.replaceCmpCode.charAt(i))) { chineseIndex = i break } } this.sayPriceObj.replaceCmpCode = this.baseUtils.cutOutString(this.sayPriceObj.replaceCmpCode, chineseIndex) } else if (this.sayPriceObj.replaceCmpCode && this.baseUtils.getRealLen(this.sayPriceObj.replaceCmpCode) > 100) { this.sayPriceObj.replaceCmpCode = this.baseUtils.cutOutString(this.sayPriceObj.replaceCmpCode, 100) } else { this.getSimilarCode() } }, getSimilarBrand: function () { if (this.sayPriceObj.replaceBrand) { this.$http.get('/search/similarBrands', {params: {keyword: this.sayPriceObj.replaceBrand}}) .then(response => { this.similarBrand = response.data this.showSimilarBrandList = response.data.length > 0 }) } else { this.showSimilarBrandList = false } }, getSimilarCode: function () { if (this.sayPriceObj.replaceCmpCode) { this.$http.get('/search/similarComponents', {params: {keyword: this.sayPriceObj.replaceCmpCode}}) .then(response => { this.similarCode = response.data this.showSimilarCodeList = response.data.length > 0 }) } else { this.showSimilarCodeList = false } }, setBrand: function (brand) { this.sayPriceObj.replaceBrand = brand this.showSimilarBrandList = false }, setCode: function (code) { this.sayPriceObj.replaceCmpCode = code this.showSimilarCodeList = false } } } /* * 商品购买数量操作 * */ export const goodsPurchaseOperate = { methods: { initGoodsStatus (goodsItem, purchaseNumber) { let pack = goodsItem.perQty || goodsItem.minPackQty if (goodsItem.breakUp) { goodsItem.purchaseNumber = purchaseNumber || goodsItem.minBuyQty goodsItem.canSub = false goodsItem.canAdd = goodsItem.purchaseNumber < goodsItem.reserve } else { if (pack >= goodsItem.minBuyQty) { goodsItem.purchaseNumber = purchaseNumber || pack } else { let max = Math.max(pack, goodsItem.minBuyQty) goodsItem.purchaseNumber = purchaseNumber || (max + max % pack) } goodsItem.canSub = false goodsItem.canAdd = goodsItem.purchaseNumber + goodsItem.minPackQty <= goodsItem.reserve } goodsItem.currentPrice = Number((this.baseUtils.getPriceByLevel(goodsItem.prices, goodsItem.purchaseNumber, goodsItem.currencyName) * goodsItem.purchaseNumber).toFixed(6)) }, onPurchaseNumberInput: function (goods) { let showPrice = this.baseUtils.getPriceByLevel(goods.goods.prices, goods.goods.purchaseNumber, goods.goods.currencyName) goods.goods.currentPrice = Number(((showPrice || goods.goods.currentPrice) * goods.goods.purchaseNumber).toFixed(6)) // console.log(goods.goods.currentPrice) }, checkPurchaseNumber: function (goods) { if ((/^[\d]*$/).test(goods.goods.purchaseNumber)) { this.changeNum(goods.goods.purchaseNumber, goods) } else { this.setRemindText('请输入整数') goods.goods.purchaseNumber = goods.goods.minBuyQty } }, setGoods: function (type, goods) { if (type === 'set') { this.checkPurchaseNumber(goods) } else { let isAdd = type === 'add' let pack = goods.goods.perQty || goods.goods.minPackQty let newNum = 0 if (goods.goods.breakUp) { newNum = isAdd ? goods.goods.purchaseNumber + 1 : goods.goods.purchaseNumber - 1 } else { newNum = isAdd ? goods.goods.purchaseNumber + pack : goods.goods.purchaseNumber - pack } this.changeNum(newNum, goods) } }, changeNum: function (newNum, goods) { let pack = goods.goods.perQty || goods.goods.minPackQty let buy = goods.goods.minBuyQty let reserve = goods.goods.reserve let breakUp = goods.goods.breakUp if (!newNum && newNum !== 0) { goods.goods.purchaseNumber = buy } else { newNum = parseInt(newNum) if (breakUp) { if (newNum < buy) { this.setRemindText('最小起订量为' + buy) goods.goods.purchaseNumber = buy goods.goods.canSub = false // goods.goods.canAdd = true } else if (newNum > reserve) { this.setRemindText('库存不足') goods.goods.purchaseNumber = reserve goods.goods.canAdd = false // goods.goods.canSub = true } else { goods.goods.canSub = true goods.goods.canAdd = true goods.goods.purchaseNumber = newNum newNum === buy && (goods.goods.canSub = false) newNum === reserve && (goods.goods.canAdd = false) } } else { if (newNum < buy) { this.setRemindText('最小起订量为' + buy) goods.goods.purchaseNumber = buy goods.goods.canSub = false if (newNum > reserve) { this.setRemindText('库存不足') goods.goods.purchaseNumber = reserve - (reserve % pack) goods.goods.canAdd = false } } else if (newNum > reserve) { goods.goods.canSub = true goods.goods.canAdd = false this.setRemindText('库存不足') goods.goods.purchaseNumber = reserve - (reserve % pack) } else { goods.goods.canSub = true goods.goods.canAdd = true let remainder = newNum % pack if (remainder !== 0) { // console.log(this.fragment.num) this.setRemindText('不支持拆包且包装量为' + pack) // 这个直接赋值的,应该给这个值进行判断(Math.floor(newNum / pack) + 1) * pack let res = (Math.floor(newNum / pack) + 1) * pack goods.goods.purchaseNumber = res > reserve ? Math.floor(newNum / pack) * pack : res } else { goods.goods.purchaseNumber = newNum } newNum === buy && (goods.goods.canSub = false) newNum === reserve && (goods.goods.canAdd = false) } } } this.onPurchaseNumberInput(goods) } } }