Files
art-design-uniapp/pages/borrow/borrow.vue
T

512 lines
13 KiB
Vue
Raw Normal View History

2025-12-05 18:08:03 +08:00
<template>
<view class="home-page">
2026-02-06 14:39:37 +08:00
<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>
2025-12-05 18:08:03 +08:00
<view class="content-wrapper">
<!-- 申请人信息卡片 -->
<view class="form-card">
<view class="form-item form-item-row">
<text class="form-label">申请人:</text>
2026-02-06 14:39:37 +08:00
<text class="form-value">{{ userinfo.name || '犇犇' }}</text>
2025-12-05 18:08:03 +08:00
</view>
<view class="form-item form-item-row">
<text class="form-label">公司名称:</text>
2026-02-06 14:39:37 +08:00
<text class="form-value">{{ userinfo.corp_name || '合塑' }}</text>
2025-12-05 18:08:03 +08:00
</view>
</view>
2026-02-06 14:39:37 +08:00
<!-- 借用时间 -->
2025-12-05 18:08:03 +08:00
<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"
2026-02-06 14:39:37 +08:00
type="date"
v-model="formData.use_start_date"
2025-12-05 18:08:03 +08:00
placeholder="请选择时间"
:border="false"
:clear-icon="false"
@change="onBorrowTimeChange"
>
<view class="custom-datetime-input">
2026-02-06 14:39:37 +08:00
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.use_start_date }">
{{ formData.use_start_date || '请选择时间' }}
2025-12-05 18:08:03 +08:00
</text>
2026-02-06 14:39:37 +08:00
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
2025-12-05 18:08:03 +08:00
</view>
</uni-datetime-picker>
</view>
</view>
</view>
2026-02-06 14:39:37 +08:00
<!-- 计划归还时间 -->
<view class="form-card4">
2025-12-05 18:08:03 +08:00
<view class="form-item form-item-row">
<text class="form-label required">计划归还时间</text>
<view class="form-input-container">
<uni-datetime-picker
2026-02-06 16:23:35 +08:00
ref="returnTimePicker"
type="date"
v-model="formData.use_end_date"
placeholder="请选择时间"
:border="false"
:clear-icon="false"
:start="formData.use_start_date"
@change="onReturnTimeChange"
>
2025-12-05 18:08:03 +08:00
<view class="custom-datetime-input">
2026-02-06 14:39:37 +08:00
<text class="custom-datetime-text" :class="{ 'placeholder': !formData.use_end_date }">
{{ formData.use_end_date || '请选择时间' }}
2025-12-05 18:08:03 +08:00
</text>
2026-02-06 14:39:37 +08:00
<uni-icons type="calendar" size="16" color="#999"></uni-icons>
2025-12-05 18:08:03 +08:00
</view>
</uni-datetime-picker>
</view>
</view>
</view>
2026-02-06 14:39:37 +08:00
<!-- ✅ 物品(可添加多条) -->
<view class="goods-card">
<view class="goods-head">
<text class="form-label required">物品</text>
<button class="goods-add-btn" size="mini" @click="addItem">+ 添加</button>
2025-12-05 18:08:03 +08:00
</view>
2026-02-06 14:39:37 +08:00
<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>
2025-12-05 18:08:03 +08:00
</view>
</view>
</view>
2026-02-06 14:39:37 +08:00
2025-12-05 18:08:03 +08:00
<view class="form-card">
<!-- 借用事由 -->
<view class="form-item">
2026-02-06 14:39:37 +08:00
<text class="form-label required form-label1">借用事由</text>
2025-12-05 18:08:03 +08:00
<uni-easyinput
2026-02-06 14:39:37 +08:00
v-model="formData.borrow_reason"
2025-12-05 18:08:03 +08:00
type="textarea"
:autoHeight="true"
placeholder="请填写借用事由"
:maxlength="500"
></uni-easyinput>
</view>
</view>
2026-02-06 14:39:37 +08:00
2025-12-05 18:08:03 +08:00
<!-- 备注卡片 -->
<view class="form-card " style="margin-bottom: 8rpx;">
<view class="form-item">
<text class="form-label">备注</text>
<uni-easyinput
2026-02-06 14:39:37 +08:00
v-model="formData.remark"
2025-12-05 18:08:03 +08:00
type="textarea"
:autoHeight="true"
placeholder="请填写备注"
:maxlength="500"
></uni-easyinput>
</view>
</view>
2026-02-06 14:39:37 +08:00
<!-- 附件上传 -->
2025-12-05 18:08:03 +08:00
<view class="form-card">
<view class="form-item">
2026-02-06 14:39:37 +08:00
<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>
2025-12-05 18:08:03 +08:00
</view>
</view>
<!-- 提交按钮 -->
2026-02-06 14:39:37 +08:00
<view class="submit-container">
<button class="submit-btn" @click="handleSubmit">提交申请</button>
2025-12-05 18:08:03 +08:00
</view>
</view>
</view>
</template>
<script>
2026-02-06 14:39:37 +08:00
import { request,showToast } from '@/api/apiT.js'
2025-12-05 18:08:03 +08:00
export default {
data() {
return {
2026-02-06 14:39:37 +08:00
userinfo: {},
maxMedia:20,
2025-12-05 18:08:03 +08:00
formData: {
2026-02-06 14:39:37 +08:00
use_start_date: '',
use_end_date: '',
items: [{ item_name_snap: '',item_id:'',request_qty:1}],
borrow_reason: '',
remark: '',
attachment: []
2025-12-05 18:08:03 +08:00
},
2026-02-06 14:39:37 +08:00
itemNameOptions: [],
2025-12-05 18:08:03 +08:00
}
},
2026-02-06 14:39:37 +08:00
onLoad() {
this.getinfo()
this.getItemNameOptions()
2026-02-06 16:23:35 +08:00
// 设置借用时间默认当天
const today = new Date()
const year = today.getFullYear()
const month = String(today.getMonth() + 1).padStart(2, '0')
const day = String(today.getDate()).padStart(2, '0')
const todayStr = `${year}-${month}-${day}`
this.formData.use_start_date = todayStr
2026-02-06 14:39:37 +08:00
},
2025-12-05 18:08:03 +08:00
methods: {
leftClick(){
uni.navigateBack({})
},
2026-02-06 14:39:37 +08:00
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
}
},
2025-12-05 18:08:03 +08:00
onBorrowTimeChange(e) {
2026-02-06 14:39:37 +08:00
this.formData.use_start_date = e
2025-12-05 18:08:03 +08:00
},
onReturnTimeChange(e) {
2026-02-06 14:39:37 +08:00
this.formData.use_end_date = e
2025-12-05 18:08:03 +08:00
},
onFileSelect(e) {
console.log('文件选择:', e)
},
2026-02-06 14:39:37 +08:00
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){
2025-12-05 18:08:03 +08:00
return
}
2026-02-06 14:39:37 +08:00
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(() => {
2025-12-05 18:08:03 +08:00
uni.showToast({
2026-02-06 14:39:37 +08:00
title:'图片上传失败,请重试',
icon:'none'
2025-12-05 18:08:03 +08:00
})
2026-02-06 14:39:37 +08:00
})
},
delfn(e){
this.formData.attachment.splice(e.index, 1)
},
handleSubmit() {
// 表单验证
if (!this.formData.use_start_date) {
uni.showToast({ title: '请选择借用时间', icon: 'none' })
2025-12-05 18:08:03 +08:00
return
}
2026-02-06 14:39:37 +08:00
if (!this.formData.use_end_date) {
uni.showToast({ title: '请选择计划归还时间', icon: 'none' })
2025-12-05 18:08:03 +08:00
return
}
2026-02-06 14:39:37 +08:00
// 物品列表校验(至少 1 条,且每条需选择名称 + 数量)
if (!Array.isArray(this.formData.items) || this.formData.items.length === 0) {
uni.showToast({ title: '请添加物品', icon: 'none' })
2025-12-05 18:08:03 +08:00
return
}
2026-02-06 14:39:37 +08:00
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' })
2025-12-05 18:08:03 +08:00
return
}
// 提交表单
console.log('提交表单:', this.formData)
2026-02-06 14:39:37 +08:00
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);
}
2025-12-05 18:08:03 +08:00
})
// 这里可以调用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;
}
2026-02-06 14:39:37 +08:00
.media-upload-wrapper{
display: flex;
flex-wrap: wrap;
gap: 16rpx;
}
2025-12-05 18:08:03 +08:00
.addimg{
width: 50px;
height:50px;
}
.form-card {
background: #fff;
2026-02-06 14:39:37 +08:00
border-radius: 16rpx;
padding: 24rpx;
2025-12-05 18:08:03 +08:00
margin-bottom: 24rpx;
2026-02-06 14:39:37 +08:00
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
2025-12-05 18:08:03 +08:00
}
.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;
}
2026-02-06 14:39:37 +08:00
/* 物品(可添加多条) */
.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;
}
2025-12-05 18:08:03 +08:00
.form-item {
margin-bottom: 32rpx;
2026-02-06 14:39:37 +08:00
&:last-child { margin-bottom: 0; }
2025-12-05 18:08:03 +08:00
}
2026-02-06 14:39:37 +08:00
.form-item-row {
display: flex;
align-items: center;
justify-content: space-between;
2025-12-05 18:08:03 +08:00
}
.form-label1{
margin-bottom: 16rpx;
}
.form-item-row .form-label {
margin-bottom: 0;
margin-right: 24rpx;
}
.form-input-container {
flex: 1;
min-width: 0;
}
2026-02-06 14:39:37 +08:00
.form-label {
font-size: 28rpx;
color: #333;
display: block;
flex-shrink: 0;
min-width: 160rpx;
&.required::before {
content: '*';
color: #ff0000;
margin-right: 4rpx;
}
}
2025-12-05 18:08:03 +08:00
.form-value {
font-size: 28rpx;
color: #666;
flex: 1;
}
2026-02-06 14:39:37 +08:00
.category-text{
font-size: 28rpx;
color: #333;
2025-12-05 18:08:03 +08:00
}
.custom-datetime-input {
2026-02-06 14:39:37 +08:00
display: flex;
align-items: center;
justify-content: space-between;
2025-12-05 18:08:03 +08:00
width: 100%;
}
.custom-datetime-text {
font-size: 28rpx;
color: #333;
&.placeholder {
color: #999;
}
}
2026-02-06 14:39:37 +08:00
.submit-container {
2025-12-05 18:08:03 +08:00
margin-top: 40rpx;
padding-bottom: 40rpx;
}
.submit-btn {
background: #3074F7;
color: #fff;
font-size: 32rpx;
2026-02-06 14:39:37 +08:00
border-radius: 12rpx;
height: 88rpx;
2025-12-05 18:08:03 +08:00
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>