<template>
|
<view class="raw-material-page">
|
<PageHeader title="原材料" @back="goBack" />
|
|
<!-- 搜索与筛选 -->
|
<view class="search-section">
|
<up-search
|
placeholder="请输入批号"
|
v-model="searchForm.batchNo"
|
@search="handleQuery"
|
@custom="handleQuery"
|
@clear="handleQuery"
|
:show-action="true"
|
action-text="搜索"
|
:animation="true"
|
></up-search>
|
<view class="filter-row">
|
<view class="filter-item" @click="showTypeSelect = true">
|
<text>{{ typeLabel }}</text>
|
<up-icon name="arrow-down" size="14" color="#999"></up-icon>
|
</view>
|
<view class="filter-item" @click="showStatusSelect = true">
|
<text>{{ statusLabel }}</text>
|
<up-icon name="arrow-down" size="14" color="#999"></up-icon>
|
</view>
|
</view>
|
</view>
|
|
<!-- 列表区域 -->
|
<view class="list-container" v-if="tableData.length > 0">
|
<view v-for="(item, index) in tableData" :key="index" class="list-item">
|
<view class="item-header">
|
<text class="product-name">{{ item.productName }}</text>
|
<up-tag :text="item.inspectState ? '已提交' : '未提交'" :type="item.inspectState ? 'success' : 'warning'" size="mini"></up-tag>
|
</view>
|
<view class="item-content">
|
<view class="item-row">
|
<text class="item-label">批次号:</text>
|
<text class="item-value">{{ item.batchNo }}</text>
|
</view>
|
<view class="item-row">
|
<text class="item-label">检验类型:</text>
|
<text class="item-value">{{ item.checkTypeText || '-' }}</text>
|
</view>
|
<view class="item-row">
|
<text class="item-label">规格型号:</text>
|
<text class="item-value">{{ item.model || '-' }}</text>
|
</view>
|
<view class="item-row">
|
<text class="item-label">检测日期:</text>
|
<text class="item-value">{{ item.checkTime || '-' }}</text>
|
</view>
|
<view class="item-row">
|
<text class="item-label">检测结果:</text>
|
<up-tag :text="item.checkResult === 1 ? '合格' : '不合格'" :type="item.checkResult === 1 ? 'success' : 'error'" size="mini"></up-tag>
|
</view>
|
</view>
|
<view class="item-actions">
|
<up-button v-if="!item.inspectState" type="primary" size="mini" @click.stop="openForm('edit', item)">编辑</up-button>
|
<up-button v-if="!item.inspectState" type="success" size="mini" @click.stop="handleConfirmSubmit(item)">提交</up-button>
|
<up-button type="error" size="mini" @click.stop="handleDelete(item)">删除</up-button>
|
</view>
|
</view>
|
<view class="pagination-container">
|
<up-loadmore :status="loadStatus" @loadmore="getList" />
|
</view>
|
</view>
|
|
<view v-else class="no-data">
|
<up-empty mode="data" text="暂无数据"></up-empty>
|
</view>
|
|
<!-- 浮动新增按钮 -->
|
<view class="fab-button" @click="openForm('add')">
|
<up-icon name="plus" size="24" color="#ffffff"></up-icon>
|
</view>
|
|
<!-- 类型选择器 -->
|
<up-action-sheet
|
:actions="typeActions"
|
:show="showTypeSelect"
|
@close="showTypeSelect = false"
|
@select="selectType"
|
title="请选择类别"
|
></up-action-sheet>
|
|
<!-- 状态选择器 -->
|
<up-action-sheet
|
:actions="statusActions"
|
:show="showStatusSelect"
|
@close="showStatusSelect = false"
|
@select="selectStatus"
|
title="请选择提交状态"
|
></up-action-sheet>
|
</view>
|
</template>
|
|
<script setup>
|
import { ref, reactive, onMounted, computed } from 'vue';
|
import {
|
findRawMaterialListPage,
|
submitRawMaterial,
|
deleteRawMaterial
|
} from '@/api/qualityManagement/rawMaterial.js';
|
import { toast, showConfirm } from '@/utils/common';
|
import useUserStore from '@/store/modules/user';
|
|
const userStore = useUserStore();
|
|
const searchForm = reactive({
|
batchNo: '',
|
checkType: '',
|
inspectState: ''
|
});
|
|
const tableData = ref([]);
|
const page = reactive({
|
current: 1,
|
size: 20,
|
total: 0
|
});
|
const loadStatus = ref('loadmore');
|
|
const showTypeSelect = ref(false);
|
const typeActions = [
|
{ name: '全部', value: '' },
|
{ name: '入厂检', value: '0' },
|
{ name: '车间检', value: '1' },
|
{ name: '出厂检', value: '2' }
|
];
|
const typeLabel = computed(() => {
|
const action = typeActions.find(a => a.value === searchForm.checkType);
|
return action ? action.name : '全部类别';
|
});
|
|
const showStatusSelect = ref(false);
|
const statusActions = [
|
{ name: '全部', value: '' },
|
{ name: '未提交', value: '0' },
|
{ name: '已提交', value: '1' }
|
];
|
const statusLabel = computed(() => {
|
const action = statusActions.find(a => a.value === searchForm.inspectState);
|
return action ? action.name : '全部状态';
|
});
|
|
const getList = () => {
|
if (loadStatus.value === 'loading' || (page.total > 0 && tableData.value.length >= page.total)) return;
|
|
loadStatus.value = 'loading';
|
const params = {
|
batchNo: searchForm.batchNo || null,
|
checkType: searchForm.checkType || null,
|
inspectState: searchForm.inspectState || null,
|
current: page.current,
|
size: page.size
|
};
|
|
findRawMaterialListPage(params).then(res => {
|
const records = res?.data?.records || [];
|
if (page.current === 1) {
|
tableData.value = records;
|
} else {
|
tableData.value = [...tableData.value, ...records];
|
}
|
page.total = res?.data?.total || 0;
|
|
if (tableData.value.length >= page.total) {
|
loadStatus.value = 'nomore';
|
} else {
|
loadStatus.value = 'loadmore';
|
page.current++;
|
}
|
}).catch(() => {
|
loadStatus.value = 'loadmore';
|
});
|
};
|
|
const handleQuery = () => {
|
page.current = 1;
|
page.total = 0;
|
tableData.value = [];
|
loadStatus.value = 'loadmore';
|
getList();
|
};
|
|
const selectType = (e) => {
|
searchForm.checkType = e.value;
|
handleQuery();
|
};
|
|
const selectStatus = (e) => {
|
searchForm.inspectState = e.value;
|
handleQuery();
|
};
|
|
const openForm = (type, item) => {
|
// Mobile usually navigates to a new page for add/edit if complex
|
// Here we'll just show a toast for now as the actual form components are many
|
toast('功能开发中,请在PC端操作');
|
};
|
|
const handleConfirmSubmit = (row) => {
|
showConfirm('确认提交该检验记录吗?').then(res => {
|
if (res.confirm) {
|
submitRawMaterial(row.id).then(() => {
|
toast('提交成功');
|
handleQuery();
|
});
|
}
|
});
|
};
|
|
const handleDelete = (row) => {
|
showConfirm('确认删除该记录吗?').then(res => {
|
if (res.confirm) {
|
deleteRawMaterial({ id: row.id }).then(() => {
|
toast('删除成功');
|
handleQuery();
|
});
|
}
|
});
|
};
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
onMounted(() => {
|
handleQuery();
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.raw-material-page {
|
padding-bottom: 20rpx;
|
background-color: #f5f7fa;
|
min-height: 100vh;
|
}
|
|
.search-section {
|
padding: 20rpx 30rpx;
|
background-color: #ffffff;
|
position: sticky;
|
top: 0;
|
z-index: 10;
|
}
|
|
.filter-row {
|
display: flex;
|
justify-content: space-around;
|
padding: 10rpx 0;
|
}
|
|
.filter-item {
|
display: flex;
|
align-items: center;
|
gap: 10rpx;
|
font-size: 28rpx;
|
color: #606266;
|
}
|
|
.list-container {
|
padding: 20rpx;
|
}
|
|
.list-item {
|
background-color: #ffffff;
|
border-radius: 16rpx;
|
padding: 30rpx;
|
margin-bottom: 20rpx;
|
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
|
}
|
|
.item-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 20rpx;
|
}
|
|
.product-name {
|
font-size: 30rpx;
|
font-weight: bold;
|
color: #303133;
|
}
|
|
.item-content {
|
margin-bottom: 20rpx;
|
}
|
|
.item-row {
|
display: flex;
|
margin-bottom: 10rpx;
|
}
|
|
.item-label {
|
color: #909399;
|
width: 180rpx;
|
font-size: 28rpx;
|
}
|
|
.item-value {
|
flex: 1;
|
color: #303133;
|
font-size: 28rpx;
|
}
|
|
.item-actions {
|
display: flex;
|
justify-content: flex-end;
|
gap: 20rpx;
|
border-top: 1rpx solid #ebeef5;
|
padding-top: 20rpx;
|
}
|
|
.no-data {
|
padding-top: 200rpx;
|
}
|
|
.fab-button {
|
position: fixed;
|
right: 40rpx;
|
bottom: 60rpx;
|
width: 100rpx;
|
height: 100rpx;
|
background-color: #3c9cff;
|
border-radius: 50%;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
box-shadow: 0 4rpx 16rpx rgba(60, 156, 255, 0.4);
|
z-index: 99;
|
}
|
</style>
|