feat: 增加智慧库房,完善项目盈亏

This commit is contained in:
砂糖
2025-08-20 16:07:18 +08:00
parent f5ab69a431
commit 26ee6430c0
40 changed files with 14771 additions and 485 deletions

View File

@@ -0,0 +1,465 @@
<template>
<view>
<!-- 排序栏 -->
<view class="sort-filter-bar">
<view
class="sort-item"
v-for="(sort, index) in sortOptions"
:key="index"
@click="handleSort(sort.field)"
>
<text
:class="{
'sort-text': true,
'active-sort': sort.field === queryParams.sortField,
}"
>
{{ sort.name }}
</text>
<template v-if="sort.hasArrow && sort.field === queryParams.sortField">
<uni-icons
:type="queryParams.sortOrder === 'asc' ? 'arrowup' : 'arrowdown'"
size="16"
color="#007aff"
></uni-icons>
<text class="sort-direction-text">
{{ queryParams.sortOrder === 'asc' ? '正序' : '倒序' }}
</text>
</template>
</view>
<view class="filter-btn" @click="showPopup">
<text class="filter-text">筛选</text>
<uni-icons type="bottom" size="16"></uni-icons>
</view>
</view>
<!-- 筛选弹窗 -->
<uni-popup
type="bottom"
ref="popup"
>
<view class="popup-content">
<view class="popup-title">筛选条件</view>
<uni-section title="项目信息" type="line" class="filter-section">
<view class="filter-item">
<text class="filter-label">项目名称</text>
<input
type="text"
v-model="queryParams.projectName"
placeholder="输入项目名称"
class="filter-input"
/>
</view>
<view class="filter-item">
<text class="filter-label">项目编号</text>
<input
type="text"
v-model="queryParams.projectNum"
placeholder="输入项目编号"
class="filter-input"
/>
</view>
</uni-section>
<uni-section title="项目状态" type="line" class="filter-section">
<view class="uni-px-5 uni-pb-5">
<uni-data-checkbox
v-model="radioProjectStatus"
:localdata="projectStatusOptions"
@change="handleStatusChange"
></uni-data-checkbox>
</view>
</uni-section>
<uni-section title="贸易属性" type="line" class="filter-section">
<view class="uni-px-5 uni-pb-5">
<uni-data-checkbox
v-model="radioDomestic"
:localdata="domesticOptions"
@change="handleDomesticChange"
></uni-data-checkbox>
</view>
</uni-section>
<uni-section title="金额筛选" type="line" class="filter-section">
<view class="filter-item">
<text class="filter-label">合同金额区间</text>
<input
type="number"
v-model="queryParams.minContractAmount"
placeholder="最小"
class="filter-input"
/>
<text class="range-text">-</text>
<input
type="number"
v-model="queryParams.maxContractAmount"
placeholder="最大"
class="filter-input"
/>
</view>
<view class="filter-item">
<text class="filter-label">盈亏金额区间</text>
<input
type="number"
v-model="queryParams.minProfitLoss"
placeholder="最小"
class="filter-input"
/>
<text class="range-text">-</text>
<input
type="number"
v-model="queryParams.maxProfitLoss"
placeholder="最大"
class="filter-input"
/>
</view>
</uni-section>
<uni-section title="时间筛选" type="line" class="filter-section">
<view class="filter-item">
<text class="filter-label">启动时间</text>
<uni-datetime-picker
type="daterange"
v-model="dateRange"
start-placeholder="开始日期"
end-placeholder="结束日期"
@change="handleDateChange"
></uni-datetime-picker>
</view>
</uni-section>
<uni-section title="盈亏类型" type="line" class="filter-section">
<view class="uni-px-5 uni-pb-5">
<uni-data-checkbox
v-model="radioProfitType"
:localdata="profitTypeOptions"
@change="handleProfitTypeChange"
></uni-data-checkbox>
</view>
</uni-section>
<view class="popup-btns">
<button class="btn-reset" @click="resetFilter">重置</button>
<button class="btn-confirm" @click="confirmFilter">确定</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
export default {
data() {
return {
showFilter: false,
dateRange: [],
dateRangeText: '',
// 单选框绑定值(非数组类型,用于单选)
radioProjectStatus: '', // 项目状态单选值
radioDomestic: '', // 贸易属性单选值
radioProfitType: '', // 盈亏类型单选值
queryParams: {
projectName: '',
projectNum: '',
projectStatus: '', // 保持字符串类型(单选)
isDomestic: '', // 保持字符串类型(单选)
minContractAmount: '',
maxContractAmount: '',
minProfitLoss: '',
maxProfitLoss: '',
beginTimeStart: '',
beginTimeEnd: '',
profitType: '', // 保持字符串类型(单选)
sortField: 'profitLoss',
sortOrder: 'desc', // 默认倒序
pageSize: 9999,
pageNum: 1
},
// 排序选项
sortOptions: [
{ name: '盈亏额', field: 'profitLoss', hasArrow: true },
{ name: '启动时间', field: 'beginTime', hasArrow: true },
],
// 项目状态选项(包含"全部"
projectStatusOptions: [
{ text: '全部状态', value: '' },
{ text: '进行中', value: '0' },
{ text: '完结', value: '1' },
],
// 国内/国外选项(包含"全部"
domesticOptions: [
{ text: '全部', value: '' },
{ text: '国内', value: '0' },
{ text: '国外', value: '1' },
],
// 盈亏类型选项(包含"全部"
profitTypeOptions: [
{ text: '全部类型', value: '' },
{ text: '盈利', value: 'profit' },
{ text: '亏损', value: 'loss' },
],
};
},
methods: {
// 处理日期范围变化
handleDateChange(e) {
this.dateRange = e;
if (e.length === 2) {
this.queryParams.beginTimeStart = e[0];
this.queryParams.beginTimeEnd = e[1];
this.dateRangeText = `${e[0]} - ${e[1]}`;
} else {
this.queryParams.beginTimeStart = '';
this.queryParams.beginTimeEnd = '';
this.dateRangeText = '';
}
},
// 重置筛选条件
resetFilter() {
this.queryParams = {
...this.queryParams,
projectName: '',
projectNum: '',
projectStatus: '',
profitType: '',
beginTimeStart: '',
beginTimeEnd: '',
minContractAmount: '',
maxContractAmount: '',
minProfitLoss: '',
maxProfitLoss: '',
isDomestic: '',
};
// 重置单选框绑定值
this.radioProjectStatus = '';
this.radioDomestic = '';
this.radioProfitType = '';
this.dateRange = [];
this.dateRangeText = '';
},
// 确认筛选条件
confirmFilter() {
this.$refs.popup.close();
this.$emit('filter-change', { ...this.queryParams });
},
// 处理排序
handleSort(field) {
if (this.queryParams.sortField === field) {
this.queryParams.sortOrder = this.queryParams.sortOrder === 'asc' ? 'desc' : 'asc';
} else {
this.queryParams.sortField = field;
this.queryParams.sortOrder = 'desc';
}
this.$emit('filter-change', { ...this.queryParams });
},
// 处理项目状态变化(单选)
handleStatusChange(value) {
console.log(value)
this.queryParams.projectStatus = value.detail.value;
},
// 处理国内/国外状态变化(单选)
handleDomesticChange(value) {
console.log(value)
this.queryParams.tradeType = value.detail.value;
},
// 处理盈亏类型变化(单选)
handleProfitTypeChange(value) {
console.log(value)
this.queryParams.profitType = value.detail.value;
},
// 显示筛选弹窗
showPopup() {
this.$refs.popup.open();
},
},
};
</script>
<style scoped>
/* 排序和筛选栏样式 */
.sort-filter-bar {
display: flex;
align-items: center;
height: 40px;
background-color: #fff;
border-bottom: 1px solid #eee;
overflow-x: auto;
white-space: nowrap;
padding: 0 10px;
}
.sort-filter-bar::-webkit-scrollbar {
display: none; /* 隐藏滚动条 */
}
.sort-item {
display: flex;
align-items: center;
padding: 0 12px;
height: 100%;
font-size: 14px;
color: #333;
cursor: pointer;
}
.sort-item:active {
background-color: #f5f5f5;
}
.active-sort {
color: #007aff;
font-weight: bold;
}
.sort-direction-text {
margin-left: 4px;
font-size: 12px;
color: #007aff;
}
.filter-btn {
display: flex;
align-items: center;
padding: 0 12px;
height: 100%;
font-size: 14px;
color: #333;
cursor: pointer;
margin-left: auto; /* 推到最右侧 */
}
.filter-btn:active {
background-color: #f5f5f5;
}
/* 筛选弹窗样式 */
.popup-content {
background-color: #fff;
border-top-left-radius: 16px;
border-top-right-radius: 16px;
padding-bottom: 20px;
overflow-y: auto;
height: 100%;
}
.popup-title {
padding: 15px;
font-size: 16px;
font-weight: bold;
border-bottom: 1px solid #eee;
position: relative;
text-align: center;
}
.popup-title::after {
content: '';
position: absolute;
bottom: -1px;
left: 50%;
transform: translateX(-50%);
width: 40px;
height: 3px;
background-color: #007aff;
}
.filter-section {
margin-bottom: 10px;
}
.filter-item {
margin-bottom: 15px;
display: flex;
align-items: center;
padding: 0 15px;
}
.filter-label {
font-size: 14px;
color: #666;
width: 100px;
flex-shrink: 0;
}
.filter-input {
flex: 1;
border: 1px solid #eee;
border-radius: 4px;
padding: 8px 10px;
font-size: 14px;
height: 36px;
box-sizing: border-box;
}
.filter-input:focus {
border-color: #007aff;
outline: none;
}
.range-text {
margin: 0 8px;
color: #999;
}
/* 弹窗按钮样式 */
.popup-btns {
display: flex;
padding: 10px 15px;
border-top: 1px solid #eee;
margin-top: 10px;
}
.btn-reset,
.btn-confirm {
flex: 1;
height: 40px;
line-height: 40px;
border-radius: 6px;
font-size: 16px;
border: none;
cursor: pointer;
}
.btn-reset {
background-color: #f5f5f5;
color: #333;
margin-right: 10px;
}
.btn-confirm {
background-color: #007aff;
color: #fff;
}
/* 解决uni组件样式冲突 */
::v-deep .uni-data-checkbox {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 5px 0;
}
::v-deep .uni-data-checkbox .uni-checkbox-item {
margin-right: 15px;
}
::v-deep .uni-datetime-picker {
flex: 1;
}
::v-deep .uni-popup {
z-index: 999;
}
::v-deep .uni-section__content {
padding: 5px 0;
}
</style>

