代码提交-3-13

This commit is contained in:
2026-03-13 14:32:24 +08:00
parent 3ca2451b2f
commit ae4aede94d
27 changed files with 2285 additions and 517 deletions

View File

@@ -0,0 +1,319 @@
<template>
<view class="container">
<uni-section title="隐患申报详情" type="line" class="mb-10" />
<view v-if="detail.id" class="detail-content">
<!-- 基本信息卡片 -->
<uni-card title="基本信息" :is-shadow="true" class="info-card">
<view class="info-grid">
<view class="info-row">
<text class="info-label">申报类型</text>
<text class="info-value">{{ detail.declarationLabel || '-' }}</text>
</view>
<view class="info-row">
<text class="info-label">申报人</text>
<text class="info-value">{{ detail.applyUser || '-' }}</text>
</view>
<view class="info-row">
<text class="info-label">申报时间</text>
<text class="info-value">{{ formatDate(detail.occurTime) }}</text>
</view>
</view>
</uni-card>
<!-- 申报内容卡片 -->
<uni-card title="申报内容" :is-shadow="true" class="content-card">
<view class="content-text">
{{ detail.requirementDescription || '暂无内容' }}
</view>
<view v-if="detail.remark" class="remark-section">
<text class="remark-label">备注</text>
<text class="remark-text">{{ detail.remark }}</text>
</view>
</uni-card>
<!-- 图片展示卡片 -->
<uni-card title="相关图片" :is-shadow="true" class="image-card" v-if="imageArray(detail.declarationImg).length > 0">
<view class="image-grid">
<view v-for="(img, idx) in imageArray(detail.declarationImg)" :key="idx" class="image-item">
<image :src="imageUrl(img)" mode="aspectFill" class="detail-image" @click="previewImage(img, detail.declarationImg)" />
</view>
</view>
</uni-card>
<!-- 无图片提示 -->
<uni-card title="相关图片" :is-shadow="true" class="image-card" v-else>
<view class="no-image-tip">
<uni-icons type="image" size="40" color="#ccc"></uni-icons>
<text class="no-image-text">暂无相关图片</text>
</view>
</uni-card>
<!-- 操作按钮 -->
<view class="action-buttons" v-if="detail.status === '0' || detail.status === 0">
<button class="edit-btn" size="default" type="primary" @click="editDeclaration">编辑申报</button>
</view>
</view>
<!-- 加载状态 -->
<view v-else-if="loading" class="loading-state">
<uni-load-more status="loading" />
</view>
<!-- 错误状态 -->
<view v-else class="error-state">
<uni-icons type="info" size="60" color="#ccc"></uni-icons>
<text class="error-text">数据加载失败或记录不存在</text>
<button size="mini" type="default" @click="goBack">返回列表</button>
</view>
</view>
</template>
<script>
import { getSafetyDeclaration } from '@/api/sidebar/sidebar.js'
import { listData } from '@/api/system/dict/data.js'
import config from '@/config'
export default {
name: "FilingDetail",
data() {
return {
id: null,
detail: {},
loading: false,
typeDict: []
}
},
async onLoad(options) {
this.id = options?.id || null
if (this.id) {
await this.initDict()
await this.fetchDetail()
}
},
methods: {
async initDict() {
try {
const typeData = await listData({ dictType: 'hs_declaration_type' })
this.typeDict = typeData.rows || []
} catch (e) {
console.error('获取字典数据失败:', e)
this.typeDict = []
}
},
async fetchDetail() {
if (!this.id) return
try {
this.loading = true
const res = await getSafetyDeclaration(this.id)
this.detail = res?.data || {}
// 设置申报类型标签
if (this.detail.declarationType) {
const typeItem = this.typeDict.find(i => String(i.dictValue) === String(this.detail.declarationType))
this.detail.declarationLabel = typeItem ? typeItem.dictLabel : this.detail.declarationType
}
} catch (e) {
console.error('获取详情失败:', e)
uni.showToast({
title: '获取详情失败',
icon: 'error'
})
} finally {
this.loading = false
}
},
imageArray(declarationImg) {
if (!declarationImg) return []
if (typeof declarationImg === 'string') {
return declarationImg.split(',').filter(Boolean)
}
return declarationImg.filter(Boolean)
},
imageUrl(path) {
if (!path) return ''
return config.baseUrl + path
},
previewImage(current, all) {
const urls = this.imageArray(all).map(p => this.imageUrl(p))
uni.previewImage({
current: this.imageUrl(current),
urls
})
},
formatDate(val) {
if (!val) return '-'
try {
const d = new Date(val)
const y = d.getFullYear()
const m = String(d.getMonth() + 1).padStart(2, '0')
const dd = String(d.getDate()).padStart(2, '0')
const hh = String(d.getHours()).padStart(2, '0')
const mm = String(d.getMinutes()).padStart(2, '0')
return `${y}-${m}-${dd} ${hh}:${mm}`
} catch (e) {
return val
}
},
getStatusText(status) {
const statusMap = {
'0': '待处理',
'1': '处理中',
'2': '已完成',
'3': '已关闭'
}
return statusMap[status] || '未知'
},
getStatusType(status) {
const typeMap = {
'0': 'error', // 待处理 - 红色
'1': 'warning', // 处理中 - 橙色
'2': 'success', // 已完成 - 绿色
'3': 'info' // 已关闭 - 蓝色
}
return typeMap[status] || 'default'
},
editDeclaration() {
if (!this.detail.id) return
this.$tab.navigateTo(`/pages/work/sidebar/safetyDeclaratio/index?id=${this.detail.id}`)
},
goBack() {
this.$tab.navigateBack()
}
}
}
</script>
<style lang="scss">
.container {
padding: 15px;
background-color: #f8f9fa;
min-height: 100vh;
}
.mb-10 {
margin-bottom: 15px;
}
.detail-content {
.info-card,
.content-card,
.image-card {
margin-bottom: 15px;
border-radius: 12px;
overflow: hidden;
}
.info-grid {
.info-row {
display: flex;
align-items: center;
margin-bottom: 12px;
&:last-child {
margin-bottom: 0;
}
.info-label {
font-size: 14px;
color: #666;
min-width: 80px;
flex-shrink: 0;
}
.info-value {
font-size: 14px;
color: #333;
flex: 1;
}
}
}
.content-text {
font-size: 15px;
line-height: 1.6;
color: #333;
margin-bottom: 15px;
}
.remark-section {
padding-top: 15px;
border-top: 1px solid #eee;
.remark-label {
font-size: 14px;
color: #666;
margin-right: 8px;
}
.remark-text {
font-size: 14px;
color: #333;
line-height: 1.5;
}
}
.image-grid {
display: flex;
flex-wrap: wrap;
gap: 10px;
.image-item {
.detail-image {
width: 100px;
height: 100px;
border-radius: 8px;
background: #f5f5f5;
border: 2px solid #fff;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
transition: transform 0.2s ease;
&:active {
transform: scale(0.95);
}
}
}
}
.no-image-tip {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px 20px;
.no-image-text {
margin-top: 10px;
font-size: 14px;
color: #999;
}
}
.action-buttons {
margin-top: 20px;
padding: 20px 0;
.edit-btn {
width: 100%;
border-radius: 25px;
font-size: 16px;
font-weight: 600;
}
}
}
.loading-state,
.error-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 60px 20px;
.error-text {
margin: 15px 0;
font-size: 14px;
color: #999;
text-align: center;
}
}
</style>

