343 lines
10 KiB
Vue
Raw Normal View History

2025-05-20 08:53:11 +08:00
<template>
<div class="usage-monitor">
2025-05-20 13:32:43 +08:00
<!-- 顶部 TabPane居中显示 -->
2025-05-21 13:44:54 +08:00
<el-tabs v-model="activeTab" class="tabs-wrapper">
<el-tab-pane label="在售中" name="onSale" />
<el-tab-pane label="未上架" name="offShelf" />
<el-tab-pane label="已失效" name="expired" />
</el-tabs>
2025-05-20 13:32:43 +08:00
<!-- 列表内容 -->
<div class="list-wrapper">
<div v-for="(p, idx) in filteredProducts" :key="p.id" class="list-item" :class="{ 'has-border': idx > 0 }">
<!-- 商品图 -->
<img class="item-img" :src="p.img" alt="商品图" />
<!-- 名称 + 月售/库存 -->
<div class="item-info">
<div class="item-name">{{ p.name }}</div>
<div class="item-stats">月售 {{ p.monthlySales }} · 库存 {{ p.stock }}</div>
2025-05-21 13:44:54 +08:00
<div class="item-price">¥ {{ p.price }} /kg</div>
2025-05-20 13:32:43 +08:00
</div>
2025-05-21 13:44:54 +08:00
<div class="item-buttom">
<div class="item-status" :class="statusClass(activeTab)">
{{ tabLabels[activeTab] }}
</div>
<div class="item-actions">
2025-05-22 10:38:36 +08:00
<el-button size="large" class="button" @click="onInspect(p.id)">抽查</el-button>
2025-05-21 13:44:54 +08:00
<el-button size="large" class="button" type="danger" @click="onRevoke(p)">取消授权</el-button>
</div>
2025-05-20 13:32:43 +08:00
</div>
</div>
</div>
2025-05-22 10:38:36 +08:00
<!-- 抽查弹窗 -->
<el-dialog v-model="dialogVisible" width="720px" top="20px" modal="false" :before-close="() => (dialogVisible = false)" title="追溯记录">
<div v-if="traceData" class="trace-record">
<!-- 基本信息 -->
<section class="section">
<h3>基本信息</h3>
<el-row :gutter="12">
<el-col :span="6">产品名称</el-col><el-col :span="18">{{ traceData.productName }}</el-col> <el-col :span="6">产品数量</el-col
><el-col :span="18">{{ traceData.quantity }}</el-col> <el-col :span="6">生产经营主体</el-col
><el-col :span="18">{{ traceData.producer }}</el-col> <el-col :span="6">原产地</el-col
><el-col :span="18">{{ traceData.origin }}</el-col> <el-col :span="6">生产日期</el-col
><el-col :span="18">{{ traceData.productionDate }}</el-col> <el-col :span="6">追溯码</el-col
><el-col :span="18">{{ traceData.traceCode }}</el-col> <el-col :span="6">追溯次数</el-col
><el-col :span="18">{{ traceData.traceCount }} </el-col>
</el-row>
</section>
<!-- 基地信息 -->
<section class="section">
<h3>基地信息</h3>
<el-row :gutter="12">
<el-col :span="6">基地地址</el-col><el-col :span="18">{{ traceData.base.address }}</el-col> <el-col :span="6">地理位置</el-col
><el-col :span="18">{{ traceData.base.location }}</el-col> <el-col :span="6">面积</el-col
><el-col :span="18">{{ traceData.base.area }} </el-col> <el-col :span="6">气候条件</el-col
><el-col :span="18">{{ traceData.base.climate }}</el-col> <el-col :span="6">土壤类型</el-col
><el-col :span="18">{{ traceData.base.soil }}</el-col>
</el-row>
</section>
<!-- 农事信息 -->
<section class="section">
<h3>农事信息</h3>
<el-table :data="traceData.farmingRecords" stripe border style="width: 100%">
<el-table-column prop="date" label="日期" width="120" />
<el-table-column prop="operation" label="操作" />
<el-table-column prop="operator" label="作业人" width="120" />
</el-table>
</section>
<!-- 包装信息 -->
<section class="section">
<h3>分拣包装</h3>
<el-row :gutter="12">
<el-col :span="6">包装企业</el-col><el-col :span="18">{{ traceData.packaging.company }}</el-col> <el-col :span="6">包装类型</el-col
><el-col :span="18">{{ traceData.packaging.type }}</el-col> <el-col :span="6">包装人</el-col
><el-col :span="18">{{ traceData.packaging.person }}</el-col> <el-col :span="6">包装时间</el-col
><el-col :span="18">{{ traceData.packaging.time }}</el-col>
</el-row>
</section>
<!-- 仓储物流 -->
<section class="section">
<h3>仓储物流信息</h3>
<el-row :gutter="12">
<el-col :span="6">存储类型</el-col><el-col :span="18">{{ traceData.logistics.storageType }}</el-col>
<el-col :span="6">存储温度</el-col><el-col :span="18">{{ traceData.logistics.temperature }}</el-col>
<el-col :span="6">发货地址</el-col><el-col :span="18">{{ traceData.logistics.shipFrom }}</el-col> <el-col :span="6">收货地址</el-col
><el-col :span="18">{{ traceData.logistics.shipTo }}</el-col>
</el-row>
</section>
<!-- 交易信息 -->
<section class="section">
<h3>交易信息</h3>
<el-row :gutter="12">
<el-col :span="6">交易时间</el-col><el-col :span="18">{{ traceData.trade.time }}</el-col> <el-col :span="6">买家</el-col
><el-col :span="18">{{ traceData.trade.buyer }}</el-col>
</el-row>
</section>
<!-- 右侧图片 -->
<div class="trace-img">
<img :src="getAssetsFile(traceData.img)" alt="产品图" />
</div>
</div>
</el-dialog>
2025-05-20 08:53:11 +08:00
</div>
</template>
<script setup>
import { ref, computed } from 'vue';
2025-05-21 13:44:54 +08:00
import { getAssetsFile } from '@/utils/index.js';
import { getMonitorList } from '@/apis/brand';
2025-05-20 08:53:11 +08:00
2025-05-20 13:32:43 +08:00
const activeTab = ref('onSale');
2025-05-22 10:38:36 +08:00
const dialogVisible = ref(false);
const traceData = ref(null);
2025-05-20 08:53:11 +08:00
2025-05-20 13:32:43 +08:00
const tabLabels = {
onSale: '在售中',
offShelf: '未上架',
expired: '已失效',
2025-05-20 08:53:11 +08:00
};
2025-05-20 13:32:43 +08:00
// 示例数据,替换为真实接口数据
2025-05-20 08:53:11 +08:00
const products = ref([
{
id: 1,
2025-05-20 13:32:43 +08:00
name: '耿马镇沙疆西红柿',
2025-05-21 13:44:54 +08:00
img: getAssetsFile('images/brand/product4.png'),
2025-05-20 08:53:11 +08:00
monthlySales: 999,
stock: 10000,
2025-05-20 13:32:43 +08:00
price: 3.0,
2025-05-20 08:53:11 +08:00
status: 'onSale',
},
{
id: 2,
2025-05-20 13:32:43 +08:00
name: '耿马镇沙疆土豆',
2025-05-21 13:44:54 +08:00
img: getAssetsFile('images/brand/product6.png'),
2025-05-20 13:32:43 +08:00
monthlySales: 123,
stock: 5000,
price: 2.5,
2025-05-20 08:53:11 +08:00
status: 'onSale',
},
{
id: 3,
2025-05-20 13:32:43 +08:00
name: '彩椒南瓜混合',
2025-05-21 13:44:54 +08:00
img: getAssetsFile('images/brand/product1.png'),
2025-05-20 13:32:43 +08:00
monthlySales: 456,
stock: 8000,
price: 4.2,
status: 'offShelf',
2025-05-20 08:53:11 +08:00
},
2025-05-20 13:32:43 +08:00
// … 更多数据
2025-05-20 08:53:11 +08:00
]);
2025-05-20 13:32:43 +08:00
// 根据当前 Tab 过滤
const filteredProducts = computed(() => products.value.filter((p) => p.status === activeTab.value));
2025-05-20 08:53:11 +08:00
2025-05-22 10:38:36 +08:00
// 点击抽查后,根据 id 单独拉取或赋值 traceData
function onInspect(id) {
console.log('查看产品:', id);
// 这里用硬编码模拟请求实际中可换成接口调用getTraceById(id).then(res=> traceData.value = res)
const mock = {
productName: '无土栽培土豆',
quantity: '200KG',
producer: '北大荒技术有限公司',
origin: '耿马县孟定镇下坝村',
productionDate: '2025-1-2',
traceCode: '10.5487542154785XSE254.1040201',
traceCount: 30,
base: {
address: '耿马县孟定镇下坝村',
location: '东经102° · 北纬24°',
area: 12000,
climate: '亚热带高原季风型,温和多雨',
soil: '红壤',
},
farmingRecords: [
{ date: '2024/1/2', operation: '播种 20250102批土豆种', operator: '张小东' },
{ date: '2024/2/2', operation: '施肥 氮肥', operator: '张小东' },
{ date: '2024/3/2', operation: '浇水', operator: '张小东' },
{ date: '2024/4/2', operation: '采摘', operator: '张小东' },
],
packaging: {
company: '瑞禾农产品包装公司',
type: '纸箱',
person: '王大福',
time: '2025-1-2 14:00:47',
},
logistics: {
storageType: '冷藏',
temperature: '2°C',
shipFrom: '北京市朝阳区解放路24号',
shipTo: '上海市黄浦区南京路36号',
},
trade: {
time: '2025-1-2 14:00:47',
buyer: '刘小花',
},
img: 'images/brand/product6.png',
};
traceData.value = mock;
dialogVisible.value = true;
}
2025-05-20 13:32:43 +08:00
const onRevoke = (p) => {
console.log('取消授权', p);
2025-05-20 08:53:11 +08:00
};
2025-05-20 13:32:43 +08:00
// 状态文字的颜色
const statusClass = (tab) => {
if (tab === 'offShelf') return 'text-warning';
if (tab === 'expired') return 'text-danger';
return 'text-success';
2025-05-20 08:53:11 +08:00
};
</script>
2025-05-20 13:32:43 +08:00
<style scoped lang="scss">
2025-05-20 08:53:11 +08:00
.usage-monitor {
padding: 20px;
2025-05-20 13:32:43 +08:00
background: #fff;
2025-05-21 13:44:54 +08:00
border-radius: 16px;
height: 100%;
2025-05-20 08:53:11 +08:00
2025-05-20 13:32:43 +08:00
.tabs-wrapper {
2025-05-21 13:44:54 +08:00
width: 100%;
2025-05-20 13:32:43 +08:00
display: flex;
2025-05-21 13:44:54 +08:00
align-items: center;
background-color: #fff;
2025-05-20 08:53:11 +08:00
2025-05-21 13:44:54 +08:00
:deep(.el-tabs__item) {
font-size: 24px;
font-weight: 700;
// border: 1 solid #f000;
2025-05-20 08:53:11 +08:00
}
2025-05-20 13:32:43 +08:00
}
2025-05-20 08:53:11 +08:00
2025-05-20 13:32:43 +08:00
.list-wrapper {
.list-item {
2025-05-21 13:44:54 +08:00
display: flex;
justify-content: start;
2025-05-20 13:32:43 +08:00
align-items: center;
2025-05-21 13:44:54 +08:00
padding: 20px 0;
2025-05-20 08:53:11 +08:00
2025-05-20 13:32:43 +08:00
.item-img {
2025-05-21 13:44:54 +08:00
width: 120px;
height: 120px;
2025-05-20 13:32:43 +08:00
object-fit: cover;
border-radius: 8px;
2025-05-20 08:53:11 +08:00
}
2025-05-20 13:32:43 +08:00
.item-info {
padding-left: 16px;
2025-05-21 13:44:54 +08:00
// background-color: #909399;
2025-05-20 13:32:43 +08:00
.item-name {
2025-05-21 13:44:54 +08:00
font-size: 20px;
font-weight: 700;
2025-05-20 13:32:43 +08:00
margin-bottom: 8px;
}
.item-stats {
color: #909399;
font-size: 14px;
2025-05-20 08:53:11 +08:00
}
}
2025-05-20 13:32:43 +08:00
.item-price {
2025-05-21 13:44:54 +08:00
font-size: 28px;
font-weight: 700;
2025-05-20 13:32:43 +08:00
color: #67c23a;
2025-05-21 13:44:54 +08:00
text-align: left;
padding-top: 8px;
}
.item-buttom {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 110px;
flex: 1;
2025-05-20 08:53:11 +08:00
}
2025-05-20 13:32:43 +08:00
.item-actions {
display: flex;
2025-05-21 13:44:54 +08:00
justify-content: flex-end;
2025-05-20 13:32:43 +08:00
gap: 8px;
2025-05-21 13:44:54 +08:00
.button {
font-size: 20px;
font-weight: 400;
border-radius: 8px;
}
2025-05-20 13:32:43 +08:00
}
.item-status {
text-align: right;
2025-05-21 13:44:54 +08:00
font-size: 20px;
font-weight: 700;
2025-05-20 13:32:43 +08:00
&.text-success {
color: #67c23a;
}
&.text-warning {
color: #e6a23c;
}
&.text-danger {
color: #f56c6c;
}
}
2025-05-20 08:53:11 +08:00
}
}
2025-05-22 10:38:36 +08:00
.trace-record {
position: relative;
padding-right: 160px; /* 给图片预留空间 */
}
.trace-record .section {
margin-bottom: 16px;
}
.trace-record h3 {
margin-bottom: 8px;
font-size: 18px;
color: #409eff;
border-left: 4px solid #409eff;
padding-left: 8px;
}
.trace-img {
position: absolute;
top: 16px;
right: 16px;
width: 128px;
text-align: center;
}
.trace-img img {
width: 100%;
border-radius: 4px;
}
2025-05-20 08:53:11 +08:00
}
</style>