You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

323 lines
8.2 KiB

7 months ago
<template>
<view class="inventory-bg">
<view class="inventory-card">
7 months ago
<view class="readonly-group">
<view class="readonly-item">
<text class="readonly-label">物资名称</text>
<text class="readonly-value">{{ materialName }}</text>
</view>
<view class="readonly-item">
<text class="readonly-label">物质代码</text>
<text class="readonly-value">{{ materialCode }}</text>
</view>
<view class="readonly-item">
<text class="readonly-label">规格型号</text>
<text class="readonly-value">{{ materialSpec }}</text>
</view>
<view class="readonly-item">
<text class="readonly-label">库存数量</text>
<text class="readonly-value">{{ stockQty }}{{ unit ? ' ' + unit : '' }}</text>
</view>
7 months ago
</view>
7 months ago
<view class="form-group" v-if="!isViewMode">
7 months ago
<text class="form-label">盘点数量</text>
<input class="form-input" type="number" v-model="countQty" placeholder="请输入盘点数量" />
</view>
7 months ago
<view class="form-group" v-if="!isViewMode">
7 months ago
<text class="form-label">盘点备注</text>
7 months ago
<textarea class="form-textarea" v-model="remark" placeholder="请输入备注信息" />
7 months ago
</view>
7 months ago
<view class="form-group" v-if="!isViewMode">
7 months ago
<text class="form-label">照片上传</text>
<view class="photo-upload">
7 months ago
<view v-for="(photo, index) in photos" :key="index" class="photo-preview">
7 months ago
<image :src="photo" mode="aspectFill" class="photo-img" />
7 months ago
<view class="photo-del" @click="deletePhoto(index)">
<text class="delete-icon">×</text>
</view>
7 months ago
</view>
7 months ago
<button v-if="photos.length < 3" class="photo-btn" @click="choosePhoto">
<text class="iconfont icon-camera"></text>
<text class="btn-text">上传照片</text>
</button>
7 months ago
</view>
</view>
7 months ago
<button class="submit-btn" v-if="!isViewMode" @click="submit"></button>
7 months ago
</view>
</view>
</template>
<script>
7 months ago
import { getMaterialInfo, saveInventoryCheck, uploadFile } from '@/api.js'
7 months ago
export default {
data() {
return {
7 months ago
isViewMode: false,
stockQty: '',
7 months ago
countQty: '',
remark: '',
7 months ago
photo: '',
photos: [],
materialName: '',
materialSpec: '',
unit: '',
materialCode: '',
material_infos_plan_id: '',
materialId: ''
7 months ago
}
},
onLoad(options) {
7 months ago
this.isViewMode = options.view === '1';
7 months ago
this.date = this.getToday();
7 months ago
this.materialId = options.code;
console.log("materialId:", this.materialId);
if (this.materialId) {
getMaterialInfo(this.materialId).then(response => {
console.log("response:", response);
if (response.data) {
this.materialName = response.data.zichanmingcheng || '-'
this.materialSpec = response.data.guigexinghao || '-'
this.unit = response.data.jiliangdanwei || '-'
this.materialCode = response.data.wuzibianma || '-'
this.material_infos_plan_id = response.data.material_infos_plan_id || ''
this.stockQty = response.data.inventorys_total || '0'
} else {
uni.showToast({ title: '未获取到物资信息', icon: 'none' })
}
}).catch(() => {
uni.showToast({ title: '获取物资信息失败', icon: 'none' })
})
7 months ago
}
},
methods: {
getToday() {
const now = new Date();
const y = now.getFullYear();
const m = String(now.getMonth() + 1).padStart(2, '0');
const d = String(now.getDate()).padStart(2, '0');
return `${y}-${m}-${d}`;
},
choosePhoto() {
7 months ago
if (this.photos.length >= 3) {
uni.showToast({ title: '最多上传3张照片', icon: 'none' });
return;
}
7 months ago
uni.chooseImage({
7 months ago
count: 3 - this.photos.length,
7 months ago
success: (res) => {
7 months ago
this.photos = [...this.photos, ...res.tempFilePaths];
7 months ago
}
});
},
7 months ago
deletePhoto(index) {
this.photos.splice(index, 1);
},
async submit() {
7 months ago
if (!this.countQty) {
uni.showToast({ title: '请输入盘点数量', icon: 'none' });
return;
}
7 months ago
if (!/^(0|[1-9][0-9]*)$/.test(this.countQty)) {
uni.showToast({ title: '盘点数量必须为0或正整数', icon: 'none' });
return;
}
uni.showLoading({ title: '提交中...' });
// 1. 上传所有照片,收集 file_id
let file_ids = [];
for (let i = 0; i < this.photos.length; i++) {
try {
const res = await uploadFile(this.photos[i]);
if (res && res.id) {
file_ids.push(res.id);
}
} catch (e) {
uni.hideLoading();
uni.showToast({ title: '图片上传失败', icon: 'none' });
return;
}
}
// 2. 组装盘点数据
const data = {
status: '1',
material_info_id: this.materialId, // 或实际物资id字段
check_num: this.countQty,
remark: this.remark,
file_ids
// 其他参数如 material_infos_plan_id、status、check_date 可按需补充
};
console.log("data:", data);
// 3. 提交盘点
saveInventoryCheck(data).then(res => {
console.log("res:", res);
uni.hideLoading();
if (res && (!res.data || res.data.errcode === undefined)) {
uni.showToast({ title: '盘点提交成功', icon: 'success' });
setTimeout(() => {
uni.reLaunch({ url: '/pages/index/index' });
}, 1200);
} else {
uni.showToast({ title: res.data.errmsg || '提交失败', icon: 'none' });
}
}).catch(() => {
uni.hideLoading();
uni.showToast({ title: '提交失败', icon: 'none' });
});
7 months ago
}
}
}
</script>
<style>
.inventory-bg {
min-height: 100vh;
7 months ago
background: #f5f6f7;
padding: 24rpx;
7 months ago
}
7 months ago
7 months ago
.inventory-card {
background: #fff;
7 months ago
border-radius: 24rpx;
padding: 32rpx 24rpx;
margin-bottom: 24rpx;
}
.readonly-group {
margin-bottom: 32rpx;
padding: 24rpx;
background: #f8f9fa;
border-radius: 16rpx;
}
.readonly-item {
7 months ago
display: flex;
7 months ago
justify-content: space-between;
margin-bottom: 20rpx;
}
.readonly-item:last-child {
margin-bottom: 0;
7 months ago
}
7 months ago
.readonly-label {
color: #666;
font-size: 28rpx;
}
.readonly-value {
color: #333;
font-size: 28rpx;
font-weight: 500;
}
7 months ago
.form-group {
7 months ago
margin-bottom: 32rpx;
7 months ago
}
7 months ago
7 months ago
.form-label {
7 months ago
font-size: 28rpx;
color: #333;
margin-bottom: 16rpx;
7 months ago
font-weight: 500;
}
7 months ago
7 months ago
.form-input {
7 months ago
height: 88rpx;
background: #f8f9fa;
border: none;
border-radius: 16rpx;
padding: 0 24rpx;
font-size: 28rpx;
color: #333;
7 months ago
}
7 months ago
7 months ago
.form-textarea {
7 months ago
min-height: 160rpx;
background: #f8f9fa;
border: none;
border-radius: 16rpx;
padding: 20rpx 24rpx;
font-size: 28rpx;
color: #333;
7 months ago
}
7 months ago
7 months ago
.photo-upload {
display: flex;
7 months ago
flex-wrap: wrap;
gap: 20rpx;
7 months ago
}
7 months ago
7 months ago
.photo-preview {
position: relative;
7 months ago
width: 160rpx;
height: 160rpx;
}
.photo-btn {
width: 160rpx;
height: 160rpx;
background: #f8f9fa;
border-radius: 16rpx;
7 months ago
display: flex;
7 months ago
flex-direction: column;
7 months ago
align-items: center;
7 months ago
justify-content: center;
padding: 0;
}
.photo-btn .iconfont {
font-size: 48rpx;
color: #666;
margin-bottom: 8rpx;
}
.btn-text {
font-size: 24rpx;
color: #666;
7 months ago
}
7 months ago
.photo-preview {
position: relative;
}
7 months ago
.photo-img {
7 months ago
width: 160rpx;
height: 160rpx;
border-radius: 16rpx;
7 months ago
}
7 months ago
7 months ago
.photo-del {
7 months ago
position: absolute;
top: -16rpx;
right: -16rpx;
width: 40rpx;
height: 40rpx;
background: rgba(0,0,0,0.6);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.delete-icon {
7 months ago
color: #ff4d4f;
7 months ago
font-size: 32rpx;
font-weight: bold;
line-height: 1;
7 months ago
}
7 months ago
7 months ago
.submit-btn {
7 months ago
width: 100%;
height: 88rpx;
background: #409eff;
7 months ago
color: #fff;
7 months ago
font-size: 32rpx;
font-weight: 500;
border-radius: 44rpx;
margin-top: 48rpx;
7 months ago
}
7 months ago
7 months ago
.submit-btn:active {
7 months ago
opacity: 0.9;
7 months ago
}
7 months ago
</style>