View File

@@ -1,150 +1,239 @@
<template>
<view class="work-container">
<uni-card v-for="(item,index) of dataList" class="parent">
<template v-slot:title>
<h3 class="title">{{item.declarationLabel}}</h3>
</template>
<h3>{{item.requirementDescription}}</h3>
<h3>{{item.occurTime}}</h3>
<view class="card-actions-item" @click="actionsClick(item.id)">
<button size="mini">详情</button>
</view>
</uni-card>
<uni-load-more status="已经没有更多数据了"></uni-load-more>
</uni-section>
</view>
<view class="container">
<uni-section title="异常隐患申报记录" type="line" class="mb-10">
<template v-slot:right>
<button size="mini" type="primary" @click.stop="addNew">新增</button>
</template>
</uni-section>
<view class="filters">
<uni-data-select v-model="queryParams.declarationType" :localdata="selectList" placeholder="申报类型" />
<uni-datetime-picker type="daterange" v-model="dateRange" :clear-icon="true" start="1990-01-01" end="2099-12-31" />
<button class="ml-6" size="mini" type="primary" @click="handleQuery">搜索</button>
<button class="ml-6" size="mini" @click="resetQuery">重置</button>
</view>
<uni-card v-for="item in dataList" :key="item.id" :title="item.declarationLabel || '异常隐患申报'" @click="onCardClick($event, item)">
<uni-row class="row" :width="730">
<uni-col :span="16">
<view>
<text class="uni-body">申报人{{ item.applyUser || '-' }}</text>
</view>
<view>
<text class="uni-body">申报时间{{ formatDate(item.occurTime) }}</text>
</view>
<view>
<text class="uni-body">备注{{ item.remark || '-' }}</text>
</view>
</uni-col>
<uni-col :span="8">
<view class="thumbs">
<image v-for="(img,idx) in firstThreeImages(item.declarationImg)" :key="idx" :src="imageUrl(img)" mode="aspectFill" class="thumb" />
</view>
</uni-col>
</uni-row>
</uni-card>
<uni-load-more :status="loadStatus" />
</view>
</template>
<script>
import {
listData
} from '@/api/system/dict/data.js'
import {
listSafetyDeclaration
} from "@/api/sidebar/sidebar.js"
import formatTime from '@/utils/formatTime.js'
import { listSafetyDeclaration } from '@/api/sidebar/sidebar.js';
import { listData } from '@/api/system/dict/data.js';
import config from '@/config';
export default {
name: "FilingLog",
data() {
return {
dataList: [],
queryParams: {
pageNum: 1, // 初始页码设为1
pageSize: 10
},
isLoading: false, // 添加一个标志位,用于防止重复请求
typeDataList: [],
total: 0
}
},
methods: {
actionsClick(e) {
uni.navigateTo({
url: `/pages/work/sidebar/safetyDeclaratio/index?id=` + e
})
},
async getList() {
if (this.isLoading) return; // 如果已经在加载中,则不执行
this.isLoading = true;
const res = await listSafetyDeclaration(this.queryParams);
if (this.typeDataList.length == 0) {
this.typeDataList = await listData({
dictType: "hs_declaration_type"
});
}
this.total = res.total
let processedDataList = res.rows.map(item => {
const matchedType = this.typeDataList.rows.find(type => type.dictValue == item.declarationType);
const time = formatTime(item.occurTime);
return {
...item,
occurTime: time,
declarationLabel: matchedType ? matchedType.dictLabel : "未知类型"
};
});
// 合并新旧数据
this.dataList = [...this.dataList, ...processedDataList];
},
onLoad(options) {
this.getList();
},
},
onReachBottom() {
this.isLoading = false;
//上拉到底时触发onReachBottom函数跟生命周期同级
let allTotal = this.queryParams.pageNum * this.queryParams.pageSize
console.log("allTotal",allTotal);
console.log("this.total",this.total);
if (allTotal < this.total) {
this.queryParams.pageNum++;
// this.queryParams.page++//当前条数小于总条数 则增加请求页数
this.getList() //调用加载数据方法
setTimeout(() => {
//结束下拉刷新
uni.stopPullDownRefresh();
}, 1000);
} else {
console.log('已加载全部数据')
}
},
onPullDownRefresh() {
this.queryParams.pageNum=1;
this.isLoading = false;
//下拉刷新触发onPullDownRefresh函数跟生命周期同级
this.dataList = []
this.getList().then(res=>{
setTimeout(() => {
//结束下拉刷新
uni.stopPullDownRefresh();
}, 1000);
})
}
}
export default {
name: "FilingLog",
data() {
return {
loadStatus: 'more',
loading: false,
total: 0,
dataList: [],
selectList: [],
dateRange: [],
queryParams: {
pageNum: 1,
pageSize: 10,
declarationType: null,
params: {}
}
}
},
created() {
this.initDict()
this.getList()
},
// 触底加载更多(页面滚动到底部)
onReachBottom() {
if (this.loadStatus !== 'more' || this.loading) return
this.loadStatus = 'loading'
this.queryParams.pageNum += 1
this.fetchList({ append: true })
},
// 页面重新显示时自动刷新列表(新增返回后生效)
onShow() {
this.getList()
},
methods: {
async initDict() {
try {
const typeData = await listData({ dictType: 'hs_declaration_type' })
this.selectList = typeData.rows.map(i => ({ value: i.dictValue, text: i.dictLabel }))
} catch (e) {
console.error('获取字典数据失败:', e)
this.selectList = []
}
},
imageUrl(path) {
if (!path) return ''
return config.baseUrl + path
},
firstThreeImages(declarationImg) {
if (!declarationImg) return []
if (typeof declarationImg === 'string') {
return declarationImg.split(',').slice(0, 3)
}
return declarationImg.slice(0, 3)
},
formatDate(val) {
if (!val) return ''
try {
const d = new Date(val)
const y = d.getFullYear()
const m = String(d.getMonth() + 1).padStart(2, '0')
const dd = String(d.getDate()).padStart(2, '0')
const hh = String(d.getHours()).padStart(2, '0')
const mm = String(d.getMinutes()).padStart(2, '0')
const ss = String(d.getSeconds()).padStart(2, '0')
return `${y}-${m}-${dd} ${hh}:${mm}:${ss}`
} catch (e) {
return val
}
},
buildParams() {
if (this.dateRange && this.dateRange.length === 2) {
this.queryParams.params = {
beginTime: this.dateRange[0],
endTime: this.dateRange[1]
}
} else {
this.queryParams.params = {}
}
},
async fetchList({ append = false } = {}) {
try {
this.loading = true
this.buildParams()
const res = await listSafetyDeclaration(this.queryParams)
const rows = res?.rows || []
// 若接口提供 total 字段则使用,否则根据 pageSize 判断是否还有更多
this.total = typeof res?.total === 'number' ? res.total : (append ? this.dataList.length + rows.length : rows.length)
if (append) {
this.dataList = this.dataList.concat(rows)
} else {
this.dataList = rows
}
// 根据是否还有更多数据设置加载状态
if (typeof res?.total === 'number') {
this.loadStatus = this.dataList.length < this.total ? 'more' : 'noMore'
} else {
// 当本次返回数量等于 pageSize默认还有下一页
const hasMore = rows.length === this.queryParams.pageSize
this.loadStatus = hasMore ? 'more' : 'noMore'
}
} catch (e) {
console.error('获取列表失败:', e)
this.loadStatus = 'noMore'
} finally {
this.loading = false
}
},
async getList() {
// 初始化查询第一页
this.queryParams.pageNum = 1
this.loadStatus = 'loading'
await this.fetchList({ append: false })
},
onCardClick(type, item) {
// 仅在内容区域点击时跳转title/extra也可按需
if (!item) return
this.goDetail(item)
},
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
resetQuery() {
this.queryParams = {
pageNum: 1,
pageSize: 10,
declarationType: null,
params: {}
}
this.dateRange = []
this.getList()
},
addNew() {
this.$tab.navigateTo('/pages/work/sidebar/safetyDeclaratio/index')
},
goDetail(item) {
const id = item?.id
if (!id) return
this.$tab.navigateTo(`/pages/work/sidebar/filingDetail/index?id=${id}`)
}
}
}
</script>
<style lang="scss">
page {
display: flex;
flex-direction: column;
box-sizing: border-box;
background-color: #fff;
min-height: 100%;
height: auto;
}
.container {
padding: 10px;
background-color: #f8f9fa;
min-height: 100vh;
}
.work-container {
margin-left: 4px
}
.filters {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 15px;
padding: 15px;
background: #fff;
border-radius: 8px;
}
.thumbs {
display: flex;
gap: 6px;
flex-wrap: wrap;
justify-content: flex-end;
.thumb {
width: 50px;
height: 50px;
border-radius: 8px;
background: #f5f5f5;
}
}
.parent {
position: relative;
.row {
display: flex;
align-items: flex-start;
}
h3 {
margin-bottom: 5px;
font-weight:600;
color: rgb(153, 153, 153);
}
.uni-body {
font-size: 14px;
color: #666;
margin-bottom: 5px;
}
.title {
font-weight:bold;
padding: 3rpx;
color: black;
}
}
// 工具类
.mb-10 {
margin-bottom: 10px;
}
.card-actions-item {
display: inline-block;
flex-direction: row;
align-items: center;
position: absolute;
bottom: 5px;
right: 30px;
button {
border-radius: 10px;
}
}
.ml-6 {
margin-left: 6px;
}
</style>

View File

@@ -133,13 +133,15 @@
// console.log();
}
},
submit(ref) {
this.$refs[ref].validate().then(res => {
this.SafetyDeclarationTable.declarationImg = this.joinList()
console.log("提交成功");
console.log("this.SafetyDeclarationTable", this.SafetyDeclarationTable);
addSafetyDeclaration(this.SafetyDeclarationTable).then(res => {
uni.showToast({
submit(ref) {
this.$refs[ref].validate().then(res => {
// 绑定当前用户为申报人
this.SafetyDeclarationTable.applyUser = this.$store.getters.name
this.SafetyDeclarationTable.declarationImg = this.joinList()
console.log("提交成功");
console.log("this.SafetyDeclarationTable", this.SafetyDeclarationTable);
addSafetyDeclaration(this.SafetyDeclarationTable).then(res => {
uni.showToast({
title: '提交成功',
icon: 'success', // 成功图标
duration: 1000 // 持续时间为2000ms