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) { if (this.$store.state.option.isMobile === true) { this.remindText = '品牌输入不合法' this.timeoutCount++ } else { this.$message.error('品牌输入不合法') } } else { if (this.$store.state.option.isMobile === true) { this.remindText = '品牌不能为空' this.timeoutCount++ } 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) { if (this.$store.state.option.isMobile === true) { this.remindText = '型号输入不合法' this.timeoutCount++ } else { this.$message.error('型号输入不合法') } } else { if (this.$store.state.option.isMobile === true) { this.remindText = '型号不能为空' this.timeoutCount++ } 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) } } } /* * 根据产品发布询价 * */ export const seekProduct = { data () { return { applyObj: { unitPrice: '', currency: 'RMB', encapsulation: '', produceDate: '', amount: '', deadline: '' }, validObj: { unitPrice: true, amount: true, deadline: true }, pickerOptions: { disabledDate (time) { // 大于等于今天 小于三个月后 return time.getTime() < Date.now() - 1000 * 60 * 60 * 24 || time.getTime() > Date.now() + 1000 * 60 * 60 * 24 * 30 * 3 } }, hasDialog: false } }, methods: { // 时间格式化 setDeadLineValid: function () { this.applyObj.deadline = this.baseUtils.formatDate(this.baseUtils.getFullDay(new Date(this.applyObj.deadline)), 'yyyy-MM-dd hh:mm:ss') this.validObj.deadline = true }, // 检查单价预算 checkUnitPrice () { this.validObj.unitPrice = this.applyObj.unitPrice === '' ? true : this.applyObj.unitPrice > 0 && this.applyObj.unitPrice < 100000000 if (!this.validObj.unitPrice && this.applyObj.unitPrice <= 0) { this.$message.error('单价必须是大于0的数字') } return this.validObj.unitPrice }, // 检查采购数量 checkAmount () { this.validObj.amount = this.applyObj.amount === '' ? true : this.applyObj.amount > 0 && this.applyObj.amount < 1000000000 return this.validObj.amount }, // 检查时间是否有输入 checkDeadline () { this.validObj.deadline = Boolean(this.applyObj.deadline) return this.validObj.deadline }, // 检查各个字段输入正常数据 checkAll () { return this.checkDeadline() && this.checkUnitPrice() && this.checkAmount() }, emptyForm () { for (let attr in this.applyObj) { this.applyObj[attr] = attr === 'currency' ? 'RMB' : '' } }, // 请求询价信息 goPublish () { // let _this = this // this.isClick = true // setTimeout(function () { // _this.isClick = false // }, 1000) if (this.checkAll()) { let inquiry = {} let inquiryItem = {} if (this.user.data.enterprise) { inquiry.enUU = this.user.data.enterprise.uu } let date = new Date() let currency = this.applyObj.unitPrice ? this.applyObj.currency : null inquiry.recorderUU = this.user.data.userUU inquiry.code = 'MALL' + date.getTime() inquiry.date = date inquiry.recorder = this.user.data.userName inquiry.endDate = this.applyObj.deadline inquiry.sourceapp = 'MALL' inquiry.amount = 1 inquiryItem.userUU = this.user.data.userUU inquiryItem.source = 'MALL' inquiryItem.userName = this.user.data.userName inquiryItem.userTel = this.user.data.userTel inquiryItem.needquantity = this.applyObj.amount inquiryItem.inbrand = this.productItem.brand inquiryItem.currency = currency inquiryItem.cmpCode = this.productItem.cmpCode.toUpperCase() inquiryItem.unitPrice = this.applyObj.unitPrice inquiryItem.produceDate = this.applyObj.produceDate inquiryItem.date = date inquiryItem.endDate = this.applyObj.deadline inquiryItem.encapsulation = this.applyObj.encapsulation inquiryItem.spec = this.productItem.spec inquiryItem.prodTitle = this.productItem.prodName let inquiryItems = [] inquiryItems.push(inquiryItem) inquiry.inquiryItems = inquiryItems inquiry.currency = this.applyObj.unitPrice ? this.applyObj.currency : null this.$http.post('/inquiry/buyer/save', inquiry) .then(res => { this.$message.success('发布成功') this.emptyForm() this.showObj.show = false }, error => { console.log(error) this.$message.error('发布失败') }) } else { if (!this.validObj.deadline) { this.$message.error('截止日期不能为空') } else if (!this.validObj.amount) { this.$message.error('请输入正确的数值') } } } } }