qingcheng-xiaochengxu/pages/personCenter/component/commissionRatePop/commissionRatePop.js

195 lines
5.0 KiB
JavaScript
Raw Normal View History

2025-06-05 01:47:29 +00:00
import { baseUrl } from "../../../../request";
2025-05-29 00:56:35 +00:00
Component({
2025-06-05 01:47:29 +00:00
data: {
pgencyPriceAble: true, // 代理单价input启用/禁用
commissionRateAble: false, // 抽成比例input启用/禁用
2025-06-05 01:47:29 +00:00
LodingHidden: false, // 遮罩禁用启用
},
2025-05-29 00:56:35 +00:00
/**
* 组件的属性列表
*/
properties: {
show: { // 控制显示/隐藏
type: Boolean,
value: false
},
2025-06-05 01:47:29 +00:00
pgencyPrice: { // 代理单价
type: String,
value: 0
},
commissionRate: { // 抽成比例
type: String,
value: 0
},
myUnitPrice: { // 我的单价
type: Number,
value: 0
},
projectDetailName: { // 项目详细名称
type: String,
value: ''
},
detailId: { // 下级项目明细id
type: Number,
value: 0
},
maxCommissionRate: { // 最大抽佣比例
type: Number,
value: 0
2025-06-05 03:21:05 +00:00
},
isSub: {
type: Boolean,
value: false
2025-06-05 01:47:29 +00:00
}
2025-05-29 00:56:35 +00:00
},
/**
* 组件的方法列表
*/
methods: {
close() {
2025-06-05 01:47:29 +00:00
this.resetStatus();
this.triggerEvent('close');
},
cancel() {
2025-06-05 01:47:29 +00:00
this.resetStatus();
this.triggerEvent('cancel');
},
confirm() {
// 触发confirm事件带数据
2025-06-05 01:47:29 +00:00
const id = this.data.detailId;
const Rate = this.data.commissionRate;
const maxRate = this.data.maxCommissionRate;
2025-06-05 03:21:05 +00:00
const isSub = this.data.isSub;
console.log('id---->', id);
console.log('Rate--->',Rate);
console.log('isSub---->',isSub);
2025-06-05 01:47:29 +00:00
if (Rate > maxRate || Rate < 0) {
wx.showModal({
title: '抽佣比率错误',
content: '抽佣比率大于最大抽成',
showCancel: false
})
return;
}
wx.showLoading({
title: '加载中',
mask: true
})
// 发送请求
2025-06-05 03:21:05 +00:00
if (isSub) {
wx.request({
url: baseUrl + '/projectCommission/update/sub/rate',
method: 'POST',
header: {
Authorization: wx.getStorageSync('token'),
},
data: {
id: id,
currentCommissionRate: Rate
},
success: res=> {
console.log('用户抽用户----->',res.data);
if ( res.data.code === 1 ) {
wx.hideLoading() // 加载框关闭
this.triggerEvent('confirm', {});
} else {
wx.showToast({
title: '服务异常',
icon: 'error'
})
}
2025-06-05 01:47:29 +00:00
}
2025-06-05 03:21:05 +00:00
})
} else {
wx.request({
url: baseUrl + '/projectCommission/update/rate',
method: 'POST',
header: {
Authorization: wx.getStorageSync('token'),
},
data: {
id: id,
currentCommissionRate: Rate
},
success: res => {
console.log('项目抽佣结果---->',res.data);
if (res.data.code === 1) {
wx.hideLoading() // 加载框关闭
this.triggerEvent('confirm', {});
} else {
wx.showToast({
title: '服务异常',
icon: 'error'
})
}
}
})
}
2025-06-05 01:47:29 +00:00
this.resetStatus();
},
// 单选框选择方法
radioChange(e) {
const selected = e.detail.value;
if (selected === '代理价') {
this.setData({
pgencyPriceAble: false,
commissionRateAble: true,
})
} else {
this.setData({
pgencyPriceAble: true,
commissionRateAble: false,
})
}
},
// 重置input状态
resetStatus() {
this.setData({
pgencyPriceAble: true,
commissionRateAble: false,
2025-06-05 01:47:29 +00:00
})
},
/**
* 处理输入框的变化
*/
handleInputChange(e) {
const { field } = e.target.dataset; // 获取字段名
this.setData({
[field]: e.detail.value, // 动态更新输入框数据
});
},
// 计算单价——当输入抽成比率失焦时自动计算
calculateUnitPrice() {
const tempCommissionRate = this.data.commissionRate / 100; // 暂存抽成比率
2025-06-05 01:47:29 +00:00
const tempMyUnitPrice = this.data.myUnitPrice; // 暂存我的单价
let res = parseFloat((tempMyUnitPrice * (1 - tempCommissionRate)).toFixed(2)) ;
console.log(tempCommissionRate, tempMyUnitPrice, res)
2025-06-05 01:47:29 +00:00
// 计算单价 (避免精度丢失问题)
this.setData({
pgencyPrice : res
})
},
2025-06-05 01:47:29 +00:00
// 计算比率——当输入代理单价失焦时自动计算
calculateRatio() {
const tempPgencyPrice = this.data.pgencyPrice; // 暂存代理单价
const tempMyUnitPrice = this.data.myUnitPrice; // 暂存我的单价
const res = parseFloat(((1 - tempPgencyPrice / tempMyUnitPrice) * 100).toFixed(2))
console.log(tempPgencyPrice, tempMyUnitPrice, res)
2025-06-05 01:47:29 +00:00
this.setData({
commissionRate: res
2025-06-05 01:47:29 +00:00
})
console.log('抽佣比率------>',this.data.commissionRate);
2025-06-05 01:47:29 +00:00
}
}
})