李红攀:V2.6.969,销售计划管理
This commit is contained in:
81
src/api/erp/sale-plan/index.ts
Normal file
81
src/api/erp/sale-plan/index.ts
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import type { PageParam, PageResult } from '@/http/types'
|
||||||
|
import { http } from '@/http/http'
|
||||||
|
|
||||||
|
/** 销售计划明细 */
|
||||||
|
export interface SalePlanItem {
|
||||||
|
id?: number
|
||||||
|
planId?: number
|
||||||
|
productId?: number
|
||||||
|
productName?: string
|
||||||
|
productUnitName?: string
|
||||||
|
planCount?: number
|
||||||
|
productPrice?: number
|
||||||
|
totalPrice?: number
|
||||||
|
completedAmount?: number
|
||||||
|
progress?: number
|
||||||
|
remark?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 销售计划 */
|
||||||
|
export interface SalePlan {
|
||||||
|
id?: number
|
||||||
|
no?: string
|
||||||
|
name?: string
|
||||||
|
customerId?: number
|
||||||
|
customerName?: string
|
||||||
|
targetAmount?: number
|
||||||
|
startTime?: number | string
|
||||||
|
endTime?: number | string
|
||||||
|
status?: number
|
||||||
|
approverId?: number
|
||||||
|
approverName?: string
|
||||||
|
remark?: string
|
||||||
|
items?: SalePlanItem[]
|
||||||
|
completedAmount?: number
|
||||||
|
progress?: number
|
||||||
|
completionStatus?: number
|
||||||
|
creatorName?: string
|
||||||
|
createTime?: number | string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取销售计划分页 */
|
||||||
|
export function getSalePlanPage(params: PageParam & {
|
||||||
|
no?: string
|
||||||
|
name?: string
|
||||||
|
customerId?: number
|
||||||
|
status?: number
|
||||||
|
creator?: number
|
||||||
|
planTime?: string[]
|
||||||
|
}) {
|
||||||
|
return http.get<PageResult<SalePlan>>('/erp/sale-plan/page', params)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取销售计划详情 */
|
||||||
|
export function getSalePlan(id: number) {
|
||||||
|
return http.get<SalePlan>(`/erp/sale-plan/get?id=${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 创建销售计划 */
|
||||||
|
export function createSalePlan(data: SalePlan) {
|
||||||
|
return http.post<number>('/erp/sale-plan/create', data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新销售计划 */
|
||||||
|
export function updateSalePlan(data: SalePlan) {
|
||||||
|
return http.put<boolean>('/erp/sale-plan/update', data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新销售计划状态 */
|
||||||
|
export function updateSalePlanStatus(id: number, status: number) {
|
||||||
|
return http.put<boolean>('/erp/sale-plan/update-status', undefined, { id, status })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除销售计划 */
|
||||||
|
export function deleteSalePlan(ids: number[]) {
|
||||||
|
return http.delete<boolean>('/erp/sale-plan/delete', undefined, { ids: ids.join(',') })
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获取销售计划简列表 */
|
||||||
|
export function getSalePlanSimpleList() {
|
||||||
|
return http.get<SalePlan[]>('/erp/sale-plan/simple-list')
|
||||||
|
}
|
||||||
293
src/pages-erp/sale-plan/detail/index.vue
Normal file
293
src/pages-erp/sale-plan/detail/index.vue
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
<template>
|
||||||
|
<view class="yd-page-container">
|
||||||
|
<wd-navbar
|
||||||
|
title="销售计划详情"
|
||||||
|
left-arrow
|
||||||
|
placeholder
|
||||||
|
safe-area-inset-top
|
||||||
|
fixed
|
||||||
|
@click-left="handleBack"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<view v-if="detail" class="pb-180rpx">
|
||||||
|
<wd-cell-group title="基本信息" border>
|
||||||
|
<wd-cell title="计划编号" :value="detail.no || '-'" />
|
||||||
|
<wd-cell title="审核状态">
|
||||||
|
<view
|
||||||
|
class="rounded-8rpx px-16rpx py-4rpx text-24rpx"
|
||||||
|
:class="getStatusClass(detail.status)"
|
||||||
|
>
|
||||||
|
{{ getStatusText(detail.status) }}
|
||||||
|
</view>
|
||||||
|
</wd-cell>
|
||||||
|
<wd-cell title="计划名称" :value="detail.name || '-'" />
|
||||||
|
<wd-cell title="计划周期" :value="`${formatPlanDate(detail.startTime)} ~ ${formatPlanDate(detail.endTime)}`" />
|
||||||
|
<wd-cell title="审批人" :value="detail.approverName || '-'" />
|
||||||
|
<wd-cell title="创建人" :value="detail.creatorName || '-'" />
|
||||||
|
<wd-cell title="创建时间" :value="formatDateTime(detail.createTime) || '-'" />
|
||||||
|
</wd-cell-group>
|
||||||
|
|
||||||
|
<wd-cell-group title="金额信息" border>
|
||||||
|
<wd-cell title="目标金额" :value="`¥${formatPrice(detail.targetAmount)}`" />
|
||||||
|
<wd-cell title="已完成金额" :value="`¥${formatPrice(detail.completedAmount)}`" />
|
||||||
|
<wd-cell title="完成状态">
|
||||||
|
<text :class="getCompletionStatusClass(detail.completionStatus)">
|
||||||
|
{{ getCompletionStatusText(detail.completionStatus) }}
|
||||||
|
</text>
|
||||||
|
</wd-cell>
|
||||||
|
<view class="px-24rpx py-20rpx">
|
||||||
|
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">整体进度</text>
|
||||||
|
<text>{{ normalizeProgress(detail.progress) }}%</text>
|
||||||
|
</view>
|
||||||
|
<view class="progress-track">
|
||||||
|
<view
|
||||||
|
class="progress-fill"
|
||||||
|
:class="normalizeProgress(detail.progress) >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
|
||||||
|
:style="{ width: `${normalizeProgress(detail.progress)}%` }"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</wd-cell-group>
|
||||||
|
|
||||||
|
<view class="mx-24rpx mt-24rpx">
|
||||||
|
<view class="mb-16rpx text-32rpx font-semibold text-[#333]">
|
||||||
|
计划明细({{ detail.items?.length || 0 }}项)
|
||||||
|
</view>
|
||||||
|
<view v-if="detail.items && detail.items.length > 0">
|
||||||
|
<view
|
||||||
|
v-for="(item, index) in detail.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">
|
||||||
|
<text class="text-28rpx font-semibold text-[#333]">{{ item.productName || '-' }}</text>
|
||||||
|
<text class="text-24rpx text-[#1890ff]">{{ item.productUnitName || '-' }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="p-24rpx">
|
||||||
|
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">计划数量</text>
|
||||||
|
<text>{{ formatNumber(item.planCount) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">销售单价</text>
|
||||||
|
<text>¥{{ formatPrice(item.productPrice) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">计划金额</text>
|
||||||
|
<text class="font-semibold text-[#1890ff]">¥{{ formatPrice(item.totalPrice) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">已完成金额</text>
|
||||||
|
<text>¥{{ formatPrice(item.completedAmount) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">进度</text>
|
||||||
|
<text>{{ normalizeProgress(item.progress) }}%</text>
|
||||||
|
</view>
|
||||||
|
<view class="progress-track">
|
||||||
|
<view
|
||||||
|
class="progress-fill"
|
||||||
|
:class="normalizeProgress(item.progress) >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
|
||||||
|
:style="{ width: `${normalizeProgress(item.progress)}%` }"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view v-if="item.remark" class="mt-16rpx 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="detail.remark" title="备注" border>
|
||||||
|
<wd-cell :value="detail.remark" />
|
||||||
|
</wd-cell-group>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="yd-detail-footer">
|
||||||
|
<view class="yd-detail-footer-actions">
|
||||||
|
<wd-button
|
||||||
|
v-if="hasAccessByCodes(['erp:sale-plan:update']) && detail?.status === 10"
|
||||||
|
class="flex-1"
|
||||||
|
type="warning"
|
||||||
|
@click="handleEdit"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</wd-button>
|
||||||
|
<wd-button
|
||||||
|
v-if="hasAccessByCodes(['erp:sale-plan:update-status']) && detail?.status === 10"
|
||||||
|
class="flex-1"
|
||||||
|
type="success"
|
||||||
|
@click="handleAudit"
|
||||||
|
>
|
||||||
|
审核
|
||||||
|
</wd-button>
|
||||||
|
<wd-button
|
||||||
|
v-if="hasAccessByCodes(['erp:sale-plan:delete'])"
|
||||||
|
class="flex-1"
|
||||||
|
type="error"
|
||||||
|
:loading="deleting"
|
||||||
|
@click="handleDelete"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</wd-button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { SalePlan } from '@/api/erp/sale-plan'
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import { useToast } from 'wot-design-uni'
|
||||||
|
import { deleteSalePlan, getSalePlan, updateSalePlanStatus } from '@/api/erp/sale-plan'
|
||||||
|
import { useAccess } from '@/hooks/useAccess'
|
||||||
|
import { formatDate, formatDateTime } from '@/utils/date'
|
||||||
|
import { navigateBackPlus } from '@/utils'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
id?: number | any
|
||||||
|
}>()
|
||||||
|
|
||||||
|
definePage({
|
||||||
|
style: {
|
||||||
|
navigationBarTitleText: '',
|
||||||
|
navigationStyle: 'custom',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { hasAccessByCodes } = useAccess()
|
||||||
|
const toast = useToast()
|
||||||
|
const detail = ref<SalePlan>()
|
||||||
|
const deleting = ref(false)
|
||||||
|
|
||||||
|
function formatPlanDate(value?: string | number) {
|
||||||
|
return value ? formatDate(value, 'YYYY-MM-DD') : '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatPrice(value?: number) {
|
||||||
|
if (value === undefined || value === null) return '0.00'
|
||||||
|
return Number(value).toFixed(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatNumber(value?: number) {
|
||||||
|
if (value === undefined || value === null) return '0'
|
||||||
|
return String(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeProgress(value?: number) {
|
||||||
|
const progress = Number(value || 0)
|
||||||
|
if (Number.isNaN(progress) || progress < 0) return 0
|
||||||
|
if (progress > 100) return 100
|
||||||
|
return Math.round(progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 getCompletionStatusText(status?: number) {
|
||||||
|
if (status === 0) return '未开始'
|
||||||
|
if (status === 1) return '进行中'
|
||||||
|
if (status === 2) return '已完成'
|
||||||
|
if (status === 3) return '已超期'
|
||||||
|
return '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCompletionStatusClass(status?: number) {
|
||||||
|
if (status === 0) return 'text-[#999]'
|
||||||
|
if (status === 1) return 'text-[#1890ff]'
|
||||||
|
if (status === 2) return 'text-[#52c41a]'
|
||||||
|
if (status === 3) return 'text-[#f5222d]'
|
||||||
|
return 'text-[#999]'
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBack() {
|
||||||
|
navigateBackPlus('/pages-erp/sale-plan/index')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDetail() {
|
||||||
|
if (!props.id) return
|
||||||
|
try {
|
||||||
|
toast.loading('加载中...')
|
||||||
|
detail.value = await getSalePlan(props.id)
|
||||||
|
} finally {
|
||||||
|
toast.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEdit() {
|
||||||
|
uni.navigateTo({ url: `/pages-erp/sale-plan/form/index?id=${props.id}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleAudit() {
|
||||||
|
if (!props.id) return
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定审核该销售计划吗?',
|
||||||
|
success: async (res) => {
|
||||||
|
if (!res.confirm) return
|
||||||
|
try {
|
||||||
|
await updateSalePlanStatus(props.id, 20)
|
||||||
|
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 deleteSalePlan([props.id])
|
||||||
|
toast.success('删除成功')
|
||||||
|
setTimeout(() => {
|
||||||
|
handleBack()
|
||||||
|
}, 500)
|
||||||
|
} finally {
|
||||||
|
deleting.value = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getDetail()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.progress-track {
|
||||||
|
width: 100%;
|
||||||
|
height: 12rpx;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
background: #f0f0f0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-fill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
512
src/pages-erp/sale-plan/form/index.vue
Normal file
512
src/pages-erp/sale-plan/form/index.vue
Normal file
@@ -0,0 +1,512 @@
|
|||||||
|
<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-cell title="计划编号" title-width="180rpx" center>
|
||||||
|
<wd-input
|
||||||
|
v-model="formData.no"
|
||||||
|
placeholder="保存后自动生成"
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
</wd-cell>
|
||||||
|
<wd-input
|
||||||
|
v-model="formData.name"
|
||||||
|
label="计划名称"
|
||||||
|
label-width="180rpx"
|
||||||
|
prop="name"
|
||||||
|
placeholder="请输入计划名称"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
<wd-datetime-picker
|
||||||
|
v-model="formData.startTime"
|
||||||
|
type="date"
|
||||||
|
label="开始时间"
|
||||||
|
label-width="180rpx"
|
||||||
|
prop="startTime"
|
||||||
|
placeholder="请选择开始时间"
|
||||||
|
/>
|
||||||
|
<wd-datetime-picker
|
||||||
|
v-model="formData.endTime"
|
||||||
|
type="date"
|
||||||
|
label="结束时间"
|
||||||
|
label-width="180rpx"
|
||||||
|
prop="endTime"
|
||||||
|
placeholder="请选择结束时间"
|
||||||
|
/>
|
||||||
|
<wd-cell title="审批人" title-width="180rpx" center>
|
||||||
|
<wd-picker
|
||||||
|
v-model="formData.approverId"
|
||||||
|
:columns="userColumns"
|
||||||
|
label=""
|
||||||
|
placeholder="请选择审批人"
|
||||||
|
@confirm="onApproverConfirm"
|
||||||
|
/>
|
||||||
|
</wd-cell>
|
||||||
|
</wd-cell-group>
|
||||||
|
|
||||||
|
<wd-cell-group title="计划产品" border>
|
||||||
|
<view class="p-24rpx">
|
||||||
|
<view
|
||||||
|
v-for="(item, index) in formData.items"
|
||||||
|
:key="index"
|
||||||
|
class="mb-16rpx rounded-12rpx bg-[#fafafa] p-24rpx"
|
||||||
|
>
|
||||||
|
<view class="mb-16rpx flex items-center justify-between">
|
||||||
|
<text class="text-28rpx font-semibold text-[#333]">
|
||||||
|
{{ item.productName || `产品${index + 1}` }}
|
||||||
|
</text>
|
||||||
|
<wd-button size="small" type="error" plain @click="removeItem(index)">
|
||||||
|
删除
|
||||||
|
</wd-button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="mb-12rpx flex items-center justify-between text-24rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">单位</text>
|
||||||
|
<text>{{ item.productUnitName || '-' }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="mb-12rpx flex items-center">
|
||||||
|
<text class="w-140rpx text-24rpx text-[#999]">计划数量</text>
|
||||||
|
<wd-input
|
||||||
|
v-model="item.planCount"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入数量"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="mb-12rpx flex items-center">
|
||||||
|
<text class="w-140rpx text-24rpx text-[#999]">销售单价</text>
|
||||||
|
<wd-input
|
||||||
|
v-model="item.productPrice"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入单价"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="mb-12rpx flex items-center justify-between text-24rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">计划金额</text>
|
||||||
|
<text class="text-28rpx font-semibold text-[#1890ff]">¥{{ formatPrice(item.totalPrice) }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view
|
||||||
|
v-if="item.completedAmount !== undefined || item.progress !== undefined"
|
||||||
|
class="mb-12rpx rounded-8rpx bg-white p-16rpx"
|
||||||
|
>
|
||||||
|
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">已完成金额</text>
|
||||||
|
<text>¥{{ formatPrice(item.completedAmount) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">进度</text>
|
||||||
|
<text>{{ normalizeProgress(item.progress) }}%</text>
|
||||||
|
</view>
|
||||||
|
<view class="progress-track">
|
||||||
|
<view
|
||||||
|
class="progress-fill"
|
||||||
|
:class="normalizeProgress(item.progress) >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
|
||||||
|
:style="{ width: `${normalizeProgress(item.progress)}%` }"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<wd-input
|
||||||
|
v-model="item.remark"
|
||||||
|
label="备注"
|
||||||
|
label-width="140rpx"
|
||||||
|
placeholder="请输入备注"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<wd-button type="primary" plain block @click="showProductPicker = true">
|
||||||
|
添加产品
|
||||||
|
</wd-button>
|
||||||
|
</view>
|
||||||
|
</wd-cell-group>
|
||||||
|
|
||||||
|
<wd-cell-group title="汇总信息" border>
|
||||||
|
<wd-cell title="目标金额" :value="`¥${formatPrice(formData.targetAmount)}`" />
|
||||||
|
<wd-cell title="已完成金额" :value="`¥${formatPrice(formData.completedAmount)}`" />
|
||||||
|
<view class="px-24rpx py-20rpx">
|
||||||
|
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">整体进度</text>
|
||||||
|
<text>{{ totalProgress }}%</text>
|
||||||
|
</view>
|
||||||
|
<view class="progress-track">
|
||||||
|
<view
|
||||||
|
class="progress-fill"
|
||||||
|
:class="totalProgress >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
|
||||||
|
:style="{ width: `${totalProgress}%` }"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<wd-popup v-model="showProductPicker" position="bottom" custom-style="height: 60%">
|
||||||
|
<view class="p-24rpx">
|
||||||
|
<view class="mb-24rpx flex items-center justify-between">
|
||||||
|
<text class="text-32rpx font-semibold">选择产品</text>
|
||||||
|
<wd-button size="small" @click="showProductPicker = false">关闭</wd-button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<scroll-view scroll-y class="product-picker-list">
|
||||||
|
<view
|
||||||
|
v-for="product in productList"
|
||||||
|
:key="product.id"
|
||||||
|
class="product-picker-item"
|
||||||
|
:class="{ 'is-active': selectedProductId === product.id }"
|
||||||
|
@click="selectedProductId = product.id"
|
||||||
|
>
|
||||||
|
<view class="product-picker-item__main">
|
||||||
|
<view class="flex-1">
|
||||||
|
<view class="text-28rpx text-[#333]">{{ product.name }}</view>
|
||||||
|
<view class="mt-8rpx text-22rpx text-[#999]">
|
||||||
|
{{ product.unitName || '-' }} / ¥{{ formatPrice(product.salePrice) }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<wd-icon
|
||||||
|
v-if="selectedProductId === product.id"
|
||||||
|
name="check"
|
||||||
|
color="#1890ff"
|
||||||
|
size="36rpx"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
|
<wd-button type="primary" block class="mt-24rpx" @click="addProduct">
|
||||||
|
确定添加
|
||||||
|
</wd-button>
|
||||||
|
</view>
|
||||||
|
</wd-popup>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import type { FormInstance } from 'wot-design-uni/components/wd-form/types'
|
||||||
|
import type { ProductSimple } from '@/api/erp/product'
|
||||||
|
import type { SalePlan, SalePlanItem } from '@/api/erp/sale-plan'
|
||||||
|
import type { User } from '@/api/system/user'
|
||||||
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
|
import { useToast } from 'wot-design-uni'
|
||||||
|
import { getProductSimpleList } from '@/api/erp/product'
|
||||||
|
import { createSalePlan, getSalePlan, updateSalePlan } from '@/api/erp/sale-plan'
|
||||||
|
import { getSimpleUserList } from '@/api/system/user'
|
||||||
|
import { navigateBackPlus } from '@/utils'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
id?: number | any
|
||||||
|
}>()
|
||||||
|
|
||||||
|
definePage({
|
||||||
|
style: {
|
||||||
|
navigationBarTitleText: '',
|
||||||
|
navigationStyle: 'custom',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const toast = useToast()
|
||||||
|
const formLoading = ref(false)
|
||||||
|
const formRef = ref<FormInstance>()
|
||||||
|
const userList = ref<User[]>([])
|
||||||
|
const productList = ref<ProductSimple[]>([])
|
||||||
|
const showProductPicker = ref(false)
|
||||||
|
const selectedProductId = ref<number>()
|
||||||
|
|
||||||
|
const getTitle = computed(() => props.id ? '编辑销售计划' : '新增销售计划')
|
||||||
|
|
||||||
|
function createDefaultFormData(): SalePlan {
|
||||||
|
const startTime = Date.now()
|
||||||
|
const endTime = startTime + 7 * 24 * 60 * 60 * 1000
|
||||||
|
return {
|
||||||
|
id: undefined,
|
||||||
|
no: undefined,
|
||||||
|
name: undefined,
|
||||||
|
targetAmount: 0,
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
status: 10,
|
||||||
|
approverId: undefined,
|
||||||
|
approverName: undefined,
|
||||||
|
remark: '',
|
||||||
|
items: [],
|
||||||
|
completedAmount: 0,
|
||||||
|
progress: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = ref<SalePlan>(createDefaultFormData())
|
||||||
|
|
||||||
|
const formRules = {
|
||||||
|
name: [{ required: true, message: '请输入计划名称' }],
|
||||||
|
startTime: [{ required: true, message: '请选择开始时间' }],
|
||||||
|
endTime: [{ required: true, message: '请选择结束时间' }],
|
||||||
|
}
|
||||||
|
|
||||||
|
const userColumns = computed(() => {
|
||||||
|
if (!userList.value.length) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return [userList.value.map(item => ({ label: item.nickname, value: item.id }))]
|
||||||
|
})
|
||||||
|
|
||||||
|
const totalProgress = computed(() => {
|
||||||
|
const targetAmount = Number(formData.value.targetAmount || 0)
|
||||||
|
const completedAmount = Number(formData.value.completedAmount || 0)
|
||||||
|
if (!targetAmount || completedAmount <= 0) return 0
|
||||||
|
return normalizeProgress((completedAmount / targetAmount) * 100)
|
||||||
|
})
|
||||||
|
|
||||||
|
function getPickerSingleValue(payload: any) {
|
||||||
|
if (Array.isArray(payload?.value)) {
|
||||||
|
return payload.value[0]
|
||||||
|
}
|
||||||
|
if (payload?.value !== undefined) {
|
||||||
|
return payload.value
|
||||||
|
}
|
||||||
|
if (Array.isArray(payload?.selectedItems) && payload.selectedItems.length > 0) {
|
||||||
|
return payload.selectedItems[0]?.value
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function onApproverConfirm(payload: any) {
|
||||||
|
const approverId = getPickerSingleValue(payload)
|
||||||
|
formData.value.approverId = approverId
|
||||||
|
const approver = userList.value.find(item => item.id === approverId)
|
||||||
|
formData.value.approverName = approver?.nickname
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeProgress(value?: number) {
|
||||||
|
const progress = Number(value || 0)
|
||||||
|
if (Number.isNaN(progress) || progress < 0) return 0
|
||||||
|
if (progress > 100) return 100
|
||||||
|
return Math.round(progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatPrice(value?: number) {
|
||||||
|
if (value === undefined || value === null) return '0.00'
|
||||||
|
return Number(value).toFixed(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
function calcItemTotal(item: SalePlanItem) {
|
||||||
|
const count = Number(item.planCount) || 0
|
||||||
|
const price = Number(item.productPrice) || 0
|
||||||
|
return Math.round(count * price * 100) / 100
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeItem(index: number) {
|
||||||
|
formData.value.items?.splice(index, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function addProduct() {
|
||||||
|
const product = productList.value.find(item => item.id === selectedProductId.value)
|
||||||
|
if (!product) {
|
||||||
|
toast.warning('请选择产品')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((formData.value.items || []).some(item => item.productId === product.id)) {
|
||||||
|
toast.warning('该产品已添加')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const newItem: SalePlanItem = {
|
||||||
|
productId: product.id,
|
||||||
|
productName: product.name,
|
||||||
|
productUnitName: product.unitName,
|
||||||
|
planCount: 1,
|
||||||
|
productPrice: product.salePrice || 0,
|
||||||
|
totalPrice: product.salePrice || 0,
|
||||||
|
remark: undefined,
|
||||||
|
}
|
||||||
|
|
||||||
|
formData.value.items = [...(formData.value.items || []), newItem]
|
||||||
|
selectedProductId.value = undefined
|
||||||
|
showProductPicker.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => formData.value.items,
|
||||||
|
(items) => {
|
||||||
|
const list = items || []
|
||||||
|
let targetAmount = 0
|
||||||
|
let completedAmount = 0
|
||||||
|
|
||||||
|
list.forEach((item) => {
|
||||||
|
item.totalPrice = calcItemTotal(item)
|
||||||
|
targetAmount += Number(item.totalPrice || 0)
|
||||||
|
completedAmount += Number(item.completedAmount || 0)
|
||||||
|
if (item.completedAmount !== undefined && Number(item.totalPrice || 0) > 0) {
|
||||||
|
item.progress = normalizeProgress((Number(item.completedAmount || 0) / Number(item.totalPrice || 0)) * 100)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
formData.value.targetAmount = Math.round(targetAmount * 100) / 100
|
||||||
|
formData.value.completedAmount = Math.round(completedAmount * 100) / 100
|
||||||
|
formData.value.progress = totalProgress.value
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleBack() {
|
||||||
|
navigateBackPlus('/pages-erp/sale-plan/index')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadOptions() {
|
||||||
|
const [usersResult, productsResult] = await Promise.allSettled([
|
||||||
|
getSimpleUserList(),
|
||||||
|
getProductSimpleList(),
|
||||||
|
])
|
||||||
|
|
||||||
|
userList.value = usersResult.status === 'fulfilled' ? (usersResult.value || []) : []
|
||||||
|
productList.value = productsResult.status === 'fulfilled' ? (productsResult.value || []) : []
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDetail() {
|
||||||
|
if (!props.id) return
|
||||||
|
try {
|
||||||
|
toast.loading('加载中...')
|
||||||
|
const data = await getSalePlan(props.id)
|
||||||
|
formData.value = {
|
||||||
|
...createDefaultFormData(),
|
||||||
|
...data,
|
||||||
|
items: data.items || [],
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
toast.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
const { valid } = await formRef.value!.validate()
|
||||||
|
if (!valid) return
|
||||||
|
|
||||||
|
const startTime = Number(formData.value.startTime)
|
||||||
|
const endTime = Number(formData.value.endTime)
|
||||||
|
if (startTime && endTime && startTime > endTime) {
|
||||||
|
toast.warning('结束时间不能早于开始时间')
|
||||||
|
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.productId) {
|
||||||
|
toast.warning(`第${i + 1}项产品未选择`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!item.planCount || Number(item.planCount) <= 0) {
|
||||||
|
toast.warning(`第${i + 1}项计划数量必须大于 0`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (item.productPrice === undefined || item.productPrice === null || Number(item.productPrice) < 0) {
|
||||||
|
toast.warning(`第${i + 1}项销售单价不正确`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
const submitData: SalePlan = {
|
||||||
|
...formData.value,
|
||||||
|
startTime: formData.value.startTime ? Number(formData.value.startTime) : undefined,
|
||||||
|
endTime: formData.value.endTime ? Number(formData.value.endTime) : undefined,
|
||||||
|
targetAmount: Number(formData.value.targetAmount || 0),
|
||||||
|
completedAmount: Number(formData.value.completedAmount || 0),
|
||||||
|
progress: totalProgress.value,
|
||||||
|
items: (formData.value.items || []).map(item => ({
|
||||||
|
...item,
|
||||||
|
totalPrice: calcItemTotal(item),
|
||||||
|
})),
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.id) {
|
||||||
|
await updateSalePlan(submitData)
|
||||||
|
toast.success('修改成功')
|
||||||
|
} else {
|
||||||
|
await createSalePlan(submitData)
|
||||||
|
toast.success('新增成功')
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
handleBack()
|
||||||
|
}, 500)
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await loadOptions()
|
||||||
|
await getDetail()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.product-picker-list {
|
||||||
|
max-height: 720rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-picker-item {
|
||||||
|
padding: 24rpx;
|
||||||
|
border-bottom: 1rpx solid #f0f0f0;
|
||||||
|
|
||||||
|
&.is-active {
|
||||||
|
background: #f0f7ff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-picker-item__main {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-track {
|
||||||
|
width: 100%;
|
||||||
|
height: 12rpx;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
background: #f0f0f0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-fill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
446
src/pages-erp/sale-plan/index.vue
Normal file
446
src/pages-erp/sale-plan/index.vue
Normal file
@@ -0,0 +1,446 @@
|
|||||||
|
<template>
|
||||||
|
<view class="yd-page-container">
|
||||||
|
<wd-navbar
|
||||||
|
title="销售计划"
|
||||||
|
left-arrow
|
||||||
|
placeholder
|
||||||
|
safe-area-inset-top
|
||||||
|
fixed
|
||||||
|
@click-left="handleBack"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<view @click="openSearchForm">
|
||||||
|
<wd-search :placeholder="searchPlaceholder" hide-cancel disabled />
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="status-tabs">
|
||||||
|
<view
|
||||||
|
:class="['status-tabs__item', { 'is-active': activeStatus === undefined }]"
|
||||||
|
@click="handleQuickFilter(undefined)"
|
||||||
|
>
|
||||||
|
全部
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
:class="['status-tabs__item', { 'is-active': activeStatus === 10 }]"
|
||||||
|
@click="handleQuickFilter(10)"
|
||||||
|
>
|
||||||
|
待审核
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
:class="['status-tabs__item', { 'is-active': activeStatus === 20 }]"
|
||||||
|
@click="handleQuickFilter(20)"
|
||||||
|
>
|
||||||
|
已审核
|
||||||
|
</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 class="ml-16rpx line-clamp-1 text-right" style="max-width: 420rpx;">{{ item.name || '-' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">计划周期</text>
|
||||||
|
<text>{{ formatPlanDate(item.startTime) }} ~ {{ formatPlanDate(item.endTime) }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="mb-8rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">审批人</text>
|
||||||
|
<text>{{ item.approverName || '-' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="mb-12rpx flex items-center justify-between text-26rpx text-[#666]">
|
||||||
|
<text class="text-[#999]">完成状态</text>
|
||||||
|
<text :class="getCompletionStatusClass(item.completionStatus)">
|
||||||
|
{{ getCompletionStatusText(item.completionStatus) }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="flex items-center justify-around border-t border-[#f0f0f0] pt-16rpx">
|
||||||
|
<view class="text-center">
|
||||||
|
<view class="text-30rpx text-[#333] font-semibold">¥{{ formatPrice(item.targetAmount) }}</view>
|
||||||
|
<view class="mt-4rpx text-22rpx text-[#999]">目标金额</view>
|
||||||
|
</view>
|
||||||
|
<view class="text-center">
|
||||||
|
<view class="text-30rpx text-[#52c41a] font-semibold">¥{{ formatPrice(item.completedAmount) }}</view>
|
||||||
|
<view class="mt-4rpx text-22rpx text-[#999]">已完成</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="mt-16rpx">
|
||||||
|
<view class="mb-8rpx flex items-center justify-between text-24rpx text-[#999]">
|
||||||
|
<text>整体进度</text>
|
||||||
|
<text>{{ normalizeProgress(item.progress) }}%</text>
|
||||||
|
</view>
|
||||||
|
<view class="progress-track">
|
||||||
|
<view
|
||||||
|
class="progress-fill"
|
||||||
|
:class="normalizeProgress(item.progress) >= 100 ? 'bg-[#52c41a]' : 'bg-[#1890ff]'"
|
||||||
|
:style="{ width: `${normalizeProgress(item.progress)}%` }"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="flex flex-wrap gap-12rpx px-24rpx pb-20rpx" @click.stop>
|
||||||
|
<wd-button
|
||||||
|
v-if="hasAccessByCodes(['erp:sale-plan:query'])"
|
||||||
|
size="small"
|
||||||
|
plain
|
||||||
|
@click="handleDetail(item)"
|
||||||
|
>
|
||||||
|
详情
|
||||||
|
</wd-button>
|
||||||
|
<wd-button
|
||||||
|
v-if="hasAccessByCodes(['erp:sale-plan:update']) && item.status === 10"
|
||||||
|
size="small"
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="handleEdit(item)"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</wd-button>
|
||||||
|
<wd-button
|
||||||
|
v-if="hasAccessByCodes(['erp:sale-plan:update-status']) && item.status === 10"
|
||||||
|
size="small"
|
||||||
|
type="success"
|
||||||
|
plain
|
||||||
|
@click="handleAudit(item.id!)"
|
||||||
|
>
|
||||||
|
审核
|
||||||
|
</wd-button>
|
||||||
|
<wd-button
|
||||||
|
v-if="hasAccessByCodes(['erp:sale-plan: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:sale-plan: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">
|
||||||
|
<view class="yd-search-form-item">
|
||||||
|
<view class="yd-search-form-label">计划编号</view>
|
||||||
|
<wd-input v-model="searchForm.no" placeholder="请输入计划编号" clearable />
|
||||||
|
</view>
|
||||||
|
<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-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 { SalePlan } from '@/api/erp/sale-plan'
|
||||||
|
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 { deleteSalePlan, getSalePlanPage, updateSalePlanStatus } from '@/api/erp/sale-plan'
|
||||||
|
import { useAccess } from '@/hooks/useAccess'
|
||||||
|
import { formatDate } from '@/utils/date'
|
||||||
|
import { navigateBackPlus } from '@/utils'
|
||||||
|
|
||||||
|
definePage({
|
||||||
|
style: {
|
||||||
|
navigationBarTitleText: '',
|
||||||
|
navigationStyle: 'custom',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const { hasAccessByCodes } = useAccess()
|
||||||
|
const toast = useToast()
|
||||||
|
const total = ref(0)
|
||||||
|
const list = ref<SalePlan[]>([])
|
||||||
|
const loadMoreState = ref<LoadMoreState>('loading')
|
||||||
|
const activeStatus = ref<number | undefined>(undefined)
|
||||||
|
const queryParams = ref<Record<string, any>>({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
status: undefined as number | undefined,
|
||||||
|
})
|
||||||
|
|
||||||
|
const searchVisible = ref(false)
|
||||||
|
const searchForm = reactive({
|
||||||
|
no: undefined as string | undefined,
|
||||||
|
name: undefined as string | undefined,
|
||||||
|
})
|
||||||
|
|
||||||
|
function openSearchForm() {
|
||||||
|
searchVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchPlaceholder = computed(() => {
|
||||||
|
const conditions: string[] = []
|
||||||
|
if (searchForm.no) conditions.push(`编号:${searchForm.no}`)
|
||||||
|
if (searchForm.name) conditions.push(`名称:${searchForm.name}`)
|
||||||
|
return conditions.length > 0 ? conditions.join(' | ') : '搜索销售计划'
|
||||||
|
})
|
||||||
|
|
||||||
|
function handleBack() {
|
||||||
|
navigateBackPlus()
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatPlanDate(value?: string | number) {
|
||||||
|
return value ? formatDate(value, 'YYYY-MM-DD') : '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatPrice(value?: number) {
|
||||||
|
if (value === undefined || value === null) return '0.00'
|
||||||
|
return Number(value).toFixed(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeProgress(value?: number) {
|
||||||
|
const progress = Number(value || 0)
|
||||||
|
if (Number.isNaN(progress) || progress < 0) return 0
|
||||||
|
if (progress > 100) return 100
|
||||||
|
return Math.round(progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 getCompletionStatusText(status?: number) {
|
||||||
|
if (status === 0) return '未开始'
|
||||||
|
if (status === 1) return '进行中'
|
||||||
|
if (status === 2) return '已完成'
|
||||||
|
if (status === 3) return '已超期'
|
||||||
|
return '-'
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCompletionStatusClass(status?: number) {
|
||||||
|
if (status === 0) return 'text-[#999]'
|
||||||
|
if (status === 1) return 'text-[#1890ff]'
|
||||||
|
if (status === 2) return 'text-[#52c41a]'
|
||||||
|
if (status === 3) return 'text-[#f5222d]'
|
||||||
|
return 'text-[#999]'
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getList() {
|
||||||
|
loadMoreState.value = 'loading'
|
||||||
|
try {
|
||||||
|
const data = await getSalePlanPage({ ...queryParams.value })
|
||||||
|
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 handleSearch() {
|
||||||
|
searchVisible.value = false
|
||||||
|
queryParams.value = {
|
||||||
|
...queryParams.value,
|
||||||
|
...searchForm,
|
||||||
|
status: activeStatus.value,
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: queryParams.value.pageSize,
|
||||||
|
}
|
||||||
|
list.value = []
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleReset() {
|
||||||
|
searchForm.no = undefined
|
||||||
|
searchForm.name = undefined
|
||||||
|
searchVisible.value = false
|
||||||
|
queryParams.value = {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
status: undefined,
|
||||||
|
}
|
||||||
|
activeStatus.value = undefined
|
||||||
|
list.value = []
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadMore() {
|
||||||
|
if (loadMoreState.value === 'finished') return
|
||||||
|
queryParams.value.pageNo++
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCardClick(item: SalePlan) {
|
||||||
|
if (item.status === 10) {
|
||||||
|
handleEdit(item)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
handleDetail(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleAdd() {
|
||||||
|
uni.navigateTo({ url: '/pages-erp/sale-plan/form/index' })
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEdit(item: SalePlan) {
|
||||||
|
uni.navigateTo({ url: `/pages-erp/sale-plan/form/index?id=${item.id}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDetail(item: SalePlan) {
|
||||||
|
uni.navigateTo({ url: `/pages-erp/sale-plan/detail/index?id=${item.id}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleAudit(id: number) {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定审核该销售计划吗?',
|
||||||
|
success: async (res) => {
|
||||||
|
if (!res.confirm) return
|
||||||
|
try {
|
||||||
|
await updateSalePlanStatus(id, 20)
|
||||||
|
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 deleteSalePlan([id])
|
||||||
|
toast.success('删除成功')
|
||||||
|
list.value = []
|
||||||
|
queryParams.value.pageNo = 1
|
||||||
|
getList()
|
||||||
|
} catch {
|
||||||
|
// error handled by http
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
loadMore()
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.status-tabs {
|
||||||
|
display: flex;
|
||||||
|
margin: 0 24rpx 16rpx;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
|
||||||
|
|
||||||
|
&__item {
|
||||||
|
flex: 1;
|
||||||
|
text-align: center;
|
||||||
|
padding: 20rpx 0;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #606266;
|
||||||
|
transition: all 0.2s;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&.is-active {
|
||||||
|
color: #018d71;
|
||||||
|
font-weight: 600;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 25%;
|
||||||
|
width: 50%;
|
||||||
|
height: 4rpx;
|
||||||
|
background: #018d71;
|
||||||
|
border-radius: 2rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:not(:last-child) {
|
||||||
|
border-right: 1rpx solid #f0f0f0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-track {
|
||||||
|
width: 100%;
|
||||||
|
height: 12rpx;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
background: #f0f0f0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-fill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -108,6 +108,14 @@ const menuGroupsData: MenuGroup[] = [
|
|||||||
iconColor: '#1890ff',
|
iconColor: '#1890ff',
|
||||||
permission: 'erp:sale-order:query',
|
permission: 'erp:sale-order:query',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'salePlan',
|
||||||
|
name: '销售计划',
|
||||||
|
icon: 'chart',
|
||||||
|
url: '/pages-erp/sale-plan/index',
|
||||||
|
iconColor: '#13c2c2',
|
||||||
|
permission: 'erp:sale-plan:query',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'saleOut',
|
key: 'saleOut',
|
||||||
name: '销售出库',
|
name: '销售出库',
|
||||||
|
|||||||
Reference in New Issue
Block a user