spring
13 小时以前 4b8f0d1cb618b00303502681159b0ad6bc4404a6
src/pages/consumablesLogistics/stockReport/index.vue
@@ -12,6 +12,37 @@
        <text>{{ t.label }}</text>
      </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">
      <view class="section-header">
        <text class="table-title">{{ tableTitle }}</text>
@@ -33,6 +64,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">
@@ -41,14 +74,13 @@
      </view>
      <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>
@@ -56,10 +88,11 @@
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 { getConsumablesInReportList, getConsumablesInInAndOutReportList } from "@/api/consumablesLogistics/consumablesIn.js";
import {
  findAllQualifiedStockInRecordTypeOptions,
} from "@/api/basicData/enum.js";
const reportTypes = [
  { label: "日报", value: "daily" },
  { label: "月报", value: "monthly" },
@@ -84,7 +117,7 @@
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";
});
@@ -102,17 +135,28 @@
  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 ? `${searchForm.value.startMonth}-01` : "";
    p.endMonth = searchForm.value.endMonth ? `${searchForm.value.endMonth}-01` : "";
  } else {
    p.startDate = searchForm.value.startDate;
    p.endDate = 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 = () => {
  const isFirstPage = page.current === 1;
@@ -160,24 +204,68 @@
  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();
  else if (target === "startDate") val = searchForm.value.startDate;
  else if (target === "endDate") val = searchForm.value.endDate;
  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();
  }
};
const initDefaultDates = () => {
@@ -186,14 +274,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");
  }
};
@@ -207,8 +296,11 @@
onShow(() => {
  initDefaultDates();
  handleQuery();
  fetchStockRecordTypeOptions();
});
initDefaultDates();
onReachBottom(() => loadMore());
const goBack = () => uni.navigateBack();