<template>
|
<view class="account-detail">
|
<PageHeader title="选择产品"
|
@back="goBack" />
|
<view class="search-bar">
|
<view class="search-input">
|
<up-input v-model="query.productName"
|
placeholder="产品名称"
|
clearable
|
@confirm="handleQuery" />
|
</view>
|
<view class="search-input">
|
<up-input v-model="query.model"
|
placeholder="规格型号"
|
clearable
|
@confirm="handleQuery" />
|
</view>
|
<view class="filter-button"
|
@click="handleQuery">
|
<up-icon name="search"
|
size="24"
|
color="#999"></up-icon>
|
</view>
|
</view>
|
<scroll-view scroll-y
|
class="list-scroll"
|
@scrolltolower="loadMore">
|
<view v-if="loading"
|
class="loading-state">
|
<up-loading-icon text="加载中..."></up-loading-icon>
|
</view>
|
<view v-else-if="list.length === 0"
|
class="no-data">
|
<up-empty mode="data"
|
text="暂无数据"></up-empty>
|
</view>
|
<view v-else
|
class="list">
|
<view v-for="row in list"
|
:key="row.id"
|
class="card"
|
@click="selectRow(row)">
|
<view class="card-title">
|
<text class="name">{{ row.productName }}</text>
|
</view>
|
<view class="card-sub">
|
<text class="label">规格</text>
|
<text class="value">{{ row.model || '-' }}</text>
|
</view>
|
<view class="card-sub">
|
<text class="label">单位</text>
|
<text class="value">{{ row.unit || '-' }}</text>
|
</view>
|
</view>
|
<up-loadmore :status="loadStatus" />
|
</view>
|
</scroll-view>
|
</view>
|
</template>
|
|
<script setup>
|
import { onMounted, reactive, ref, getCurrentInstance } from "vue";
|
import PageHeader from "@/components/PageHeader.vue";
|
import { pageModel } from "@/api/basicData/product.js";
|
|
const loading = ref(false);
|
const loadStatus = ref("loadmore");
|
const list = ref([]);
|
const total = ref(0);
|
const page = reactive({ current: 1, size: 20 });
|
const topParentProductId = ref(undefined);
|
|
const query = reactive({
|
productName: "",
|
model: "",
|
});
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
const fetchList = () => {
|
if (loading.value) return;
|
loading.value = true;
|
loadStatus.value = "loading";
|
pageModel({
|
productName: query.productName,
|
model: query.model,
|
current: page.current,
|
size: page.size,
|
topProductParentId: topParentProductId.value,
|
})
|
.then(res => {
|
const records = res?.records || res?.data?.records || res?.data || [];
|
const rows = Array.isArray(records) ? records : [];
|
const normalized = rows.map(r => {
|
const modelId = r?.id ?? r?.productModelId ?? r?.materialModelId;
|
return modelId == null ? r : { ...r, id: modelId };
|
});
|
list.value = page.current === 1 ? normalized : [...list.value, ...normalized];
|
total.value = Number(res?.total ?? res?.data?.total ?? list.value.length);
|
loadStatus.value = list.value.length >= total.value ? "nomore" : "loadmore";
|
})
|
.catch(() => {
|
loadStatus.value = "loadmore";
|
})
|
.finally(() => {
|
loading.value = false;
|
});
|
};
|
|
const handleQuery = () => {
|
page.current = 1;
|
list.value = [];
|
fetchList();
|
};
|
|
const loadMore = () => {
|
if (loadStatus.value !== "loadmore") return;
|
page.current++;
|
fetchList();
|
};
|
|
const selectRow = row => {
|
const instance = getCurrentInstance();
|
const eventChannel = instance?.proxy?.getOpenerEventChannel?.();
|
if (eventChannel?.emit) {
|
eventChannel.emit("selected", row);
|
} else {
|
uni.$emit("stockManagement:selectedProductModel", row);
|
}
|
goBack();
|
};
|
|
onMounted(() => {
|
const options = getCurrentPages()?.slice(-1)?.[0]?.options || {};
|
topParentProductId.value = options.topParentProductId ? Number(options.topParentProductId) : undefined;
|
fetchList();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
@import "@/static/scss/form-common.scss";
|
|
.search-bar {
|
margin: 20rpx;
|
background-color: #fff;
|
border-radius: 16rpx;
|
padding: 0 30rpx;
|
height: 80rpx;
|
display: flex;
|
align-items: center;
|
gap: 16rpx;
|
|
.search-input {
|
flex: 1;
|
min-width: 0;
|
}
|
|
:deep(.u-input) {
|
background-color: #f2f2f2;
|
border-radius: 40rpx;
|
padding: 0 30rpx;
|
height: 80rpx;
|
margin-bottom: 0;
|
}
|
|
:deep(.u-input__content__field-wrapper__field) {
|
height: 80rpx;
|
line-height: 80rpx;
|
}
|
|
.filter-button {
|
width: 80rpx;
|
height: 80rpx;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
flex-shrink: 0;
|
}
|
}
|
|
.list-scroll {
|
flex: 1;
|
min-height: 0;
|
}
|
|
.list {
|
padding: 0 20rpx 20rpx 20rpx;
|
}
|
|
.card {
|
background: #fff;
|
border-radius: 16rpx;
|
padding: 24rpx;
|
margin-bottom: 20rpx;
|
}
|
|
.card-title {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 10rpx;
|
}
|
|
.name {
|
font-size: 30rpx;
|
font-weight: 600;
|
color: #303133;
|
}
|
|
.card-sub {
|
display: flex;
|
justify-content: space-between;
|
margin-top: 10rpx;
|
font-size: 26rpx;
|
}
|
|
.label {
|
color: #909399;
|
}
|
|
.value {
|
color: #303133;
|
font-weight: 500;
|
}
|
|
.loading-state,
|
.no-data {
|
padding-top: 200rpx;
|
}
|
</style>
|