✨ 限制毛利分析查询日期为一个月
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :xs="24" :sm="12" :lg="8">
|
<el-col :xs="24" :sm="12" :lg="8">
|
||||||
<el-form-item label="计费日期" class="filter-item" required>
|
<el-form-item label="计费日期" class="filter-item" :error="dateRangeError" required>
|
||||||
<el-date-picker
|
<el-date-picker
|
||||||
v-model="dateRange"
|
v-model="dateRange"
|
||||||
type="daterange"
|
type="daterange"
|
||||||
@@ -270,7 +270,12 @@ import { exportAsync } from '@/utils/excelExport'
|
|||||||
|
|
||||||
const { customer_area, bms_currency } = useDict('customer_area', 'bms_currency')
|
const { customer_area, bms_currency } = useDict('customer_area', 'bms_currency')
|
||||||
const multiValueFilterLimit = 2000
|
const multiValueFilterLimit = 2000
|
||||||
const dateRange = ref([formatLocalDate(-30), formatLocalDate(0)])
|
const dateRange = ref(defaultDateRange())
|
||||||
|
const dateRangeError = computed(() => {
|
||||||
|
if (!hasCompleteDateRange()) return ''
|
||||||
|
const [start, end] = dateRange.value
|
||||||
|
return end > maxEndDate(start) ? '计费日期最多查询一个月' : ''
|
||||||
|
})
|
||||||
const arBillStatus = ref('')
|
const arBillStatus = ref('')
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
customerArea: '',
|
customerArea: '',
|
||||||
@@ -342,15 +347,31 @@ function createRateForm(row = {}) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function formatLocalDate(offset) {
|
function formatLocalDate(date) {
|
||||||
const date = new Date()
|
|
||||||
date.setDate(date.getDate() + offset)
|
|
||||||
const year = date.getFullYear()
|
const year = date.getFullYear()
|
||||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
const day = String(date.getDate()).padStart(2, '0')
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
return `${year}-${month}-${day}`
|
return `${year}-${month}-${day}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 次月没有对应日期时取月末,再减一天;起止日期均包含当天。
|
||||||
|
function maxEndDate(start) {
|
||||||
|
const [year, month, day] = start.split('-').map(Number)
|
||||||
|
const lastDayOfNextMonth = new Date(year, month + 1, 0).getDate()
|
||||||
|
const limit = new Date(year, month, Math.min(day, lastDayOfNextMonth))
|
||||||
|
limit.setDate(limit.getDate() - 1)
|
||||||
|
return formatLocalDate(limit)
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultDateRange() {
|
||||||
|
const end = new Date()
|
||||||
|
const start = new Date(end.getFullYear(), end.getMonth(), end.getDate())
|
||||||
|
const endText = formatLocalDate(end)
|
||||||
|
start.setDate(start.getDate() - 31)
|
||||||
|
while (maxEndDate(formatLocalDate(start)) < endText) start.setDate(start.getDate() + 1)
|
||||||
|
return [formatLocalDate(start), endText]
|
||||||
|
}
|
||||||
|
|
||||||
function buildQuery(paged = true) {
|
function buildQuery(paged = true) {
|
||||||
const params = { ...query }
|
const params = { ...query }
|
||||||
if (arBillStatus.value) params.arBillStatus = arBillStatus.value
|
if (arBillStatus.value) params.arBillStatus = arBillStatus.value
|
||||||
@@ -394,6 +415,10 @@ function validateRequiredFilters(showMessage = true) {
|
|||||||
if (showMessage) ElMessage.warning('请选择完整的计费日期')
|
if (showMessage) ElMessage.warning('请选择完整的计费日期')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if (dateRangeError.value) {
|
||||||
|
if (showMessage) ElMessage.warning(dateRangeError.value)
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,7 +468,7 @@ function handleReset() {
|
|||||||
Object.keys(query).forEach(key => { query[key] = '' })
|
Object.keys(query).forEach(key => { query[key] = '' })
|
||||||
query.customerArea = customer_area.value[0]?.value ?? ''
|
query.customerArea = customer_area.value[0]?.value ?? ''
|
||||||
arBillStatus.value = ''
|
arBillStatus.value = ''
|
||||||
dateRange.value = [formatLocalDate(-30), formatLocalDate(0)]
|
dateRange.value = defaultDateRange()
|
||||||
hasSearched.value = false
|
hasSearched.value = false
|
||||||
clearReportResults()
|
clearReportResults()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user