From 4b8f0d1cb618b00303502681159b0ad6bc4404a6 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 24 三月 2026 14:54:40 +0800
Subject: [PATCH] fix: 真机运行时,日期组件默认当前日期
---
src/pages/inventoryManagement/stockReport/index.vue | 177 +++++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 141 insertions(+), 36 deletions(-)
diff --git a/src/pages/inventoryManagement/stockReport/index.vue b/src/pages/inventoryManagement/stockReport/index.vue
index 1eba7a4..eba56c3 100644
--- a/src/pages/inventoryManagement/stockReport/index.vue
+++ b/src/pages/inventoryManagement/stockReport/index.vue
@@ -15,7 +15,37 @@
</view>
</view>
- <!-- 鏃堕棿閫夋嫨鍖哄煙宸插幓闄わ紝浣跨敤榛樿鏃ユ湡閫昏緫 -->
+ <!-- 鏃堕棿閫夋嫨鍖哄煙 -->
+ <view class="search-section">
+ <!-- 鏃ユ姤锛氶�夋嫨骞存湀鏃� -->
+ <view v-if="searchForm.reportType === 'daily'" class="search-row">
+ <view class="date-picker" @click="openDatePicker('single')">
+ <text>{{ searchForm.singleDate || '璇烽�夋嫨鏃ユ湡' }}</text>
+ </view>
+ </view>
+
+ <!-- 鏈堟姤锛氶�夋嫨骞存湀 -->
+ <view v-else-if="searchForm.reportType === 'monthly'" class="search-row">
+ <view class="date-picker" @click="openDatePicker('startMonth')">
+ <text>{{ searchForm.startMonth || '璇烽�夋嫨寮�濮嬫湀浠�' }}</text>
+ </view>
+ ~
+ <view class="date-picker" @click="openDatePicker('endMonth')">
+ <text>{{ searchForm.endMonth || '璇烽�夋嫨缁撴潫鏈堜唤' }}</text>
+ </view>
+ </view>
+
+ <!-- 杩涘嚭瀛橈細閫夋嫨骞存湀鏃ユ椂闂磋寖鍥� -->
+ <view v-else-if="searchForm.reportType === 'inout'" class="search-row">
+ <view class="date-picker" @click="openDatePicker('startDate')">
+ <text>{{ searchForm.startDate || '璇烽�夋嫨寮�濮嬫棩鏈�' }}</text>
+ </view>
+ ~
+ <view class="date-picker" @click="openDatePicker('endDate')">
+ <text>{{ searchForm.endDate || '璇烽�夋嫨缁撴潫鏃ユ湡' }}</text>
+ </view>
+ </view>
+ </view>
<!-- 鍒楄〃 + 婊氬姩鍒嗛〉 -->
<view class="list-section">
@@ -39,6 +69,8 @@
<view class="row" v-if="searchForm.reportType === 'inout'"><text class="l">鍑哄簱鏁伴噺</text><text class="r">{{ item.totalStockOut }}</text></view>
<view class="row"><text class="l">鐜板湪搴撳瓨</text><text class="r highlight">{{ item.currentStock }}</text></view>
<view class="row" v-if="item.createBy"><text class="l">鍏ュ簱浜�</text><text class="r">{{ item.createBy }}</text></view>
+ <view class="row" v-if="item.currentWeight"><text class="l">鐜板噣閲�(鍚�)</text><text class="r">{{ item.currentWeight }}</text></view>
+ <view class="row" v-if="item.recordType"><text class="l">鏉ユ簮</text><text class="r">{{ getRecordType(item.recordType) }}</text></view>
</view>
</view>
<view class="load-more-wrap">
@@ -48,14 +80,13 @@
<view v-else class="no-data">鏆傛棤鏁版嵁</view>
</view>
- <up-popup :show="showDatePicker" mode="bottom" @close="showDatePicker = false">
- <up-datetime-picker
- v-model="dateValue"
- :mode="datePickerMode"
- @confirm="onDateConfirm"
- @cancel="showDatePicker = false"
- />
- </up-popup>
+ <up-datetime-picker
+ v-model="dateValue"
+ :mode="datePickerMode"
+ :show="showDatePicker"
+ @confirm="onDateConfirm"
+ @cancel="showDatePicker = false"
+ />
</view>
</template>
@@ -63,12 +94,12 @@
import { ref, reactive, toRefs, computed, watch } from 'vue'
import dayjs from 'dayjs'
import PageHeader from '@/components/PageHeader.vue'
-import { formatDateToYMD } from '@/utils/ruoyi'
-import { onShow, onReachBottom } from '@dcloudio/uni-app'
+import { onShow } from '@dcloudio/uni-app'
import {
getStockInventoryReportList,
getStockInventoryInAndOutReportList
} from '@/api/inventoryManagement/stockInventory.js'
+import {findAllQualifiedStockInRecordTypeOptions} from "@/api/basicData/enum";
const reportTypes = [
{ label: '鏃ユ姤', value: 'daily' },
@@ -88,13 +119,14 @@
startMonth: '',
endMonth: '',
startDate: '',
- endDate: ''
+ endDate: '',
}
})
+
const { searchForm } = toRefs(data)
const datePickerMode = computed(() => {
- if (datePickerTarget.value === 'startMonth' || datePickerTarget.value === 'endMonth') return 'month'
+ if (datePickerTarget.value === 'startMonth' || datePickerTarget.value === 'endMonth') return 'year-month'
return 'date'
})
@@ -112,16 +144,27 @@
if (searchForm.value.reportType === 'daily') {
p.reportDate = searchForm.value.singleDate
} else if (searchForm.value.reportType === 'monthly') {
- p.startMonth = searchForm.value.startMonth
- p.endMonth = searchForm.value.endMonth
- } else if (searchForm.value.reportType === 'monthly') {
- p.startMonth = searchForm.value.startMonth
- p.endMonth = searchForm.value.endMonth
+ p.startMonth = searchForm.value.startMonth + '-01'
+ p.endMonth = searchForm.value.endMonth + '-01'
} else {
- p.startDate = searchForm.value.startDate
- p.endDate = searchForm.value.endDate
+ p.startMonth = searchForm.value.startDate
+ p.endMonth = searchForm.value.endDate
}
return p
+}
+
+const stockRecordTypeOptions = ref([])
+
+const getRecordType = (recordType) => {
+ return stockRecordTypeOptions.value.find(item => item.value === recordType)?.label || ''
+}
+
+// 鑾峰彇鏉ユ簮绫诲瀷閫夐」
+const fetchStockRecordTypeOptions = () => {
+ findAllQualifiedStockInRecordTypeOptions()
+ .then(res => {
+ stockRecordTypeOptions.value = res.data;
+ })
}
const getList = () => {
@@ -170,24 +213,82 @@
getList()
}
+const toPickerTimestamp = (val, target) => {
+ if (!val) return Date.now()
+ let parsed
+ if (target === 'startMonth' || target === 'endMonth') {
+ parsed = dayjs(`${val}-01`).valueOf()
+ } else {
+ parsed = dayjs(val).valueOf()
+ }
+ return Number.isNaN(parsed) ? Date.now() : parsed
+}
+
+const formatPickerDate = (value, isMonth) => {
+ const parsed = dayjs(value)
+ if (!parsed.isValid()) return ''
+ return parsed.format(isMonth ? 'YYYY-MM' : 'YYYY-MM-DD')
+}
+
const openDatePicker = (target) => {
- datePickerTarget.value = target
let val = ''
- if (target === 'single') val = searchForm.value.singleDate
- else if (target === 'startMonth') val = searchForm.value.startMonth
- else if (target === 'endMonth') val = searchForm.value.endMonth
- dateValue.value = val ? new Date(val).getTime() : Date.now()
+ datePickerTarget.value = target
+ switch (target) {
+ case 'single':
+ val = searchForm.value.singleDate
+ break
+ case 'startMonth':
+ val = searchForm.value.startMonth
+ break
+ case 'endMonth':
+ val = searchForm.value.endMonth
+ break
+ case 'startDate':
+ val = searchForm.value.startDate
+ break
+ case 'endDate':
+ val = searchForm.value.endDate
+ break
+ }
+ dateValue.value = toPickerTimestamp(val, target)
showDatePicker.value = true
}
const onDateConfirm = (e) => {
const isMonth = datePickerTarget.value === 'startMonth' || datePickerTarget.value === 'endMonth'
- const str = isMonth ? dayjs(e.value).format('YYYY-MM') : formatDateToYMD(e.value)
- if (datePickerTarget.value === 'single') searchForm.value.singleDate = str
- else if (datePickerTarget.value === 'startMonth') searchForm.value.startMonth = str
- else if (datePickerTarget.value === 'endMonth') searchForm.value.endMonth = str
- showDatePicker.value = false
- handleQuery()
+ const str = formatPickerDate(e.value, isMonth)
+ if (!str) {
+ showDatePicker.value = false
+ uni.showToast({ title: '鏃ユ湡鏍煎紡鏃犳晥', icon: 'none' })
+ return
+ }
+
+ if (datePickerTarget.value === 'single') {
+ searchForm.value.singleDate = str
+ showDatePicker.value = false
+ handleQuery()
+ } else if (datePickerTarget.value === 'startMonth') {
+ searchForm.value.startMonth = str
+ showDatePicker.value = false
+ setTimeout(() => {
+ openDatePicker('endMonth')
+ }, 300)
+ } else if (datePickerTarget.value === 'endMonth') {
+ searchForm.value.endMonth = str
+ showDatePicker.value = false
+ handleQuery()
+ } else if (datePickerTarget.value === 'startDate') {
+ searchForm.value.startDate = str
+ showDatePicker.value = false
+ // 纭寮�濮嬫棩鏈熷悗锛屾墦寮�缁撴潫鏃ユ湡閫夋嫨妗�
+ setTimeout(() => {
+ openDatePicker('endDate')
+ }, 300)
+ } else if (datePickerTarget.value === 'endDate') {
+ searchForm.value.endDate = str
+ showDatePicker.value = false
+ handleQuery()
+ }
}
// 鍒濆鍖栵細鏃ユ姤榛樿浠婂ぉ锛屾湀鎶ラ粯璁ゆ湰鏈堬紝杩涘嚭瀛橀粯璁ゆ渶杩�7澶�
@@ -197,14 +298,15 @@
searchForm.value.singleDate = today.format('YYYY-MM-DD')
}
if (!searchForm.value.startMonth || !searchForm.value.endMonth) {
- const startOfMonth = today.startOf('month').format('YYYY-MM-DD')
- const endOfMonth = today.endOf('month').format('YYYY-MM-DD')
- searchForm.value.startMonth = startOfMonth
- searchForm.value.endMonth = endOfMonth
+ searchForm.value.startMonth = today.format('YYYY-MM')
+ searchForm.value.endMonth = today.add(1, 'month').format('YYYY-MM')
}
if (!searchForm.value.startDate || !searchForm.value.endDate) {
searchForm.value.endDate = today.format('YYYY-MM-DD')
searchForm.value.startDate = today.subtract(6, 'day').format('YYYY-MM-DD')
+ }
+ if (!datePickerTarget.value) {
+ dateValue.value = toPickerTimestamp(searchForm.value.singleDate, 'single')
}
}
@@ -219,7 +321,10 @@
onShow(() => {
initDefaultDates()
handleQuery()
+ fetchStockRecordTypeOptions()
})
+
+initDefaultDates()
const goBack = () => uni.navigateBack()
</script>
@@ -271,4 +376,4 @@
.card-body .l { color: #666; } .card-body .r { color: #333; } .card-body .r.highlight { color: #2979ff; font-weight: 500; }
.no-data { text-align: center; padding: 60rpx 0; color: #999; font-size: 28rpx; }
.load-more-wrap { padding: 24rpx 0 8rpx; }
-</style>
+</style>
\ No newline at end of file
--
Gitblit v1.9.3