VUE项目js计算两个日期之前所差年月日
var mons = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]function isLeapYear(year) {varr = year / 100if (r === parseInt(r)) {r = year / 400return r === parseInt(r)}...
·
var mons = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
function isLeapYear(year) {
var r = year / 100
if (r === parseInt(r)) {
r = year / 400
return r === parseInt(r)
}
r = year / 4
if (r === parseInt(r)) {
return true
}
return false
}
function getDaysOfMonth(month, year) {
if (month === 2 && isLeapYear(year)) {
return 29
}
return mons[month]
}
function getMonthsOfYear(year) {
if (isLeapYear(year)) {
return 366
}
return 365
}
function diff(s1, s2) {
var arr1 = s1.split('-').map(Number)
var arr2 = s2.split('-').map(Number)
var [year, month, day] = arr2.map((n, i) => n - arr1[i])
if (day < 0) {
day += getDaysOfMonth(arr2[1], arr2[0])
month--
}
if (month < 0) {
month += getMonthsOfYear(arr2[0])
year--
}
return [year, month, day]
}
打印接口浏览打印页面回显数据
printInitialCheckTable(row) {
getPrint({
chdeId: row.chdeChilId
}).then(((res) => {
if (res.data.code && res.data.code === '100000') {
this.initialCheckInfo = res.data.data
//计算死亡时龄
var d1_str = this.initialCheckInfo.chilBirthDate
var d2_str = this.initialCheckInfo.chdeDeathTime
this.$set(this.initialCheckInfo, 'deathage', diff(d1_str, d2_str))
this.$nextTick(() => {
this.handlePrint('print-table')
})
} else {
this.$Message.error({
content: res.data.message,
duration: 3,
closable: true
})
this.$nextTick(() => {
this.handlePrint('print-table')
})
}
}))
},
data中初始化值
initialCheckInfo: {
deathage:[0,0,0]
},
打印页面回显数据
<td colspan="2" style="width:50%;padding:5px;">
<span style="padding-right:20px">死亡日龄</span>
<span>{{dataSource.deathage[1]}}月{{dataSource.deathage[2]}}天</span>
</td>
更多推荐
已为社区贡献4条内容
所有评论(0)