<template>
|
<PageHeader :title="pageTitle" @back="goBack" />
|
<view class="account-detail">
|
<view class="box">
|
<view style="margin-bottom: 20rpx;">
|
<uni-data-select v-model="ledgerVlaue" :localdata="ledgerList" placeholder="请选择采购订单号"
|
:disabled="type == 'edit'" @change="switchLedger"></uni-data-select>
|
</view>
|
<view v-for="(item, index) in goodsList" class="form-box" :key="index">
|
<checkbox-group v-if="type == 'add'" @change="switchCheck(index)">
|
<checkbox value="cb" style="transform:scale(0.7)" />
|
</checkbox-group>
|
<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="请输入名称" disabled />
|
</uni-forms-item>
|
<uni-forms-item label="高度" required>
|
<uni-easyinput v-model="item.specificationModel" type="number" placeholder="请输入高度" disabled />
|
</uni-forms-item>
|
<uni-forms-item label="高度单位" required>
|
<uni-easyinput v-model="item.unit" placeholder="请输入高度单位" disabled />
|
</uni-forms-item>
|
<uni-forms-item label="纸箱规格" required>
|
<uni-easyinput v-model="item.cartonSpecifications" placeholder="请输入纸箱规格"
|
:disabled="type == 'edit'" />
|
</uni-forms-item>
|
<uni-forms-item label="待入库数量/件" required>
|
<uni-number-box v-model="item.quantity0" :min="0" disabled></uni-number-box>
|
</uni-forms-item>
|
<uni-forms-item label="入库数量/件" required>
|
<uni-number-box v-model="item.quantityStock" :min="0" :max="item.quantity0"></uni-number-box>
|
</uni-forms-item>
|
<uni-forms-item label="每件数量/支" required>
|
<uni-number-box v-model="item.boxNum" :min="0" :disabled="type == 'edit'"></uni-number-box>
|
</uni-forms-item>
|
<uni-forms-item label="单价(元)/件" required>
|
<uni-number-box v-model="item.taxInclusiveUnitPrice" :min="0" :step="0.01"
|
disabled></uni-number-box>
|
</uni-forms-item>
|
<uni-forms-item label="单价(美元)/件" required>
|
<uni-number-box v-model="item.dollarPrice" :min="0" :step="0.01"
|
:disabled="type == 'edit'"></uni-number-box>
|
</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 { ledgerListPage, productlist, stockinAdd, stockinUpdate } from '@/api/inventoryManagement/receiptManagement.js'
|
import useUserStore from '@/store/modules/user'
|
const userStore = useUserStore()
|
const pageTitle = ref('新增自定义入库')
|
const goodsList = ref([])
|
const type = ref('add')
|
const props = defineProps(['goods'])
|
const defaultGoods = {
|
boxNum: 0,
|
cartonSpecifications: "",
|
id: null,
|
inboundDate: "",
|
quantityStock: 0,
|
itemType: "",
|
productCategory: "",
|
specificationModel: "",
|
supplierName: "",
|
taxExclusiveTotalPrice: 0,
|
taxInclusiveTotalPrice: 0,
|
taxInclusiveUnitPrice: 0,
|
dollarPrice: 0,
|
taxRate: 0,
|
unit: "",
|
url: "",
|
}
|
const switchCheck = (index) => {
|
goodsList.value[index].checked = !goodsList.value[index].checked
|
}
|
const goBack = () => {
|
uni.navigateBack()
|
}
|
const submitForm = async () => {
|
let _list = []
|
goodsList.value.map(item => {
|
if (item.checked && type.value == 'add') {
|
item.inboundQuantity = item.quantityStock
|
item.unitPrice = item.taxInclusiveUnitPrice
|
_list.push(item)
|
}
|
if (type.value == 'edit') {
|
_list.push({ ...item, quantityStock: item.inboundNum })
|
}
|
})
|
if (_list.length === 0) {
|
uni.showToast({
|
title: '请选择要入库的产品',
|
icon: 'none'
|
})
|
return
|
}
|
let pamaes = {
|
}
|
let supplierName = ''
|
ledgerList.value.map((item) => {
|
if (ledgerVlaue.value == item.value) {
|
supplierName = item.supplierName
|
}
|
})
|
if (type.value == 'add') {
|
pamaes = {
|
entryDate: getCurrentDate(),
|
purchaseContractNumber: ledgerVlaue.value,
|
inboundBatch: '',
|
inboundTime: formatDateTime(),
|
nickName: userStore.nickName,
|
remark: '',
|
supplierId: null,
|
supplierName: supplierName,
|
recorderName: userStore.name,
|
id: null,
|
details: _list
|
}
|
} else {
|
pamaes = {
|
id: _list[0].id,
|
quantityStock: _list[0].quantityStock
|
}
|
}
|
console.log('pamaes', pamaes)
|
let requiredApi = ''
|
if (type.value == 'add') {
|
requiredApi = stockinAdd
|
} else {
|
requiredApi = stockinUpdate
|
}
|
let res = await requiredApi(pamaes)
|
if (res.code !== 200) {
|
uni.showToast({
|
title: res.msg,
|
icon: 'none'
|
})
|
return
|
}
|
uni.showToast({
|
title: '新增成功',
|
icon: 'none'
|
})
|
goBack()
|
}
|
|
function getCurrentDate() {
|
return formatDateTime(new Date(), false);
|
}
|
function formatDateTime(date = new Date(), includeTime = true) {
|
const d = new Date(date);
|
const year = d.getFullYear();
|
const month = String(d.getMonth() + 1).padStart(2, '0');
|
const day = String(d.getDate()).padStart(2, '0');
|
|
if (!includeTime) {
|
return `${year}-${month}-${day}`;
|
}
|
|
const hours = String(d.getHours()).padStart(2, '0');
|
const minutes = String(d.getMinutes()).padStart(2, '0');
|
const seconds = String(d.getSeconds()).padStart(2, '0');
|
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
}
|
|
//采购订单号相关
|
|
const ledgerList = ref([])
|
const ledgerVlaue = ref(0)
|
const getLedgerList = async (_goods) => {
|
let res = await ledgerListPage({ current: -1, size: -1 })
|
if (res.code !== 200) return
|
ledgerList.value = res.data?.records || []
|
ledgerList.value = ledgerList.value.map(item => {
|
return {
|
text: item.purchaseContractNumber + '·' + item.supplierName,
|
value: item.purchaseContractNumber,
|
supplierName: item.supplierName
|
}
|
})
|
if (_goods.id) {
|
ledgerList.value.map(item => {
|
if (item.value == _goods.purchaseContractNumber) {
|
ledgerVlaue.value = _goods.purchaseContractNumber
|
switchLedger(_goods.purchaseContractNumber)
|
}
|
|
})
|
}
|
}
|
|
const switchLedger = (purchaseContractNumber) => {
|
getGoodsList(purchaseContractNumber)
|
}
|
const getGoodsList = async (purchaseContractNumber) => {
|
let res = await productlist({ purchaseContractNumber })
|
if (res.code !== 200) return
|
if (type.value == 'edit') {
|
goodsList.value.map((el) => {
|
res.data.map(item => {
|
if (el.id == item.recordId) {
|
el.quantity0 = item.quantity0
|
}
|
})
|
})
|
} else {
|
goodsList.value = res.data.map(item => {
|
return { ...defaultGoods, ...item }
|
})
|
}
|
|
}
|
onMounted(() => {
|
let _goods = JSON.parse(props.goods)
|
if (_goods.id) {
|
pageTitle.value = '编辑自定义入库'
|
type.value = 'edit'
|
goodsList.value.push({ ...defaultGoods, ..._goods })
|
}
|
getLedgerList(_goods)
|
userStore.getInfo()
|
})
|
</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;
|
}
|
|
.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>
|