mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-05 05:39:49 +08:00
【修复】修复接龙模块选购商品合计金额误差的问题。
This commit is contained in:
@@ -1,210 +0,0 @@
|
|||||||
/**
|
|
||||||
* 格式化器
|
|
||||||
* @Author: wenjm
|
|
||||||
* @Date: 2018-02-24 23:28:28
|
|
||||||
* @Last Modified by: wenjm
|
|
||||||
* @Last Modified time: 2018-05-15 14:35:01
|
|
||||||
*/
|
|
||||||
export default {
|
|
||||||
|
|
||||||
formatDateTime(value) {
|
|
||||||
return this.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 格式化时间显示方式
|
|
||||||
* 用法:format="yyyy-MM-dd hh:mm:ss";
|
|
||||||
*/
|
|
||||||
formatDate(value, format = 'yyyy-MM-dd') {
|
|
||||||
if (!value) return "";
|
|
||||||
if (!format) format = "yyyy-MM-dd";
|
|
||||||
let d = value;
|
|
||||||
if (typeof value === 'string') {
|
|
||||||
if (value.indexOf("/Date(") > -1)
|
|
||||||
d = new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
|
|
||||||
else
|
|
||||||
d = new Date(Date.parse(value.replace(/-/g, "/").replace("T", " ").split(".")[0])); //.split(".")[0] 用来处理出现毫秒的情况,截取掉.xxx,否则会出错
|
|
||||||
}
|
|
||||||
let o = {
|
|
||||||
"M+": d.getMonth() + 1, //month
|
|
||||||
"d+": d.getDate(), //day
|
|
||||||
"h+": d.getHours(), //hour
|
|
||||||
"m+": d.getMinutes(), //minute
|
|
||||||
"s+": d.getSeconds(), //second
|
|
||||||
"q+": Math.floor((d.getMonth() + 3) / 3), //quarter
|
|
||||||
"S": d.getMilliseconds() //millisecond
|
|
||||||
};
|
|
||||||
if (/(y+)/.test(format)) {
|
|
||||||
format = format.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
||||||
}
|
|
||||||
for (let k in o) {
|
|
||||||
if (new RegExp("(" + k + ")").test(format)) {
|
|
||||||
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return format;
|
|
||||||
},
|
|
||||||
|
|
||||||
formatTime(t) {
|
|
||||||
if (isNaN(t) || t == 0) { return 0; }
|
|
||||||
|
|
||||||
let n = 31536000000;
|
|
||||||
if (t >= n) {
|
|
||||||
return this.formatNumber(t / n, '#,##0.##') + ' 年';
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 86400000;
|
|
||||||
if (t >= n) {
|
|
||||||
return this.formatNumber(t / n, '#,##0.##') + ' 日';
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 3600000;
|
|
||||||
if (t >= n) {
|
|
||||||
return this.formatNumber(t / n, '#,##0.##') + ' 小时';
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 60000;
|
|
||||||
if (t >= n) {
|
|
||||||
return this.formatNumber(t / n, '#,##0.##') + ' 分';
|
|
||||||
}
|
|
||||||
|
|
||||||
n = 1000;
|
|
||||||
if (t >= n) {
|
|
||||||
return this.formatNumber(t / n, '#,##0.##') + ' 秒';
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.formatNumber(t, '#,##0.##') + ' 毫秒';
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 格式化数字显示方式
|
|
||||||
* 用法
|
|
||||||
* formatNumber(12345.999,'#,##0.00');
|
|
||||||
* formatNumber(12345.999,'#,##0.##');
|
|
||||||
* formatNumber(123,'000000');
|
|
||||||
*/
|
|
||||||
formatNumber(value, pattern) {
|
|
||||||
if (value == null)
|
|
||||||
return value;
|
|
||||||
let strarr = value ? value.toString().split('.') : ['0'];
|
|
||||||
let fmtarr = pattern ? pattern.split('.') : [''];
|
|
||||||
let retstr = '';
|
|
||||||
// 整数部分
|
|
||||||
let str = strarr[0];
|
|
||||||
let fmt = fmtarr[0];
|
|
||||||
let i = str.length - 1;
|
|
||||||
let comma = false;
|
|
||||||
for (let f = fmt.length - 1; f >= 0; f--) {
|
|
||||||
switch (fmt.substr(f, 1)) {
|
|
||||||
case '#':
|
|
||||||
if (i >= 0) retstr = str.substr(i--, 1) + retstr;
|
|
||||||
break;
|
|
||||||
case '0':
|
|
||||||
if (i >= 0) retstr = str.substr(i--, 1) + retstr;
|
|
||||||
else retstr = '0' + retstr;
|
|
||||||
break;
|
|
||||||
case ',':
|
|
||||||
comma = true;
|
|
||||||
retstr = ',' + retstr;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i >= 0) {
|
|
||||||
if (comma) {
|
|
||||||
let l = str.length;
|
|
||||||
for (; i >= 0; i--) {
|
|
||||||
retstr = str.substr(i, 1) + retstr;
|
|
||||||
if (i > 0 && ((l - i) % 3) == 0) retstr = ',' + retstr;
|
|
||||||
}
|
|
||||||
} else retstr = str.substr(0, i + 1) + retstr;
|
|
||||||
}
|
|
||||||
retstr = retstr + '.';
|
|
||||||
// 处理小数部分
|
|
||||||
str = strarr.length > 1 ? strarr[1] : '';
|
|
||||||
fmt = fmtarr.length > 1 ? fmtarr[1] : '';
|
|
||||||
i = 0;
|
|
||||||
for (let f = 0; f < fmt.length; f++) {
|
|
||||||
switch (fmt.substr(f, 1)) {
|
|
||||||
case '#':
|
|
||||||
if (i < str.length) retstr += str.substr(i++, 1);
|
|
||||||
break;
|
|
||||||
case '0':
|
|
||||||
if (i < str.length) retstr += str.substr(i++, 1);
|
|
||||||
else retstr += '0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retstr.replace(/^,+/, '').replace(/\.$/, '');
|
|
||||||
},
|
|
||||||
|
|
||||||
//格式化金额
|
|
||||||
formatMoney(value, pattern) {
|
|
||||||
if (!value || value == 0)
|
|
||||||
return 0;
|
|
||||||
let sign = value < 0 ? '-' : '';
|
|
||||||
return sign + this.formatNumber(Math.abs(value), pattern || '#,##0.00');
|
|
||||||
},
|
|
||||||
|
|
||||||
formatMoneyCn(value) {
|
|
||||||
return '¥' + this.formatMoney(value);
|
|
||||||
},
|
|
||||||
|
|
||||||
formatWeek(value) {
|
|
||||||
let week = new Array("日", "一", "二", "三", "四", "五", "六");
|
|
||||||
let datetimeReg = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\s+(20|21|22|23|[0-1]\d):[0-5]\d:[0-5]\d$/;
|
|
||||||
if (datetimeReg.test(value)) {
|
|
||||||
value = value.replace(/-/g, "/");
|
|
||||||
}
|
|
||||||
let day = new Date(value).getDay();
|
|
||||||
|
|
||||||
return "星期" + week[day];
|
|
||||||
},
|
|
||||||
|
|
||||||
formatMoneyAuto(value, pattern = '#,##0.00') {
|
|
||||||
let unit = "元";
|
|
||||||
if (value) {
|
|
||||||
let unitNum = {
|
|
||||||
// '千': 1000.00,
|
|
||||||
'万': 10000.00,
|
|
||||||
'千万': 10000000.00,
|
|
||||||
'亿': 100000000.00,
|
|
||||||
'百亿': 10000000000.00
|
|
||||||
};
|
|
||||||
let unitCount = {
|
|
||||||
// "4": '千',
|
|
||||||
"5": '万',
|
|
||||||
"8": '千万',
|
|
||||||
"9": '亿',
|
|
||||||
"11": '百亿'
|
|
||||||
};
|
|
||||||
let count = 0;
|
|
||||||
let money = value;
|
|
||||||
|
|
||||||
while (money >= 1) {
|
|
||||||
money = money / 10;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
let tmp = unitCount[count + ""];
|
|
||||||
while (count >= 4 && tmp === undefined) {
|
|
||||||
tmp = unitCount[(--count) + ""];
|
|
||||||
}
|
|
||||||
unit = tmp === undefined ? unit : tmp;
|
|
||||||
value = (count >= 4) ? value / (unitNum[unit]) : value;
|
|
||||||
}
|
|
||||||
return this.formatMoney(value, pattern) + unit || "";
|
|
||||||
},
|
|
||||||
|
|
||||||
formatFileSize(value) {
|
|
||||||
if (null == value || value == '') {
|
|
||||||
return "0 Bytes";
|
|
||||||
}
|
|
||||||
var unitArr = new Array("Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
|
|
||||||
var index = 0;
|
|
||||||
var srcsize = parseFloat(value);
|
|
||||||
index = Math.floor(Math.log(srcsize) / Math.log(1024));
|
|
||||||
var size = srcsize / Math.pow(1024, index);
|
|
||||||
size = size.toFixed(2);
|
|
||||||
return size + unitArr[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
格式化器:
|
|
||||||
支持日期格式化、格式化数字显示、格式化金额、格式化星期、小写金额转大写、文件格式化
|
|
||||||
|
|
||||||
使用:
|
|
||||||
日期格式使用:
|
|
||||||
2018-02-24 23:28:28 :
|
|
||||||
var date=formatter.formatDateTime(new Date());
|
|
||||||
2018-02-24
|
|
||||||
var date=formatter.formatDate(new Date(),"yyyy-MM-dd");
|
|
||||||
2018/02/24
|
|
||||||
var date=formatter.formatDate(new Date(),"yyyy/MM/dd");
|
|
||||||
2018-02-24 23:28
|
|
||||||
var date=formatter.formatDate(new Date(),"yyyy-MM-dd HH:mm");
|
|
||||||
|
|
||||||
格式化数字显示方式:
|
|
||||||
123,45.999
|
|
||||||
var money=formatter.formatNumber(12345.999,'#,##0.00');
|
|
||||||
星期五
|
|
||||||
var week=formatter.formatWeek("五");
|
|
||||||
小写转大写
|
|
||||||
一千二百三十四
|
|
||||||
var chinese=formatter.formatMoneyAuto("1234");
|
|
||||||
文件大小转化:
|
|
||||||
1Kb
|
|
||||||
var fileSize=formatter.formatFileSize("1024");
|
|
||||||
|
|
||||||
1Mb
|
|
||||||
var fileSize=formatter.formatFileSize("1024*1024");
|
|
||||||
|
|
||||||
|
|
||||||
案例:
|
|
||||||
<script>
|
|
||||||
import formatter from '@/common/utils/formatter.js';
|
|
||||||
export default {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
appcache: '0Mb'
|
|
||||||
};
|
|
||||||
},
|
|
||||||
onLoad(e) {
|
|
||||||
var self = this;
|
|
||||||
// #ifdef APP-PLUS
|
|
||||||
// 获取当前应用缓存大小并转化为MB、KB、GB等格式
|
|
||||||
plus.cache.calculate(function(size) {
|
|
||||||
console.log(size);
|
|
||||||
self.appcache = formatter.formatFileSize(size);
|
|
||||||
});
|
|
||||||
// #endif
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<view class="solitaire-details-product-item" v-for="(item, index) in items" :key="index">
|
<view class="solitaire-details-product-item" v-for="(item, index) in items" :key="index">
|
||||||
<view class="coreshop-flex">
|
<view class="coreshop-flex">
|
||||||
<u-avatar :src="item.productObj.images ? item.productObj.images+'?x-oss-process=image/resize,m_lfit,h_320,w_240' : item.goodObj.image+'?x-oss-process=image/resize,m_lfit,h_320,w_240'" :size="60" shape="square"></u-avatar>
|
<u-avatar :src="item.productObj.images ? item.productObj.images+'?x-oss-process=image/resize,m_lfit,h_320,w_240' : item.goodObj.image+'?x-oss-process=image/resize,m_lfit,h_320,w_240'" :size="60" shape="square"></u-avatar>
|
||||||
<view class="coreshop-margin-left-10">
|
<view class="coreshop-margin-left-10 coreshop-btn-all">
|
||||||
<view class="coreshop-font-13 u-line-2">{{item.goodObj.name}} </view>
|
<view class="coreshop-font-13 u-line-2">{{item.goodObj.name}} </view>
|
||||||
<view class="coreshop-font-12 coreshop-text-yellow coreshop-margin-top-10 u-line-1">{{ item.productObj.spesDesc }}</view>
|
<view class="coreshop-font-12 coreshop-text-yellow coreshop-margin-top-10 u-line-1">{{ item.productObj.spesDesc }}</view>
|
||||||
<view class="coreshop-flex coreshop-justify-between coreshop-margin-top-10">
|
<view class="coreshop-flex coreshop-justify-between coreshop-margin-top-10">
|
||||||
@@ -134,8 +134,6 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 右边浮动球 -->
|
|
||||||
<!--<coreshop-fab horizontal="right" vertical="bottom" direction="vertical"></coreshop-fab>-->
|
|
||||||
<!-- 登录提示 -->
|
<!-- 登录提示 -->
|
||||||
<coreshop-login-modal></coreshop-login-modal>
|
<coreshop-login-modal></coreshop-login-modal>
|
||||||
|
|
||||||
@@ -144,7 +142,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import formatter from '@/common/utils/formatter.js';
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
@@ -160,7 +157,7 @@
|
|||||||
background: 'none',
|
background: 'none',
|
||||||
color: '#fff'
|
color: '#fff'
|
||||||
},
|
},
|
||||||
totalprice: '0.00',
|
totalprice: 0,
|
||||||
cart: [],
|
cart: [],
|
||||||
type: 2,
|
type: 2,
|
||||||
cartType: this.$globalConstVars.paymentType.solitaire,
|
cartType: this.$globalConstVars.paymentType.solitaire,
|
||||||
@@ -209,11 +206,10 @@
|
|||||||
this.cart.forEach(function (item, index, input) {
|
this.cart.forEach(function (item, index, input) {
|
||||||
goodsTotalMoney += item.price * item.nums
|
goodsTotalMoney += item.price * item.nums
|
||||||
})
|
})
|
||||||
//this.totalprice = this.$common.formatMoney(goodsTotalMoney, 2, '')
|
this.totalprice = parseFloat(goodsTotalMoney).toFixed(2);
|
||||||
this.totalprice = parseFloat(formatter.formatMoney(goodsTotalMoney))
|
console.log(this.totalprice);
|
||||||
},
|
},
|
||||||
toNumberChange: function (e) {
|
toNumberChange: function (e) {
|
||||||
console.log(e);
|
|
||||||
this.$u.throttle(this.numberChange(e), 500)
|
this.$u.throttle(this.numberChange(e), 500)
|
||||||
},
|
},
|
||||||
numberChange: function (e) {
|
numberChange: function (e) {
|
||||||
@@ -221,6 +217,11 @@
|
|||||||
var item = this.items[e.name];
|
var item = this.items[e.name];
|
||||||
var nums = e.value;
|
var nums = e.value;
|
||||||
|
|
||||||
|
uni.showLoading({
|
||||||
|
title: '加载中',
|
||||||
|
mask: true
|
||||||
|
});
|
||||||
|
|
||||||
if (nums > 0) {
|
if (nums > 0) {
|
||||||
let data = {
|
let data = {
|
||||||
ProductId: item.productId,
|
ProductId: item.productId,
|
||||||
@@ -267,9 +268,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_this.getGoodsTotalMoney();
|
_this.getGoodsTotalMoney();
|
||||||
|
setTimeout(function () {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 500);
|
||||||
} else {
|
} else {
|
||||||
_this.$u.toast(res.msg);
|
_this.$u.toast(res.msg);
|
||||||
|
setTimeout(function () {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -277,7 +283,6 @@
|
|||||||
var deleteId = 0;
|
var deleteId = 0;
|
||||||
for (var i = 0; i < _this.cart.length; i++) {
|
for (var i = 0; i < _this.cart.length; i++) {
|
||||||
if (_this.cart[i].key == e.name && _this.cart[i].productId == item.productId) {
|
if (_this.cart[i].key == e.name && _this.cart[i].productId == item.productId) {
|
||||||
//移除数据库
|
|
||||||
deleteIndex = i;
|
deleteIndex = i;
|
||||||
deleteId = _this.cart[i].id;
|
deleteId = _this.cart[i].id;
|
||||||
}
|
}
|
||||||
@@ -290,6 +295,13 @@
|
|||||||
if (res.status) {
|
if (res.status) {
|
||||||
_this.cart.splice(deleteIndex, 1);
|
_this.cart.splice(deleteIndex, 1);
|
||||||
_this.getGoodsTotalMoney();
|
_this.getGoodsTotalMoney();
|
||||||
|
setTimeout(function () {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 500);
|
||||||
|
} else {
|
||||||
|
setTimeout(function () {
|
||||||
|
uni.hideLoading();
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -300,9 +312,11 @@
|
|||||||
this.$u.toast('请先选择商品')
|
this.$u.toast('请先选择商品')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
var totalprice = parseFloat(formatter.formatMoney(this.totalprice));
|
var totalprice = parseFloat(this.totalprice);
|
||||||
var startBuyPrice = parseFloat(formatter.formatMoney(this.model.startBuyPrice));
|
var startBuyPrice = parseFloat(this.model.startBuyPrice);
|
||||||
if (totalprice < startBuyPrice) {
|
console.log('商品价格:' + this.totalprice);
|
||||||
|
console.log('起购价格:' + this.model.startBuyPrice);
|
||||||
|
if (this.totalprice < this.model.startBuyPrice) {
|
||||||
this.$u.toast('最小购买价格为' + this.model.startBuyPrice + '元,请增加购买产品')
|
this.$u.toast('最小购买价格为' + this.model.startBuyPrice + '元,请增加购买产品')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user