李红攀:V2.0.001小程序的采购管理
This commit is contained in:
298
src/pages-erp/farmer/form/index.vue
Normal file
298
src/pages-erp/farmer/form/index.vue
Normal file
@@ -0,0 +1,298 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
:title="getTitle"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<view class="pb-180rpx">
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-input
|
||||
v-model="formData.name"
|
||||
label="户主姓名"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入户主姓名"
|
||||
prop="name"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.idCardNumber"
|
||||
label="身份证号"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入身份证号"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.mobile"
|
||||
label="手机号码"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入手机号码"
|
||||
type="number"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.address"
|
||||
label="住址"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入住址"
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="种植信息" border>
|
||||
<wd-input
|
||||
v-model="formData.plantingBase"
|
||||
label="种植基地"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入所属种植基地"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.contractNumber"
|
||||
label="合同号"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入合同号"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.contractedArea"
|
||||
label="签订面积"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入签订面积"
|
||||
type="number"
|
||||
suffix-icon="亩"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.orderQuantity"
|
||||
label="订购数量"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入订购数量"
|
||||
type="number"
|
||||
suffix-icon="株"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.actualArea"
|
||||
label="实种面积"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入实种面积"
|
||||
type="number"
|
||||
suffix-icon="亩"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="移栽时间" title-width="180rpx" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.transplantTime"
|
||||
type="date"
|
||||
label=""
|
||||
placeholder="请选择移栽时间"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.transplantQuantity"
|
||||
label="移栽数量"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入移栽数量"
|
||||
type="number"
|
||||
suffix-icon="盘"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="成熟时间" title-width="180rpx" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.maturityTime"
|
||||
type="date"
|
||||
label=""
|
||||
placeholder="请选择成熟时间"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="预计采收" title-width="180rpx" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.expectedHarvestTime"
|
||||
type="date"
|
||||
label=""
|
||||
placeholder="请选择预计采收时间"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="使用品种" title-width="180rpx" center>
|
||||
<wd-picker
|
||||
v-model="formData.usedVariety"
|
||||
:columns="varietyColumns"
|
||||
label=""
|
||||
placeholder="请选择使用品种"
|
||||
@confirm="onVarietyConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.plantingMethod"
|
||||
label="种植方式"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入种植方式"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.adminName"
|
||||
label="管理员"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入管理员姓名"
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="其他信息" border>
|
||||
<wd-cell title="开启状态" title-width="180rpx" center>
|
||||
<wd-switch v-model="statusEnabled" />
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.sort"
|
||||
label="排序"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入排序"
|
||||
type="number"
|
||||
clearable
|
||||
/>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 底部保存按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
type="primary"
|
||||
block
|
||||
:loading="formLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||
import type { Farmer } from '@/api/erp/farmer'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { createFarmer, getFarmer, updateFarmer, VARIETY_OPTIONS } from '@/api/erp/farmer'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const getTitle = computed(() => props.id ? '编辑农户' : '新增农户')
|
||||
const formLoading = ref(false)
|
||||
const formData = ref<Farmer>({
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
idCardNumber: undefined,
|
||||
mobile: undefined,
|
||||
address: undefined,
|
||||
plantingBase: undefined,
|
||||
contractNumber: undefined,
|
||||
contractedArea: undefined,
|
||||
orderQuantity: undefined,
|
||||
actualArea: undefined,
|
||||
transplantTime: undefined,
|
||||
transplantQuantity: undefined,
|
||||
maturityTime: undefined,
|
||||
expectedHarvestTime: undefined,
|
||||
usedVariety: undefined,
|
||||
plantingMethod: undefined,
|
||||
adminName: undefined,
|
||||
remark: undefined,
|
||||
status: 0,
|
||||
sort: 0,
|
||||
})
|
||||
const formRules = {
|
||||
name: [{ required: true, message: '户主姓名不能为空' }],
|
||||
}
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
// 状态开关
|
||||
const statusEnabled = ref(true)
|
||||
watch(statusEnabled, (val) => {
|
||||
formData.value.status = val ? 0 : 1
|
||||
})
|
||||
watch(() => formData.value.status, (val) => {
|
||||
statusEnabled.value = val === 0
|
||||
})
|
||||
|
||||
/** 品种下拉列 */
|
||||
const varietyColumns = computed(() => [
|
||||
VARIETY_OPTIONS.map(v => ({ value: v.value, label: v.label })),
|
||||
])
|
||||
|
||||
/** 品种选择回调 */
|
||||
function onVarietyConfirm({ value }: any) {
|
||||
formData.value.usedVariety = value?.[0]
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/farmer/index')
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) return
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getFarmer(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交表单 */
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid) return
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
if (props.id) {
|
||||
await updateFarmer(formData.value)
|
||||
toast.success('修改成功')
|
||||
} else {
|
||||
await createFarmer(formData.value)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
289
src/pages-erp/farmer/index.vue
Normal file
289
src/pages-erp/farmer/index.vue
Normal file
@@ -0,0 +1,289 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="农户管理"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<view @click="searchVisible = true">
|
||||
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<!-- 农户列表 -->
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
@click="handleEdit(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<!-- 头部:姓名 + 状态 -->
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ item.name || '-' }}
|
||||
</view>
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="item.status === 0 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff1f0] text-[#f5222d]'"
|
||||
>
|
||||
{{ item.status === 0 ? '正常' : '停用' }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 住址 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">住址</text>
|
||||
<text>{{ item.address || '-' }}</text>
|
||||
</view>
|
||||
<!-- 种植基地 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">种植基地</text>
|
||||
<text>{{ item.plantingBase || '-' }}</text>
|
||||
</view>
|
||||
<!-- 合同号 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">合同号</text>
|
||||
<text>{{ item.contractNumber || '-' }}</text>
|
||||
</view>
|
||||
<!-- 使用品种 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">使用品种</text>
|
||||
<text>{{ item.usedVariety || '-' }}</text>
|
||||
</view>
|
||||
<!-- 管理员 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">管理员</text>
|
||||
<text>{{ item.adminName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 数量区域 -->
|
||||
<view class="flex items-center justify-around mt-12rpx pt-16rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.contractedArea ?? '-' }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">签订面积</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.actualArea ?? '-' }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">实种面积</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#1890ff] font-semibold">{{ item.orderQuantity ?? '-' }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">订购数量</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:farmer:update'])"
|
||||
size="small" type="primary" plain @click="handleEdit(item)"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:farmer:delete'])"
|
||||
size="small" type="error" plain @click="handleDelete(item.id!)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无农户数据" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="list.length > 0"
|
||||
:state="loadMoreState"
|
||||
@reload="loadMore"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 新增按钮 -->
|
||||
<wd-fab
|
||||
v-if="hasAccessByCodes(['erp:farmer:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<wd-popup v-model="searchVisible" position="top" @close="searchVisible = false">
|
||||
<view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">户主姓名</view>
|
||||
<wd-input v-model="searchForm.name" placeholder="请输入户主姓名" clearable />
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">种植基地</view>
|
||||
<wd-input v-model="searchForm.plantingBase" placeholder="请输入种植基地" clearable />
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">使用品种</view>
|
||||
<wd-picker
|
||||
v-model="searchForm.usedVariety"
|
||||
:columns="varietyColumns"
|
||||
placeholder="请选择使用品种"
|
||||
@confirm="onVarietyConfirm"
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-search-form-actions">
|
||||
<wd-button class="flex-1" plain @click="handleReset">重置</wd-button>
|
||||
<wd-button class="flex-1" type="primary" @click="handleSearch">搜索</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { Farmer } from '@/api/erp/farmer'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deleteFarmer, getFarmerPage, VARIETY_OPTIONS } from '@/api/erp/farmer'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { getNavbarHeight, navigateBackPlus } from '@/utils'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<Farmer[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const queryParams = ref<Record<string, any>>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
// 搜索相关
|
||||
const searchVisible = ref(false)
|
||||
const searchForm = reactive({
|
||||
name: undefined as string | undefined,
|
||||
plantingBase: undefined as string | undefined,
|
||||
usedVariety: undefined as string | undefined,
|
||||
})
|
||||
|
||||
/** 品种下拉列 */
|
||||
const varietyColumns = computed(() => [
|
||||
[{ value: '', label: '全部' }, ...VARIETY_OPTIONS.map(v => ({ value: v.value, label: v.label }))],
|
||||
])
|
||||
|
||||
/** 搜索条件 placeholder */
|
||||
const searchPlaceholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (searchForm.name) conditions.push(`姓名:${searchForm.name}`)
|
||||
if (searchForm.plantingBase) conditions.push(`基地:${searchForm.plantingBase}`)
|
||||
if (searchForm.usedVariety) conditions.push(`品种:${searchForm.usedVariety}`)
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索农户'
|
||||
})
|
||||
|
||||
/** 品种选择回调 */
|
||||
function onVarietyConfirm({ value }: any) {
|
||||
searchForm.usedVariety = value?.[0] || undefined
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
/** 查询农户列表 */
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params = { ...queryParams.value }
|
||||
const data = await getFarmerPage(params)
|
||||
list.value = [...list.value, ...data.list]
|
||||
total.value = data.total
|
||||
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
|
||||
loadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
searchVisible.value = false
|
||||
queryParams.value = {
|
||||
...searchForm,
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
searchForm.name = undefined
|
||||
searchForm.plantingBase = undefined
|
||||
searchForm.usedVariety = undefined
|
||||
searchVisible.value = false
|
||||
queryParams.value = { pageNo: 1, pageSize: 10 }
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 加载更多 */
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') return
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 新增农户 */
|
||||
function handleAdd() {
|
||||
uni.navigateTo({ url: '/pages-erp/farmer/form/index' })
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(item: Farmer) {
|
||||
uni.navigateTo({ url: `/pages-erp/farmer/form/index?id=${item.id}` })
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
function handleDelete(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该农户吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deleteFarmer(id)
|
||||
toast.success('删除成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 触底加载更多 */
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
104
src/pages-erp/purchase-in/components/search-form.vue
Normal file
104
src/pages-erp/purchase-in/components/search-form.vue
Normal file
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<!-- 搜索框入口 -->
|
||||
<view @click="visible = true">
|
||||
<wd-search :placeholder="placeholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<wd-popup v-model="visible" position="top" @close="visible = false">
|
||||
<view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
入库单编号
|
||||
</view>
|
||||
<wd-input
|
||||
v-model="formData.no"
|
||||
placeholder="请输入入库单编号"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
审核状态
|
||||
</view>
|
||||
<wd-radio-group v-model="formData.status" shape="button">
|
||||
<wd-radio :value="-1">
|
||||
全部
|
||||
</wd-radio>
|
||||
<wd-radio :value="10">
|
||||
未审核
|
||||
</wd-radio>
|
||||
<wd-radio :value="20">
|
||||
已审核
|
||||
</wd-radio>
|
||||
<wd-radio :value="30">
|
||||
不合格
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</view>
|
||||
<view class="yd-search-form-actions">
|
||||
<wd-button class="flex-1" plain @click="handleReset">
|
||||
重置
|
||||
</wd-button>
|
||||
<wd-button class="flex-1" type="primary" @click="handleSearch">
|
||||
搜索
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { getNavbarHeight } from '@/utils'
|
||||
|
||||
const emit = defineEmits<{
|
||||
search: [data: Record<string, any>]
|
||||
reset: []
|
||||
}>()
|
||||
|
||||
const visible = ref(false)
|
||||
const formData = reactive({
|
||||
no: undefined as string | undefined,
|
||||
status: -1,
|
||||
})
|
||||
|
||||
const statusMap: Record<number, string> = {
|
||||
10: '未审核',
|
||||
20: '已审核',
|
||||
30: '不合格',
|
||||
}
|
||||
|
||||
/** 搜索条件 placeholder 拼接 */
|
||||
const placeholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (formData.no) {
|
||||
conditions.push(`编号:${formData.no}`)
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
conditions.push(`状态:${statusMap[formData.status] || formData.status}`)
|
||||
}
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索采购入库单'
|
||||
})
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
visible.value = false
|
||||
const params: Record<string, any> = {}
|
||||
if (formData.no) {
|
||||
params.no = formData.no
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
params.status = formData.status
|
||||
}
|
||||
emit('search', params)
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
formData.no = undefined
|
||||
formData.status = -1
|
||||
visible.value = false
|
||||
emit('reset')
|
||||
}
|
||||
</script>
|
||||
395
src/pages-erp/purchase-in/detail/index.vue
Normal file
395
src/pages-erp/purchase-in/detail/index.vue
Normal file
@@ -0,0 +1,395 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采购入库详情"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 详情内容 -->
|
||||
<view v-if="formData">
|
||||
<!-- 基本信息 -->
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="入库单编号" :value="formData.no" />
|
||||
<wd-cell title="审核状态">
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(formData.status, formData.isQualified)"
|
||||
>
|
||||
{{ getStatusText(formData.status, formData.isQualified) }}
|
||||
</view>
|
||||
</wd-cell>
|
||||
<wd-cell title="供应商" :value="formData.supplierName || '-'" />
|
||||
<wd-cell title="入库时间" :value="formatDateTime(formData.inTime)" />
|
||||
<wd-cell title="关联订单" :value="formData.orderNo || '-'" />
|
||||
<wd-cell title="创建人" :value="formData.creatorName || '-'" />
|
||||
<wd-cell title="创建时间" :value="formatDateTime(formData.createTime)" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 金额信息 -->
|
||||
<wd-cell-group title="金额信息" border>
|
||||
<wd-cell title="合计数量" :value="String(formData.totalCount || 0)" />
|
||||
<wd-cell title="合计产品价格" :value="`¥${formData.totalProductPrice || 0}`" />
|
||||
<wd-cell title="合计税额" :value="`¥${formData.totalTaxPrice || 0}`" />
|
||||
<wd-cell title="优惠率" :value="`${formData.discountPercent || 0}%`" />
|
||||
<wd-cell title="优惠金额" :value="`¥${formData.discountPrice || 0}`" />
|
||||
<wd-cell title="其他费用" :value="`¥${formData.otherPrice || 0}`" />
|
||||
<wd-cell title="应付金额">
|
||||
<text class="text-[#e6a23c] font-semibold">¥{{ formData.totalPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="已付金额">
|
||||
<text class="text-[#52c41a] font-semibold">¥{{ formData.paymentPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="未付金额">
|
||||
<text
|
||||
class="font-semibold"
|
||||
:class="(formData.totalPrice || 0) - (formData.paymentPrice || 0) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
|
||||
>
|
||||
¥{{ (formData.totalPrice || 0) - (formData.paymentPrice || 0) }}
|
||||
</text>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 不合格信息 -->
|
||||
<wd-cell-group v-if="formData.status !== 10 && !formData.isQualified" title="不合格信息" border>
|
||||
<wd-cell title="返回方式" :value="getReturnTypeLabel(formData.returnType)" />
|
||||
<wd-cell v-if="formData.returnRemark" title="返回备注" :value="formData.returnRemark" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 入库明细 -->
|
||||
<view class="mx-24rpx mt-24rpx">
|
||||
<view class="mb-16rpx text-32rpx text-[#333] font-semibold">
|
||||
入库明细({{ formData.items?.length || 0 }}项)
|
||||
</view>
|
||||
<view v-if="formData.items && formData.items.length > 0">
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="item.id || index"
|
||||
class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
>
|
||||
<!-- 产品头部 -->
|
||||
<view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-16rpx">
|
||||
<view class="flex items-center">
|
||||
<text class="text-28rpx text-[#333] font-semibold">{{ item.productName || '-' }}</text>
|
||||
<text v-if="item.productBarCode" class="ml-12rpx text-22rpx text-[#999]">{{ item.productBarCode }}</text>
|
||||
</view>
|
||||
<text v-if="item.warehouseName" class="text-24rpx text-[#1890ff]">{{ item.warehouseName }}</text>
|
||||
</view>
|
||||
<view class="p-24rpx">
|
||||
<!-- 产品规格 -->
|
||||
<view v-if="item.productSpec" class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<text class="mr-8rpx text-[#999]">规格:</text>
|
||||
<text>{{ item.productSpec }}</text>
|
||||
</view>
|
||||
<!-- 单价 / 数量 / 单位 -->
|
||||
<view class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">单价:</text>
|
||||
<text class="text-[#f5222d]">¥{{ item.productPrice || 0 }}</text>
|
||||
</view>
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">数量:</text>
|
||||
<text class="font-semibold">{{ item.count || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">单位:</text>
|
||||
<text>{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 税率 / 税额 -->
|
||||
<view v-if="item.taxPercent" class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">税率:</text>
|
||||
<text>{{ item.taxPercent }}%</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">税额:</text>
|
||||
<text>¥{{ item.taxPrice || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 金额 / 库存 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">金额:</text>
|
||||
<text class="text-[#e6a23c]">¥{{ item.totalPrice || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">库存:</text>
|
||||
<text>{{ item.stockCount || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 备注 -->
|
||||
<view v-if="item.remark" class="text-24rpx text-[#999]">
|
||||
备注:{{ item.remark }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="py-60rpx text-center text-28rpx text-[#999]">
|
||||
暂无入库明细
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 备注 -->
|
||||
<wd-cell-group v-if="formData.remark" title="备注" border>
|
||||
<wd-cell :value="formData.remark" />
|
||||
</wd-cell-group>
|
||||
</view>
|
||||
|
||||
<!-- 底部操作按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<view class="yd-detail-footer-actions">
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:update']) && formData?.status === 10"
|
||||
class="flex-1" type="warning" @click="handleEdit"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:update-status']) && formData?.status === 10"
|
||||
class="flex-1" type="success" @click="handleAudit"
|
||||
>
|
||||
审核
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:update-status']) && (formData?.status === 20 || formData?.status === 30)"
|
||||
class="flex-1" type="warning" @click="handleReverseAudit"
|
||||
>
|
||||
反审核
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:delete']) && formData?.status === 10"
|
||||
class="flex-1" type="error" :loading="deleting" @click="handleDelete"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 审核弹窗 -->
|
||||
<wd-popup v-model="auditVisible" position="bottom" closable @close="auditVisible = false">
|
||||
<view class="p-32rpx">
|
||||
<view class="text-32rpx text-[#333] font-semibold mb-32rpx text-center">
|
||||
采购入库审核
|
||||
</view>
|
||||
<view class="mb-24rpx">
|
||||
<view class="text-26rpx text-[#666] mb-12rpx">是否合格</view>
|
||||
<wd-switch v-model="auditForm.isQualified" @change="handleQualifiedChange" />
|
||||
</view>
|
||||
<view v-if="!auditForm.isQualified" class="mb-24rpx">
|
||||
<view class="text-26rpx text-[#666] mb-12rpx">返回方式</view>
|
||||
<wd-radio-group v-model="auditForm.returnType" shape="button">
|
||||
<wd-radio
|
||||
v-for="opt in RETURN_TYPE_OPTIONS"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</view>
|
||||
<view v-if="!auditForm.isQualified" class="mb-24rpx">
|
||||
<view class="text-26rpx text-[#666] mb-12rpx">返回备注</view>
|
||||
<wd-textarea
|
||||
v-model="auditForm.returnRemark"
|
||||
placeholder="请输入返回方式备注"
|
||||
:maxlength="200"
|
||||
/>
|
||||
</view>
|
||||
<view class="flex gap-24rpx mt-32rpx">
|
||||
<wd-button class="flex-1" plain @click="auditVisible = false">
|
||||
取消
|
||||
</wd-button>
|
||||
<wd-button class="flex-1" type="primary" :loading="auditLoading" @click="submitAudit">
|
||||
确定
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PurchaseIn } from '@/api/erp/purchase-in'
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deletePurchaseIn, getPurchaseIn, RETURN_TYPE_OPTIONS, updatePurchaseInStatus } from '@/api/erp/purchase-in'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import { formatDateTime } from '@/utils/date'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const formData = ref<PurchaseIn>()
|
||||
const deleting = ref(false)
|
||||
|
||||
// 审核相关
|
||||
const auditVisible = ref(false)
|
||||
const auditLoading = ref(false)
|
||||
const auditForm = reactive({
|
||||
isQualified: true,
|
||||
returnType: undefined as string | undefined,
|
||||
returnRemark: undefined as string | undefined,
|
||||
})
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number, isQualified?: boolean) {
|
||||
if (status === 10) return '未审核'
|
||||
if (status === 20) return isQualified ? '已审核' : '不合格'
|
||||
if (status === 30) return '不合格'
|
||||
return '未知'
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number, isQualified?: boolean) {
|
||||
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
if (status === 20) return isQualified ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff1f0] text-[#f5222d]'
|
||||
if (status === 30) return 'bg-[#fff1f0] text-[#f5222d]'
|
||||
return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
|
||||
/** 获取返回方式标签 */
|
||||
function getReturnTypeLabel(value?: string | null) {
|
||||
if (!value) return '-'
|
||||
const option = RETURN_TYPE_OPTIONS.find(opt => opt.value === value)
|
||||
return option ? option.label : value
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/purchase-in/index')
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getPurchaseIn(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 编辑操作 */
|
||||
function handleEdit() {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-in/form/index?id=${props.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 打开审核弹窗 */
|
||||
function handleAudit() {
|
||||
auditForm.isQualified = true
|
||||
auditForm.returnType = undefined
|
||||
auditForm.returnRemark = undefined
|
||||
auditVisible.value = true
|
||||
}
|
||||
|
||||
/** 合格状态变化 */
|
||||
function handleQualifiedChange(val: boolean) {
|
||||
if (val) {
|
||||
auditForm.returnType = undefined
|
||||
auditForm.returnRemark = undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交审核 */
|
||||
async function submitAudit() {
|
||||
if (!props.id) return
|
||||
if (!auditForm.isQualified && !auditForm.returnType) {
|
||||
toast.warning('请选择返回方式')
|
||||
return
|
||||
}
|
||||
auditLoading.value = true
|
||||
try {
|
||||
await updatePurchaseInStatus({
|
||||
id: props.id,
|
||||
isQualified: auditForm.isQualified,
|
||||
returnType: auditForm.returnType,
|
||||
returnRemark: auditForm.returnRemark,
|
||||
status: auditForm.isQualified ? 20 : 30,
|
||||
})
|
||||
toast.success('审核成功')
|
||||
auditVisible.value = false
|
||||
getDetail()
|
||||
} finally {
|
||||
auditLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 反审核操作 */
|
||||
function handleReverseAudit() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要反审核该入库单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updatePurchaseInStatus({
|
||||
id: props.id,
|
||||
isQualified: false,
|
||||
status: 10,
|
||||
})
|
||||
toast.success('反审核成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除操作 */
|
||||
function handleDelete() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该采购入库单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
deleting.value = true
|
||||
try {
|
||||
await deletePurchaseIn([props.id])
|
||||
toast.success('删除成功')
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
612
src/pages-erp/purchase-in/form/index.vue
Normal file
612
src/pages-erp/purchase-in/form/index.vue
Normal file
@@ -0,0 +1,612 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
:title="getTitle"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="入库单号" title-width="180rpx" center>
|
||||
<wd-input
|
||||
v-model="formData.no"
|
||||
placeholder="不填则自动生成"
|
||||
:disabled="!!props.id"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="入库时间" title-width="180rpx" prop="inTime" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.inTime"
|
||||
type="date"
|
||||
label=""
|
||||
placeholder="请选择入库时间"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="关联订单" title-width="180rpx" center is-link @click="openOrderSelect">
|
||||
<text v-if="formData.orderNo" class="text-[#1890ff]">{{ formData.orderNo }}</text>
|
||||
<text v-else class="text-[#999]">点击选择采购订单</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="供应商" title-width="180rpx" center>
|
||||
<text>{{ getSupplierName() || '-' }}</text>
|
||||
</wd-cell>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="费用信息" border>
|
||||
<wd-input
|
||||
v-model="formData.discountPercent"
|
||||
label="优惠率(%)"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入优惠率"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="付款优惠" title-width="180rpx" center>
|
||||
<text>¥{{ formData.discountPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.otherPrice"
|
||||
label="其他费用"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入其他费用"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="优惠后金额" title-width="180rpx" center>
|
||||
<text>¥{{ (formData.totalPrice || 0) - (formData.otherPrice || 0) }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="结算账户" title-width="180rpx" prop="accountId" center>
|
||||
<wd-picker
|
||||
v-model="formData.accountId"
|
||||
:columns="accountColumns"
|
||||
label=""
|
||||
placeholder="请选择结算账户"
|
||||
@confirm="onAccountConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="应付金额" title-width="180rpx" center>
|
||||
<text class="text-[#e6a23c] font-semibold">¥{{ formData.totalPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 入库明细 -->
|
||||
<view class="mx-24rpx mt-24rpx pb-180rpx">
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-32rpx text-[#333] font-semibold">
|
||||
入库明细({{ formData.items?.length || 0 }}项)
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="index"
|
||||
class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
>
|
||||
<view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-12rpx">
|
||||
<text class="text-28rpx text-[#333] font-semibold">产品 #{{ index + 1 }} {{ item.productName || '' }}</text>
|
||||
<wd-button
|
||||
v-if="formData.items && formData.items.length > 1"
|
||||
size="small" type="error" plain @click="handleRemoveItem(index)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
<view class="p-24rpx">
|
||||
<!-- 仓库选择 -->
|
||||
<view class="mb-16rpx">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">仓库</text>
|
||||
<wd-picker
|
||||
v-model="item.warehouseId"
|
||||
:columns="warehouseColumns"
|
||||
placeholder="请选择仓库"
|
||||
@confirm="(e: any) => onWarehouseConfirm(e, index)"
|
||||
/>
|
||||
</view>
|
||||
<!-- 自动填充的产品信息(只读) -->
|
||||
<view v-if="item.productId" class="mb-16rpx rounded-8rpx bg-[#f9f9f9] p-16rpx">
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">产品名称</text>
|
||||
<text class="text-[#333]">{{ item.productName || '-' }}</text>
|
||||
</view>
|
||||
<view v-if="item.productSpec" class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">规格</text>
|
||||
<text class="text-[#333]">{{ item.productSpec }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">单位</text>
|
||||
<text class="text-[#333]">{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">条码</text>
|
||||
<text class="text-[#333]">{{ item.productBarCode || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">库存</text>
|
||||
<text class="text-[#333]">{{ item.stockCount || 0 }}</text>
|
||||
</view>
|
||||
<view v-if="item.totalCount != null" class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">原数量</text>
|
||||
<text class="text-[#333]">{{ item.totalCount }}</text>
|
||||
</view>
|
||||
<view v-if="item.inCount != null" class="flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">已入库</text>
|
||||
<text class="text-[#333]">{{ item.inCount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mb-16rpx flex gap-16rpx">
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">数量</text>
|
||||
<wd-input
|
||||
v-model="item.count"
|
||||
type="number"
|
||||
placeholder="数量"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">单价(元)</text>
|
||||
<wd-input
|
||||
v-model="item.productPrice"
|
||||
type="number"
|
||||
placeholder="单价"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mb-16rpx flex gap-16rpx">
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">税率(%)</text>
|
||||
<wd-input
|
||||
v-model="item.taxPercent"
|
||||
type="number"
|
||||
placeholder="税率"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">金额</text>
|
||||
<text class="block pt-16rpx text-28rpx text-[#333]">{{ calcTotalPrice(item) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">备注</text>
|
||||
<wd-input
|
||||
v-model="item.remark"
|
||||
placeholder="请输入备注"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="!formData.items?.length" class="py-60rpx text-center text-28rpx text-[#999]">
|
||||
暂无产品,请先选择关联订单
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部保存按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
type="primary"
|
||||
block
|
||||
:loading="formLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
|
||||
<!-- 采购订单选择弹窗 -->
|
||||
<wd-popup v-model="orderSelectVisible" position="right" custom-style="width: 100%; height: 100%;">
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
title="选择采购订单"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="orderSelectVisible = false"
|
||||
/>
|
||||
<wd-search
|
||||
v-model="orderQueryParams.no"
|
||||
placeholder="搜索订单单号"
|
||||
@search="getOrderList"
|
||||
@clear="getOrderList"
|
||||
/>
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in orderList"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
:class="{ 'border-2 border-[#1890ff]': selectedOrderId === item.id }"
|
||||
@click="handleSelectOrder(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<view class="mb-12rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.no }}</view>
|
||||
<wd-icon v-if="selectedOrderId === item.id" name="check" color="#1890ff" size="40rpx" />
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">供应商</text>
|
||||
<text>{{ item.supplierName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text class="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<view class="flex items-center justify-around mt-12rpx pt-12rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">总数量</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#52c41a] font-semibold">{{ item.inCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">已入库</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#e6a23c] font-semibold">¥{{ item.totalPrice || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">含税金额</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="orderList.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无可入库订单" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="orderList.length > 0"
|
||||
:state="orderLoadMoreState"
|
||||
@reload="loadMoreOrders"
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button type="primary" block :disabled="!selectedOrderId" @click="confirmSelectOrder">
|
||||
确认选择
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||
import type { PurchaseIn, PurchaseInItem } from '@/api/erp/purchase-in'
|
||||
import type { PurchaseOrder } from '@/api/erp/purchase-order'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { createPurchaseIn, getPurchaseIn, updatePurchaseIn } from '@/api/erp/purchase-in'
|
||||
import { getPurchaseOrder, getPurchaseOrderPage } from '@/api/erp/purchase-order'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
/** 账户简单信息 */
|
||||
interface AccountSimple {
|
||||
id: number
|
||||
name: string
|
||||
defaultStatus?: boolean
|
||||
}
|
||||
|
||||
/** 仓库简单信息 */
|
||||
interface WarehouseSimple {
|
||||
id: number
|
||||
name: string
|
||||
defaultStatus?: boolean
|
||||
}
|
||||
|
||||
/** 供应商简单信息 */
|
||||
interface SupplierSimple {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const getTitle = computed(() => props.id ? '编辑采购入库' : '新增采购入库')
|
||||
const formLoading = ref(false)
|
||||
const formData = ref<PurchaseIn>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
supplierId: undefined,
|
||||
accountId: undefined,
|
||||
inTime: undefined,
|
||||
orderId: undefined,
|
||||
orderNo: undefined,
|
||||
discountPercent: 0,
|
||||
discountPrice: 0,
|
||||
otherPrice: 0,
|
||||
totalPrice: 0,
|
||||
remark: '',
|
||||
items: [],
|
||||
})
|
||||
const formRules = {
|
||||
inTime: [{ required: true, message: '入库时间不能为空' }],
|
||||
}
|
||||
const formRef = ref<FormInstance>()
|
||||
const supplierList = ref<SupplierSimple[]>([])
|
||||
const accountList = ref<AccountSimple[]>([])
|
||||
const warehouseList = ref<WarehouseSimple[]>([])
|
||||
const defaultWarehouse = ref<WarehouseSimple>()
|
||||
|
||||
// 采购订单选择相关
|
||||
const orderSelectVisible = ref(false)
|
||||
const orderList = ref<PurchaseOrder[]>([])
|
||||
const orderLoadMoreState = ref<LoadMoreState>('loading')
|
||||
const orderQueryParams = ref({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
no: undefined as string | undefined,
|
||||
inEnable: true,
|
||||
})
|
||||
const orderTotal = ref(0)
|
||||
const selectedOrderId = ref<number>()
|
||||
|
||||
/** 账户下拉列 */
|
||||
const accountColumns = computed(() => [
|
||||
accountList.value.map(a => ({ value: a.id, label: a.name })),
|
||||
])
|
||||
|
||||
/** 仓库下拉列 */
|
||||
const warehouseColumns = computed(() => [
|
||||
warehouseList.value.map(w => ({ value: w.id, label: w.name })),
|
||||
])
|
||||
|
||||
/** 获取供应商名称 */
|
||||
function getSupplierName() {
|
||||
if (!formData.value.supplierId) return ''
|
||||
const supplier = supplierList.value.find(s => s.id === formData.value.supplierId)
|
||||
return supplier?.name || formData.value.supplierName || ''
|
||||
}
|
||||
|
||||
/** 账户选择回调 */
|
||||
function onAccountConfirm({ value }: any) {
|
||||
formData.value.accountId = value?.[0]
|
||||
}
|
||||
|
||||
/** 仓库选择回调 */
|
||||
function onWarehouseConfirm({ value }: any, index: number) {
|
||||
if (formData.value.items && formData.value.items[index]) {
|
||||
formData.value.items[index].warehouseId = value?.[0]
|
||||
const warehouse = warehouseList.value.find(w => w.id === value?.[0])
|
||||
if (warehouse) {
|
||||
formData.value.items[index].warehouseName = warehouse.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 计算行项金额 */
|
||||
function calcTotalPrice(item: PurchaseInItem) {
|
||||
if (item.productPrice && item.count) {
|
||||
const productTotal = Number(item.productPrice) * Number(item.count)
|
||||
const taxPrice = item.taxPercent ? productTotal * Number(item.taxPercent) / 100 : 0
|
||||
return `¥${(productTotal + taxPrice).toFixed(2)}`
|
||||
}
|
||||
return '-'
|
||||
}
|
||||
|
||||
/** 监听表单数据变化,计算总价 */
|
||||
watch(
|
||||
() => formData.value,
|
||||
(val) => {
|
||||
if (!val || !val.items) return
|
||||
// 计算每个明细的金额
|
||||
val.items.forEach((item) => {
|
||||
if (item.productPrice && item.count) {
|
||||
item.totalProductPrice = Number(item.productPrice) * Number(item.count)
|
||||
item.taxPrice = item.taxPercent ? item.totalProductPrice * Number(item.taxPercent) / 100 : 0
|
||||
item.totalPrice = item.totalProductPrice + (item.taxPrice || 0)
|
||||
}
|
||||
})
|
||||
// 计算总价
|
||||
const totalPrice = val.items.reduce((prev, curr) => prev + (curr.totalPrice || 0), 0)
|
||||
const discountPrice = val.discountPercent ? totalPrice * Number(val.discountPercent) / 100 : 0
|
||||
formData.value.discountPrice = Math.round(discountPrice * 100) / 100
|
||||
formData.value.totalPrice = Math.round((totalPrice - discountPrice + Number(val.otherPrice || 0)) * 100) / 100
|
||||
},
|
||||
{ deep: true },
|
||||
)
|
||||
|
||||
/** 加载下拉列表数据 */
|
||||
async function loadDropdownData() {
|
||||
try {
|
||||
const { http } = await import('@/http/http')
|
||||
const [suppliers, accounts, warehouses] = await Promise.all([
|
||||
http.get<SupplierSimple[]>('/erp/supplier/simple-list'),
|
||||
http.get<AccountSimple[]>('/erp/account/simple-list'),
|
||||
http.get<WarehouseSimple[]>('/erp/warehouse/simple-list'),
|
||||
])
|
||||
supplierList.value = suppliers || []
|
||||
accountList.value = accounts || []
|
||||
warehouseList.value = warehouses || []
|
||||
// 设置默认账户
|
||||
const defaultAccount = accountList.value.find(a => a.defaultStatus)
|
||||
if (defaultAccount && !formData.value.accountId) {
|
||||
formData.value.accountId = defaultAccount.id
|
||||
}
|
||||
// 设置默认仓库
|
||||
defaultWarehouse.value = warehouseList.value.find(w => w.defaultStatus)
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/purchase-in/index')
|
||||
}
|
||||
|
||||
/** 删除入库明细行 */
|
||||
function handleRemoveItem(index: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确定要删除第 ${index + 1} 项产品吗?`,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
formData.value.items?.splice(index, 1)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 打开订单选择弹窗 */
|
||||
function openOrderSelect() {
|
||||
orderSelectVisible.value = true
|
||||
orderQueryParams.value.pageNo = 1
|
||||
orderList.value = []
|
||||
selectedOrderId.value = formData.value.orderId
|
||||
getOrderList()
|
||||
}
|
||||
|
||||
/** 获取可入库订单列表 */
|
||||
async function getOrderList() {
|
||||
orderLoadMoreState.value = 'loading'
|
||||
try {
|
||||
const data = await getPurchaseOrderPage(orderQueryParams.value)
|
||||
if (orderQueryParams.value.pageNo === 1) {
|
||||
orderList.value = data.list
|
||||
} else {
|
||||
orderList.value = [...orderList.value, ...data.list]
|
||||
}
|
||||
orderTotal.value = data.total
|
||||
orderLoadMoreState.value = orderList.value.length >= orderTotal.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
orderLoadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载更多订单 */
|
||||
function loadMoreOrders() {
|
||||
if (orderLoadMoreState.value === 'finished') return
|
||||
orderQueryParams.value.pageNo++
|
||||
getOrderList()
|
||||
}
|
||||
|
||||
/** 选择订单 */
|
||||
function handleSelectOrder(item: PurchaseOrder) {
|
||||
selectedOrderId.value = item.id
|
||||
}
|
||||
|
||||
/** 确认选择订单 */
|
||||
async function confirmSelectOrder() {
|
||||
if (!selectedOrderId.value) return
|
||||
try {
|
||||
toast.loading('加载订单详情...')
|
||||
const orderDetail = await getPurchaseOrder(selectedOrderId.value)
|
||||
// 设置订单信息
|
||||
formData.value.orderId = orderDetail.id
|
||||
formData.value.orderNo = orderDetail.no
|
||||
formData.value.supplierId = orderDetail.supplierId
|
||||
formData.value.supplierName = orderDetail.supplierName
|
||||
formData.value.accountId = orderDetail.accountId
|
||||
formData.value.discountPercent = orderDetail.discountPercent
|
||||
formData.value.remark = orderDetail.remark
|
||||
// 设置入库明细
|
||||
if (orderDetail.items) {
|
||||
formData.value.items = orderDetail.items
|
||||
.filter(item => (item.count || 0) - (item.inCount || 0) > 0)
|
||||
.map(item => ({
|
||||
productId: item.productId,
|
||||
productName: item.productName,
|
||||
productUnitId: item.productUnitId,
|
||||
productUnitName: item.productUnitName,
|
||||
productPrice: item.productPrice,
|
||||
productSpec: item.productSpec,
|
||||
productBarCode: item.productBarCode,
|
||||
count: (item.count || 0) - (item.inCount || 0),
|
||||
totalCount: item.count,
|
||||
inCount: item.inCount,
|
||||
taxPercent: item.taxPercent,
|
||||
warehouseId: defaultWarehouse.value?.id,
|
||||
warehouseName: defaultWarehouse.value?.name,
|
||||
stockCount: item.stockCount,
|
||||
orderItemId: item.id,
|
||||
remark: item.remark,
|
||||
}))
|
||||
}
|
||||
orderSelectVisible.value = false
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getPurchaseIn(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交表单 */
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
// 校验入库明细
|
||||
if (!formData.value.items || formData.value.items.length === 0) {
|
||||
toast.warning('请至少添加一项入库产品')
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < formData.value.items.length; i++) {
|
||||
const item = formData.value.items[i]
|
||||
if (!item.warehouseId) {
|
||||
toast.warning(`第 ${i + 1} 项产品请选择仓库`)
|
||||
return
|
||||
}
|
||||
if (!item.count || Number(item.count) <= 0) {
|
||||
toast.warning(`第 ${i + 1} 项产品数量不能为空`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
if (props.id) {
|
||||
await updatePurchaseIn(formData.value)
|
||||
toast.success('修改成功')
|
||||
} else {
|
||||
await createPurchaseIn(formData.value)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
await loadDropdownData()
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
447
src/pages-erp/purchase-in/index.vue
Normal file
447
src/pages-erp/purchase-in/index.vue
Normal file
@@ -0,0 +1,447 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采购入库"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<SearchForm @search="handleQuery" @reset="handleReset" />
|
||||
|
||||
<!-- 状态快速筛选 -->
|
||||
<view class="flex items-center overflow-hidden rounded-12rpx bg-white mx-24rpx mb-16rpx shadow-sm">
|
||||
<view
|
||||
v-for="tab in statusTabs"
|
||||
:key="tab.value"
|
||||
class="flex-1 py-20rpx text-center text-26rpx relative"
|
||||
:class="activeStatus === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
|
||||
@click="handleQuickFilter(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
<view
|
||||
v-if="activeStatus === tab.value"
|
||||
class="absolute bottom-0 left-1/4 w-1/2 h-4rpx rounded-2rpx bg-[#1890ff]"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 采购入库列表 -->
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
@click="handleCardClick(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<!-- 头部:单号 + 状态 -->
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ item.no }}
|
||||
</view>
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(item.status, item.isQualified)"
|
||||
>
|
||||
{{ getStatusText(item.status, item.isQualified) }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 供应商 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">供应商</text>
|
||||
<text>{{ item.supplierName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 产品 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text class="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<!-- 入库时间 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">入库时间</text>
|
||||
<text>{{ formatDate(item.inTime) }}</text>
|
||||
</view>
|
||||
<!-- 创建人 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">创建人</text>
|
||||
<text>{{ item.creatorName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 数量金额区域 -->
|
||||
<view class="flex items-center justify-around mt-12rpx pt-16rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">总数量</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#e6a23c] font-semibold">¥{{ item.totalPrice || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">应付</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#52c41a] font-semibold">¥{{ item.paymentPrice || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">已付</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view
|
||||
class="text-30rpx font-semibold"
|
||||
:class="(item.totalPrice || 0) - (item.paymentPrice || 0) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
|
||||
>
|
||||
¥{{ (item.totalPrice || 0) - (item.paymentPrice || 0) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">未付</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:query'])"
|
||||
size="small" plain @click="handleDetail(item)"
|
||||
>
|
||||
详情
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:update']) && item.status === 10"
|
||||
size="small" type="primary" plain @click="handleEdit(item)"
|
||||
>
|
||||
修改
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:update-status']) && item.status === 10"
|
||||
size="small" type="success" plain @click="handleAudit(item)"
|
||||
>
|
||||
审核
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:update-status']) && (item.status === 20 || item.status === 30)"
|
||||
size="small" type="warning" plain @click="handleReverseAudit(item.id!)"
|
||||
>
|
||||
反审核
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:delete']) && item.status === 10"
|
||||
size="small" type="error" plain @click="handleDelete(item.id!)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无采购入库数据" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="list.length > 0"
|
||||
:state="loadMoreState"
|
||||
@reload="loadMore"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 新增按钮 -->
|
||||
<wd-fab
|
||||
v-if="hasAccessByCodes(['erp:purchase-in:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
|
||||
<!-- 审核弹窗 -->
|
||||
<wd-popup v-model="auditVisible" position="bottom" closable @close="auditVisible = false">
|
||||
<view class="p-32rpx">
|
||||
<view class="text-32rpx text-[#333] font-semibold mb-32rpx text-center">
|
||||
采购入库审核
|
||||
</view>
|
||||
<view class="mb-24rpx">
|
||||
<view class="text-26rpx text-[#666] mb-12rpx">是否合格</view>
|
||||
<wd-switch v-model="auditForm.isQualified" @change="handleQualifiedChange" />
|
||||
</view>
|
||||
<view v-if="!auditForm.isQualified" class="mb-24rpx">
|
||||
<view class="text-26rpx text-[#666] mb-12rpx">返回方式</view>
|
||||
<wd-radio-group v-model="auditForm.returnType" shape="button">
|
||||
<wd-radio
|
||||
v-for="opt in RETURN_TYPE_OPTIONS"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</view>
|
||||
<view v-if="!auditForm.isQualified" class="mb-24rpx">
|
||||
<view class="text-26rpx text-[#666] mb-12rpx">返回备注</view>
|
||||
<wd-textarea
|
||||
v-model="auditForm.returnRemark"
|
||||
placeholder="请输入返回方式备注"
|
||||
:maxlength="200"
|
||||
/>
|
||||
</view>
|
||||
<view class="flex gap-24rpx mt-32rpx">
|
||||
<wd-button class="flex-1" plain @click="auditVisible = false">
|
||||
取消
|
||||
</wd-button>
|
||||
<wd-button class="flex-1" type="primary" :loading="auditLoading" @click="submitAudit">
|
||||
确定
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PurchaseIn } from '@/api/erp/purchase-in'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deletePurchaseIn, getPurchaseInPage, RETURN_TYPE_OPTIONS, updatePurchaseInStatus } from '@/api/erp/purchase-in'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import SearchForm from './components/search-form.vue'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<PurchaseIn[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const activeStatus = ref<number | undefined>(undefined)
|
||||
const queryParams = ref<Record<string, any>>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
const statusTabs = [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '未审核', value: 10 },
|
||||
{ label: '已审核', value: 20 },
|
||||
{ label: '不合格', value: 30 },
|
||||
]
|
||||
|
||||
// 审核相关
|
||||
const auditVisible = ref(false)
|
||||
const auditLoading = ref(false)
|
||||
const auditForm = reactive({
|
||||
id: undefined as number | undefined,
|
||||
isQualified: true,
|
||||
returnType: undefined as string | undefined,
|
||||
returnRemark: undefined as string | undefined,
|
||||
})
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(date?: string) {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number, isQualified?: boolean) {
|
||||
if (status === 10) return '未审核'
|
||||
if (status === 20) return isQualified ? '已审核' : '不合格'
|
||||
if (status === 30) return '不合格'
|
||||
return '未知'
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number, isQualified?: boolean) {
|
||||
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
if (status === 20) return isQualified ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff1f0] text-[#f5222d]'
|
||||
if (status === 30) return 'bg-[#fff1f0] text-[#f5222d]'
|
||||
return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
/** 查询采购入库列表 */
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params = { ...queryParams.value }
|
||||
const data = await getPurchaseInPage(params)
|
||||
list.value = [...list.value, ...data.list]
|
||||
total.value = data.total
|
||||
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
|
||||
loadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 状态快速筛选 */
|
||||
function handleQuickFilter(status?: number) {
|
||||
activeStatus.value = status
|
||||
queryParams.value.status = status
|
||||
queryParams.value.pageNo = 1
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
function handleQuery(data?: Record<string, any>) {
|
||||
queryParams.value = {
|
||||
...data,
|
||||
status: activeStatus.value,
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
function handleReset() {
|
||||
activeStatus.value = undefined
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
/** 加载更多 */
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') {
|
||||
return
|
||||
}
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 卡片点击 — 已审核打开详情,未审核打开编辑 */
|
||||
function handleCardClick(item: PurchaseIn) {
|
||||
if (item.status === 20 || item.status === 30) {
|
||||
handleDetail(item)
|
||||
} else if (item.status === 10) {
|
||||
handleEdit(item)
|
||||
}
|
||||
}
|
||||
|
||||
/** 新增采购入库 */
|
||||
function handleAdd() {
|
||||
uni.navigateTo({
|
||||
url: '/pages-erp/purchase-in/form/index',
|
||||
})
|
||||
}
|
||||
|
||||
/** 查看详情 */
|
||||
function handleDetail(item: PurchaseIn) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-in/detail/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(item: PurchaseIn) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-in/form/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 打开审核弹窗 */
|
||||
function handleAudit(item: PurchaseIn) {
|
||||
auditForm.id = item.id
|
||||
auditForm.isQualified = true
|
||||
auditForm.returnType = undefined
|
||||
auditForm.returnRemark = undefined
|
||||
auditVisible.value = true
|
||||
}
|
||||
|
||||
/** 合格状态变化 */
|
||||
function handleQualifiedChange(val: boolean) {
|
||||
if (val) {
|
||||
auditForm.returnType = undefined
|
||||
auditForm.returnRemark = undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交审核 */
|
||||
async function submitAudit() {
|
||||
if (!auditForm.id) return
|
||||
if (!auditForm.isQualified && !auditForm.returnType) {
|
||||
toast.warning('请选择返回方式')
|
||||
return
|
||||
}
|
||||
auditLoading.value = true
|
||||
try {
|
||||
await updatePurchaseInStatus({
|
||||
id: auditForm.id,
|
||||
isQualified: auditForm.isQualified,
|
||||
returnType: auditForm.returnType,
|
||||
returnRemark: auditForm.returnRemark,
|
||||
status: auditForm.isQualified ? 20 : 30,
|
||||
})
|
||||
toast.success('审核成功')
|
||||
auditVisible.value = false
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} finally {
|
||||
auditLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 反审核 */
|
||||
function handleReverseAudit(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定反审核该入库单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePurchaseInStatus({
|
||||
id,
|
||||
isQualified: false,
|
||||
status: 10,
|
||||
})
|
||||
toast.success('反审核成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
function handleDelete(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该采购入库单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deletePurchaseIn([id])
|
||||
toast.success('删除成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 触底加载更多 */
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
100
src/pages-erp/purchase-return/components/search-form.vue
Normal file
100
src/pages-erp/purchase-return/components/search-form.vue
Normal file
@@ -0,0 +1,100 @@
|
||||
<template>
|
||||
<!-- 搜索框入口 -->
|
||||
<view @click="visible = true">
|
||||
<wd-search :placeholder="placeholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<wd-popup v-model="visible" position="top" @close="visible = false">
|
||||
<view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
退货单编号
|
||||
</view>
|
||||
<wd-input
|
||||
v-model="formData.no"
|
||||
placeholder="请输入退货单编号"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">
|
||||
审核状态
|
||||
</view>
|
||||
<wd-radio-group v-model="formData.status" shape="button">
|
||||
<wd-radio :value="-1">
|
||||
全部
|
||||
</wd-radio>
|
||||
<wd-radio :value="10">
|
||||
待审核
|
||||
</wd-radio>
|
||||
<wd-radio :value="20">
|
||||
已审核
|
||||
</wd-radio>
|
||||
</wd-radio-group>
|
||||
</view>
|
||||
<view class="yd-search-form-actions">
|
||||
<wd-button class="flex-1" plain @click="handleReset">
|
||||
重置
|
||||
</wd-button>
|
||||
<wd-button class="flex-1" type="primary" @click="handleSearch">
|
||||
搜索
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { getNavbarHeight } from '@/utils'
|
||||
|
||||
const emit = defineEmits<{
|
||||
search: [data: Record<string, any>]
|
||||
reset: []
|
||||
}>()
|
||||
|
||||
const visible = ref(false)
|
||||
const formData = reactive({
|
||||
no: undefined as string | undefined,
|
||||
status: -1,
|
||||
})
|
||||
|
||||
const statusMap: Record<number, string> = {
|
||||
10: '待审核',
|
||||
20: '已审核',
|
||||
}
|
||||
|
||||
/** 搜索条件 placeholder 拼接 */
|
||||
const placeholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (formData.no) {
|
||||
conditions.push(`编号:${formData.no}`)
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
conditions.push(`状态:${statusMap[formData.status] || formData.status}`)
|
||||
}
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索采购退货单'
|
||||
})
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
visible.value = false
|
||||
const params: Record<string, any> = {}
|
||||
if (formData.no) {
|
||||
params.no = formData.no
|
||||
}
|
||||
if (formData.status !== -1) {
|
||||
params.status = formData.status
|
||||
}
|
||||
emit('search', params)
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
formData.no = undefined
|
||||
formData.status = -1
|
||||
visible.value = false
|
||||
emit('reset')
|
||||
}
|
||||
</script>
|
||||
309
src/pages-erp/purchase-return/detail/index.vue
Normal file
309
src/pages-erp/purchase-return/detail/index.vue
Normal file
@@ -0,0 +1,309 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采购退货详情"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 详情内容 -->
|
||||
<view v-if="formData">
|
||||
<!-- 基本信息 -->
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="退货单编号" :value="formData.no" />
|
||||
<wd-cell title="审核状态">
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(formData.status)"
|
||||
>
|
||||
{{ getStatusText(formData.status) }}
|
||||
</view>
|
||||
</wd-cell>
|
||||
<wd-cell title="供应商" :value="formData.supplierName || '-'" />
|
||||
<wd-cell title="退货时间" :value="formatDateTime(formData.returnTime)" />
|
||||
<wd-cell title="关联订单" :value="formData.orderNo || '-'" />
|
||||
<wd-cell title="创建人" :value="formData.creatorName || '-'" />
|
||||
<wd-cell title="创建时间" :value="formatDateTime(formData.createTime)" />
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 金额信息 -->
|
||||
<wd-cell-group title="金额信息" border>
|
||||
<wd-cell title="合计数量" :value="String(formData.totalCount || 0)" />
|
||||
<wd-cell title="合计产品价格" :value="`¥${formData.totalProductPrice || 0}`" />
|
||||
<wd-cell title="合计税额" :value="`¥${formData.totalTaxPrice || 0}`" />
|
||||
<wd-cell title="优惠率" :value="`${formData.discountPercent || 0}%`" />
|
||||
<wd-cell title="优惠金额" :value="`¥${formData.discountPrice || 0}`" />
|
||||
<wd-cell title="其他费用" :value="`¥${formData.otherPrice || 0}`" />
|
||||
<wd-cell title="应退金额">
|
||||
<text class="text-[#e6a23c] font-semibold">¥{{ formData.totalPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="已退金额">
|
||||
<text class="text-[#52c41a] font-semibold">¥{{ formData.refundPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="未退金额">
|
||||
<text
|
||||
class="font-semibold"
|
||||
:class="(formData.totalPrice || 0) - (formData.refundPrice || 0) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
|
||||
>
|
||||
¥{{ (formData.totalPrice || 0) - (formData.refundPrice || 0) }}
|
||||
</text>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
|
||||
<!-- 退货明细 -->
|
||||
<view class="mx-24rpx mt-24rpx">
|
||||
<view class="mb-16rpx text-32rpx text-[#333] font-semibold">
|
||||
退货明细({{ formData.items?.length || 0 }}项)
|
||||
</view>
|
||||
<view v-if="formData.items && formData.items.length > 0">
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="item.id || index"
|
||||
class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
>
|
||||
<!-- 产品头部 -->
|
||||
<view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-16rpx">
|
||||
<view class="flex items-center">
|
||||
<text class="text-28rpx text-[#333] font-semibold">{{ item.productName || '-' }}</text>
|
||||
<text v-if="item.productBarCode" class="ml-12rpx text-22rpx text-[#999]">{{ item.productBarCode }}</text>
|
||||
</view>
|
||||
<text v-if="item.warehouseName" class="text-24rpx text-[#1890ff]">{{ item.warehouseName }}</text>
|
||||
</view>
|
||||
<view class="p-24rpx">
|
||||
<!-- 产品规格 -->
|
||||
<view v-if="item.productSpec" class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<text class="mr-8rpx text-[#999]">规格:</text>
|
||||
<text>{{ item.productSpec }}</text>
|
||||
</view>
|
||||
<!-- 单价 / 数量 / 单位 -->
|
||||
<view class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">单价:</text>
|
||||
<text class="text-[#f5222d]">¥{{ item.productPrice || 0 }}</text>
|
||||
</view>
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">数量:</text>
|
||||
<text class="font-semibold">{{ item.count || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">单位:</text>
|
||||
<text>{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 税率 / 税额 -->
|
||||
<view v-if="item.taxPercent" class="mb-12rpx flex items-center text-26rpx text-[#666]">
|
||||
<view class="mr-24rpx flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">税率:</text>
|
||||
<text>{{ item.taxPercent }}%</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">税额:</text>
|
||||
<text>¥{{ item.taxPrice || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 金额 / 库存 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">金额:</text>
|
||||
<text class="text-[#e6a23c]">¥{{ item.totalPrice || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<text class="mr-8rpx text-[#999]">库存:</text>
|
||||
<text>{{ item.stockCount || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 备注 -->
|
||||
<view v-if="item.remark" class="text-24rpx text-[#999]">
|
||||
备注:{{ item.remark }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else class="py-60rpx text-center text-28rpx text-[#999]">
|
||||
暂无退货明细
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 备注 -->
|
||||
<wd-cell-group v-if="formData.remark" title="备注" border>
|
||||
<wd-cell :value="formData.remark" />
|
||||
</wd-cell-group>
|
||||
</view>
|
||||
|
||||
<!-- 底部操作按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<view class="yd-detail-footer-actions">
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:update']) && formData?.status === 10"
|
||||
class="flex-1" type="warning" @click="handleEdit"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:update-status']) && formData?.status === 10"
|
||||
class="flex-1" type="success" @click="handleAudit"
|
||||
>
|
||||
审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:update-status']) && formData?.status === 20"
|
||||
class="flex-1" type="warning" @click="handleReverseAudit"
|
||||
>
|
||||
反审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:delete'])"
|
||||
class="flex-1" type="error" :loading="deleting" @click="handleDelete"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PurchaseReturn } from '@/api/erp/purchase-return'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deletePurchaseReturn, getPurchaseReturn, updatePurchaseReturnStatus } from '@/api/erp/purchase-return'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import { formatDateTime } from '@/utils/date'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const formData = ref<PurchaseReturn>()
|
||||
const deleting = ref(false)
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number) {
|
||||
if (status === 10) return '待审核'
|
||||
if (status === 20) return '已审核'
|
||||
return '未知'
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number) {
|
||||
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/purchase-return/index')
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getPurchaseReturn(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 编辑操作 */
|
||||
function handleEdit() {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-return/form/index?id=${props.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 审批操作 */
|
||||
function handleAudit() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要审批该退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updatePurchaseReturnStatus(props.id, 20)
|
||||
toast.success('审批成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 反审批操作 */
|
||||
function handleReverseAudit() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要反审批该退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updatePurchaseReturnStatus(props.id, 10)
|
||||
toast.success('反审批成功')
|
||||
getDetail()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除操作 */
|
||||
function handleDelete() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该采购退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) {
|
||||
return
|
||||
}
|
||||
deleting.value = true
|
||||
try {
|
||||
await deletePurchaseReturn([props.id])
|
||||
toast.success('删除成功')
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
609
src/pages-erp/purchase-return/form/index.vue
Normal file
609
src/pages-erp/purchase-return/form/index.vue
Normal file
@@ -0,0 +1,609 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
:title="getTitle"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<wd-cell-group title="基本信息" border>
|
||||
<wd-cell title="退货单号" title-width="180rpx" center>
|
||||
<wd-input
|
||||
v-model="formData.no"
|
||||
placeholder="保存时自动生成"
|
||||
disabled
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="退货时间" title-width="180rpx" prop="returnTime" center>
|
||||
<wd-datetime-picker
|
||||
v-model="formData.returnTime"
|
||||
type="date"
|
||||
label=""
|
||||
placeholder="请选择退货时间"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="关联订单" title-width="180rpx" center is-link @click="openOrderSelect">
|
||||
<text v-if="formData.orderNo" class="text-[#1890ff]">{{ formData.orderNo }}</text>
|
||||
<text v-else class="text-[#999]">点击选择采购订单</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="供应商" title-width="180rpx" center>
|
||||
<text>{{ getSupplierName() || '-' }}</text>
|
||||
</wd-cell>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="费用信息" border>
|
||||
<wd-input
|
||||
v-model="formData.discountPercent"
|
||||
label="优惠率(%)"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入优惠率"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="退款优惠" title-width="180rpx" center>
|
||||
<text>¥{{ formData.discountPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.otherPrice"
|
||||
label="其他费用"
|
||||
label-width="180rpx"
|
||||
type="number"
|
||||
placeholder="请输入其他费用"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="优惠后金额" title-width="180rpx" center>
|
||||
<text>¥{{ formData.totalPrice || 0 }}</text>
|
||||
</wd-cell>
|
||||
<wd-cell title="结算账户" title-width="180rpx" prop="accountId" center>
|
||||
<wd-picker
|
||||
v-model="formData.accountId"
|
||||
:columns="accountColumns"
|
||||
label=""
|
||||
placeholder="请选择结算账户"
|
||||
@confirm="onAccountConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 退货明细 -->
|
||||
<view class="mx-24rpx mt-24rpx pb-180rpx">
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-32rpx text-[#333] font-semibold">
|
||||
退货明细({{ formData.items?.length || 0 }}项)
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
v-for="(item, index) in formData.items"
|
||||
:key="index"
|
||||
class="mb-16rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
>
|
||||
<view class="flex items-center justify-between bg-[#f8f8f8] px-24rpx py-12rpx">
|
||||
<text class="text-28rpx text-[#333] font-semibold">产品 #{{ index + 1 }} {{ item.productName || '' }}</text>
|
||||
<wd-button
|
||||
v-if="formData.items && formData.items.length > 1"
|
||||
size="small" type="error" plain @click="handleRemoveItem(index)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
<view class="p-24rpx">
|
||||
<!-- 仓库选择 -->
|
||||
<view class="mb-16rpx">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">仓库</text>
|
||||
<wd-picker
|
||||
v-model="item.warehouseId"
|
||||
:columns="warehouseColumns"
|
||||
placeholder="请选择仓库"
|
||||
@confirm="(e: any) => onWarehouseConfirm(e, index)"
|
||||
/>
|
||||
</view>
|
||||
<!-- 自动填充的产品信息(只读) -->
|
||||
<view v-if="item.productId" class="mb-16rpx rounded-8rpx bg-[#f9f9f9] p-16rpx">
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">产品名称</text>
|
||||
<text class="text-[#333]">{{ item.productName || '-' }}</text>
|
||||
</view>
|
||||
<view v-if="item.productSpec" class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">规格</text>
|
||||
<text class="text-[#333]">{{ item.productSpec }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">单位</text>
|
||||
<text class="text-[#333]">{{ item.productUnitName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">条码</text>
|
||||
<text class="text-[#333]">{{ item.productBarCode || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">库存</text>
|
||||
<text class="text-[#333]">{{ item.stockCount || 0 }}</text>
|
||||
</view>
|
||||
<view v-if="item.inCount != null" class="mb-8rpx flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">已入库</text>
|
||||
<text class="text-[#333]">{{ item.inCount }}</text>
|
||||
</view>
|
||||
<view v-if="item.returnCount != null" class="flex justify-between text-24rpx">
|
||||
<text class="text-[#999]">已退货</text>
|
||||
<text class="text-[#333]">{{ item.returnCount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mb-16rpx flex gap-16rpx">
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">数量</text>
|
||||
<wd-input
|
||||
v-model="item.count"
|
||||
type="number"
|
||||
placeholder="数量"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">单价(元)</text>
|
||||
<wd-input
|
||||
v-model="item.productPrice"
|
||||
type="number"
|
||||
placeholder="单价"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="mb-16rpx flex gap-16rpx">
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">税率(%)</text>
|
||||
<wd-input
|
||||
v-model="item.taxPercent"
|
||||
type="number"
|
||||
placeholder="税率"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-1">
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">金额</text>
|
||||
<text class="block pt-16rpx text-28rpx text-[#333]">{{ calcTotalPrice(item) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<text class="mb-8rpx block text-24rpx text-[#999]">备注</text>
|
||||
<wd-input
|
||||
v-model="item.remark"
|
||||
placeholder="请输入备注"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="!formData.items?.length" class="py-60rpx text-center text-28rpx text-[#999]">
|
||||
暂无产品,请先选择关联订单
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部保存按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
type="primary"
|
||||
block
|
||||
:loading="formLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
|
||||
<!-- 采购订单选择弹窗(可退货订单) -->
|
||||
<wd-popup v-model="orderSelectVisible" position="right" custom-style="width: 100%; height: 100%;">
|
||||
<view class="yd-page-container">
|
||||
<wd-navbar
|
||||
title="选择采购订单"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="orderSelectVisible = false"
|
||||
/>
|
||||
<wd-search
|
||||
v-model="orderQueryParams.no"
|
||||
placeholder="搜索订单单号"
|
||||
@search="getOrderList"
|
||||
@clear="getOrderList"
|
||||
/>
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in orderList"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
:class="{ 'border-2 border-[#1890ff]': selectedOrderId === item.id }"
|
||||
@click="handleSelectOrder(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<view class="mb-12rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.no }}</view>
|
||||
<wd-icon v-if="selectedOrderId === item.id" name="check" color="#1890ff" size="40rpx" />
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">供应商</text>
|
||||
<text>{{ item.supplierName || '-' }}</text>
|
||||
</view>
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text class="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<view class="flex items-center justify-around mt-12rpx pt-12rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">总数量</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#52c41a] font-semibold">{{ item.inCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">已入库</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-28rpx text-[#f5222d] font-semibold">{{ item.returnCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999]">已退货</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="orderList.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无可退货订单" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="orderList.length > 0"
|
||||
:state="orderLoadMoreState"
|
||||
@reload="loadMoreOrders"
|
||||
/>
|
||||
</view>
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button type="primary" block :disabled="!selectedOrderId" @click="confirmSelectOrder">
|
||||
确认选择
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||
import type { PurchaseReturn, PurchaseReturnItem } from '@/api/erp/purchase-return'
|
||||
import type { PurchaseOrder } from '@/api/erp/purchase-order'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { createPurchaseReturn, getPurchaseReturn, updatePurchaseReturn } from '@/api/erp/purchase-return'
|
||||
import { getPurchaseOrder, getPurchaseOrderPage } from '@/api/erp/purchase-order'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
/** 账户简单信息 */
|
||||
interface AccountSimple {
|
||||
id: number
|
||||
name: string
|
||||
defaultStatus?: boolean
|
||||
}
|
||||
|
||||
/** 仓库简单信息 */
|
||||
interface WarehouseSimple {
|
||||
id: number
|
||||
name: string
|
||||
defaultStatus?: boolean
|
||||
}
|
||||
|
||||
/** 供应商简单信息 */
|
||||
interface SupplierSimple {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const getTitle = computed(() => props.id ? '编辑采购退货' : '新增采购退货')
|
||||
const formLoading = ref(false)
|
||||
const formData = ref<PurchaseReturn>({
|
||||
id: undefined,
|
||||
no: undefined,
|
||||
supplierId: undefined,
|
||||
accountId: undefined,
|
||||
returnTime: undefined,
|
||||
orderId: undefined,
|
||||
orderNo: undefined,
|
||||
discountPercent: 0,
|
||||
discountPrice: 0,
|
||||
otherPrice: 0,
|
||||
totalPrice: 0,
|
||||
remark: '',
|
||||
items: [],
|
||||
})
|
||||
const formRules = {
|
||||
returnTime: [{ required: true, message: '退货时间不能为空' }],
|
||||
}
|
||||
const formRef = ref<FormInstance>()
|
||||
const supplierList = ref<SupplierSimple[]>([])
|
||||
const accountList = ref<AccountSimple[]>([])
|
||||
const warehouseList = ref<WarehouseSimple[]>([])
|
||||
const defaultWarehouse = ref<WarehouseSimple>()
|
||||
|
||||
// 采购订单选择相关(可退货订单)
|
||||
const orderSelectVisible = ref(false)
|
||||
const orderList = ref<PurchaseOrder[]>([])
|
||||
const orderLoadMoreState = ref<LoadMoreState>('loading')
|
||||
const orderQueryParams = ref({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
no: undefined as string | undefined,
|
||||
returnEnable: true, // 可退货订单
|
||||
})
|
||||
const orderTotal = ref(0)
|
||||
const selectedOrderId = ref<number>()
|
||||
|
||||
/** 账户下拉列 */
|
||||
const accountColumns = computed(() => [
|
||||
accountList.value.map(a => ({ value: a.id, label: a.name })),
|
||||
])
|
||||
|
||||
/** 仓库下拉列 */
|
||||
const warehouseColumns = computed(() => [
|
||||
warehouseList.value.map(w => ({ value: w.id, label: w.name })),
|
||||
])
|
||||
|
||||
/** 获取供应商名称 */
|
||||
function getSupplierName() {
|
||||
if (!formData.value.supplierId) return ''
|
||||
const supplier = supplierList.value.find(s => s.id === formData.value.supplierId)
|
||||
return supplier?.name || formData.value.supplierName || ''
|
||||
}
|
||||
|
||||
/** 账户选择回调 */
|
||||
function onAccountConfirm({ value }: any) {
|
||||
formData.value.accountId = value?.[0]
|
||||
}
|
||||
|
||||
/** 仓库选择回调 */
|
||||
function onWarehouseConfirm({ value }: any, index: number) {
|
||||
if (formData.value.items && formData.value.items[index]) {
|
||||
formData.value.items[index].warehouseId = value?.[0]
|
||||
const warehouse = warehouseList.value.find(w => w.id === value?.[0])
|
||||
if (warehouse) {
|
||||
formData.value.items[index].warehouseName = warehouse.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 计算行项金额 */
|
||||
function calcTotalPrice(item: PurchaseReturnItem) {
|
||||
if (item.productPrice && item.count) {
|
||||
const productTotal = Number(item.productPrice) * Number(item.count)
|
||||
const taxPrice = item.taxPercent ? productTotal * Number(item.taxPercent) / 100 : 0
|
||||
return `¥${(productTotal + taxPrice).toFixed(2)}`
|
||||
}
|
||||
return '-'
|
||||
}
|
||||
|
||||
/** 监听表单数据变化,计算总价 */
|
||||
watch(
|
||||
() => formData.value,
|
||||
(val) => {
|
||||
if (!val || !val.items) return
|
||||
// 计算每个明细的金额
|
||||
val.items.forEach((item) => {
|
||||
if (item.productPrice && item.count) {
|
||||
item.totalProductPrice = Number(item.productPrice) * Number(item.count)
|
||||
item.taxPrice = item.taxPercent ? item.totalProductPrice * Number(item.taxPercent) / 100 : 0
|
||||
item.totalPrice = item.totalProductPrice + (item.taxPrice || 0)
|
||||
}
|
||||
})
|
||||
// 计算总价
|
||||
const totalPrice = val.items.reduce((prev, curr) => prev + (curr.totalPrice || 0), 0)
|
||||
const discountPrice = val.discountPercent ? totalPrice * Number(val.discountPercent) / 100 : 0
|
||||
formData.value.discountPrice = Math.round(discountPrice * 100) / 100
|
||||
formData.value.totalPrice = Math.round((totalPrice - discountPrice + Number(val.otherPrice || 0)) * 100) / 100
|
||||
},
|
||||
{ deep: true },
|
||||
)
|
||||
|
||||
/** 加载下拉列表数据 */
|
||||
async function loadDropdownData() {
|
||||
try {
|
||||
const { http } = await import('@/http/http')
|
||||
const [suppliers, accounts, warehouses] = await Promise.all([
|
||||
http.get<SupplierSimple[]>('/erp/supplier/simple-list'),
|
||||
http.get<AccountSimple[]>('/erp/account/simple-list'),
|
||||
http.get<WarehouseSimple[]>('/erp/warehouse/simple-list'),
|
||||
])
|
||||
supplierList.value = suppliers || []
|
||||
accountList.value = accounts || []
|
||||
warehouseList.value = warehouses || []
|
||||
// 设置默认账户
|
||||
const defaultAccount = accountList.value.find(a => a.defaultStatus)
|
||||
if (defaultAccount && !formData.value.accountId) {
|
||||
formData.value.accountId = defaultAccount.id
|
||||
}
|
||||
// 设置默认仓库
|
||||
defaultWarehouse.value = warehouseList.value.find(w => w.defaultStatus)
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/purchase-return/index')
|
||||
}
|
||||
|
||||
/** 删除退货明细行 */
|
||||
function handleRemoveItem(index: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确定要删除第 ${index + 1} 项产品吗?`,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
formData.value.items?.splice(index, 1)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 打开订单选择弹窗 */
|
||||
function openOrderSelect() {
|
||||
orderSelectVisible.value = true
|
||||
orderQueryParams.value.pageNo = 1
|
||||
orderList.value = []
|
||||
selectedOrderId.value = formData.value.orderId
|
||||
getOrderList()
|
||||
}
|
||||
|
||||
/** 获取可退货订单列表 */
|
||||
async function getOrderList() {
|
||||
orderLoadMoreState.value = 'loading'
|
||||
try {
|
||||
const data = await getPurchaseOrderPage(orderQueryParams.value)
|
||||
if (orderQueryParams.value.pageNo === 1) {
|
||||
orderList.value = data.list
|
||||
} else {
|
||||
orderList.value = [...orderList.value, ...data.list]
|
||||
}
|
||||
orderTotal.value = data.total
|
||||
orderLoadMoreState.value = orderList.value.length >= orderTotal.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
orderLoadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载更多订单 */
|
||||
function loadMoreOrders() {
|
||||
if (orderLoadMoreState.value === 'finished') return
|
||||
orderQueryParams.value.pageNo++
|
||||
getOrderList()
|
||||
}
|
||||
|
||||
/** 选择订单 */
|
||||
function handleSelectOrder(item: PurchaseOrder) {
|
||||
selectedOrderId.value = item.id
|
||||
}
|
||||
|
||||
/** 确认选择订单 */
|
||||
async function confirmSelectOrder() {
|
||||
if (!selectedOrderId.value) return
|
||||
try {
|
||||
toast.loading('加载订单详情...')
|
||||
const orderDetail = await getPurchaseOrder(selectedOrderId.value)
|
||||
// 设置订单信息
|
||||
formData.value.orderId = orderDetail.id
|
||||
formData.value.orderNo = orderDetail.no
|
||||
formData.value.supplierId = orderDetail.supplierId
|
||||
formData.value.supplierName = orderDetail.supplierName
|
||||
formData.value.accountId = orderDetail.accountId
|
||||
formData.value.discountPercent = orderDetail.discountPercent
|
||||
formData.value.remark = orderDetail.remark
|
||||
// 设置退货明细(可退货数量 = 已入库 - 已退货)
|
||||
if (orderDetail.items) {
|
||||
formData.value.items = orderDetail.items
|
||||
.filter(item => ((item.inCount || 0) - (item.returnCount || 0)) > 0)
|
||||
.map(item => ({
|
||||
productId: item.productId,
|
||||
productName: item.productName,
|
||||
productUnitId: item.productUnitId,
|
||||
productUnitName: item.productUnitName,
|
||||
productPrice: item.productPrice,
|
||||
productSpec: item.productSpec,
|
||||
productBarCode: item.productBarCode,
|
||||
count: (item.inCount || 0) - (item.returnCount || 0),
|
||||
inCount: item.inCount,
|
||||
returnCount: item.returnCount,
|
||||
taxPercent: item.taxPercent,
|
||||
warehouseId: defaultWarehouse.value?.id,
|
||||
warehouseName: defaultWarehouse.value?.name,
|
||||
stockCount: item.stockCount,
|
||||
orderItemId: item.id,
|
||||
remark: item.remark,
|
||||
}))
|
||||
}
|
||||
orderSelectVisible.value = false
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getPurchaseReturn(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交表单 */
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
// 校验退货明细
|
||||
if (!formData.value.items || formData.value.items.length === 0) {
|
||||
toast.warning('请至少添加一项退货产品')
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < formData.value.items.length; i++) {
|
||||
const item = formData.value.items[i]
|
||||
if (!item.warehouseId) {
|
||||
toast.warning(`第 ${i + 1} 项产品请选择仓库`)
|
||||
return
|
||||
}
|
||||
if (!item.count || Number(item.count) <= 0) {
|
||||
toast.warning(`第 ${i + 1} 项产品数量不能为空`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
if (props.id) {
|
||||
await updatePurchaseReturn(formData.value)
|
||||
toast.success('修改成功')
|
||||
} else {
|
||||
await createPurchaseReturn(formData.value)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(async () => {
|
||||
await loadDropdownData()
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
366
src/pages-erp/purchase-return/index.vue
Normal file
366
src/pages-erp/purchase-return/index.vue
Normal file
@@ -0,0 +1,366 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="采购退货"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<SearchForm @search="handleQuery" @reset="handleReset" />
|
||||
|
||||
<!-- 状态快速筛选 -->
|
||||
<view class="flex items-center overflow-hidden rounded-12rpx bg-white mx-24rpx mb-16rpx shadow-sm">
|
||||
<view
|
||||
v-for="tab in statusTabs"
|
||||
:key="tab.value"
|
||||
class="flex-1 py-20rpx text-center text-26rpx relative"
|
||||
:class="activeStatus === tab.value ? 'text-[#1890ff] font-semibold' : 'text-[#666]'"
|
||||
@click="handleQuickFilter(tab.value)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
<view
|
||||
v-if="activeStatus === tab.value"
|
||||
class="absolute bottom-0 left-1/4 w-1/2 h-4rpx rounded-2rpx bg-[#1890ff]"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 采购退货列表 -->
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
@click="handleCardClick(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<!-- 头部:单号 + 状态 -->
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ item.no }}
|
||||
</view>
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="getStatusClass(item.status)"
|
||||
>
|
||||
{{ getStatusText(item.status) }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 供应商 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">供应商</text>
|
||||
<text>{{ item.supplierName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 产品 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">产品</text>
|
||||
<text class="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.productNames || '-' }}</text>
|
||||
</view>
|
||||
<!-- 退货时间 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">退货时间</text>
|
||||
<text>{{ formatDate(item.returnTime) }}</text>
|
||||
</view>
|
||||
<!-- 创建人 -->
|
||||
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">创建人</text>
|
||||
<text>{{ item.creatorName || '-' }}</text>
|
||||
</view>
|
||||
<!-- 数量金额区域 -->
|
||||
<view class="flex items-center justify-around mt-12rpx pt-16rpx border-t border-[#f0f0f0]">
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#333] font-semibold">{{ item.totalCount || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">总数量</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#e6a23c] font-semibold">¥{{ item.totalPrice || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">应退</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view class="text-30rpx text-[#52c41a] font-semibold">¥{{ item.refundPrice || 0 }}</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">已退</view>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<view
|
||||
class="text-30rpx font-semibold"
|
||||
:class="(item.totalPrice || 0) - (item.refundPrice || 0) > 0 ? 'text-[#f5222d]' : 'text-[#999]'"
|
||||
>
|
||||
¥{{ (item.totalPrice || 0) - (item.refundPrice || 0) }}
|
||||
</view>
|
||||
<view class="text-22rpx text-[#999] mt-4rpx">未退</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:query'])"
|
||||
size="small" plain @click="handleDetail(item)"
|
||||
>
|
||||
详情
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:update']) && item.status === 10"
|
||||
size="small" type="primary" plain @click="handleEdit(item)"
|
||||
>
|
||||
修改
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:update-status']) && item.status === 10"
|
||||
size="small" type="success" plain @click="handleAudit(item.id!)"
|
||||
>
|
||||
审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:update-status']) && item.status === 20"
|
||||
size="small" type="warning" plain @click="handleReverseAudit(item.id!)"
|
||||
>
|
||||
反审批
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:delete'])"
|
||||
size="small" type="error" plain @click="handleDelete(item.id!)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无采购退货数据" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="list.length > 0"
|
||||
:state="loadMoreState"
|
||||
@reload="loadMore"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 新增按钮 -->
|
||||
<wd-fab
|
||||
v-if="hasAccessByCodes(['erp:purchase-return:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { PurchaseReturn } from '@/api/erp/purchase-return'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deletePurchaseReturn, getPurchaseReturnPage, updatePurchaseReturnStatus } from '@/api/erp/purchase-return'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import SearchForm from './components/search-form.vue'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<PurchaseReturn[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const activeStatus = ref<number | undefined>(undefined)
|
||||
const queryParams = ref<Record<string, any>>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
const statusTabs = [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '待审核', value: 10 },
|
||||
{ label: '已审核', value: 20 },
|
||||
]
|
||||
|
||||
/** 格式化日期 */
|
||||
function formatDate(date?: string) {
|
||||
if (!date) return '-'
|
||||
return new Date(date).toLocaleDateString('zh-CN')
|
||||
}
|
||||
|
||||
/** 获取状态文本 */
|
||||
function getStatusText(status?: number) {
|
||||
if (status === 10) return '待审核'
|
||||
if (status === 20) return '已审核'
|
||||
return '未知'
|
||||
}
|
||||
|
||||
/** 获取状态样式 */
|
||||
function getStatusClass(status?: number) {
|
||||
if (status === 10) return 'bg-[#fff7e6] text-[#fa8c16]'
|
||||
if (status === 20) return 'bg-[#f6ffed] text-[#52c41a]'
|
||||
return 'bg-[#f5f5f5] text-[#999]'
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
/** 查询采购退货列表 */
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params = { ...queryParams.value }
|
||||
const data = await getPurchaseReturnPage(params)
|
||||
list.value = [...list.value, ...data.list]
|
||||
total.value = data.total
|
||||
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
|
||||
loadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 状态快速筛选 */
|
||||
function handleQuickFilter(status?: number) {
|
||||
activeStatus.value = status
|
||||
queryParams.value.status = status
|
||||
queryParams.value.pageNo = 1
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
function handleQuery(data?: Record<string, any>) {
|
||||
queryParams.value = {
|
||||
...data,
|
||||
status: activeStatus.value,
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
function handleReset() {
|
||||
activeStatus.value = undefined
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
/** 加载更多 */
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') {
|
||||
return
|
||||
}
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 卡片点击 — 已审核打开详情,待审核打开编辑 */
|
||||
function handleCardClick(item: PurchaseReturn) {
|
||||
if (item.status === 20) {
|
||||
handleDetail(item)
|
||||
} else if (item.status === 10) {
|
||||
handleEdit(item)
|
||||
}
|
||||
}
|
||||
|
||||
/** 新增采购退货 */
|
||||
function handleAdd() {
|
||||
uni.navigateTo({
|
||||
url: '/pages-erp/purchase-return/form/index',
|
||||
})
|
||||
}
|
||||
|
||||
/** 查看详情 */
|
||||
function handleDetail(item: PurchaseReturn) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-return/detail/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(item: PurchaseReturn) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-erp/purchase-return/form/index?id=${item.id}`,
|
||||
})
|
||||
}
|
||||
|
||||
/** 审批 */
|
||||
function handleAudit(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定审批该退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePurchaseReturnStatus(id, 20)
|
||||
toast.success('审批成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 反审批 */
|
||||
function handleReverseAudit(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定反审批该退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await updatePurchaseReturnStatus(id, 10)
|
||||
toast.success('反审批成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
function handleDelete(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该采购退货单吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deletePurchaseReturn([id])
|
||||
toast.success('删除成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 触底加载更多 */
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
307
src/pages-erp/supplier/form/index.vue
Normal file
307
src/pages-erp/supplier/form/index.vue
Normal file
@@ -0,0 +1,307 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
:title="getTitle"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 表单区域 -->
|
||||
<view class="pb-180rpx">
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<wd-cell-group title="基础信息" border>
|
||||
<wd-input
|
||||
v-model="formData.name"
|
||||
label="名称"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入供应商名称"
|
||||
prop="name"
|
||||
clearable
|
||||
/>
|
||||
<wd-cell title="企业性质" title-width="180rpx" center>
|
||||
<wd-picker
|
||||
v-model="formData.enterpriseNature"
|
||||
:columns="enterpriseNatureColumns"
|
||||
label=""
|
||||
placeholder="请选择企业性质"
|
||||
@confirm="onEnterpriseNatureConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-cell title="供应商类型" title-width="180rpx" center>
|
||||
<wd-picker
|
||||
v-model="formData.type"
|
||||
:columns="supplierTypeColumns"
|
||||
label=""
|
||||
placeholder="请选择供应商类型"
|
||||
@confirm="onSupplierTypeConfirm"
|
||||
/>
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.registeredCapital"
|
||||
label="注册资金"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入注册资金"
|
||||
type="number"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.validPeriod"
|
||||
label="营业期限"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入使用/营业期限"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.zipCode"
|
||||
label="邮编"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入邮编"
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="联系信息" border>
|
||||
<wd-input
|
||||
v-model="formData.contact"
|
||||
label="联系人"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入联系人"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.mobile"
|
||||
label="手机号码"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入手机号码"
|
||||
type="number"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.telephone"
|
||||
label="联系电话"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入联系电话"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.email"
|
||||
label="电子邮箱"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入电子邮箱"
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="财务信息" border>
|
||||
<wd-input
|
||||
v-model="formData.taxNo"
|
||||
label="纳税人识别号"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入纳税人识别号"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.taxPercent"
|
||||
label="税率(%)"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入税率"
|
||||
type="number"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.bankName"
|
||||
label="开户行"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入开户行"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.bankAccount"
|
||||
label="开户账号"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入开户账号"
|
||||
clearable
|
||||
/>
|
||||
<wd-input
|
||||
v-model="formData.bankAddress"
|
||||
label="开户地址"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入开户地址"
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
|
||||
<wd-cell-group title="其他信息" border>
|
||||
<wd-cell title="开启状态" title-width="180rpx" center>
|
||||
<wd-switch v-model="statusEnabled" />
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-model="formData.sort"
|
||||
label="排序"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入排序"
|
||||
type="number"
|
||||
clearable
|
||||
/>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
label-width="180rpx"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 底部保存按钮 -->
|
||||
<view class="yd-detail-footer">
|
||||
<wd-button
|
||||
type="primary"
|
||||
block
|
||||
:loading="formLoading"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
保存
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||
import type { Supplier } from '@/api/erp/supplier'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { createSupplier, getSupplier, updateSupplier } from '@/api/erp/supplier'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
|
||||
const props = defineProps<{
|
||||
id?: number | any
|
||||
}>()
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const getTitle = computed(() => props.id ? '编辑供应商' : '新增供应商')
|
||||
const formLoading = ref(false)
|
||||
const formData = ref<Supplier & { enterpriseNature?: string, type?: number, registeredCapital?: number, validPeriod?: string, zipCode?: string }>({
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
contact: undefined,
|
||||
mobile: undefined,
|
||||
telephone: undefined,
|
||||
email: undefined,
|
||||
remark: undefined,
|
||||
status: 0,
|
||||
sort: 0,
|
||||
taxNo: undefined,
|
||||
taxPercent: undefined,
|
||||
bankName: undefined,
|
||||
bankAccount: undefined,
|
||||
bankAddress: undefined,
|
||||
enterpriseNature: undefined,
|
||||
type: undefined,
|
||||
registeredCapital: undefined,
|
||||
validPeriod: undefined,
|
||||
zipCode: undefined,
|
||||
})
|
||||
const formRules = {
|
||||
name: [{ required: true, message: '供应商名称不能为空' }],
|
||||
}
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
// 状态开关
|
||||
const statusEnabled = ref(true)
|
||||
watch(statusEnabled, (val) => {
|
||||
formData.value.status = val ? 0 : 1
|
||||
})
|
||||
watch(() => formData.value.status, (val) => {
|
||||
statusEnabled.value = val === 0
|
||||
})
|
||||
|
||||
/** 企业性质选项 */
|
||||
const enterpriseNatureOptions = [
|
||||
{ value: '国有企业', label: '国有企业' },
|
||||
{ value: '集体企业', label: '集体企业' },
|
||||
{ value: '私营企业', label: '私营企业' },
|
||||
{ value: '股份制企业', label: '股份制企业' },
|
||||
{ value: '外资企业', label: '外资企业' },
|
||||
{ value: '合资企业', label: '合资企业' },
|
||||
{ value: '其他', label: '其他' },
|
||||
]
|
||||
const enterpriseNatureColumns = computed(() => [
|
||||
enterpriseNatureOptions.map(v => ({ value: v.value, label: v.label })),
|
||||
])
|
||||
function onEnterpriseNatureConfirm({ value }: any) {
|
||||
formData.value.enterpriseNature = value?.[0]
|
||||
}
|
||||
|
||||
/** 供应商类型选项 */
|
||||
const supplierTypeOptions = [
|
||||
{ value: 1, label: '生产型' },
|
||||
{ value: 2, label: '贸易型' },
|
||||
{ value: 3, label: '服务型' },
|
||||
{ value: 4, label: '其他' },
|
||||
]
|
||||
const supplierTypeColumns = computed(() => [
|
||||
supplierTypeOptions.map(v => ({ value: v.value, label: v.label })),
|
||||
])
|
||||
function onSupplierTypeConfirm({ value }: any) {
|
||||
formData.value.type = value?.[0]
|
||||
}
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus('/pages-erp/supplier/index')
|
||||
}
|
||||
|
||||
/** 加载详情 */
|
||||
async function getDetail() {
|
||||
if (!props.id) return
|
||||
try {
|
||||
toast.loading('加载中...')
|
||||
formData.value = await getSupplier(props.id)
|
||||
} finally {
|
||||
toast.close()
|
||||
}
|
||||
}
|
||||
|
||||
/** 提交表单 */
|
||||
async function handleSubmit() {
|
||||
const { valid } = await formRef.value!.validate()
|
||||
if (!valid) return
|
||||
|
||||
formLoading.value = true
|
||||
try {
|
||||
if (props.id) {
|
||||
await updateSupplier(formData.value)
|
||||
toast.success('修改成功')
|
||||
} else {
|
||||
await createSupplier(formData.value)
|
||||
toast.success('新增成功')
|
||||
}
|
||||
setTimeout(() => {
|
||||
handleBack()
|
||||
}, 500)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
260
src/pages-erp/supplier/index.vue
Normal file
260
src/pages-erp/supplier/index.vue
Normal file
@@ -0,0 +1,260 @@
|
||||
<template>
|
||||
<view class="yd-page-container">
|
||||
<!-- 顶部导航栏 -->
|
||||
<wd-navbar
|
||||
title="供应商管理"
|
||||
left-arrow placeholder safe-area-inset-top fixed
|
||||
@click-left="handleBack"
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<view @click="searchVisible = true">
|
||||
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
|
||||
</view>
|
||||
|
||||
<!-- 供应商列表 -->
|
||||
<view class="px-24rpx">
|
||||
<view
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
class="mb-20rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
@click="handleEdit(item)"
|
||||
>
|
||||
<view class="p-24rpx">
|
||||
<!-- 头部:名称 + 状态 -->
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-30rpx text-[#333] font-semibold">
|
||||
{{ item.name || '-' }}
|
||||
</view>
|
||||
<view
|
||||
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||
:class="item.status === 0 ? 'bg-[#f6ffed] text-[#52c41a]' : 'bg-[#fff1f0] text-[#f5222d]'"
|
||||
>
|
||||
{{ item.status === 0 ? '正常' : '停用' }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 联系人 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">联系人</text>
|
||||
<text>{{ item.contact || '-' }}</text>
|
||||
</view>
|
||||
<!-- 手机号码 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">手机号码</text>
|
||||
<text>{{ item.mobile || '-' }}</text>
|
||||
</view>
|
||||
<!-- 联系电话 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">联系电话</text>
|
||||
<text>{{ item.telephone || '-' }}</text>
|
||||
</view>
|
||||
<!-- 电子邮箱 -->
|
||||
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">电子邮箱</text>
|
||||
<text>{{ item.email || '-' }}</text>
|
||||
</view>
|
||||
<!-- 备注 -->
|
||||
<view class="flex items-center justify-between text-26rpx text-[#666]">
|
||||
<text class="text-[#999]">备注</text>
|
||||
<text class="ml-16rpx line-clamp-1 text-right" style="max-width: 400rpx;">{{ item.remark || '无备注' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:supplier:update']) && item.name !== '-'"
|
||||
size="small" type="primary" plain @click="handleEdit(item)"
|
||||
>
|
||||
编辑
|
||||
</wd-button>
|
||||
<wd-button
|
||||
v-if="hasAccessByCodes(['erp:supplier:delete']) && item.name !== '-'"
|
||||
size="small" type="error" plain @click="handleDelete(item.id!)"
|
||||
>
|
||||
删除
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
|
||||
<wd-status-tip image="content" tip="暂无供应商数据" />
|
||||
</view>
|
||||
<wd-loadmore
|
||||
v-if="list.length > 0"
|
||||
:state="loadMoreState"
|
||||
@reload="loadMore"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 新增按钮 -->
|
||||
<wd-fab
|
||||
v-if="hasAccessByCodes(['erp:supplier:create'])"
|
||||
position="right-bottom"
|
||||
type="primary"
|
||||
:expandable="false"
|
||||
@click="handleAdd"
|
||||
/>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<wd-popup v-model="searchVisible" position="top" @close="searchVisible = false">
|
||||
<view class="yd-search-form-container" :style="{ paddingTop: `${getNavbarHeight()}px` }">
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">供应商名称</view>
|
||||
<wd-input v-model="searchForm.name" placeholder="请输入供应商名称" clearable />
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">手机号码</view>
|
||||
<wd-input v-model="searchForm.mobile" placeholder="请输入手机号码" clearable />
|
||||
</view>
|
||||
<view class="yd-search-form-item">
|
||||
<view class="yd-search-form-label">联系电话</view>
|
||||
<wd-input v-model="searchForm.telephone" placeholder="请输入联系电话" clearable />
|
||||
</view>
|
||||
<view class="yd-search-form-actions">
|
||||
<wd-button class="flex-1" plain @click="handleReset">重置</wd-button>
|
||||
<wd-button class="flex-1" type="primary" @click="handleSearch">搜索</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { Supplier } from '@/api/erp/supplier'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { deleteSupplier, getSupplierPage } from '@/api/erp/supplier'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { getNavbarHeight, navigateBackPlus } from '@/utils'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '',
|
||||
navigationStyle: 'custom',
|
||||
},
|
||||
})
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const total = ref(0)
|
||||
const list = ref<Supplier[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const queryParams = ref<Record<string, any>>({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
})
|
||||
|
||||
// 搜索相关
|
||||
const searchVisible = ref(false)
|
||||
const searchForm = reactive({
|
||||
name: undefined as string | undefined,
|
||||
mobile: undefined as string | undefined,
|
||||
telephone: undefined as string | undefined,
|
||||
})
|
||||
|
||||
/** 搜索条件 placeholder */
|
||||
const searchPlaceholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
if (searchForm.name) conditions.push(`名称:${searchForm.name}`)
|
||||
if (searchForm.mobile) conditions.push(`手机:${searchForm.mobile}`)
|
||||
if (searchForm.telephone) conditions.push(`电话:${searchForm.telephone}`)
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索供应商'
|
||||
})
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
navigateBackPlus()
|
||||
}
|
||||
|
||||
/** 查询供应商列表 */
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params = { ...queryParams.value }
|
||||
const data = await getSupplierPage(params)
|
||||
list.value = [...list.value, ...data.list]
|
||||
total.value = data.total
|
||||
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
|
||||
loadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
searchVisible.value = false
|
||||
queryParams.value = {
|
||||
...searchForm,
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
searchForm.name = undefined
|
||||
searchForm.mobile = undefined
|
||||
searchForm.telephone = undefined
|
||||
searchVisible.value = false
|
||||
queryParams.value = { pageNo: 1, pageSize: 10 }
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 加载更多 */
|
||||
function loadMore() {
|
||||
if (loadMoreState.value === 'finished') return
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 新增供应商 */
|
||||
function handleAdd() {
|
||||
uni.navigateTo({ url: '/pages-erp/supplier/form/index' })
|
||||
}
|
||||
|
||||
/** 编辑 */
|
||||
function handleEdit(item: Supplier) {
|
||||
if (item.name === '-') return
|
||||
uni.navigateTo({ url: `/pages-erp/supplier/form/index?id=${item.id}` })
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
function handleDelete(id: number) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该供应商吗?',
|
||||
success: async (res) => {
|
||||
if (!res.confirm) return
|
||||
try {
|
||||
await deleteSupplier(id)
|
||||
toast.success('删除成功')
|
||||
list.value = []
|
||||
queryParams.value.pageNo = 1
|
||||
getList()
|
||||
} catch {
|
||||
// error handled by http
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 触底加载更多 */
|
||||
onReachBottom(() => {
|
||||
loadMore()
|
||||
})
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
</style>
|
||||
Reference in New Issue
Block a user