define({ name: "discount", template: `
折扣
{{attr_hide.level_discount_name ? attr_hide.level_discount_name : "会员等级" }}
折扣 固定金额 成本比例
`, style: ` `, props: { form: { default() { return {}; }, }, attr_hide: { default() { return {} } }, }, data() { return { hide_discount_method:true, }; }, watch:{ 'form.discount_method': { handler(){ for(let item of this.form.levels) { item.discount_value = '' } }, } }, mounted () { if (this.attr_hide.discount_method) { this.form.discount_method = this.attr_hide.discount_method; this.hide_discount_method = false; } }, methods: { validate() { let levelsData = JSON.parse(JSON.stringify(this.form.levels)); discount_value = {} levelsData.forEach(item => { discount_value[item.level_id] = item.discount_value }); return { discount_value, level_discount_type:this.form.level_discount_type, discount_method:this.form.discount_method } }, // 处理输入框小数点两位问题 clearNoNumTwo(value) { value = value.replace(/[^\d.]/g, ''); //清除“数字”和“.”以外的字符 value = value.replace(/\.{2,}/g, '.'); //只保留第一个. 清除多余的 value = value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); if(this.form.discount_method == 2) { value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数 } if (value.indexOf('.') < 0 && value != '') { //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额 value = parseFloat(value); } let strObj = value.toString(); if (strObj.indexOf('.') > -1 && strObj === '0.00') { value = parseFloat(value).toFixed(1); } return value; }, }, });