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
+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%;
}