commission--yt-commit
This commit is contained in:
@ -1,4 +1,11 @@
|
||||
import { baseUrl } from "../../../../request";
|
||||
Component({
|
||||
|
||||
data: {
|
||||
pgencyPriceAble: true, // 代理单价input启用/禁用
|
||||
commissionRateAble: true, // 抽成比例input启用/禁用
|
||||
LodingHidden: false, // 遮罩禁用启用
|
||||
},
|
||||
/**
|
||||
* 组件的属性列表
|
||||
*/
|
||||
@ -7,18 +14,30 @@ Component({
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
pgencyPrice: 0, // 代理价
|
||||
commissionRate: 0, // 抽成比例
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理输入框的变化
|
||||
*/
|
||||
handleInputChange(e) {
|
||||
const { field } = e.target.dataset; // 获取字段名
|
||||
this.setData({
|
||||
[field]: e.detail.value, // 动态更新输入框数据
|
||||
});
|
||||
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
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -26,15 +45,116 @@ Component({
|
||||
*/
|
||||
methods: {
|
||||
close() {
|
||||
this.resetStatus();
|
||||
this.triggerEvent('close');
|
||||
},
|
||||
cancel() {
|
||||
this.resetStatus();
|
||||
this.triggerEvent('cancel');
|
||||
},
|
||||
confirm() {
|
||||
// 触发confirm事件带数据
|
||||
this.triggerEvent('confirm', {/*数据*/});
|
||||
const id = this.data.detailId;
|
||||
const Rate = this.data.commissionRate;
|
||||
const maxRate = this.data.maxCommissionRate;
|
||||
// console.log('maxRate---->', maxRate);
|
||||
if (Rate > maxRate || Rate < 0) {
|
||||
wx.showModal({
|
||||
title: '抽佣比率错误',
|
||||
content: '抽佣比率大于最大抽成',
|
||||
showCancel: false
|
||||
})
|
||||
return;
|
||||
}
|
||||
wx.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
})
|
||||
// 发送请求
|
||||
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'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
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: true,
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 处理输入框的变化
|
||||
*/
|
||||
handleInputChange(e) {
|
||||
const { field } = e.target.dataset; // 获取字段名
|
||||
this.setData({
|
||||
[field]: e.detail.value, // 动态更新输入框数据
|
||||
});
|
||||
},
|
||||
|
||||
// 计算单价——当输入抽成比率失焦时自动计算
|
||||
calculateUnitPrice() {
|
||||
const tempCommissionRate = this.data.commissionRate/100; // 暂存抽成比率
|
||||
const tempMyUnitPrice = this.data.myUnitPrice; // 暂存我的单价
|
||||
let res = parseFloat( (tempMyUnitPrice * (1- tempCommissionRate)).toPrecision(2) ) ;
|
||||
// 计算单价 (避免精度丢失问题)
|
||||
this.setData({
|
||||
pgencyPrice : res
|
||||
})
|
||||
},
|
||||
|
||||
// 计算比率——当输入代理单价失焦时自动计算
|
||||
calculateRatio() {
|
||||
const tempPgencyPrice = this.data.pgencyPrice; // 暂存代理单价
|
||||
const tempMyUnitPrice = this.data.myUnitPrice; // 暂存我的单价
|
||||
if (tempPgencyPrice == tempMyUnitPrice) {
|
||||
this.setData({ commissionRate: 100 })
|
||||
} else {
|
||||
let res = (tempMyUnitPrice - tempPgencyPrice) / tempMyUnitPrice;
|
||||
this.setData({
|
||||
commissionRate: parseFloat((res*100).toPrecision(2))
|
||||
})
|
||||
}
|
||||
console.log('抽佣比率------>',this.data.commissionRate);
|
||||
}
|
||||
}
|
||||
})
|
@ -4,34 +4,53 @@
|
||||
<text class="self-center font text">代理价设置</text>
|
||||
<view class="flex-col self-stretch mt-24">
|
||||
<view class="flex-col">
|
||||
<text class="self-start font_2 text_2">我的价格0.30,我的抽成0.17元</text>
|
||||
<text class="self-start font_2 text_2">我的价格{{ myUnitPrice }},我的抽成{{ (myUnitPrice*100 - pgencyPrice*100)/100 }}元</text>
|
||||
<view class="flex-col self-stretch section_2 mt-13">
|
||||
<view class="flex-row justify-between items-center">
|
||||
<text class="font_2 text_4">结算标准</text>
|
||||
<text class="font_2 text_3">3.6元购买30元券包3.6元购买</text>
|
||||
<text class="font_2 text_3">{{ projectDetailName }}</text>
|
||||
</view>
|
||||
<view class="flex-row justify-between items-center group">
|
||||
<text class="font_2 text_5">代理价</text>
|
||||
<view class="flex-col justify-start items-start text-wrapper">
|
||||
<input class="text_6 font" placeholder="0.30" />
|
||||
<input
|
||||
class="text_8 font"
|
||||
type="digit"
|
||||
placeholder="请输入代理单价"
|
||||
data-field="pgencyPrice"
|
||||
value="{{ pgencyPrice }}"
|
||||
disabled="{{ pgencyPriceAble }}"
|
||||
bindblur="calculateRatio"
|
||||
bindinput="handleInputChange"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="flex-row justify-between items-center group_2">
|
||||
<text class="font_2 text_7">抽成比例</text>
|
||||
<view class="flex-col justify-start items-start text-wrapper">
|
||||
<input class="text_8 font" placeholder="0.30" />
|
||||
<view class="flex-col justify-start items-start text-wrapper input-container">
|
||||
<image class="input-icon" src="./images/baifenbi.png"></image>
|
||||
<input
|
||||
class="text_8 font"
|
||||
placeholder="请输入抽成比例"
|
||||
type="digit"
|
||||
data-field="commissionRate"
|
||||
value="{{ commissionRate }}"
|
||||
disabled="{{ commissionRateAble }}"
|
||||
bindblur="calculateUnitPrice"
|
||||
bindinput="handleInputChange"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="flex-row justify-between items-center group_3">
|
||||
<text class="font_2 text_10">设价方式</text>
|
||||
<radio-group class="flex-col group_4">
|
||||
<radio-group class="flex-col group_4" bindchange="radioChange">
|
||||
<view class="flex-row items-center">
|
||||
<radio class="radio" color="#FF8D1A"></radio>
|
||||
<radio class="radio" color="#FF8D1A" value="代理价"></radio>
|
||||
<text class="font_2 text_9 ml-7">代理价</text>
|
||||
</view>
|
||||
<view class="flex-row items-center mt-14">
|
||||
<radio class="radio_1" color="#FF8D1A"></radio>
|
||||
<radio class="radio_1" color="#FF8D1A" value="抽成比例"></radio>
|
||||
<text class="font_2 text_11 ml-7">抽成比例</text>
|
||||
</view>
|
||||
</radio-group>
|
||||
|
@ -121,6 +121,19 @@ radio {
|
||||
transform: scale(0.8); /* 调整为你需要的缩放比例 */
|
||||
}
|
||||
|
||||
/* 在.wxss文件中 */
|
||||
.input-container {
|
||||
position: relative; /* 容器使用相对定位 */
|
||||
}
|
||||
|
||||
.input-icon {
|
||||
position: absolute; /* 图标使用绝对定位 */
|
||||
left: 82px; /* 设置图标距离左边的距离 */
|
||||
top: 9px; /* 设置图标距离顶部的距离 */
|
||||
width: 15px; /* 图标宽度 */
|
||||
height: 15px; /* 图标高度 */
|
||||
}
|
||||
|
||||
/* 弹窗外围容器,覆盖全屏并居中 */
|
||||
.popup-wrapper {
|
||||
position: fixed;
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
Reference in New Issue
Block a user