|
|
|
@ -36,6 +36,7 @@ const user = ref({ |
|
|
|
jwcode: null, |
|
|
|
name: "", |
|
|
|
market: "", |
|
|
|
red: null, |
|
|
|
historySumGold: null, |
|
|
|
historyPermanentGold: null, |
|
|
|
historyFreeGold: null, |
|
|
|
@ -56,6 +57,7 @@ const addConsume = ref({ |
|
|
|
// jwcode 是数字 |
|
|
|
jwcode: null, //精网号 |
|
|
|
goodsName: "",// 商品名称 |
|
|
|
price: null, // 原价 |
|
|
|
sumGold: null, // 消费金币总数 |
|
|
|
freeGold: null, // 免费金币 |
|
|
|
permanentGold: null, // 永久金币 |
|
|
|
@ -171,6 +173,24 @@ function validateInput() { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
// 仅在鼠标离开(blur)时校验:消耗金币数 + 红包抵扣金额 ≥ 原价 |
|
|
|
function validateRedLimit() { |
|
|
|
const sumGold = parseFloat(addConsume.value.sumGold); |
|
|
|
const price = Number(addConsume.value.price || 0); |
|
|
|
const redMax = Number(user.value.red || 0); |
|
|
|
if (!isNaN(price) && price > 0) { |
|
|
|
if (isNaN(sumGold) || sumGold <= 0) { |
|
|
|
ElMessage.error(t('elmessage.noEmptySumGold')); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (sumGold + redMax < price) { |
|
|
|
ElMessage.error(t('elmessage.limitRedAmount')); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
// 消耗金币计算函数 |
|
|
|
function calculateCoins(sumGold) { |
|
|
|
console.log("消耗金币计算函数:计算金币", sumGold); |
|
|
|
@ -240,6 +260,7 @@ const add = async function () { |
|
|
|
data: { |
|
|
|
jwcode: addConsume.value.jwcode, |
|
|
|
adminId: adminData.value.id, |
|
|
|
price: Number(addConsume.value.price || 0) * 100, |
|
|
|
sumGold: addConsume.value.sumGold * 100, |
|
|
|
freeGold: addConsume.value.freeGold * 100, |
|
|
|
taskGold: addConsume.value.taskGold * 100, |
|
|
|
@ -392,6 +413,9 @@ const addBefore = () => { |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (!validateInput() || !validateRedLimit()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
ReadCookies.value = `coinConsume:${addConsume.value.jwcode}:${addConsume.value.goodsName.value}` |
|
|
|
// 获取cookie |
|
|
|
const cookie = Cookies.get(ReadCookies.value) |
|
|
|
@ -491,7 +515,8 @@ const getGoods = async function () { |
|
|
|
goods.value = result.data.map(item => ({ |
|
|
|
id: item.id, |
|
|
|
label: item.name, |
|
|
|
value: item.name |
|
|
|
value: item.name, |
|
|
|
price: item.price |
|
|
|
})); |
|
|
|
} catch (error) { |
|
|
|
console.log("请求失败", error); |
|
|
|
@ -521,6 +546,18 @@ watch( |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
// 监听商品选择,自动展示原价 |
|
|
|
watch( |
|
|
|
() => addConsume.value.goodsName, |
|
|
|
(newGoods) => { |
|
|
|
if (newGoods && typeof newGoods === 'object') { |
|
|
|
addConsume.value.price = Number(newGoods.price || 0) || null; |
|
|
|
} else { |
|
|
|
addConsume.value.price = null; |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
/* |
|
|
|
====================挂载================================= |
|
|
|
*/ |
|
|
|
@ -551,10 +588,13 @@ onMounted(async function () { |
|
|
|
|
|
|
|
</el-select> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item prop="price" :label="t('common_add.price')"> |
|
|
|
<el-input v-model="addConsume.price" style="width: 120px" disabled /> |
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
<el-form-item prop="sumGold" :label="t('common_add.consumeTotalGold')"> |
|
|
|
<el-input v-model="addConsume.sumGold" style="width: 120px" @input="validateInput()" |
|
|
|
@change="calculateCoins(addConsume.sumGold)" /> |
|
|
|
<el-input v-model="addConsume.sumGold" style="width: 120px" |
|
|
|
@blur="validateRedLimit()" /> |
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
|
|
|
|
@ -659,6 +699,11 @@ onMounted(async function () { |
|
|
|
<p>{{ user.market }}</p> |
|
|
|
</el-form-item> |
|
|
|
</el-col> |
|
|
|
<el-col :span="14"> |
|
|
|
<el-form-item :label="$t('common_add_user.maxReductionAmount')"> |
|
|
|
<p style="color: #2fa1ff">{{ user.red }} </p> |
|
|
|
</el-form-item> |
|
|
|
</el-col> |
|
|
|
</el-row> |
|
|
|
</el-form> |
|
|
|
</el-card> |
|
|
|
|