<template>
|
<view class="demand-page">
|
<PageHeader title="采购需求"
|
@back="goBack" />
|
|
<!-- 筛选区域 -->
|
<view class="search-section">
|
<view class="search-bar">
|
<view class="search-input">
|
<up-input class="search-text"
|
v-model="queryParams.productName"
|
placeholder="请输入产品名称"
|
clearable
|
@change="handleSearch" />
|
</view>
|
</view>
|
<view class="search-bar">
|
<view class="search-input">
|
<up-input class="search-text"
|
v-model="queryParams.productModel"
|
placeholder="请输入规格型号"
|
clearable
|
@change="handleSearch" />
|
</view>
|
<view class="filter-button"
|
@click="showStatusSheet = true">
|
<text class="filter-text">{{ statusLabel }}</text>
|
<up-icon name="arrow-down"
|
size="14"
|
color="#999999"></up-icon>
|
</view>
|
</view>
|
</view>
|
|
<!-- 列表区域 -->
|
<view v-if="list.length > 0"
|
class="ledger-list">
|
<view v-for="item in list"
|
:key="item.id"
|
class="ledger-item">
|
<view class="item-header">
|
<view class="item-left">
|
<view class="document-icon">
|
<up-icon name="shopping-cart"
|
size="16"
|
color="#ffffff"></up-icon>
|
</view>
|
<text class="item-id">{{ item.sourceBomNo || "无来源BOM" }}</text>
|
</view>
|
<up-tag :text="statusText(item.status)"
|
:type="statusType(item.status)"
|
size="mini" />
|
</view>
|
<up-divider></up-divider>
|
<view class="item-details">
|
<view class="detail-row">
|
<text class="detail-label">产品名称</text>
|
<text class="detail-value">{{ item.productName || "-" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">规格型号</text>
|
<text class="detail-value">{{ item.productModel || "-" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">单位</text>
|
<text class="detail-value">{{ item.unit || "-" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">缺口需求量</text>
|
<text class="detail-value danger">{{ num(item.demandQuantity) }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">库存储备快照</text>
|
<text class="detail-value">{{ num(item.stockQuantity) }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">来源BOM编号</text>
|
<text class="detail-value">{{ item.sourceBomNo || "-" }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">创建时间</text>
|
<text class="detail-value">{{ item.createTime || "-" }}</text>
|
</view>
|
</view>
|
<view class="action-buttons">
|
<up-button v-if="isPending(item)"
|
class="action-btn"
|
size="small"
|
type="primary"
|
@click="handleChangeStatus(item, 1)">标记已转采购</up-button>
|
<up-button v-if="isPending(item)"
|
class="action-btn"
|
size="small"
|
type="warning"
|
@click="handleChangeStatus(item, 2)">取消</up-button>
|
<up-button class="action-btn"
|
size="small"
|
type="error"
|
plain
|
:disabled="!isPending(item)"
|
@click="handleDelete(item)">删除</up-button>
|
</view>
|
</view>
|
<up-loadmore :status="pageStatus" />
|
</view>
|
<view v-else
|
class="no-data">
|
<up-empty text="暂无采购需求"
|
mode="data"></up-empty>
|
</view>
|
|
<!-- 状态筛选 -->
|
<up-action-sheet :show="showStatusSheet"
|
:actions="statusOptions"
|
title="选择状态"
|
@select="handleStatusSelect"
|
@close="showStatusSheet = false" />
|
</view>
|
</template>
|
|
<script setup>
|
import { reactive, ref } from "vue";
|
import { onReachBottom, onShow } from "@dcloudio/uni-app";
|
import { listPage, changeStatus, del } from "@/api/procurementManagement/procurementDemand";
|
import PageHeader from "@/components/PageHeader.vue";
|
|
const STATUS_MAP = {
|
0: { text: "待处理", type: "warning" },
|
1: { text: "已转采购", type: "success" },
|
2: { text: "已取消", type: "info" },
|
};
|
|
const queryParams = reactive({
|
productName: "",
|
productModel: "",
|
status: "",
|
});
|
const list = ref([]);
|
const pageStatus = ref("loadmore");
|
const page = reactive({
|
current: 1,
|
size: 10,
|
total: 0,
|
});
|
|
const showStatusSheet = ref(false);
|
const statusOptions = [
|
{ name: "全部", value: "" },
|
{ name: "待处理", value: 0 },
|
{ name: "已转采购", value: 1 },
|
{ name: "已取消", value: 2 },
|
];
|
const statusLabel = ref("全部状态");
|
|
// decimal 可能是字符串,统一转数字兜底
|
const num = val => Number(val) || 0;
|
|
const statusText = status => (STATUS_MAP[Number(status)] || STATUS_MAP[0]).text;
|
const statusType = status => (STATUS_MAP[Number(status)] || STATUS_MAP[0]).type;
|
// 仅待处理可操作(删除也由后端兜底校验)
|
const isPending = item => Number(item.status) === 0;
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const handleSearch = () => {
|
page.current = 1;
|
pageStatus.value = "loadmore";
|
list.value = [];
|
getList();
|
};
|
|
const getList = () => {
|
if (pageStatus.value === "loading" || pageStatus.value === "nomore") return;
|
|
pageStatus.value = "loading";
|
listPage({
|
current: page.current,
|
size: page.size,
|
productName: queryParams.productName,
|
productModel: queryParams.productModel,
|
status: queryParams.status,
|
})
|
.then(res => {
|
const records = res?.data?.records || res?.records || [];
|
const total = res?.data?.total || res?.total || 0;
|
|
if (page.current === 1) {
|
list.value = records;
|
} else {
|
list.value = [...list.value, ...records];
|
}
|
|
page.total = total;
|
if (list.value.length >= total) {
|
pageStatus.value = "nomore";
|
} else {
|
pageStatus.value = "loadmore";
|
page.current++;
|
}
|
})
|
.catch(() => {
|
// 错误提示由 request 统一处理
|
pageStatus.value = "loadmore";
|
});
|
};
|
|
const handleStatusSelect = action => {
|
queryParams.status = action.value;
|
statusLabel.value = action.value === "" ? "全部状态" : action.name;
|
showStatusSheet.value = false;
|
handleSearch();
|
};
|
|
const handleChangeStatus = (item, status) => {
|
const actionText = status === 1 ? "标记为已转采购" : "取消";
|
uni.showModal({
|
title: "提示",
|
content: `确定将该采购需求${actionText}吗?`,
|
success: res => {
|
if (!res.confirm) return;
|
uni.showLoading({ title: "处理中...", mask: true });
|
changeStatus({ ids: item.id, status })
|
.then(() => {
|
uni.hideLoading();
|
uni.showToast({ title: "操作成功", icon: "none" });
|
handleSearch();
|
})
|
.catch(() => {
|
uni.hideLoading();
|
});
|
},
|
});
|
};
|
|
const handleDelete = item => {
|
uni.showModal({
|
title: "删除确认",
|
content: "确定删除该采购需求吗?",
|
success: res => {
|
if (!res.confirm) return;
|
uni.showLoading({ title: "处理中...", mask: true });
|
del([item.id])
|
.then(() => {
|
uni.hideLoading();
|
uni.showToast({ title: "删除成功", icon: "none" });
|
handleSearch();
|
})
|
.catch(() => {
|
// 非待处理状态后端会返回提示,此处不再重复弹窗
|
uni.hideLoading();
|
});
|
},
|
});
|
};
|
|
onReachBottom(() => {
|
getList();
|
});
|
|
onShow(() => {
|
handleSearch();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/styles/procurement-common.scss";
|
|
.demand-page {
|
min-height: 100vh;
|
background: #f8f9fa;
|
}
|
|
.search-bar + .search-bar {
|
margin-top: 16rpx;
|
}
|
|
// 公共样式里 .filter-button 是 40px 见方的图标按钮,这里要放状态文案,需按内容撑开
|
.filter-button {
|
width: auto;
|
min-width: 40px;
|
padding: 0 12px;
|
flex-shrink: 0;
|
background: #f5f5f5;
|
}
|
|
.filter-text {
|
font-size: 24rpx;
|
color: #333;
|
margin-right: 4rpx;
|
white-space: nowrap;
|
}
|
|
.no-data {
|
padding-top: 100rpx;
|
text-align: center;
|
color: #999;
|
font-size: 28rpx;
|
}
|
|
.action-buttons {
|
display: flex;
|
justify-content: flex-end;
|
gap: 15rpx;
|
padding: 0 30rpx 30rpx;
|
flex-wrap: wrap;
|
}
|
|
.action-btn {
|
width: calc(33.33% - 10rpx);
|
margin: 0 !important;
|
margin-bottom: 15rpx !important;
|
}
|
</style>
|