<template>
|
<PageHeader :title="pageTitle" @back="goBack" />
|
<view class="account-detail">
|
<view class="box">
|
<view v-if="type == 'add'" style="margin-bottom: 20rpx;">
|
<button class="mini-btn" type="primary" size="mini" style="margin-left: 0;margin-right: 0;"
|
@click="addItem">新增</button>
|
</view>
|
<view v-for="(item, index) in goodsList" class="form-box">
|
<button v-if="type == 'add'" class="mini-btn del-btn" type="warn" size="mini" style="margin-left: 0;margin-right: 0;"
|
@click="delItem(index)">删除</button>
|
<uni-forms :key="index" label-position="top" label-width="400rpx">
|
<uni-forms-item label="产品图片" required>
|
<view class="add-img">
|
<image v-if="item.url" class="img" :src="baseUrl + item.url" mode="aspectFill"
|
@click="addImg(index)" />
|
<uni-icons v-else type="camera-filled" size="56" style="color: #8a8a8a"
|
@click="addImg(index)"></uni-icons>
|
</view>
|
</uni-forms-item>
|
<uni-forms-item label="名称" required>
|
<uni-easyinput v-model="item.productCategory" placeholder="请输入名称" />
|
</uni-forms-item>
|
<uni-forms-item label="高度" required>
|
<uni-easyinput v-model="item.specificationModel" type="number" placeholder="请输入高度" />
|
</uni-forms-item>
|
<uni-forms-item label="高度单位" required>
|
<uni-easyinput v-model="item.unit" placeholder="请输入高度单位" />
|
</uni-forms-item>
|
<uni-forms-item label="纸箱规格" required>
|
<uni-easyinput v-model="item.cartonSpecifications" placeholder="请输入纸箱规格" />
|
</uni-forms-item>
|
<uni-forms-item label="入库数量/件" required>
|
<uni-number-box v-model="item.inboundNum" :min="0"></uni-number-box>
|
</uni-forms-item>
|
<uni-forms-item label="每件数量/支" required>
|
<uni-number-box v-model="item.boxNum" :min="0"></uni-number-box>
|
</uni-forms-item>
|
<uni-forms-item label="单价(元)/件" required>
|
<uni-number-box v-model="item.taxInclusiveUnitPrice" :min="0" :step="0.01"></uni-number-box>
|
</uni-forms-item>
|
<uni-forms-item label="单价(美元)/件" required>
|
<uni-number-box v-model="item.dollarPrice" :min="0" :step="0.01"></uni-number-box>
|
</uni-forms-item>
|
<uni-forms-item label="入库日期" required>
|
<uni-datetime-picker type="date" :clear-icon="false" v-model="item.inboundDate" />
|
</uni-forms-item>
|
</uni-forms>
|
</view>
|
<view style="display: flex;justify-content: flex-end;">
|
<button class="mini-btn" type="primary" size="mini"
|
style="margin-left: 0;margin-right: 0;margin-right: 20rpx;" @click="submitForm">确定</button>
|
<button class="mini-btn" size="mini" style="margin-left: 0;margin-right: 0;" @click="goBack">取消</button>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script setup>
|
import { onMounted, ref } from 'vue'
|
import { getToken } from "@/utils/auth";
|
import { addCustom } from '@/api/inventoryManagement/receiptManagement.js'
|
import config from '@/config'
|
const baseUrl = config.imgUrl
|
const pageTitle = ref('新增自定义入库')
|
const goodsList = ref([])
|
const type = ref('add')
|
const props = defineProps(['goods'])
|
const defaultGoods = {
|
boxNum: 0,
|
cartonSpecifications: "",
|
id: null,
|
inboundDate: "",
|
inboundNum: 0,
|
itemType: "",
|
productCategory: "",
|
specificationModel: "",
|
supplierName: "",
|
taxExclusiveTotalPrice: 0,
|
taxInclusiveTotalPrice: 0,
|
taxInclusiveUnitPrice: 0,
|
dollarPrice: 0,
|
taxRate: 0,
|
unit: "",
|
url: "",
|
}
|
|
const goBack = () => {
|
uni.navigateBack()
|
}
|
const showToast = (msg)=>{
|
uni.showToast({
|
title: msg,
|
icon: 'none',
|
duration: 1500
|
})
|
}
|
const submitForm = async() => {
|
if (!goodsList.value.length) {
|
showToast('请至少添加一条产品数据')
|
return
|
}
|
|
// 验证自定义添加的数据必填字段
|
for (let i = 0; i < goodsList.value.length; i++) {
|
const product = goodsList.value[i];
|
if (!product.productCategory || !product.specificationModel || !product.unit) {
|
showToast(`第${i + 1}行产品数据未填写完整(产品、产品高度、高度单位为必填)`)
|
return
|
}
|
if (!product.url) {
|
showToast(`第${i + 1}行产品未上传产品图片`)
|
return
|
}
|
if (!product.cartonSpecifications) {
|
showToast(`第${i + 1}行产品未填写纸箱规格`)
|
return
|
}
|
// if (!product.itemType) {
|
// proxy.$modal.msgError(`第${i + 1}行请选择物品类型`)
|
// return
|
// }
|
const stock = Number(product?.inboundNum ?? 0);
|
if (!Number.isFinite(stock) || stock <= 0) {
|
showToast(`第${i + 1}行本次入库数量需大于0`)
|
return
|
}
|
const boxNum = Number(product?.boxNum ?? 0);
|
if (!Number.isFinite(boxNum) || boxNum <= 0) {
|
showToast(`第${i + 1}行每件数量/支需大于0`)
|
return
|
}
|
const taxInclusiveUnitPrice = Number(product?.taxInclusiveUnitPrice ?? 0);
|
if (!Number.isFinite(taxInclusiveUnitPrice) || taxInclusiveUnitPrice <= 0) {
|
showToast(`第${i + 1}行单价(元)需大于0`)
|
return
|
}
|
const dollarPrice = Number(product?.dollarPrice ?? 0);
|
if (!Number.isFinite(dollarPrice) || dollarPrice <= 0) {
|
showToast(`第${i + 1}行单价(美元)需大于0`)
|
return
|
}
|
if (!product.inboundDate) {
|
showToast(`第${i + 1}行请选择入库日期`)
|
return
|
}
|
|
}
|
let res = await addCustom(goodsList.value)
|
if(res.code !== 200){
|
uni.showToast({
|
title: res.msg,
|
icon: 'none'
|
})
|
return
|
}
|
uni.showToast({
|
title: '新增成功',
|
icon: 'none'
|
})
|
goBack()
|
}
|
|
const addImg = (index) => {
|
uni.chooseMedia({
|
count: 1,
|
mediaType: ['image'],
|
sourceType: ['album', 'camera'],
|
sizeType: ['original', 'compressed'],
|
success: (res) => {
|
let imgList = []
|
let isHeGe = true
|
if (res.tempFiles && res.tempFiles.length) {
|
res.tempFiles.forEach(item => {
|
imgList.push(item.tempFilePath)
|
if (item.size > 10000000) {
|
isHeGe = false
|
}
|
})
|
}
|
if (!isHeGe) {
|
uni.showToast({
|
title: "图片不能大于10M",
|
icon: "none"
|
})
|
return
|
}
|
UploadImage(imgList[0], index)
|
},
|
fail: (e) => {
|
console.log('chooseMedia:fail', e)
|
if (e.errMsg == 'chooseMedia:fail cancel') {
|
return
|
}
|
if (e.errMsg == 'user cancel') {
|
return
|
}
|
uni.showToast({
|
title: "上传失败",
|
icon: 'none',
|
duration: 1500
|
})
|
}
|
})
|
}
|
const delItem = (index)=>{
|
console.log('xxxx')
|
goodsList.value.splice(index,1)
|
}
|
const UploadImage = (url, index) => {
|
uni.uploadFile({
|
url: baseUrl + '/file/upload', // 替换为实际的上传接口
|
filePath: url,
|
name: 'file',
|
header: { Authorization: 'Bearer ' + getToken() },
|
success: (res) => {
|
const data = JSON.parse(res.data)
|
if (data.code === 200) {
|
goodsList.value[index].url = data.data.tempPath
|
uni.showToast({
|
title: '上传成功',
|
icon: 'none',
|
duration: 1500
|
})
|
} else {
|
console.log('上传失败', res)
|
uni.showToast({
|
title: '上传失败',
|
icon: 'none'
|
})
|
}
|
},
|
fail: (e) => {
|
console.log('uploadFile:fail', e)
|
uni.showToast({
|
title: '上传失败',
|
icon: 'none'
|
})
|
}
|
})
|
}
|
|
onMounted(() => {
|
let _goods = JSON.parse(props.goods)
|
if (_goods.id) {
|
pageTitle.value = '编辑自定义入库'
|
type.value = 'edit'
|
}
|
goodsList.value.push({...defaultGoods,..._goods})
|
})
|
const addItem = () => {
|
goodsList.value.push({...defaultGoods})
|
}
|
</script>
|
<style lang="scss" scoped>
|
.box {
|
background-color: #fff;
|
box-sizing: border-box;
|
padding: 20rpx;
|
min-height: 80rpx;
|
padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
|
}
|
|
.form-box {
|
box-sizing: border-box;
|
margin-bottom: 20rpx;
|
padding: 20rpx;
|
// background-color: #f5f5f5;
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
transition: box-shadow 0.3s ease;
|
border-radius: 20rpx;
|
position: relative;
|
.del-btn{
|
position: absolute;
|
right: 20rpx;
|
top: 40rpx;
|
z-index: 40;
|
}
|
}
|
|
.form-box:hover {
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
|
}
|
|
.add-img {
|
.img {
|
background-color: #efefef;
|
border-radius: 10rpx;
|
width: 200rpx;
|
height: 200rpx;
|
}
|
}
|
</style>
|