View File

@@ -0,0 +1,341 @@
<template>
<view class="container">
<!-- 列表内容区域 -->
<view class="list-container">
<uni-skeleton
v-if="loading"
:row="5"
:loading="loading"
title
avatar
></uni-skeleton>
<view v-else-if="profitList.length === 0" class="empty-view">
<uni-icons type="empty" size="60" color="#ccc"></uni-icons>
<text class="empty-text">暂无数据</text>
</view>
<view class="project-card" v-for="(item, index) in profitList" :key="index">
<view class="card-header">
<view class="header-left">
<text class="project-name">{{ item.projectName }}</text>
<text class="project-num">{{ item.projectNum }}</text>
</view>
<uni-tag
:text="item.projectStatus === '0' ? '进行中' : '完结'"
:type="item.projectStatus === '0' ? 'success' : 'primary'"
size="small"
></uni-tag>
</view>
<view class="card-body">
<view class="info-row">
<text class="info-label">贸易类型</text>
<text class="info-value">{{ getTradeTypeName(item.tradeType) }}</text>
</view>
<view class="info-row">
<text class="info-label">合同金额</text>
<text class="info-value">{{ item.originalFunds || item.detailIncome }}</text>
</view>
<view class="info-row">
<text class="info-label">人民币金额</text>
<text class="info-value">¥{{ item.totalIncomeCny }}</text>
</view>
<view class="info-row">
<text class="info-label">启动时间</text>
<text class="info-value">{{ item.beginTime }}</text>
</view>
</view>
<view class="card-footer">
<view class="profit-info" :style="getProfitLossStyle(item)">
<text class="profit-label">盈亏金额</text>
<text class="profit-value">{{ parseFloat(item.profitLoss || 0).toFixed(2) }}</text>
</view>
<uni-tag
v-if="getProfitRate(item) !== null"
:text="getProfitRateTag(item)"
:type="getProfitRateType(item)"
size="small"
></uni-tag>
</view>
</view>
</view>
<!-- 分页组件 -->
<uni-pagination
v-if="total > 0"
:total="total"
:pageSize="pagination.pageSize"
:current="pagination.pageNum"
@change="onPageChange"
mode="number"
show-icon
style="margin: 20px auto;"
></uni-pagination>
</view>
</template>
<script>
import { listProfit } from '@/api/oa/finance/profit';
export default {
props: {
// 接收从父组件传递的筛选参数
filterParams: {
type: Object,
default: () => ({})
}
},
data() {
return {
loading: false,
profitList: [],
total: 0,
// 分页参数
pagination: {
pageNum: 1,
pageSize: 10
},
// 盈亏阈值配置
profitThresholds: {
highProfit: 100000, // 高盈利阈值
highLoss: -50000, // 高亏损阈值
warningProfit: 50000, // 警告盈利阈值
warningLoss: -20000 // 警告亏损阈值
},
// 贸易类型字典
tradeTypeDict: [
{ value: 1, label: '外贸' },
{ value: 0, label: '内贸' },
]
};
},
watch: {
// 监听筛选参数变化,重新加载数据
filterParams: {
deep: true,
handler() {
// 筛选条件变化时重置页码
this.pagination.pageNum = 1;
this.getList();
}
}
},
methods: {
// 获取列表数据
getList() {
this.loading = true;
// 合并筛选参数和分页参数
const params = {
...this.filterParams,
...this.pagination
};
listProfit(params)
.then((res) => {
this.profitList = res.rows || [];
this.total = res.total || 0;
this.loading = false;
})
.catch(() => {
this.loading = false;
uni.showToast({
title: '加载失败',
icon: 'none',
});
});
},
// 分页变化
onPageChange(e) {
this.pagination.pageNum = e.current;
this.pagination.pageSize = e.size;
this.getList();
},
// 盈亏相关计算
getProfitRate(row) {
// 计算盈亏百分比
const base = row.originalFunds && row.originalFunds !== 0
? row.originalFunds
: row.detailIncome;
if (!base || base === 0) return null;
return row.profitLoss / base;
},
getProfitRateTag(row) {
const rate = this.getProfitRate(row);
if (rate === null) return '-';
if (rate >= 0.2) return '高盈利';
if (rate <= -0.2) return '高亏损';
if (rate < 0) return '亏损';
if (rate >= 0 && rate <= 0.05) return '低盈利';
return '盈利';
},
getProfitRateType(row) {
const rate = this.getProfitRate(row);
if (rate === null) return 'default';
if (rate >= 0.2) return 'success';
if (rate <= -0.2) return 'error';
if (rate < 0) return 'warning';
return rate >= 0 && rate <= 0.05 ? 'info' : 'success';
},
getProfitLossStyle(row) {
const rate = this.getProfitRate(row);
if (rate === null) return {};
if (rate >= 0.2) {
return {
color: '#67C23A',
fontWeight: 'bold',
};
} else if (rate <= -0.2) {
return {
color: '#F56C6C',
fontWeight: 'bold',
};
} else if (rate < 0) {
return {
color: '#F56C6C',
};
} else if (rate >= 0 && rate <= 0.05) {
return {
color: '#E6A23C',
};
} else {
return { color: '#67C23A' };
}
},
// 获取贸易类型名称
getTradeTypeName(value) {
const item = this.tradeTypeDict.find(item => item.value === value);
return item ? item.label : value;
}
},
// 组件挂载时加载数据
mounted() {
this.getList();
}
};
</script>
<style scoped>
.container {
flex: 1;
flex-direction: column;
background-color: #f5f5f5;
min-height: 100vh;
}
/* 列表样式 */
.list-container {
padding: 10px;
}
.project-card {
background-color: #fff;
border-radius: 8px;
padding: 15px;
margin-bottom: 10px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.card-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 10px;
}
.header-left {
flex: 1;
}
.project-name {
font-size: 16px;
font-weight: bold;
display: block;
margin-bottom: 5px;
color: #333;
}
.project-num {
font-size: 12px;
color: #666;
}
.card-body {
margin-bottom: 10px;
}
.info-row {
display: flex;
margin-bottom: 8px;
font-size: 14px;
}
.info-label {
color: #666;
width: 80px;
flex-shrink: 0;
}
.info-value {
flex: 1;
color: #333;
}
.card-footer {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 10px;
border-top: 1px dashed #eee;
}
.profit-info {
display: flex;
align-items: center;
}
.profit-label {
color: #666;
margin-right: 5px;
}
.profit-value {
font-weight: bold;
}
/* 空状态 */
.empty-view {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 50px 0;
}
.empty-text {
color: #999;
margin-top: 10px;
font-size: 14px;
}
/* 解决uni组件样式冲突 */
::v-deep .uni-tag {
margin-top: 2px;
}
::v-deep .uni-pagination {
text-align: center;
}
</style>