Commit 9d1965ff authored by 李硕's avatar 李硕

奖品的排行榜和保存库存值判断

parent cdc42d4b
...@@ -3,9 +3,7 @@ const { function: fc } = cloud; ...@@ -3,9 +3,7 @@ const { function: fc } = cloud;
const plugin = requirePlugin("myPlugin"); const plugin = requirePlugin("myPlugin");
import { bizCode } from "/config"; import { bizCode } from "/config";
import { queryBenefitByEname } from "/api"; import { queryBenefitByEname } from "/api";
import { chooseImage, getImageInfo, validateRangeNumber } from "/utils"; import { chooseImage, getImageInfo, validateRangeNumber } from "/utils";
const EQUITY_TYPE = 1; const EQUITY_TYPE = 1;
const CREDITS_TYPE = 2; const CREDITS_TYPE = 2;
const OBJECT_TYPE = 3; const OBJECT_TYPE = 3;
...@@ -360,14 +358,31 @@ Component({ ...@@ -360,14 +358,31 @@ Component({
this.showItemTips("prizeNameTips", "success", ""); this.showItemTips("prizeNameTips", "success", "");
} }
if ((type == OBJECT_TYPE || type == EQUITY_TYPE) && switchStock === STOCK_LIMIT && !validateRangeNumber(stock, [0, 9999])) { //库存奖品的库存值判断
let usePass = switchStock == 1 ? +stock >= +useStock : true;
console.log('stock==', stock, 'useStock==', useStock);
if ((type == OBJECT_TYPE || type == EQUITY_TYPE) && switchStock === STOCK_LIMIT && (!validateRangeNumber(stock, [0, 99999]) || !usePass)) {
if (!validateRangeNumber(stock, [0, 99999])) {
this.showItemTips(
"prizeNumberTips",
"error",
"奖品库存为0-99999之间的整数且大于发放库存"
);
}
if (!usePass) {
this.showItemTips(
"prizeNumberTips",
"error",
"奖品库存必须大于发放库存"
);
}
}
else {
this.showItemTips( this.showItemTips(
"prizeNumberTips", "prizeNumberTips",
"error", "success",
"奖品库存为0-9999之间的整数" ""
); );
} else {
this.showItemTips("prizeNumberTips", "success", "");
} }
if (type == CREDITS_TYPE && !validateRangeNumber(credits, [0, 999])) { if (type == CREDITS_TYPE && !validateRangeNumber(credits, [0, 999])) {
...@@ -380,8 +395,16 @@ Component({ ...@@ -380,8 +395,16 @@ Component({
this.showItemTips("creditsValueTips", "success", ""); this.showItemTips("creditsValueTips", "success", "");
} }
//排行榜奖品保存判断
const rankArr = rank.split('-');
let isRankPass = dialogType == "rank"
? (rankArr.length == 2
? +rankArr[0] <= +rankArr[1]
&& /^[1-9]+[0-9]*$/.test(+rankArr[0])
&& /^[1-9]+[0-9]*$/.test(+rankArr[1])
: false) : true;
if (dialogType === 'rank') { if (dialogType === 'rank') {
if (!rank) { if (!isRankPass) {
this.showItemTips( this.showItemTips(
"rankValueTips", "rankValueTips",
"error", "error",
...@@ -390,17 +413,14 @@ Component({ ...@@ -390,17 +413,14 @@ Component({
} else { } else {
this.showItemTips("rankValueTips", "success", ""); this.showItemTips("rankValueTips", "success", "");
} }
if (maxRankLimit && rankArr[rankArr.length - 1] > maxRankLimit) {
} my.showToast({
const rankArr = rank.split('-'); type: "fail",
if (dialogType === 'rank' && maxRankLimit && rankArr[rankArr.length - 1] > maxRankLimit) { content: `最多配置前${maxRankLimit}名奖品`
my.showToast({ });
type: "fail", return;
content: `最多配置前${maxRankLimit}名奖品` }
});
return;
} }
const { probablityTips, prizeNumberTips, creditsValueTips } = this.data; const { probablityTips, prizeNumberTips, creditsValueTips } = this.data;
const isImagePass = image && imageTips.status !== "error"; const isImagePass = image && imageTips.status !== "error";
......
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
</form-item> </form-item>
<view class="submit-btn"> <view class="submit-btn">
<!-- 20200824LS活动结束不可编辑 --> <!-- 活动结束不可编辑 -->
<button a:if="{{!isEnd}}" onTap="onSubmit" type="primary">确定</button> <button a:if="{{!isEnd}}" onTap="onSubmit" type="primary">确定</button>
<button onTap="cancelEdit">取消</button> <button onTap="cancelEdit">取消</button>
</view> </view>
......
export function debounce(fn, wait) { function debounce(fn, wait) {
var timeout = null var timeout = null
return function () { return function () {
if (timeout !== null) clearTimeout(timeout) if (timeout !== null) clearTimeout(timeout)
timeout = setTimeout(fn, wait) timeout = setTimeout(fn, wait)
} }
} }
//域名
const passUrlList = [
'1688.cn',
'1688.com',
'alibaba.cn',
'alibaba.com',
'aliexpress.com',
'alimama.cn',
'alimama.com',
'alipay.com.cn',
'alipay.com',
'alipay.net',
'aliplay.com',
'alisoft.cn',
'alisoft.com',
'aliyun.com',
'aliyun.net',
'koubei.cn',
'koubei.com',
'taobao.cn',
'taobao.com',
'taobao.net',
'tb.cn',
'tmall.com',
'zhifu.com',
'zhifubao.com',
'juhuasuan.com',
'tmall.hk',
'tmall.com.hk',
'jiyoujia.com',
'pailitao.com',
'cainiao.com',
'dingtalk.com',
'yushanfang.com',
'guoguo - app.com',
'alihealth.cn',
'miaostreet.com',
'uc123.com',
'uc.cn',
'ucweb.com',
'aliyun - inc.com',
'cainiaoyizhan.com',
'umeng.com',
'aliplus.com',
'aliplay.com',
'taopiaopiao.com',
'youku.com',
'tudou.com',
'xinlingshou.cn',
'fliggy.com',
'feizhu.com',
'feizhu.cn'
];
// 解决小数相加精度问题 // 解决小数相加精度问题
export function addFloat(num1, num2) { function addFloat(num1, num2) {
var r1, r2, m var r1, r2, m
r1 = num1.toString().split(".")[1] ? num1.toString().split(".")[1].length : 0 r1 = num1.toString().split(".")[1] ? num1.toString().split(".")[1].length : 0
r2 = num2.toString().split(".")[1] ? num2.toString().split(".")[1].length : 0 r2 = num2.toString().split(".")[1] ? num2.toString().split(".")[1].length : 0
m = Math.pow(10, Math.max(r1, r2)) m = Math.pow(10, Math.max(r1, r2))
return (num1 * m + num2 * m) / m return (num1 * m + num2 * m) / m
} }
\ No newline at end of file
//小数相除
const accMul = function (arg1, arg2) {
var m = 0,
s1 = arg1.toString(),
s2 = arg2.toString();
try {
m += s1.split(".")[1].length;
} catch (e) { }
try {
m += s2.split(".")[1].length;
} catch (e) { }
return (
(Number(s1.replace(".", "")) * Number(s2.replace(".", ""))) /
Math.pow(10, m)
);
}
//小数相乘
const signFigures = function (num, rank = 6) {
if (!num) return 0;
const sign = num / Math.abs(num);
const number = num * sign;
const temp = rank - 1 - Math.floor(Math.log10(number));
let ans;
if (temp > 0) {
ans = parseFloat(number.toFixed(temp));
} else if (temp < 0) {
ans = Math.round(number / Math.pow(10, temp)) * temp;
} else {
ans = Math.round(number);
}
return ans * sign;
};
module.exports = {
passUrlList,
signFigures,
debounce,
accMul,
addFloat
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment