This commit is contained in:
浅念
2026-02-06 14:39:37 +08:00
parent 423fc8b7e1
commit bf3d85de0d
28 changed files with 5631 additions and 1164 deletions
+303 -228
View File
@@ -1,103 +1,108 @@
<template>
<view class="home-page">
<uni-nav-bar leftText=" " :fixed="true" leftIcon="back" :border="false" @clickLeft="leftClick" color="#fff" backgroundColor="rgb(79 137 247)" :statusBar="true" title="借用申请"></uni-nav-bar>
<uni-nav-bar leftText=" " :fixed="true" leftIcon="back" :border="false" color="#fff" backgroundColor="rgb(79 137 247)" :statusBar="true" title="借用申请" @clickLeft="leftClick"></uni-nav-bar>
<view class="content-wrapper">
<!-- 申请人信息卡片 -->
<view class="form-card">
<view class="form-item form-item-row">
<text class="form-label">申请人:</text>
<text class="form-value">{{ formData.applicant || '犇犇' }}</text>
<text class="form-value">{{ userinfo.name || '犇犇' }}</text>
</view>
<view class="form-item form-item-row">
<text class="form-label">公司名称:</text>
<text class="form-value">{{ formData.companyName || '合塑' }}</text>
<text class="form-value">{{ userinfo.corp_name || '合塑' }}</text>
</view>
</view>
<!-- 借用详情卡片 -->
<!-- 借用时间 -->
<view class="form-card4">
<!-- 借用时间 -->
<view class="form-item form-item-row">
<text class="form-label required">借用时间</text>
<view class="form-input-container">
<uni-datetime-picker
ref="borrowTimePicker"
type="datetime"
v-model="formData.borrowTime"
type="date"
v-model="formData.use_start_date"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
@change="onBorrowTimeChange"
>
<view class="custom-datetime-input">
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.borrowTime }">
{{ formData.borrowTime || '请选择时间' }}
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.use_start_date }">
{{ formData.use_start_date || '请选择时间' }}
</text>
<uni-icons type="calendar" size="18" color="#999"></uni-icons>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
</view>
</view>
<view class="form-card4">
<!-- 计划归还时间 -->
<!-- 计划归还时间 -->
<view class="form-card4">
<view class="form-item form-item-row">
<text class="form-label required">计划归还时间</text>
<view class="form-input-container">
<uni-datetime-picker
ref="returnTimePicker"
type="datetime"
v-model="formData.returnTime"
type="date"
v-model="formData.use_end_date"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
@change="onReturnTimeChange"
>
<view class="custom-datetime-input">
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.returnTime }">
{{ formData.returnTime || '请选择时间' }}
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.use_end_date }">
{{ formData.use_end_date || '请选择时间' }}
</text>
<uni-icons type="calendar" size="18" color="#999"></uni-icons>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
</view>
</view>
<view class="form-card4">
<!-- 物品名称 -->
<view class="form-item form-item-row">
<text class="form-label required">物品名称</text>
<view class="form-input-container">
<uni-data-select
v-model="formData.itemName"
:localdata="itemNameOptions"
placeholder="请选择"
:clear="false"
></uni-data-select>
</view>
<!-- ✅ 物品(可添加多条) -->
<view class="goods-card">
<view class="goods-head">
<text class="form-label required">物品</text>
<button class="goods-add-btn" size="mini" @click="addItem">+ 添加</button>
</view>
</view>
<view class="form-card4">
<!-- 物品所属公司 -->
<view class="form-item form-item-row">
<text class="form-label required">物品所属公司</text>
<view class="form-input-container">
<uni-data-select
v-model="formData.itemCompany"
:localdata="itemCompanyOptions"
placeholder="请选择"
:clear="false"
></uni-data-select>
<view class="goods-module" v-for="(it, idx) in formData.items" :key="idx">
<view class="goods-module-top">
<text class="goods-module-title">物品 {{ idx + 1 }}</text>
<uni-icons
v-if="formData.items.length > 1"
type="trash"
size="18"
color="#ff4d4f"
@click="removeItem(idx)"
></uni-icons>
</view>
<view class="goods-module-body">
<view class="goods-name">
<picker mode="selector" :range="itemNameOptions" range-key="item_name" @change="(e) => onItemNameChange(e, idx)">
<view class="category-content">
<text class="category-text">{{it.item_name_snap || '请选择物品'}}</text>
</view>
</picker>
</view>
<view class="goods-qty">
<uni-number-box v-model="it.request_qty" :min="1" :max="999"></uni-number-box>
</view>
</view>
</view>
</view>
<view class="form-card">
<!-- 借用事由 -->
<view class="form-item">
<text class="form-label required">借用事由</text>
<text class="form-label required form-label1">借用事由</text>
<uni-easyinput
v-model="formData.borrowReason"
v-model="formData.borrow_reason"
type="textarea"
:autoHeight="true"
placeholder="请填写借用事由"
@@ -105,12 +110,13 @@
></uni-easyinput>
</view>
</view>
<!-- 备注卡片 -->
<view class="form-card " style="margin-bottom: 8rpx;">
<view class="form-item">
<text class="form-label">备注</text>
<uni-easyinput
v-model="formData.remarks"
v-model="formData.remark"
type="textarea"
:autoHeight="true"
placeholder="请填写备注"
@@ -118,116 +124,204 @@
></uni-easyinput>
</view>
</view>
<!-- 附件卡片 -->
<!-- 附件上传 -->
<view class="form-card">
<view class="form-item">
<text class="form-label form-label1">附件</text>
<uni-file-picker
v-model="formData.attachments"
file-mediatype="image"
mode="grid"
:limit="9"
:auto-upload="false"
@select="onFileSelect"
>
<image src="/static/image/upload.png" mode="" class="addimg"></image>
</uni-file-picker>
<text class="form-label">附件</text>
<view class="media-upload-wrapper">
<uni-file-picker ref="mediaPicker" limit="20" fileMediatype="image" @select="selectMedia" @delete="delfn" >
<view class="upload-icon-wrapper">
<image src="/static/image/upload.png" mode="" class="addimg"></image>
</view>
</uni-file-picker>
</view>
</view>
</view>
<!-- 提交按钮 -->
<view class="submit-btn-wrapper">
<button class="submit-btn" @click="handleSubmit">提交</button>
<view class="submit-container">
<button class="submit-btn" @click="handleSubmit">提交申请</button>
</view>
</view>
</view>
</template>
<script>
import { request,showToast } from '@/api/apiT.js'
export default {
data() {
return {
userinfo: {},
maxMedia:20,
formData: {
applicant: '犇犇',
companyName: '合塑',
borrowTime: '',
returnTime: '',
itemName: '',
itemCompany: '',
borrowReason: '',
remarks: '',
attachments: []
use_start_date: '',
use_end_date: '',
items: [{ item_name_snap: '',item_id:'',request_qty:1}],
borrow_reason: '',
remark: '',
attachment: []
},
itemNameOptions: [
{ text: '物品1', value: 'item1' },
{ text: '物品2', value: 'item2' },
{ text: '物品3', value: 'item3' }
],
itemCompanyOptions: [
{ text: '公司A', value: 'companyA' },
{ text: '公司B', value: 'companyB' },
{ text: '公司C', value: 'companyC' }
]
itemNameOptions: [],
}
},
onLoad() {
this.getinfo()
this.getItemNameOptions()
},
methods: {
leftClick(){
uni.navigateBack({})
},
getinfo(){
request({
url:'common/user/info',
method:'get',
}).then(res => {
this.userinfo=res.data.data.user
})
},
//物品下拉
getItemNameOptions() {
request({
url:'mobile/inv/item/preset',
method:'get',
}).then(res => {
this.itemNameOptions = res.data.data
this.itemNameOptions.forEach(item => {
item.item_name = item.item_name + '(' + item.company_name + ')'
})
console.log(this.itemNameOptions)
})
},
onItemNameChange(e, itemIndex) {
console.log(e, itemIndex)
const index = e.detail.value; // picker 返回的 index
const selectItem = this.itemNameOptions[index]; // 直接取整条数据
if (this.formData.items[itemIndex]) {
this.formData.items[itemIndex].item_name_snap = selectItem.item_name
this.formData.items[itemIndex].item_id = selectItem.id
}
},
onBorrowTimeChange(e) {
// uni-datetime-picker返回的已经是格式化后的字符串
this.formData.borrowTime = e
this.formData.use_start_date = e
},
onReturnTimeChange(e) {
// uni-datetime-picker返回的已经是格式化后的字符串
this.formData.returnTime = e
this.formData.use_end_date = e
},
onFileSelect(e) {
console.log('文件选择:', e)
},
addItem() {
// 追加一条物品
this.formData.items = Array.isArray(this.formData.items) ? this.formData.items : []
this.formData.items.push({
item_name_snap: '',
item_id: '',
request_qty: 1
})
},
removeItem(index) {
// 删除指定物品(至少保留 1 条)
if (!Array.isArray(this.formData.items)) return
if (this.formData.items.length <= 1) return
this.formData.items.splice(index, 1)
},
uploadfn(imgUrl){
return new Promise((resolve, reject) => {
uni.uploadFile({
url: 'https://fdesk.hnxinyouhe.com/upload?scene=itemsimg',
filePath: imgUrl,
name: 'file',
header:{'Fdesk-Corp-Abbr':uni.getStorageSync('corp_abbr'),'Fdesk-Auth-Token': 'Bearer ' + uni.getStorageSync('token'),'Fdesk-Language': uni.getStorageSync('i18locale')?uni.getStorageSync('i18locale'):'zh','Fdesk-Login-Type': 'feishu','Fdesk-System-Code':'fdesk'},
success: (uploadFileRes) => {
const res = JSON.parse(uploadFileRes.data || '{}')
if(res && res.data && res.data.file_name){
resolve(res.data)
}else{
reject('上传失败')
}
},
fail: (err) => reject(err)
});
})
},
selectMedia(e){
const allowCount = this.maxMedia - this.formData.attachment.length
const tempFilePaths = e.tempFilePaths || (e.tempFiles || []).map(item => item.path || item.url)
const paths = tempFilePaths.slice(0, allowCount)
if(paths.length === 0){
return
}
Promise.all(paths.map(p => this.uploadfn(p))).then(urls => {
urls.forEach(url => {
const obj={}
obj.original_name =url.original_name
obj.file_path =url.file_name
this.formData.attachment.push(obj)
})
}).catch(() => {
uni.showToast({
title:'图片上传失败,请重试',
icon:'none'
})
})
},
delfn(e){
this.formData.attachment.splice(e.index, 1)
},
handleSubmit() {
// 表单验证
if (!this.formData.borrowTime) {
uni.showToast({
title: '请选择借用时间',
icon: 'none'
})
if (!this.formData.use_start_date) {
uni.showToast({ title: '请选择借用时间', icon: 'none' })
return
}
if (!this.formData.returnTime) {
uni.showToast({
title: '请选择计划归还时间',
icon: 'none'
})
return
}
if (!this.formData.itemName) {
uni.showToast({
title: '请选择物品名称',
icon: 'none'
})
return
}
if (!this.formData.itemCompany) {
uni.showToast({
title: '请选择物品所属公司',
icon: 'none'
})
return
}
if (!this.formData.borrowReason) {
uni.showToast({
title: '请填写借用事由',
icon: 'none'
})
if (!this.formData.use_end_date) {
uni.showToast({ title: '请选择计划归还时间', icon: 'none' })
return
}
// 物品列表校验(至少 1 条,且每条需选择名称 + 数量)
if (!Array.isArray(this.formData.items) || this.formData.items.length === 0) {
uni.showToast({ title: '请添加物品', icon: 'none' })
return
}
for (let i = 0; i < this.formData.items.length; i++) {
const it = this.formData.items[i] || {}
if (!it.item_name_snap) {
uni.showToast({ title: `请选择第${i + 1}个物品名称`, icon: 'none' })
return
}
const request_qty = Number(it.request_qty)
if (!request_qty || request_qty <= 0) {
uni.showToast({ title: `请填写第${i + 1}个物品数量`, icon: 'none' })
return
}
}
if (!this.formData.borrow_reason) {
uni.showToast({ title: '请填写借用事由', icon: 'none' })
return
}
// 提交表单
console.log('提交表单:', this.formData)
uni.showToast({
title: '提交成功',
icon: 'success'
request({
url:'mobile/inv/requisition/apply',
method:'post',
data:this.formData
}).then(res => {
uni.showToast({
title: res.data.message,
icon: 'none'
});
if(res.data.code==200){
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index',// 替换为你要跳转的页面路径
});
}, 1000);
}
})
// 这里可以调用API提交数据
}
@@ -246,16 +340,21 @@
.content-wrapper{
margin-top: 20rpx;
}
.media-upload-wrapper{
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.addimg{
width: 50px;
height:50px;
}
.form-card {
background: #fff;
border-radius: 12rpx;
padding:20rpx 34rpx;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.form-card4 {
background: #fff;
@@ -266,152 +365,130 @@
height: 35px;
line-height: 35px;
}
.form-item {
margin-bottom: 32rpx;
&:last-child {
margin-bottom: 0;
}
&.form-item-row {
display: flex;
align-items: center;
flex-wrap: nowrap;
}
/* 物品(可添加多条) */
.goods-card {
background: #fff;
border-radius: 6px;
padding: 12px 17px;
margin-bottom: 4px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.goods-head {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
margin-bottom: 10px;
}
.goods-add-btn {
background: #3074F7;
color: #fff;
border-radius: 14px;
font-size: 24rpx;
margin-left: auto;
margin-right: inherit;
}
.goods-module {
background: #F7F8FA;
border-radius: 8px;
padding: 10px;
margin-bottom: 10px;
}
.goods-module-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.goods-module-title {
font-size: 26rpx;
color: #333;
}
.goods-module-body {
display: flex;
align-items: center;
}
.goods-name {
flex: 1;
min-width: 0;
}
.goods-qty {
width: 220rpx;
display: flex;
justify-content: flex-end;
margin-left: 16rpx;
}
::v-deep .goods-qty .uni-numbox {
scale: 0.95;
transform-origin: right center;
}
.form-item {
margin-bottom: 32rpx;
&:last-child { margin-bottom: 0; }
}
.form-item-row {
display: flex;
align-items: center;
justify-content: space-between;
}
.form-label1{
margin-bottom: 16rpx;
}
.form-item-row .form-label {
margin-bottom: 0;
margin-right: 24rpx;
}
.form-input-container {
flex: 1;
min-width: 0;
}
.form-label {
font-size: 28rpx;
color: #333;
// margin-bottom: 16rpx;
display: block;
flex-shrink: 0;
min-width: 160rpx;
&.required::before {
content: '*';
color: #ff0000;
margin-right: 4rpx;
}
}
.form-label1{
margin-bottom: 16rpx;
}
.form-item-row .form-label {
margin-bottom: 0;
margin-right: 24rpx;
}
.form-input-container {
flex: 1;
min-width: 0;
}
.form-value {
font-size: 28rpx;
color: #666;
flex: 1;
text-align: right;
}
.form-input-wrapper {
width: 100%;
.category-text{
font-size: 28rpx;
color: #333;
}
.form-input-container .form-input-wrapper {
width: 100%;
}
.custom-datetime-input {
border-radius: 4px;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
text-align: right;
}
.custom-datetime-text {
font-size: 28rpx;
color: #333;
flex: 1;
&.placeholder {
color: #999;
}
}
// uni-datetime-picker 样式覆盖
::v-deep .uni-date-editor {
width: 100%;
}
::v-deep .uni-date-editor--x {
border: none !important;
background: transparent !important;
padding: 0 !important;
}
::v-deep .uni-date-x {
width: 100%;
padding: 0 !important;
}
::v-deep .uni-date__x-input {
display: none;
}
::v-deep .icon-calendar {
display: none;
}
.submit-btn-wrapper {
.submit-container {
margin-top: 40rpx;
padding-bottom: 40rpx;
}
.submit-btn {
width: 70%;
height: 88rpx;
background: #3074F7;
color: #fff;
border-radius: 44rpx;
font-size: 32rpx;
border-radius: 12rpx;
height: 88rpx;
line-height: 88rpx;
border: none;
&::after {
border: none;
}
}
// uni-data-select 样式调整
::v-deep .uni-stat__select {
width: 100%;
}
::v-deep .uni-select {
width: 100%;
border: none;
text-align: right;
}
::v-deep .uni-select__input-text {
font-size: 28rpx;
color: #333;
}
::v-deep .uni-select__input-placeholder {
color: #999;
}
// uni-easyinput 样式调整
::v-deep .uni-easyinput {
width: 100%;
}
::v-deep .uni-easyinput__content {
border: none;
min-height: 120rpx;
}
::v-deep .uni-easyinput__content-textarea {
@@ -420,8 +497,6 @@
min-height: 120rpx;
padding-left: 0px;
}
// uni-file-picker 样式调整
::v-deep .uni-file-picker {
width: 100%;
}
+406 -135
View File
@@ -1,71 +1,122 @@
<template>
<view class="home-page">
<uni-nav-bar leftText=" " :fixed="true" leftIcon="back" :border="false" @clickLeft="leftClick" color="#fff" backgroundColor="rgb(79 137 247)" :statusBar="true" title="详情"></uni-nav-bar>
<uni-nav-bar
leftText=" "
:fixed="true"
leftIcon="back"
:border="false"
@clickLeft="leftClick"
color="#fff"
backgroundColor="rgb(79 137 247)"
:statusBar="true"
title="详情"
></uni-nav-bar>
<view class="content-wrapper">
<view class="detail-card">
<!-- 状态丝带 -->
<view class="status-ribbon" :class="statusClass">
<text class="ribbon-text">{{ statusText }}</text>
<view class="status-ribbon" :class="statusMeta.cls">
<text class="ribbon-text">{{ statusMeta.text }}</text>
</view>
<!-- 标题 -->
<!-- 头部信息 -->
<view class="card-header">
<text class="item-title">{{ detail.itemName }}</text>
</view>
<!-- 申请信息 -->
<view class="section">
<text class="section-title">申请信息</text>
<view class="info-row">
<text class="label">申请人</text>
<text class="value">{{ detail.applicant }}</text>
</view>
<view class="info-row">
<text class="label">公司名称</text>
<text class="value">{{ detail.companyName }}</text>
</view>
<view class="info-row">
<text class="label">物品所属公司</text>
<text class="value">{{ detail.itemCompany }}</text>
</view>
<view class="info-row">
<text class="label">借用时间</text>
<text class="value">{{ detail.borrowTime }}</text>
</view>
<view class="info-row">
<text class="label">计划归还时间</text>
<text class="value">{{ detail.returnTime }}</text>
</view>
<view class="info-row">
<text class="label">借用事由</text>
<text class="value">{{ detail.borrowReason }}</text>
</view>
<view class="info-row" v-if="detail.remarks">
<text class="label">备注</text>
<text class="value">{{ detail.remarks }}</text>
<view class="header-left">
<text class="order-no">{{ detail.order_no || ('#' + id) }}</text>
<text class="sub-line">
申请人:{{ detail.applicant_name || '—' }}
<text class="dot">·</text>
提交:{{ detail.created_at || '—' }}
</text>
</view>
</view>
<!-- 复核信息 -->
<!-- 使用时间 -->
<view class="section">
<text class="section-title">复核信息</text>
<view class="info-row">
<text class="label">复核人</text>
<text class="value">{{ detail.reviewer || '—' }}</text>
<text class="section-title">借用时间</text>
<view class="kv">
<text class="kv-label">开始</text>
<text class="kv-value">{{ detail.use_start_date || '—' }}</text>
</view>
<view class="info-row">
<text class="label">复核时间</text>
<text class="value">{{ detail.reviewTime || '—' }}</text>
<view class="kv">
<text class="kv-label">结束</text>
<text class="kv-value">{{ detail.use_end_date || '—' }}</text>
</view>
<view class="info-row">
<text class="label">复核结果</text>
<text class="value">{{ detail.reviewResult || '—' }}</text>
</view>
<!-- 物品列表 -->
<view class="section">
<view class="section-title-row">
<text class="section-title">物品明细</text>
<text class="section-sub" v-if="Array.isArray(detail.item)">
共 {{ detail.item.length }} 条
</text>
</view>
<view class="info-row" v-if="detail.reviewRemark">
<text class="label">复核说明</text>
<text class="value">{{ detail.reviewRemark }}</text>
<view v-if="Array.isArray(detail.item) && detail.item.length" class="items">
<view class="item-card" v-for="(it, idx) in detail.item" :key="it.id || idx">
<view class="item-top">
<text class="item-name">{{ it.item_name_snap || '—' }}</text>
<text class="item-tag" v-if="String(it.is_consumable_snap) === '1'">耗材</text>
</view>
<view class="item-grid">
<view class="grid-cell">
<text class="g-label">申请</text>
<text class="g-val">{{ safeNum(it.request_qty) }}</text>
</view>
<view class="grid-cell">
<text class="g-label">归还</text>
<text class="g-val">{{ safeNum(it.returned_qty) }}</text>
</view>
</view>
<view class="item-remark" v-if="it.remark">
<text class="remark-label">备注</text>
<text class="remark-value">{{ it.remark }}</text>
</view>
</view>
</view>
<view v-else class="empty-hint">暂无物品明细</view>
</view>
<!-- 借用事由/备注 -->
<view class="section">
<text class="section-title">借用说明</text>
<view class="text-block">
<text class="text-label">借用事由</text>
<text class="text-value">{{ detail.borrow_reason || '—' }}</text>
</view>
<view class="text-block" v-if="detail.remark">
<text class="text-label">备注</text>
<text class="text-value">{{ detail.remark }}</text>
</view>
</view>
<!-- 附件 -->
<view class="section">
<view class="section-title-row">
<text class="section-title">附件</text>
<text class="section-sub" v-if="Array.isArray(detail.attachment)">
{{ detail.attachment.length || 0 }} 张
</text>
</view>
<view v-if="Array.isArray(detail.attachment) && detail.attachment.length" class="attach-grid">
<view
class="attach-item"
v-for="(a, index) in detail.attachment"
:key="a.id || index"
@click="previewAttachment(index)"
>
<image class="attach-img" :src="a.file_path_pull" mode="aspectFill"></image>
</view>
</view>
<view v-else class="empty-hint">暂无附件</view>
</view>
<!-- 底部操作(可选:与列表页一致) -->
<view class="bottom-actions" v-if="showBottomAction">
<button class="primary-btn" @click="goAction">{{ bottomActionText }}</button>
</view>
</view>
</view>
@@ -73,121 +124,343 @@
</template>
<script>
import { request, showToast } from '@/api/apiT.js'
export default {
data() {
return {
id: '',
detail: {
status: 'returned', // returned | notReturned | pendingReview
itemName: '公章',
applicant: '刘宇',
companyName: '合塑',
itemCompany: '合塑',
borrowTime: '2024-11-06 09:41:18',
returnTime: '2024-11-10 18:00:00',
borrowReason: '合同签署使用',
remarks: '请保持物品完整',
reviewer: '张伟',
reviewTime: '2024-11-07 09:00:00',
reviewResult: '已复核',
reviewRemark: '流程符合规定'
}
detail: {}
}
},
computed: {
statusText() {
const map = {
returned: '已归还',
notReturned: '未归还',
pendingReview: '待复核'
// 状态映射
statusMeta() {
const status = String(this.detail.status)
const isReturned = String(this.detail.is_returned) === '1'
const statusMap = {
'10': { text: '待审核', cls: 'ribbon-pendingReview' },
'11': { text: '审批中', cls: 'ribbon-pendingReview' },
'12': { text: '待归还', cls: 'ribbon-notReturned' },
'13': { text: '借用拒绝', cls: 'ribbon-notReturned' },
'14': { text: '归还待审核', cls: 'ribbon-pendingReview' },
'15': { text: '归还审批中', cls: 'ribbon-pendingReview' },
'16': { text: '部分归还', cls: 'ribbon-notReturned' },
'17': { text: '已归还', cls: 'ribbon-returned' },
'18': { text: '归还拒绝', cls: 'ribbon-notReturned' },
'19': { text: '损耗品', cls: 'ribbon-notReturned' }
}
return map[this.detail.status] || ''
if (isReturned) return { text: '已归还', cls: 'ribbon-returned' }
return statusMap[status] || { text: '未知状态', cls: 'ribbon-notReturned' }
},
statusClass() {
return `ribbon-${this.detail.status}`
showBottomAction() {
// 仅在“待归还”和“部分归还”时展示按钮
const status = String(this.detail.status)
const isReturned = String(this.detail.is_returned) === '1'
if (isReturned) return false
return ['12', '16'].includes(status)
},
bottomActionText() {
// 待归还和部分归还状态显示“去归还”按钮
return '去归还'
}
},
onLoad(options) {
this.id = options.id;
this.id = options.id || ''
this.getDetails()
},
methods: {
leftClick(){
leftClick() {
uni.navigateBack({})
},
getDetails() {
if (!this.id) return
request({
url: 'mobile/inv/requisition/show',
method: 'get',
data: { id: this.id }
}).then((res) => {
if (res?.data?.code !== 200) {
showToast({ title: res?.data?.msg || '获取详情失败' })
return
}
const d = res.data.data || {}
// 兜底,避免 v-for 报错
d.item = Array.isArray(d.item) ? d.item : []
d.attachment = Array.isArray(d.attachment) ? d.attachment : []
this.detail = d
})
},
safeNum(v) {
const n = Number(v)
return Number.isFinite(n) ? n : 0
},
previewAttachment(index) {
const urls = (this.detail.attachment || [])
.map((a) => a.file_path_pull)
.filter(Boolean)
if (!urls.length) return
uni.previewImage({
current: urls[index] || urls[0],
urls
})
},
goAction() {
// 待归还和部分归还状态点击按钮导航到归还页面
uni.navigateTo({
url: '/pages/borrow/return?id=' + this.id
})
}
}
}
</script>
<style lang="scss">
.home-page{
.home-page {
min-height: 100vh;
background: linear-gradient(180.05deg, #3074F7 0.04%, #F4F6F8 34.07%);
background: linear-gradient(180.05deg, #3074f7 0.04%, #f4f6f8 34.07%);
box-sizing: border-box;
padding-bottom: 120rpx;
padding: 0px 28rpx;
padding: 0 28rpx 120rpx;
}
.content-wrapper{
.content-wrapper {
margin-top: 20rpx;
}
.detail-card{
.detail-card {
position: relative;
background: #fff;
border-radius: 12rpx;
padding: 32rpx;
box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.05);
padding: 28rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
overflow: hidden;
}
.card-header{
margin-bottom: 16rpx;
.card-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
padding-top: 10rpx;
margin-bottom: 18rpx;
}
.item-title{
.header-left {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.order-no {
font-size: 32rpx;
font-weight: 700;
color: #222;
}
.sub-line {
font-size: 24rpx;
color: #8a8a8a;
}
.dot {
padding: 0 10rpx;
color: #c0c0c0;
}
.section {
margin-top: 22rpx;
padding-top: 10rpx;
border-top: 1rpx solid #f2f2f2;
}
.section-title-row {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 10rpx;
}
.section-title {
font-size: 28rpx;
font-weight: 600;
color: #333;
}
.section{
margin-top: 24rpx;
padding-top: 12rpx;
}
.section-title{
font-size: 28rpx;
font-weight: 500;
color: #444;
margin-bottom: 12rpx;
margin-bottom: 10rpx;
display: block;
}
.info-row{
.section-sub {
font-size: 24rpx;
color: #9a9a9a;
}
.kv {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 12rpx;
align-items: center;
padding: 8rpx 0;
}
.label{
.kv-label {
font-size: 26rpx;
color: #666;
font-size: 26rpx;
}
.value{
color: #333;
.kv-value {
font-size: 26rpx;
color: #333;
text-align: right;
max-width: 66%;
}
.status-ribbon{
.items {
display: flex;
flex-direction: column;
gap: 14rpx;
margin-top: 8rpx;
}
.item-card {
background: #fafbff;
border: 1rpx solid #eef2ff;
border-radius: 12rpx;
padding: 18rpx;
}
.item-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12rpx;
margin-bottom: 14rpx;
}
.item-name {
font-size: 28rpx;
font-weight: 600;
color: #2b2b2b;
flex: 1;
}
.item-tag {
font-size: 22rpx;
padding: 6rpx 12rpx;
border-radius: 999rpx;
color: #3074f7;
background: rgba(48, 116, 247, 0.1);
white-space: nowrap;
}
.item-grid {
display: flex;
gap: 10rpx;
}
.grid-cell {
flex: 1;
background: #ffffff;
border-radius: 10rpx;
padding: 14rpx 10rpx;
text-align: center;
border: 1rpx solid #f0f0f0;
}
.g-label {
display: block;
font-size: 22rpx;
color: #888;
margin-bottom: 6rpx;
}
.g-val {
display: block;
font-size: 30rpx;
font-weight: 700;
color: #222;
}
.item-remark {
margin-top: 12rpx;
display: flex;
gap: 12rpx;
align-items: flex-start;
}
.remark-label {
font-size: 24rpx;
color: #888;
white-space: nowrap;
}
.remark-value {
font-size: 24rpx;
color: #333;
flex: 1;
}
.text-block {
padding: 10rpx 0;
}
.text-label {
display: block;
font-size: 24rpx;
color: #888;
margin-bottom: 6rpx;
}
.text-value {
display: block;
font-size: 26rpx;
color: #333;
line-height: 1.6;
white-space: pre-wrap;
}
.attach-grid {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
margin-top: 10rpx;
}
.attach-item {
width: 32%;
height: 208rpx;
border-radius: 12rpx;
overflow: hidden;
background: #f6f6f6;
}
.attach-img {
width: 100%;
height: 100%;
}
.empty-hint {
padding: 18rpx 0 6rpx;
font-size: 24rpx;
color: #9a9a9a;
}
.bottom-actions {
margin-top: 26rpx;
}
.primary-btn {
width: 100%;
height: 88rpx;
line-height: 88rpx;
border-radius: 14rpx;
background: #3074f7;
color: #fff;
font-size: 30rpx;
font-weight: 600;
}
.status-ribbon {
position: absolute;
top: -5px;
right: -24px;
width: 75px;
height: 37px;
background: #08A400;
top: -4px;
right: -32px;
width: 100px;
height: 47px;
transform: rotate(45deg);
z-index: 10;
display: flex;
@@ -195,25 +468,23 @@
justify-content: center;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}
.ribbon-returned{
background: #08A400;
.ribbon-returned {
background: #08a400;
}
.ribbon-notReturned{
background: #BD0000;
.ribbon-notReturned {
background: #bd0000;
}
.ribbon-pendingReview{
background: #3471FF;
.ribbon-pendingReview {
background: #3471ff;
}
.ribbon-text{
.ribbon-text {
color: #fff;
font-size: 20rpx;
font-weight: 500;
transform: rotate(0deg);
transform-origin: center;
display: block;
text-align: center;
margin-top: 16rpx;
+621
View File
@@ -0,0 +1,621 @@
<template>
<view class="home-page">
<uni-nav-bar leftText=" " :fixed="true" leftIcon="back" :border="false" color="#fff" backgroundColor="rgb(79 137 247)" :statusBar="true" title="借用申请" @clickLeft="leftClick"></uni-nav-bar>
<view class="content-wrapper">
<!-- 申请人信息卡片 -->
<view class="form-card">
<view class="form-item form-item-row">
<text class="form-label">申请人:</text>
<text class="form-value">{{ userinfo.name || '犇犇' }}</text>
</view>
<view class="form-item form-item-row">
<text class="form-label">公司名称:</text>
<text class="form-value">{{ userinfo.corp_name || '合塑' }}</text>
</view>
</view>
<!-- 借用时间 -->
<view class="form-card4">
<view class="form-item form-item-row">
<text class="form-label required">借用时间</text>
<view class="form-input-container">
<uni-datetime-picker
ref="borrowTimePicker"
type="date"
v-model="formData.use_start_date"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
@change="onBorrowTimeChange"
>
<view class="custom-datetime-input">
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.use_start_date }">
{{ formData.use_start_date || '请选择时间' }}
</text>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
</view>
</view>
<!-- 计划归还时间 -->
<view class="form-card4">
<view class="form-item form-item-row">
<text class="form-label required">计划归还时间</text>
<view class="form-input-container">
<uni-datetime-picker
ref="returnTimePicker"
type="date"
v-model="formData.use_end_date"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
@change="onReturnTimeChange"
>
<view class="custom-datetime-input">
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.use_end_date }">
{{ formData.use_end_date || '请选择时间' }}
</text>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
</view>
</view>
<!-- ✅ 物品(可添加多条) -->
<view class="goods-card">
<view class="goods-head">
<text class="form-label required">物品</text>
<button class="goods-add-btn" size="mini" @click="addItem">+ 添加</button>
</view>
<view class="goods-module" v-for="(it, idx) in formData.items" :key="idx">
<view class="goods-module-top">
<text class="goods-module-title">物品 {{ idx + 1 }}</text>
<uni-icons
v-if="formData.items.length > 1"
type="trash"
size="18"
color="#ff4d4f"
@click="removeItem(idx)"
></uni-icons>
</view>
<view class="goods-module-body">
<view class="goods-name">
<picker mode="selector" :range="itemNameOptions" range-key="item_name" @change="onItemNameChange($event, idx)">
<view class="category-content">
<text class="category-text">{{it.item_name_snap || '请选择物品'}}</text>
</view>
</picker>
</view>
<view class="goods-qty">
<uni-number-box v-model="it.request_qty" :min="1" :max="999"></uni-number-box>
</view>
</view>
</view>
</view>
<view class="form-card">
<!-- 借用事由 -->
<view class="form-item">
<text class="form-label required form-label1">借用事由</text>
<uni-easyinput
v-model="formData.borrow_reason"
type="textarea"
:autoHeight="true"
placeholder="请填写借用事由"
:maxlength="500"
></uni-easyinput>
</view>
</view>
<!-- 备注卡片 -->
<view class="form-card " style="margin-bottom: 8rpx;">
<view class="form-item">
<text class="form-label">备注</text>
<uni-easyinput
v-model="formData.remark"
type="textarea"
:autoHeight="true"
placeholder="请填写备注"
:maxlength="500"
></uni-easyinput>
</view>
</view>
<!-- 附件上传 -->
<view class="form-card">
<view class="form-item">
<text class="form-label">附件</text>
<view class="media-upload-wrapper">
<!--
说明:
1) 回显用 :value="mediaValue",每项至少包含 { url }。
2) 关闭组件自带自动上传(auto-upload=false),我们用自己的 uploadfn 上传到后端。
3) 提交给后台时只传 file_path(formData.attachment),展示用 file_path_pull(mediaValue.url)。
-->
<uni-file-picker
ref="mediaPicker"
:limit="maxMedia"
fileMediatype="image"
:auto-upload="false"
:value="mediaValue"
@select="selectMedia"
@delete="delfn"
>
<view class="upload-icon-wrapper">
<image src="/static/image/upload.png" mode="" class="addimg"></image>
</view>
</uni-file-picker>
</view>
</view>
</view>
<!-- 提交按钮 -->
<view class="submit-container">
<button class="submit-btn" @click="handleSubmit">提交申请</button>
</view>
</view>
</view>
</template>
<script>
import { request,showToast } from '@/api/apiT.js'
export default {
data() {
return {
id:'',
userinfo: {},
maxMedia:20,
// uni-file-picker 用于回显的文件列表(展示用)
// 结构:[{ url: 'https://...', name: 'xxx.jpg' }]
mediaValue: [],
formData: {
use_start_date: '',
use_end_date: '',
items: [{ item_name_snap: '',item_id:'',request_qty:1}],
borrow_reason: '',
remark: '',
attachment: []
},
itemNameOptions: [],
}
},
onLoad(options) {
this.id = options.id
this.getinfo()
this.getItemNameOptions()
// 编辑页:有 id 则回显详情
if (this.id) {
this.getdetils()
}
},
methods: {
leftClick(){
uni.navigateBack({})
},
// 获取详情并回显
getdetils() {
request({
url:'mobile/inv/requisition/show',
method:'get',
data:{id:this.id}
}).then(res => {
const d = (res.data && res.data.data) ? res.data.data : {}
// 1) 基础字段
this.formData.id = d.id
this.formData.use_start_date = d.use_start_date || ''
this.formData.use_end_date = d.use_end_date || ''
this.formData.borrow_reason = d.borrow_reason || ''
this.formData.remark = d.remark || ''
// 2) 物品列表:后端字段是 item,这里统一成 items
const items = Array.isArray(d.item) ? d.item : []
this.formData.items = items.length
? items.map(it => ({
// 保留 id 等字段,方便后端识别是更新还是新增
id: it.id,
requisition_id: it.requisition_id,
item_id: it.item_id,
item_name_snap: it.item_name_snap,
request_qty: Number(it.request_qty || 1),
approved_qty: it.approved_qty,
returned_qty: it.returned_qty,
remark: it.remark || ''
}))
: [{ item_name_snap: '', item_id: '', request_qty: 1 }]
// 3) 附件:
// - formData.attachment:提交给后台(file_path)
// - mediaValue:回显展示(file_path_pull)
const atts = Array.isArray(d.attachment) ? d.attachment : []
this.formData.attachment = atts.map(a => ({
id: a.id,
original_name: a.file_name,
file_path: a.file_path
}))
this.mediaValue = atts.map(a => ({
url: a.file_path_pull || a.file_path,
name: a.file_name
}))
})
},
getinfo(){
request({
url:'common/user/info',
method:'get',
}).then(res => {
this.userinfo=res.data.data.user
})
},
//物品下拉
getItemNameOptions() {
request({
url:'mobile/inv/item/preset',
method:'get',
}).then(res => {
this.itemNameOptions = res.data.data
this.itemNameOptions.forEach(item => {
item.item_name = item.item_name + '(' + item.company_name + ')'
})
console.log(this.itemNameOptions)
})
},
// 选择物品(注意:需要知道是第几行物品)
onItemNameChange(e, rowIndex) {
const optIndex = e.detail.value // picker 返回选项下标
const selectItem = this.itemNameOptions[optIndex]
if (!selectItem) return
if (!Array.isArray(this.formData.items)) this.formData.items = []
if (!this.formData.items[rowIndex]) return
this.formData.items[rowIndex].item_name_snap = selectItem.item_name
this.formData.items[rowIndex].item_id = selectItem.id
},
onBorrowTimeChange(e) {
this.formData.use_start_date = e
},
onReturnTimeChange(e) {
this.formData.use_end_date = e
},
onFileSelect(e) {
console.log('文件选择:', e)
},
addItem() {
// 追加一条物品
this.formData.items = Array.isArray(this.formData.items) ? this.formData.items : []
this.formData.items.push({
item_name_snap: '',
item_id: '',
request_qty: 1
})
},
removeItem(index) {
// 删除指定物品(至少保留 1 条)
if (!Array.isArray(this.formData.items)) return
if (this.formData.items.length <= 1) return
this.formData.items.splice(index, 1)
},
uploadfn(imgUrl){
return new Promise((resolve, reject) => {
uni.uploadFile({
url: 'https://fdesk.hnxinyouhe.com/upload?scene=itemsimg',
filePath: imgUrl,
name: 'file',
header:{'Fdesk-Corp-Abbr':uni.getStorageSync('corp_abbr'),'Fdesk-Auth-Token': 'Bearer ' + uni.getStorageSync('token'),'Fdesk-Language': uni.getStorageSync('i18locale')?uni.getStorageSync('i18locale'):'zh','Fdesk-Login-Type': 'feishu','Fdesk-System-Code':'fdesk'},
success: (uploadFileRes) => {
const res = JSON.parse(uploadFileRes.data || '{}')
if(res && res.data && res.data.file_name){
resolve(res.data)
}else{
reject('上传失败')
}
},
fail: (err) => reject(err)
});
})
},
selectMedia(e){
// 选择图片后:先占位写入 attachment,确保“删除”时 index 一致
this.formData.attachment = Array.isArray(this.formData.attachment) ? this.formData.attachment : []
const allowCount = this.maxMedia - this.formData.attachment.length
const tempFilePaths = e.tempFilePaths || (e.tempFiles || []).map(item => item.path || item.url)
const paths = tempFilePaths.slice(0, allowCount)
if(paths.length === 0) return
const startIndex = this.formData.attachment.length
paths.forEach(p => {
this.formData.attachment.push({
__local_path: p,
original_name: '',
file_path: ''
})
})
Promise.all(
paths.map((p, i) =>
this.uploadfn(p)
.then(data => ({ i, ok: true, data }))
.catch(err => ({ i, ok: false, err }))
)
).then(results => {
// 先写入成功结果
results.forEach(r => {
if (!r.ok) return
const idx = startIndex + r.i
const row = this.formData.attachment[idx]
if (!row) return
row.original_name = r.data.original_name
// 后端需要的路径字段(注意:接口返回里叫 file_name,但实际是存储路径)
row.file_path = r.data.file_name
delete row.__local_path
})
// 再从后往前移除失败项(同时把 picker 里也删掉)
const failed = results.filter(r => !r.ok).map(r => r.i).sort((a,b) => b - a)
if (failed.length) {
failed.forEach(i => {
const idx = startIndex + i
// 删除占位
this.formData.attachment.splice(idx, 1)
// 同步删除 picker 中对应图片
this.$nextTick(() => {
if (this.$refs.mediaPicker && this.$refs.mediaPicker.clearFiles) {
this.$refs.mediaPicker.clearFiles(idx)
}
})
})
uni.showToast({
title:'部分图片上传失败,已自动移除,请重试',
icon:'none'
})
}
})
},
delfn(e){
this.formData.attachment.splice(e.index, 1)
// 仅删除“回显列表”里对应的旧附件(新选的图片不在 mediaValue 中)
if (Array.isArray(this.mediaValue) && e.index < this.mediaValue.length) {
this.mediaValue.splice(e.index, 1)
}
},
handleSubmit() {
// 表单验证
if (!this.formData.use_start_date) {
uni.showToast({ title: '请选择借用时间', icon: 'none' })
return
}
if (!this.formData.use_end_date) {
uni.showToast({ title: '请选择计划归还时间', icon: 'none' })
return
}
// 物品列表校验(至少 1 条,且每条需选择名称 + 数量)
if (!Array.isArray(this.formData.items) || this.formData.items.length === 0) {
uni.showToast({ title: '请添加物品', icon: 'none' })
return
}
for (let i = 0; i < this.formData.items.length; i++) {
const it = this.formData.items[i] || {}
if (!it.item_name_snap) {
uni.showToast({ title: `请选择第${i + 1}个物品名称`, icon: 'none' })
return
}
const request_qty = Number(it.request_qty)
if (!request_qty || request_qty <= 0) {
uni.showToast({ title: `请填写第${i + 1}个物品数量`, icon: 'none' })
return
}
}
if (!this.formData.borrow_reason) {
uni.showToast({ title: '请填写借用事由', icon: 'none' })
return
}
// 附件:如有占位未上传完成,不允许提交
if (Array.isArray(this.formData.attachment)) {
const uploading = this.formData.attachment.some(a => !a || !a.file_path)
if (uploading) {
uni.showToast({ title: '附件上传中,请稍后再提交', icon: 'none' })
return
}
}
// 提交表单
console.log('提交表单:', this.formData)
request({
url:'mobile/inv/requisition/update',
method:'post',
data:this.formData
}).then(res => {
uni.showToast({
title: res.data.message,
icon: 'none'
});
if(res.data.code==200){
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index',// 替换为你要跳转的页面路径
});
}, 1000);
}
})
// 这里可以调用API提交数据
}
}
}
</script>
<style lang="scss">
.home-page{
min-height: 100vh;
background: linear-gradient(180.05deg, #3074F7 0.04%, #F4F6F8 34.07%);
box-sizing: border-box;
padding-bottom: 120rpx;
padding: 0px 28rpx;
}
.content-wrapper{
margin-top: 20rpx;
}
.media-upload-wrapper{
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.addimg{
width: 50px;
height:50px;
}
.form-card {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.form-card4 {
background: #fff;
border-radius: 6px;
padding: 3px 17px;
margin-bottom: 4px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
height: 35px;
line-height: 35px;
}
/* 物品(可添加多条) */
.goods-card {
background: #fff;
border-radius: 6px;
padding: 12px 17px;
margin-bottom: 4px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.goods-head {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
margin-bottom: 10px;
}
.goods-add-btn {
background: #3074F7;
color: #fff;
border-radius: 14px;
font-size: 24rpx;
margin-left: auto;
margin-right: inherit;
}
.goods-module {
background: #F7F8FA;
border-radius: 8px;
padding: 10px;
margin-bottom: 10px;
}
.goods-module-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.goods-module-title {
font-size: 26rpx;
color: #333;
}
.goods-module-body {
display: flex;
align-items: center;
}
.goods-name {
flex: 1;
min-width: 0;
}
.goods-qty {
width: 220rpx;
display: flex;
justify-content: flex-end;
margin-left: 16rpx;
}
::v-deep .goods-qty .uni-numbox {
scale: 0.95;
transform-origin: right center;
}
.form-item {
margin-bottom: 32rpx;
&:last-child { margin-bottom: 0; }
}
.form-item-row {
display: flex;
align-items: center;
justify-content: space-between;
}
.form-label1{
margin-bottom: 16rpx;
}
.form-item-row .form-label {
margin-bottom: 0;
margin-right: 24rpx;
}
.form-input-container {
flex: 1;
min-width: 0;
}
.form-label {
font-size: 28rpx;
color: #333;
display: block;
flex-shrink: 0;
min-width: 160rpx;
&.required::before {
content: '*';
color: #ff0000;
margin-right: 4rpx;
}
}
.form-value {
font-size: 28rpx;
color: #666;
flex: 1;
}
.category-text{
font-size: 28rpx;
color: #333;
}
.custom-datetime-input {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
.custom-datetime-text {
font-size: 28rpx;
color: #333;
&.placeholder {
color: #999;
}
}
.submit-container {
margin-top: 40rpx;
padding-bottom: 40rpx;
}
.submit-btn {
background: #3074F7;
color: #fff;
font-size: 32rpx;
border-radius: 12rpx;
height: 88rpx;
line-height: 88rpx;
}
::v-deep .uni-easyinput__content-textarea {
font-size: 28rpx;
color: #333;
min-height: 120rpx;
padding-left: 0px;
}
::v-deep .uni-file-picker {
width: 100%;
}
</style>
+4 -4
View File
@@ -223,10 +223,10 @@
// 状态标签(旋转丝带效果)
.status-ribbon {
position: absolute;
top: -5px;
right: -24px;
width: 75px;
height: 37px;
top: -4px;
right: -32px;
width: 100px;
height: 47px;
background: #4CAF50;
transform: rotate(45deg);
z-index: 10;
+4 -4
View File
@@ -221,10 +221,10 @@
// 状态标签(旋转丝带效果)
.status-ribbon {
position: absolute;
top: -5px;
right: -24px;
width: 75px;
height: 37px;
top: -4px;
right: -32px;
width: 100px;
height: 47px;
background: #4CAF50;
transform: rotate(45deg);
z-index: 10;
+123 -108
View File
@@ -1,6 +1,6 @@
<template>
<view class="home-page">
<z-paging ref="paging" :auto="false" v-model="contList" @query="queryList" empty-view-text="暂无数据!">
<z-paging ref="paging" :auto="false" v-model="borrowList" @query="queryList" empty-view-text="暂无数据!">
<template #top>
<uni-nav-bar leftText=" " :fixed="true" leftIcon="back" :border="false" @clickLeft="leftClick" color="#fff" backgroundColor="rgb(48, 116, 247)" :statusBar="true" title="借用列表"></uni-nav-bar>
<!-- Tab栏 -->
@@ -21,9 +21,8 @@
<view class="list-container">
<view
class="borrow-card"
v-for="(item, index) in filteredList"
v-for="(item, index) in borrowList"
:key="index"
@click="handleCardClick(item)"
>
<!-- 状态标签(右上角旋转丝带) -->
<view class="status-ribbon" :class="'ribbon-' + item.status">
@@ -32,26 +31,29 @@
<!-- 卡片内容 -->
<view class="card-content">
<view class="card-title">{{ item.itemName }}</view>
<view class="card-info">
<text class="info-item">申请人: {{ item.applicant }}</text>
<text class="info-item">借用时间: {{ item.borrowTime }}</text>
<view class="action-btns">
<text class="info-item">公司名称: {{ item.companyName }}</text>
<!-- 操作按钮 -->
<view class="card-actions" v-if="item.status !== 'returned'">
<button
class="action-btn"
:class="'btn-' + item.status"
@click="handleAction(item)"
>
{{ getActionText(item.status) }}
</button>
</view>
<view class="card-title" @click="handleCardClick(item)">
<uni-tag :text="item1.item_name_snap" size="mini" type="primary" v-for="(item1, index) in item.item" :key="index"/>
</view>
<view class="card-info" @click="handleCardClick(item)">
<text class="info-item">申请人: {{ item.applicant_name }}</text>
<text class="info-item">借用时间: {{ item.use_start_date || '-' }} ~ {{ item.use_end_date || '-' }}</text>
</view>
<view class="action-btns">
<!-- <text class="info-item">公司名称: {{ item.companyName }}</text> -->
<text class="info-item"></text>
<!-- 操作按钮 -->
<view class="card-actions" v-if="item.status !== 'returned'">
<button
class="action-btn"
:class="'btn-' + item.status"
@click="handleAction(item)"
v-if="item.status==10||item.status==12||item.status==14||item.status==16"
>
{{ getActionText(item.status) }}
</button>
</view>
</view>
</view>
</view>
</view>
@@ -61,55 +63,23 @@
</template>
<script>
import { request,showToast } from '@/api/apiT.js'
export default {
data() {
return {
currentTab: 0,
tabList: ['全部', '已归还', '未归还', '待复核'],
borrowList: [
{
id: 1,
itemName: '公章',
applicant: '刘宇',
borrowTime: '2024-11-06 09:41:18',
companyName: '合塑',
status: 'returned' // returned, notReturned, pendingReview
},
{
id: 2,
itemName: '公章',
applicant: '刘宇',
borrowTime: '2024-11-06 09:41:18',
companyName: '合塑',
status: 'notReturned'
},
{
id: 3,
itemName: '公章',
applicant: '刘宇',
borrowTime: '2024-11-06 09:41:18',
companyName: '合塑',
status: 'pendingReview'
},
{
id: 4,
itemName: '公章',
applicant: '刘宇',
borrowTime: '2024-11-06 09:41:18',
companyName: '合塑',
status: 'pendingReview'
},
{
id: 5,
itemName: '公章',
applicant: '刘宇',
borrowTime: '2024-11-06 09:41:18',
companyName: '合塑',
status: 'pendingReview'
return {
currentTab: 0,
tabList: ['全部', '已归还', '未归还', '待审核'],
borrowList: []
}
},
onLoad() {
// 页面加载时初始化数据
this.$nextTick(() => {
if (this.$refs.paging) {
this.$refs.paging.reload()
}
]
}
},
})
},
computed: {
filteredList() {
if (this.currentTab === 0) {
@@ -130,19 +100,55 @@
},
switchTab(index) {
this.currentTab = index
// 重置分页并重新加载数据
if (this.$refs.paging) {
this.$refs.paging.reload()
}
},
queryList(pageNo, pageSize, from) {
this.loading = true;
var that = this;
const params = {
current:pageNo,
size:10,
applicant_id:'self',
status: this.currentTab === 0 ? '' : (this.currentTab === 1 ? 'repaid' : (this.currentTab === 2 ? 'unreturned' : 'approve'))
};
request({
url:'mobile/inv/requisition/list',
method:'get',
data: params
}).then(res => {
if(res.data.code ==200){
var datas = res.data.data.records;
this.$refs.paging.complete(datas);
}else{
}
uni.stopPullDownRefresh();
//
})
},
getStatusText(status) {
const statusMap = {
'returned': '已归还',
'notReturned': '未归还',
'pendingReview': '待复核'
'10': '待审核',
'11': '审批中',
'12': '待归还',
'13': '借用拒绝',
'14': '归还待审核',
'15': '归还审批中',
'16': '部分归还',
'17': '已归还',
'18': '归还拒绝',
'19': '损耗品'
}
return statusMap[status] || ''
},
getActionText(status) {
const actionMap = {
'notReturned': '立即归还',
'pendingReview': '立即复核'
'12': '归还',
'14': '编辑',
'10': '编辑',
'16': '归还',
}
return actionMap[status] || ''
},
@@ -152,28 +158,19 @@
});
},
handleAction(item) {
if (item.status === 'notReturned') {
if (item.status == 12 || item.status == 16) {
// 归还操作
uni.navigateTo({
url: '/pages/borrow/return'
url: '/pages/borrow/return?id='+item.id
});
// uni.showModal({
// title: '提示',
// content: '确定要归还该物品吗?',
// success: (res) => {
// if (res.confirm) {
// uni.showToast({
// title: '归还成功',
// icon: 'success'
// })
// // 这里可以调用API更新状态
// }
// }
// })
} else if (item.status === 'pendingReview') {
// 复核操作
} else if (item.status == 10) {
uni.navigateTo({
url: '/pages/borrow/review'
url: '/pages/borrow/borrow_edit?id='+item.id
});
} else if (item.status == 14) {
uni.navigateTo({
url: '/pages/borrow/return_edit?id='+item.id
});
}
}
@@ -242,10 +239,10 @@
// 状态标签(旋转丝带效果)
.status-ribbon {
position: absolute;
top: -5px;
right: -24px;
width: 75px;
height: 37px;
top: -4px;
right: -32px;
width: 100px;
height: 47px;
background: #08A400;
transform: rotate(45deg);
z-index: 10;
@@ -254,19 +251,39 @@
justify-content: center;
box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.15);
}
.ribbon-returned {
background: #08A400; // 绿色
}
.ribbon-notReturned {
background: #BD0000; // 红色
}
.ribbon-pendingReview {
.ribbon-10 {
background: #3471FF; // 蓝色
}
.ribbon-11 {
background: #FA8C16;
}
.ribbon-12 {
background: #722ED1;
}
.ribbon-13 {
background: #F5222D;
}
.ribbon-14 {
background: #13C2C2;
}
.ribbon-15 {
background: #FAAD14;
}
.ribbon-16 {
background: #52C41A;
}
.ribbon-17 {
background: #389E0D;
}
.ribbon-18 {
background: #A8071A;
}
.ribbon-19 {
background: #8C8C8C;
}
.ribbon-text {
color: #fff;
font-size: 20rpx;
@@ -290,6 +307,8 @@
font-weight: 500;
color: #333;
margin-bottom: 24rpx;
display: flex;
gap: 10px;
}
.card-info {
@@ -330,11 +349,7 @@
}
}
.btn-notReturned {
background: #3074F7;
}
.btn-pendingReview {
background: #3074F7;
.btn-12, .btn-16 {
background: #52C41A;
}
</style>
+417 -274
View File
@@ -1,398 +1,567 @@
<template>
<view class="home-page">
<uni-nav-bar leftText=" " :fixed="true" leftIcon="back" :border="false" @clickLeft="leftClick" color="#fff" backgroundColor="rgb(79 137 247)" :statusBar="true" title="物品归还"></uni-nav-bar>
<uni-nav-bar
leftText=" "
:fixed="true"
leftIcon="back"
:border="false"
color="#fff"
backgroundColor="rgb(79 137 247)"
:statusBar="true"
title="物品归还"
@clickLeft="leftClick"
></uni-nav-bar>
<view class="content-wrapper">
<!-- 申请人信息卡片 -->
<!-- 借用基本信息 -->
<view class="form-card">
<view class="form-item form-item-row">
<text class="form-label">申请人:</text>
<text class="form-value">{{ formData.applicant || '犇犇' }}</text>
<text class="form-label">申请人</text>
<text class="form-value">{{ detail.applicant_name || '-' }}</text>
</view>
<view class="form-item form-item-row">
<text class="form-label">公司名称:</text>
<text class="form-value">{{ formData.companyName || '合塑' }}</text>
<text class="form-label">单号</text>
<text class="form-value">{{ detail.order_no || '-' }}</text>
</view>
</view>
<!-- 借用详情卡片 -->
<view class="form-card4">
<!-- 借用时间 -->
<view class="form-item form-item-row">
<text class="form-label">借用时间</text>
<view class="form-input-container">
<uni-datetime-picker
ref="borrowTimePicker"
type="datetime"
v-model="formData.borrowTime"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
@change="onBorrowTimeChange"
>
<view class="custom-datetime-input">
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.borrowTime }">
{{ formData.borrowTime || '请选择时间' }}
</text>
<uni-icons type="calendar" size="18" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
<text class="form-value">{{ detail.use_start_date || '-' }}</text>
</view>
</view>
<view class="form-card4">
<!-- 计划归还时间 -->
<view class="form-item form-item-row">
<text class="form-label">计划归还时间</text>
<view class="form-input-container">
<uni-datetime-picker
ref="returnTimePicker"
type="datetime"
v-model="formData.returnTime"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
@change="onReturnTimeChange"
>
<view class="custom-datetime-input">
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.returnTime }">
{{ formData.returnTime || '请选择时间' }}
</text>
<uni-icons type="calendar" size="18" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
<text class="form-label">计划归还</text>
<text class="form-value">{{ detail.use_end_date || '-' }}</text>
</view>
</view>
<view class="form-card4">
<!-- 物品所属公司 -->
<view class="form-item form-item-row">
<text class="form-label">物品所属公司</text>
<view class="form-input-container">
<uni-data-select
v-model="formData.itemCompany"
:localdata="itemCompanyOptions"
placeholder="请选择"
:clear="false"
></uni-data-select>
</view>
</view>
</view>
<view class="form-card">
<!-- 借用事由 -->
<view class="form-item">
<text class="form-label">借用事由</text>
<uni-easyinput
v-model="formData.borrowReason"
type="textarea"
:autoHeight="true"
placeholder="请填写借用事由"
:maxlength="500"
></uni-easyinput>
<view class="text-block">{{ detail.borrow_reason || '-' }}</view>
</view>
</view>
<view class="form-card4">
<!-- 物品名称 -->
<view class="form-item form-item-row">
<text class="form-label required">归还物品名称</text>
<view class="form-input-container">
<uni-data-select
v-model="formData.itemName"
:localdata="itemNameOptions"
placeholder="请选择"
:clear="false"
></uni-data-select>
<!-- 归还物品(可删减 + 改数量) -->
<view class="goods-card">
<view class="goods-head">
<text class="goods-title">归还物品</text>
<text class="goods-sub">可删减物品,数量不超过“可归还”</text>
</view>
<view v-if="returnItems.length === 0" class="empty-tip">
暂无可归还物品
</view>
<view class="goods-module" v-for="(it, idx) in returnItems" :key="it._key">
<view class="goods-module-top">
<view class="goods-module-title">
<text class="name">{{ it.item_name_snap || '-' }}</text>
</view>
<uni-icons
type="trash"
size="18"
color="#ff4d4f"
@click="removeReturnItem(idx)"
></uni-icons>
</view>
<view class="goods-meta">
<view class="meta">
<text class="k">借用</text>
<text class="v">{{ it.approved_qty }}</text>
</view>
<view class="meta">
<text class="k">已还</text>
<text class="v">{{ it.returned_qty }}</text>
</view>
<view class="meta">
<text class="k">可归还</text>
<text class="v">{{ it.can_return }}</text>
</view>
</view>
<view class="goods-module-body">
<text class="qty-label required">本次归还数量</text>
<uni-number-box
v-model="it.return_qty"
:min="1"
:max="it.can_return"
></uni-number-box>
</view>
</view>
</view>
<view class="form-card">
<!-- 计划归还时间 -->
</view>
<!-- 实际归还时间 -->
<view class="form-card4">
<view class="form-item form-item-row">
<text class="form-label required">实际归还时间</text>
<view class="form-input-container">
<uni-datetime-picker
ref="returnTimePicker"
type="datetime"
v-model="formData.returnTime"
type="date"
v-model="formData.return_at"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
@change="onReturnTimeChange"
>
<view class="custom-datetime-input">
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.returnTime }">
{{ formData.returnTime || '请选择时间' }}
<text class="custom-datetime-text" :class="{ placeholder: !formData.return_at }">
{{ formData.return_at || '请选择时间' }}
</text>
<uni-icons type="calendar" size="18" color="#999"></uni-icons>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
</view>
</view>
<!-- 备注卡片 -->
<view class="form-card " style="margin-bottom: 8rpx;">
<!-- 备注 -->
<view class="form-card" style="margin-bottom: 8rpx;">
<view class="form-item">
<text class="form-label">备注</text>
<uni-easyinput
v-model="formData.remarks"
type="textarea"
<text class="form-label">归还备注</text>
<uni-easyinput
v-model="formData.apply_remark"
type="textarea"
:autoHeight="true"
placeholder="请填写备注"
placeholder="请填写归还备注"
:maxlength="500"
></uni-easyinput>
</view>
</view>
<!-- 附件卡片 -->
<!-- 附件(多图) -->
<view class="form-card">
<view class="form-item">
<text class="form-label form-label1">附件</text>
<uni-file-picker
v-model="formData.attachments"
file-mediatype="image"
mode="grid"
:limit="9"
:auto-upload="false"
@select="onFileSelect"
>
<image src="/static/image/upload.png" mode="" class="addimg"></image>
</uni-file-picker>
<text class="form-label">附件</text>
<view class="media-upload-wrapper">
<uni-file-picker
:value="mediaValue"
limit="20"
fileMediatype="image"
:disabled="uploading"
:auto-upload="false"
@select="selectMedia"
@delete="delfn"
>
<view class="upload-icon-wrapper">
<image src="/static/image/upload.png" class="addimg"></image>
</view>
</uni-file-picker>
</view>
</view>
</view>
<!-- 提交按钮 -->
<view class="submit-btn-wrapper">
<button class="submit-btn" @click="handleSubmit">提交</button>
<!-- 提交 -->
<view class="submit-container">
<button class="submit-btn" :disabled="submitting || uploading" @click="handleSubmit">
{{ submitting ? '提交中...' : '提交归还' }}
</button>
</view>
</view>
</view>
</template>
<script>
import { request } from '@/api/apiT.js'
export default {
data() {
return {
id: '',
detail: {},
returnItems: [],
formData: {
applicant: '犇犇',
companyName: '合塑',
borrowTime: '',
returnTime: '',
itemName: '',
itemCompany: '',
borrowReason: '',
remarks: '',
attachments: []
},
itemNameOptions: [
{ text: '物品1', value: 'item1' },
{ text: '物品2', value: 'item2' },
{ text: '物品3', value: 'item3' }
],
itemCompanyOptions: [
{ text: '公司A', value: 'companyA' },
{ text: '公司B', value: 'companyB' },
{ text: '公司C', value: 'companyC' }
]
return_at: '',
apply_remark: '',
attachment: [] // 仅用于提交后台:[{original_name,file_path}]
},
mediaValue: [], // 仅用于 file-picker 展示:[{url,name,...}]
uploading: false,
submitting: false,
maxMedia: 20,
// 注意:根据你后端实际路由调整(目前项目里只有 apply/list/show)
RETURN_API: 'mobile/inv/requisition/return/store'
}
},
onLoad(options) {
this.id = options.id || ''
if (this.id) {
this.getDetails()
}
},
methods: {
leftClick(){
leftClick() {
uni.navigateBack({})
},
onBorrowTimeChange(e) {
// uni-datetime-picker返回的已经是格式化后的字符串
this.formData.borrowTime = e
},
onReturnTimeChange(e) {
// uni-datetime-picker返回的已经是格式化后的字符串
this.formData.returnTime = e
},
onFileSelect(e) {
console.log('文件选择:', e)
},
handleSubmit() {
// 表单验证
if (!this.formData.borrowTime) {
uni.showToast({
title: '请选择借用时间',
icon: 'none'
})
return
}
if (!this.formData.returnTime) {
uni.showToast({
title: '请选择计划归还时间',
icon: 'none'
})
return
}
if (!this.formData.itemName) {
uni.showToast({
title: '请选择物品名称',
icon: 'none'
})
return
}
if (!this.formData.itemCompany) {
uni.showToast({
title: '请选择物品所属公司',
icon: 'none'
})
return
}
if (!this.formData.borrowReason) {
uni.showToast({
title: '请填写借用事由',
icon: 'none'
})
return
}
// 提交表单
console.log('提交表单:', this.formData)
uni.showToast({
title: '提交成功',
icon: 'success'
// 拉取详情并回显
getDetails() {
request({
url: 'mobile/inv/requisition/show',
method: 'get',
data: { id: this.id }
}).then(res => {
const d = (res && res.data && res.data.data) ? res.data.data : {}
this.detail = d || {}
this.buildReturnItems(d)
})
},
// 把借用明细转换为“可归还”明细
buildReturnItems(d) {
const list = Array.isArray(d && d.item) ? d.item : []
const items = []
list.forEach(row => {
const approved = Number(row.approved_qty || row.request_qty || 0)
const returned = Number(row.returned_qty || 0)
const canReturn = Math.max(approved - returned, 0)
if (canReturn <= 0) return
items.push({
_key: `${row.id || row.item_id || ''}_${Date.now()}_${Math.random()}`,
id: row.id, // requisition_item_id
item_id: row.item_id,
item_name_snap: row.item_name_snap,
approved_qty: approved,
returned_qty: returned,
can_return: canReturn,
return_qty: canReturn // 默认全部归还(可自行改小/删减)
})
})
this.returnItems = items
},
removeReturnItem(idx) {
if (!Array.isArray(this.returnItems)) return
this.returnItems.splice(idx, 1)
},
// 上传单张(复用你项目里的 OSS 上传地址 + Header)
uploadfn(imgUrl) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: 'https://fdesk.hnxinyouhe.com/upload?scene=itemsimg',
filePath: imgUrl,
name: 'file',
header: {
'Fdesk-Corp-Abbr': uni.getStorageSync('corp_abbr'),
'Fdesk-Auth-Token': 'Bearer ' + uni.getStorageSync('token'),
'Fdesk-Language': uni.getStorageSync('i18locale') ? uni.getStorageSync('i18locale') : 'zh',
'Fdesk-Login-Type': 'feishu',
'Fdesk-System-Code': 'fdesk'
},
success: (uploadFileRes) => {
let json = {}
try {
json = JSON.parse(uploadFileRes.data || '{}')
} catch (e) {}
if (json && json.data && (json.data.file_name || json.data.file_path || json.data.file)) {
resolve(json.data)
} else {
reject('上传失败')
}
},
fail: (err) => reject(err)
})
})
},
selectMedia(e) {
if (this.uploading) return
const allowCount = this.maxMedia - this.formData.attachment.length
const tempFilePaths = e.tempFilePaths || (e.tempFiles || []).map(item => item.path || item.url)
const paths = tempFilePaths.slice(0, allowCount)
if (paths.length === 0) return
this.uploading = true
Promise.all(paths.map(p => this.uploadfn(p)))
.then(list => {
list.forEach((u, i) => {
// 兼容后端返回字段(你上面示例是 file_name/original_name)
const original = u.original_name || u.file_original_name || u.name || ('image_' + Date.now())
const filePath = u.file_name || u.file_path || u.path || ''
this.formData.attachment.push({
original_name: original,
file_path: filePath
})
// file-picker 展示用:本地选择的临时路径更直观
this.mediaValue.push({
name: original,
url: paths[i]
})
})
})
.catch(() => {
uni.showToast({ title: '图片上传失败,请重试', icon: 'none' })
})
.finally(() => {
this.uploading = false
})
},
delfn(e) {
// file-picker 的 index 和本地 mediaValue 一致;我们让 attachment 同步删除
const idx = e.index
if (idx >= 0) {
this.mediaValue.splice(idx, 1)
this.formData.attachment.splice(idx, 1)
}
},
handleSubmit() {
if (this.submitting || this.uploading) return
if (!this.id) {
uni.showToast({ title: '缺少借用申请ID', icon: 'none' })
return
}
if (!this.formData.return_at) {
uni.showToast({ title: '请选择归还时间', icon: 'none' })
return
}
if (!Array.isArray(this.returnItems) || this.returnItems.length === 0) {
uni.showToast({ title: '请选择需要归还的物品', icon: 'none' })
return
}
for (let i = 0; i < this.returnItems.length; i++) {
const it = this.returnItems[i] || {}
const qty = Number(it.return_qty)
if (!qty || qty <= 0) {
uni.showToast({ title: `请填写第${i + 1}个物品的归还数量`, icon: 'none' })
return
}
if (qty > Number(it.can_return || 0)) {
uni.showToast({ title: `第${i + 1}个物品归还数量超过可归还`, icon: 'none' })
return
}
}
const payload = {
requisition_id: this.id,
return_at: this.formData.return_at,
apply_remark: this.formData.apply_remark,
attachment: this.formData.attachment,
items: this.returnItems.map(it => ({
requisition_item_name: it.item_name_snap || '',
requisition_item_id: it.id, // requisition_item_id
return_qty: it.return_qty
}))
}
this.submitting = true
request({
url: this.RETURN_API,
method: 'post',
data: payload
}).then(res => {
uni.showToast({
title: res.data.message,
icon: 'none'
});
if(res.data.code==200){
setTimeout(() => {
uni.navigateTo({
url: '/pages/borrow/borrow_list'
});
}, 1000);
}
}).finally(() => {
this.submitting = false
})
// 这里可以调用API提交数据
}
}
}
</script>
<style lang="scss">
.home-page{
.home-page {
min-height: 100vh;
background: linear-gradient(180.05deg, #3074F7 0.04%, #F4F6F8 34.07%);
box-sizing: border-box;
padding-bottom: 120rpx;
padding: 0px 28rpx;
}
.content-wrapper{
.content-wrapper {
margin-top: 20rpx;
}
.addimg{
width: 50px;
height:50px;
}
.form-card {
background: #fff;
border-radius: 12rpx;
padding:20rpx 34rpx;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.form-card4 {
background: #fff;
border-radius: 6px;
padding: 3px 17px;
margin-bottom: 4px;
margin-bottom: 10px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
height: 35px;
line-height: 35px;
}
.form-item {
margin-bottom: 32rpx;
margin-bottom: 20rpx;
&:last-child {
margin-bottom: 0;
}
&.form-item-row {
display: flex;
align-items: center;
flex-wrap: nowrap;
}
}
.form-label {
font-size: 28rpx;
color: #333;
// margin-bottom: 16rpx;
display: block;
flex-shrink: 0;
min-width: 160rpx;
&.required::before {
content: '*';
color: #ff0000;
margin-right: 4rpx;
}
}
.form-label1{
margin-bottom: 16rpx;
}
.form-item-row .form-label {
margin-bottom: 0;
margin-right: 24rpx;
}
.form-input-container {
flex: 1;
min-width: 0;
}
.form-value {
font-size: 28rpx;
color: #666;
flex: 1;
text-align: right;
}
.form-input-wrapper {
width: 100%;
.text-block {
font-size: 28rpx;
color: #666;
line-height: 1.6;
padding-top: 10rpx;
}
.form-input-container .form-input-wrapper {
width: 100%;
}
.custom-datetime-input {
border-radius: 4px;
box-sizing: border-box;
width: 100%;
text-align: right;
}
.custom-datetime-text {
font-size: 28rpx;
color: #333;
flex: 1;
&.placeholder {
color: #999;
}
}
// uni-datetime-picker 样式覆盖
::v-deep .uni-date-editor {
width: 100%;
}
::v-deep .uni-date-editor--x {
border: none !important;
background: transparent !important;
padding: 0 !important;
}
::v-deep .uni-date-x {
width: 100%;
padding: 0 !important;
}
::v-deep .uni-date__x-input {
display: none;
}
::v-deep .icon-calendar {
display: none;
}
.submit-btn-wrapper {
margin-top: 40rpx;
padding-bottom: 40rpx;
.goods-card {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.goods-head {
display: flex;
flex-direction: column;
gap: 6rpx;
margin-bottom: 12rpx;
}
.goods-title {
font-size: 30rpx;
color: #111;
font-weight: 600;
}
.goods-sub {
font-size: 24rpx;
color: #999;
}
.empty-tip {
padding: 24rpx 0;
text-align: center;
color: #999;
font-size: 26rpx;
}
.goods-module {
border: 1px solid #eef0f3;
border-radius: 14rpx;
padding: 18rpx;
margin-top: 16rpx;
}
.goods-module-top {
display: flex;
align-items: center;
justify-content: space-between;
}
.goods-module-title .name {
font-size: 28rpx;
color: #333;
font-weight: 600;
}
.goods-meta {
display: flex;
justify-content: space-between;
margin-top: 12rpx;
padding: 12rpx;
border-radius: 12rpx;
background: #f7f8fa;
}
.goods-meta .meta {
display: flex;
flex-direction: column;
align-items: center;
flex: 1;
}
.goods-meta .k {
font-size: 22rpx;
color: #999;
}
.goods-meta .v {
font-size: 28rpx;
color: #333;
margin-top: 6rpx;
}
.goods-module-body {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 14rpx;
}
.qty-label {
font-size: 26rpx;
color: #333;
&.required::before {
content: '*';
color: #ff0000;
margin-right: 4rpx;
}
}
.media-upload-wrapper {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.addimg {
width: 50px;
height: 50px;
}
.submit-container {
margin-top: 30rpx;
padding-bottom: 40rpx;
display: flex;
justify-content: center;
}
.submit-btn {
width: 70%;
height: 88rpx;
@@ -402,50 +571,24 @@
font-size: 32rpx;
line-height: 88rpx;
border: none;
&::after {
border: none;
}
&[disabled] {
opacity: 0.6;
}
}
// uni-data-select 样式调整
::v-deep .uni-stat__select {
width: 100%;
}
::v-deep .uni-select {
width: 100%;
border: none;
text-align: right;
}
::v-deep .uni-select__input-text {
font-size: 28rpx;
color: #333;
}
::v-deep .uni-select__input-placeholder {
color: #999;
}
// uni-easyinput 样式调整
::v-deep .uni-easyinput {
width: 100%;
}
::v-deep .uni-easyinput__content {
border: none;
min-height: 120rpx;
}
::v-deep .uni-easyinput__content-textarea {
font-size: 28rpx;
color: #333;
min-height: 120rpx;
padding-left: 0px;
}
// uni-file-picker 样式调整
::v-deep .uni-file-picker {
width: 100%;
}
+724
View File
@@ -0,0 +1,724 @@
<template>
<view class="home-page">
<uni-nav-bar
leftText=" "
:fixed="true"
leftIcon="back"
:border="false"
color="#fff"
backgroundColor="rgb(79 137 247)"
:statusBar="true"
title="编辑物品归还"
@clickLeft="leftClick"
></uni-nav-bar>
<view class="content-wrapper">
<!-- 借用基本信息 -->
<view class="form-card">
<view class="form-item form-item-row">
<text class="form-label">申请人</text>
<text class="form-value">{{ detail.apply_user_name || borrowDetail.applicant_name || '-' }}</text>
</view>
<view class="form-item form-item-row">
<text class="form-label">单号</text>
<text class="form-value">{{ detail.order_no || borrowDetail.order_no || '-' }}</text>
</view>
<view class="form-item form-item-row">
<text class="form-label">借用时间</text>
<text class="form-value">{{ borrowDetail.use_start_date || '-' }} ~ {{ borrowDetail.use_end_date || '-' }}</text>
</view>
<view class="form-item">
<text class="form-label">借用事由</text>
<view class="text-block">{{ borrowDetail.borrow_reason || '-' }}</view>
</view>
</view>
<!-- 归还物品(可删减 + 改数量) -->
<view class="goods-card">
<view class="goods-head">
<text class="goods-title">归还物品</text>
<text class="goods-sub">可删减物品,数量不超过"可归还"</text>
</view>
<view v-if="returnItems.length === 0" class="empty-tip">
暂无可归还物品
</view>
<view class="goods-module" v-for="(it, idx) in returnItems" :key="it._key">
<view class="goods-module-top">
<view class="goods-module-title">
<text class="name">{{ it.item_name_snap || '-' }}</text>
</view>
<uni-icons
type="trash"
size="18"
color="#ff4d4f"
@click="removeReturnItem(idx)"
></uni-icons>
</view>
<view class="goods-meta">
<view class="meta">
<text class="k">借用</text>
<text class="v">{{ it.approved_qty }}</text>
</view>
<view class="meta">
<text class="k">已还</text>
<text class="v">{{ it.returned_qty }}</text>
</view>
<view class="meta">
<text class="k">可归还</text>
<text class="v">{{ it.can_return }}</text>
</view>
</view>
<view class="goods-module-body">
<text class="qty-label required">本次归还数量</text>
<uni-number-box
v-model="it.return_qty"
:min="1"
:max="it.can_return"
></uni-number-box>
</view>
</view>
</view>
<!-- 实际归还时间 -->
<view class="form-card4">
<view class="form-item form-item-row">
<text class="form-label required">实际归还时间</text>
<view class="form-input-container">
<uni-datetime-picker
type="date"
v-model="formData.return_at"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
>
<view class="custom-datetime-input">
<text class="custom-datetime-text" :class="{ placeholder: !formData.return_at }">
{{ formData.return_at || '请选择时间' }}
</text>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
</view>
</view>
<!-- 备注 -->
<view class="form-card" style="margin-bottom: 8rpx;">
<view class="form-item">
<text class="form-label">归还备注</text>
<uni-easyinput
v-model="formData.apply_remark"
type="textarea"
:autoHeight="true"
placeholder="请填写归还备注"
:maxlength="500"
></uni-easyinput>
</view>
</view>
<!-- 附件(多图) -->
<view class="form-card">
<view class="form-item">
<text class="form-label">附件</text>
<view class="media-upload-wrapper">
<uni-file-picker
:value="mediaValue"
limit="20"
fileMediatype="image"
:disabled="uploading"
:auto-upload="false"
@select="selectMedia"
@delete="delfn"
>
<view class="upload-icon-wrapper">
<image src="/static/image/upload.png" class="addimg"></image>
</view>
</uni-file-picker>
</view>
</view>
</view>
<!-- 提交 -->
<view class="submit-container">
<button class="submit-btn" :disabled="submitting || uploading" @click="handleSubmit">
{{ submitting ? '提交中...' : '更新归还' }}
</button>
</view>
</view>
</view>
</template>
<script>
import { request } from '@/api/apiT.js'
export default {
data() {
return {
id: '',
return_id: '',
detail: {},
borrowDetail: {}, // 借用详情数据
returnItems: [],
formData: {
return_at: '',
apply_remark: '',
attachment: [] // 仅用于提交后台:[{original_name,file_path}]
},
mediaValue: [], // 仅用于 file-picker 展示:[{url,name,...}]
uploading: false,
submitting: false,
maxMedia: 20,
// 注意:根据你后端实际路由调整
RETURN_API: 'mobile/inv/requisition/return/update'
}
},
onLoad(options) {
this.id = options.id || ''
this.return_id = options.id
this.getDetails()
},
methods: {
leftClick() {
uni.navigateBack({})
},
// 拉取详情并回显
getDetails() {
request({
url: 'mobile/inv/requisition/return/show',
method: 'get',
data: { id: this.id }
}).then(res => {
const d = (res && res.data && res.data.data) ? res.data.data : {}
this.detail = d || {}
this.formData.return_at = d.return_at || ''
this.formData.apply_remark = d.apply_remark || ''
// 处理附件
if (Array.isArray(d.return_attachment)) {
d.return_attachment.forEach(item => {
this.formData.attachment.push({
original_name: item.file_name || '',
file_path: item.file_path || ''
})
this.mediaValue.push({
name: item.file_name || '',
url: item.file_path_pull || item.file_path || ''
})
})
} else if (Array.isArray(d.attachment)) {
// 兼容旧的 attachment 字段
d.attachment.forEach(item => {
this.formData.attachment.push({
original_name: item.original_name || '',
file_path: item.file_path || ''
})
this.mediaValue.push({
name: item.original_name || '',
url: item.file_path_pull || item.file_path || ''
})
})
}
// 如果有借用详情的id,则获取借用详情数据
// 注意:这里应该使用 requisition_id 来获取借用详情
const borrowId = d.requisition_id || d.item_id
if (borrowId) {
this.getBorrowDetail(borrowId)
} else {
// 如果没有借用详情的id,则直接构建归还物品列表
this.buildReturnItems(d)
}
})
},
// 获取借用详情数据
getBorrowDetail(borrowId) {
request({
url: 'mobile/inv/requisition/show',
method: 'GET',
data: { id: borrowId }
}).then((res) => {
if (res.data && res.data.code === 200) {
this.borrowDetail = res.data.data || {}
// 兜底,避免 v-for 报错
this.borrowDetail.item = Array.isArray(this.borrowDetail.item) ? this.borrowDetail.item : []
// 获取借用详情后重新构建归还物品列表
this.buildReturnItems(this.detail)
} else {
uni.showToast({ title: res.data.message || '获取借用详情失败', icon: 'none' })
}
})
},
// 安全处理数字显示
safeNum(v) {
const n = Number(v)
return Number.isFinite(n) ? n : 0
},
// 把借用明细转换为“可归还”明细
buildReturnItems(d) {
const items = []
// 从借用详情中获取完整的物品列表
if (this.borrowDetail.id && this.borrowDetail.item && this.borrowDetail.item.length > 0) {
console.log('从借用详情中获取物品列表:', this.borrowDetail.item)
this.borrowDetail.item.forEach(row => {
const approved = Number(row.approved_qty || row.request_qty || 0)
const returned = Number(row.returned_qty || 0)
const canReturn = Math.max(approved - returned, 0)
if (canReturn <= 0) return
// 检查是否已经在归还列表中
let returnQty = 0
if (Array.isArray(d.item_return)) {
const existingReturn = d.item_return.find(item => {
// 尝试匹配 item_id 或 requisition_item_id
return item.item_id === row.id ||
(item.requisition_item && (item.requisition_item.item_id === row.id || item.requisition_item.id === row.id))
})
if (existingReturn) {
returnQty = Number(existingReturn.return_qty || 0)
}
}
console.log('处理物品:', row.item_name_snap || row.item_name, '可归还数量:', canReturn, '已归还数量:', returnQty)
items.push({
_key: `${row.id || ''}_${Date.now()}_${Math.random()}`,
id: row.id,
item_id: row.id,
item_name_snap: row.item_name_snap || row.item_name,
approved_qty: approved,
returned_qty: returned,
can_return: canReturn,
return_qty: returnQty
})
})
console.log('构建完成的归还物品列表:', items)
} else if (Array.isArray(d.item_return)) {
// 从 item_return 中获取归还物品信息
console.log('从 item_return 中获取物品列表:', d.item_return)
d.item_return.forEach(returnItem => {
if (returnItem.requisition_item) {
const reqItem = returnItem.requisition_item
const approved = Number(reqItem.approved_qty || reqItem.request_qty || 0)
const returned = Number(reqItem.returned_qty || 0)
const canReturn = Math.max(approved - returned, 0)
if (canReturn <= 0) return
items.push({
_key: `${reqItem.id || ''}_${Date.now()}_${Math.random()}`,
id: reqItem.id,
item_id: reqItem.item_id,
item_name_snap: reqItem.item_name_snap || '',
approved_qty: approved,
returned_qty: returned,
can_return: canReturn,
return_qty: Number(returnItem.return_qty || 0)
})
}
})
} else {
// 尝试从不同字段获取物品列表,确保兼容性
const list = Array.isArray(d && d.items) ? d.items : (Array.isArray(d && d.item) ? d.item : [])
if (list.length > 0 && d.return_qty) {
list.forEach(row => {
items.push({
_key: `${row.id || d.item_id || ''}_${Date.now()}_${Math.random()}`,
id: d.requisition_item_id,
item_id: row.id,
item_name_snap: row.item_name,
approved_qty: d.return_qty,
returned_qty: 0,
can_return: d.return_qty,
return_qty: d.return_qty
})
})
}
}
this.returnItems = items
console.log('最终的归还物品列表:', this.returnItems)
},
removeReturnItem(idx) {
if (!Array.isArray(this.returnItems)) return
this.returnItems.splice(idx, 1)
},
// 上传单张(复用你项目里的 OSS 上传地址 + Header)
uploadfn(imgUrl) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: 'https://fdesk.hnxinyouhe.com/upload?scene=itemsimg',
filePath: imgUrl,
name: 'file',
header: {
'Fdesk-Corp-Abbr': uni.getStorageSync('corp_abbr'),
'Fdesk-Auth-Token': 'Bearer ' + uni.getStorageSync('token'),
'Fdesk-Language': uni.getStorageSync('i18locale') ? uni.getStorageSync('i18locale') : 'zh',
'Fdesk-Login-Type': 'feishu',
'Fdesk-System-Code': 'fdesk'
},
success: (uploadFileRes) => {
let json = {}
try {
json = JSON.parse(uploadFileRes.data || '{}')
} catch (e) {}
if (json && json.data && (json.data.file_name || json.data.file_path || json.data.file)) {
resolve(json.data)
} else {
reject('上传失败')
}
},
fail: (err) => reject(err)
})
})
},
selectMedia(e) {
if (this.uploading) return
const allowCount = this.maxMedia - this.formData.attachment.length
const tempFilePaths = e.tempFilePaths || (e.tempFiles || []).map(item => item.path || item.url)
const paths = tempFilePaths.slice(0, allowCount)
if (paths.length === 0) return
this.uploading = true
Promise.all(paths.map(p => this.uploadfn(p)))
.then(list => {
list.forEach((u, i) => {
// 兼容后端返回字段(你上面示例是 file_name/original_name)
const original = u.original_name || u.file_original_name || u.name || ('image_' + Date.now())
const filePath = u.file_name || u.file_path || u.path || ''
this.formData.attachment.push({
original_name: original,
file_path: filePath
})
// file-picker 展示用:本地选择的临时路径更直观
this.mediaValue.push({
name: original,
url: paths[i]
})
})
})
.catch(() => {
uni.showToast({ title: '图片上传失败,请重试', icon: 'none' })
})
.finally(() => {
this.uploading = false
})
},
delfn(e) {
// file-picker 的 index 和本地 mediaValue 一致;我们让 attachment 同步删除
const idx = e.index
if (idx >= 0) {
this.mediaValue.splice(idx, 1)
this.formData.attachment.splice(idx, 1)
}
},
handleSubmit() {
if (this.submitting || this.uploading) return
if (!this.id || !this.return_id) {
uni.showToast({ title: '缺少必要参数', icon: 'none' })
return
}
if (!this.formData.return_at) {
uni.showToast({ title: '请选择归还时间', icon: 'none' })
return
}
if (!Array.isArray(this.returnItems) || this.returnItems.length === 0) {
uni.showToast({ title: '请选择需要归还的物品', icon: 'none' })
return
}
// 过滤掉归还数量为0的物品
const validReturnItems = this.returnItems.filter(item => {
const qty = Number(item.return_qty)
return qty > 0
})
// 检查是否有有效的归还物品
if (validReturnItems.length === 0) {
uni.showToast({ title: '请至少选择一个物品并填写归还数量', icon: 'none' })
return
}
// 检查每个有效物品的归还数量是否超过可归还数量
for (let i = 0; i < validReturnItems.length; i++) {
const it = validReturnItems[i] || {}
const qty = Number(it.return_qty)
if (qty > Number(it.can_return || 0)) {
uni.showToast({ title: `第${i + 1}个物品归还数量超过可归还`, icon: 'none' })
return
}
}
const payload = {
id: this.return_id,
requisition_id: this.id,
return_at: this.formData.return_at,
apply_remark: this.formData.apply_remark,
attachment: this.formData.attachment,
items: validReturnItems.map(it => ({
requisition_item_id: it.id,
item_id: it.item_id,
return_qty: it.return_qty
}))
}
this.submitting = true
request({
url: this.RETURN_API,
method: 'post',
data: payload
}).then(res => {
uni.showToast({
title: res.data.message,
icon: 'none'
});
if(res.data.code==200){
setTimeout(() => {
uni.navigateTo({
url: '/pages/borrow/borrow_list'
});
}, 1000);
}
}).finally(() => {
this.submitting = false
})
}
}
}
</script>
<style lang="scss">
.home-page {
min-height: 100vh;
background: linear-gradient(180.05deg, #3074F7 0.04%, #F4F6F8 34.07%);
box-sizing: border-box;
padding-bottom: 120rpx;
padding: 0px 28rpx;
}
.content-wrapper {
margin-top: 20rpx;
}
.form-card {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.form-card4 {
background: #fff;
border-radius: 6px;
padding: 3px 17px;
margin-bottom: 10px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
height: 35px;
line-height: 35px;
}
.form-item {
margin-bottom: 20rpx;
&:last-child {
margin-bottom: 0;
}
&.form-item-row {
display: flex;
align-items: center;
flex-wrap: nowrap;
}
}
.form-label {
font-size: 28rpx;
color: #333;
display: block;
flex-shrink: 0;
min-width: 160rpx;
&.required::before {
content: '*';
color: #ff0000;
margin-right: 4rpx;
}
}
.form-item-row .form-label {
margin-bottom: 0;
margin-right: 24rpx;
}
.form-input-container {
flex: 1;
min-width: 0;
}
.form-value {
font-size: 28rpx;
color: #666;
flex: 1;
text-align: right;
}
.text-block {
font-size: 28rpx;
color: #666;
line-height: 1.6;
padding-top: 10rpx;
}
.custom-datetime-input {
border-radius: 4px;
box-sizing: border-box;
width: 100%;
text-align: right;
}
.custom-datetime-text {
font-size: 28rpx;
color: #333;
&.placeholder {
color: #999;
}
}
::v-deep .uni-date-editor {
width: 100%;
}
::v-deep .uni-date-editor--x {
border: none !important;
background: transparent !important;
padding: 0 !important;
}
::v-deep .uni-date__x-input {
display: none;
}
::v-deep .icon-calendar {
display: none;
}
.goods-card {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.goods-head {
display: flex;
flex-direction: column;
gap: 6rpx;
margin-bottom: 12rpx;
}
.goods-title {
font-size: 30rpx;
color: #111;
font-weight: 600;
}
.goods-sub {
font-size: 24rpx;
color: #999;
}
.empty-tip {
padding: 24rpx 0;
text-align: center;
color: #999;
font-size: 26rpx;
}
.goods-module {
border: 1px solid #eef0f3;
border-radius: 14rpx;
padding: 18rpx;
margin-top: 16rpx;
}
.goods-module-top {
display: flex;
align-items: center;
justify-content: space-between;
}
.goods-module-title .name {
font-size: 28rpx;
color: #333;
font-weight: 600;
}
.goods-meta {
display: flex;
justify-content: space-between;
margin-top: 12rpx;
padding: 12rpx;
border-radius: 12rpx;
background: #f7f8fa;
}
.goods-meta .meta {
display: flex;
flex-direction: column;
align-items: center;
flex: 1;
}
.goods-meta .k {
font-size: 22rpx;
color: #999;
}
.goods-meta .v {
font-size: 28rpx;
color: #333;
margin-top: 6rpx;
}
.goods-module-body {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 14rpx;
}
.qty-label {
font-size: 26rpx;
color: #333;
&.required::before {
content: '*';
color: #ff0000;
margin-right: 4rpx;
}
}
.media-upload-wrapper {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
.addimg {
width: 50px;
height: 50px;
}
.submit-container {
margin-top: 30rpx;
padding-bottom: 40rpx;
display: flex;
justify-content: center;
}
.submit-btn {
width: 70%;
height: 88rpx;
background: #3074F7;
color: #fff;
border-radius: 44rpx;
font-size: 32rpx;
line-height: 88rpx;
border: none;
&::after {
border: none;
}
&[disabled] {
opacity: 0.6;
}
}
::v-deep .uni-easyinput__content {
border: none;
min-height: 120rpx;
}
::v-deep .uni-easyinput__content-textarea {
font-size: 28rpx;
color: #333;
min-height: 120rpx;
padding-left: 0px;
}
::v-deep .uni-file-picker {
width: 100%;
}
</style>
+3 -3
View File
@@ -38,7 +38,7 @@
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.borrowTime }">
{{ formData.borrowTime || '请选择时间' }}
</text>
<uni-icons type="calendar" size="18" color="#999"></uni-icons>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
@@ -62,7 +62,7 @@
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.returnTime }">
{{ formData.returnTime || '请选择时间' }}
</text>
<uni-icons type="calendar" size="18" color="#999"></uni-icons>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>
@@ -127,7 +127,7 @@
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.returnTime }">
{{ formData.returnTime || '请选择时间' }}
</text>
<uni-icons type="calendar" size="18" color="#999"></uni-icons>
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
</view>
</uni-datetime-picker>
</view>