添加商品改价管理

This commit is contained in:
lewis 2025-04-03 16:36:51 +08:00
parent a8cfbafc00
commit 3ab090f646
5 changed files with 682 additions and 0 deletions

View File

@ -0,0 +1,39 @@
import request from '@/utils/request'
// 商品价格更改列表
export function apiStoreProductPriceLists(params: any) {
return request.get({ url: '/storeproductprice/lists', params }, { urlPrefix: 'psi' })
}
// 添加商品价格更改
export function apiStoreProductPriceAdd(params: any) {
return request.post({ url: '/storeproductprice/add', params }, { urlPrefix: 'psi' })
}
// 编辑商品价格更改
export function apiStoreProductPriceEdit(params: any) {
return request.post({ url: '/storeproductprice/edit', params }, { urlPrefix: 'psi' })
}
// 删除商品价格更改
export function apiStoreProductPriceDelete(params: any) {
return request.post({ url: '/storeproductprice/delete', params }, { urlPrefix: 'psi' })
}
// 商品价格更改详情
export function apiStoreProductPriceDetail(params: any) {
return request.get({ url: '/storeproductprice/detail', params }, { urlPrefix: 'psi' })
}
// 确认改价
export function apiStoreProductPriceEnterPrice(params: any) {
return request.post({ url: '/storeproductprice/enterPrice', params }, { urlPrefix: 'psi' })
}
export function apiStoreProductPriceExport(params: any) {
return request.post({ url: '/storeproductprice/export', params }, { urlPrefix: 'psi' })
}
export function apiStoreProductPriceChart(params: any) {
return request.get({ url: '/storeproductprice/chart', params }, { urlPrefix: 'psi' })
}

View File

@ -0,0 +1,98 @@
<template>
<div class="workbench">
<el-card shadow="never" class="mt-4 !border-none">
<div>
<v-charts style="height: 400px" :option="visitorOption" :autoresize="true" />
</div>
</el-card>
</div>
</template>
<script lang="ts" setup name="product">
import {
apiStoreProductPriceChart
} from '@/api/psi/store_product_price'
import moment from 'moment'
import vCharts from 'vue-echarts'
//
const visitorOption : any = reactive({
xAxis: {
type: 'category',
data: [0],
axisLabel: {
rotate: 45,
color: '#333'
}
},
yAxis: {
type: 'value',
name: '金额',
position: 'left',
axisLabel: {
formatter: '{value}'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
legend: {
data: ['访问量']
},
itemStyle: {
//
color: 'red'
},
tooltip: {
trigger: 'axis'
},
series: [
{
name: '访问量',
data: [0],
type: 'line',
smooth: true
}
]
})
const props = defineProps({
type: Number,
productId: Number
})
const getData = () => {
let queryParams = {
type: props.type,
product_id: props.productId
}
apiStoreProductPriceChart(queryParams).then((res) => {
// echarts
visitorOption.xAxis.data = []
visitorOption.series = []
visitorOption.legend.data = res.series.map((item : any) => item.name)
//
res.x.forEach((item : any) => {
visitorOption.xAxis.data.push(item)
})
visitorOption.series = res.series.map((item : any) => {
return {
type: 'line',
smooth: true,
data: item.value,
name: item.name
}
})
})
}
onMounted(() => {
getData()
})
</script>
<style lang="scss" scoped></style>

View File

@ -0,0 +1,146 @@
<template>
<div class="edit-popup">
<popup ref="popupRef" title="详情" :async="true" width="550px" :cancelButtonText="false"
:confirmButtonText="false">
<el-form ref="formRef" :model="formData" label-width="90px">
<el-form-item label="预订单id" prop="bhoid">
<el-input v-model="formData.bhoid" clearable placeholder="请输入预订单id" :readonly="true" />
</el-form-item>
<el-form-item label="采购主id" prop="offer_id">
<el-input v-model="formData.offer_id" clearable placeholder="请输入采购主id" :readonly="true" />
</el-form-item>
<el-form-item label="仓库id" prop="warehouse_id">
<el-input v-model="formData.warehouse_id" clearable placeholder="请输入仓库id" :readonly="true" />
</el-form-item>
<el-form-item label="入库单商品id" prop="warehouse_product_id">
<el-input v-model="formData.warehouse_product_id" clearable placeholder="请输入入库单商品id"
:readonly="true" />
</el-form-item>
<el-form-item label="商品ID" prop="product_id">
<el-input v-model="formData.product_id" clearable placeholder="请输入商品ID" :readonly="true" />
</el-form-item>
<el-form-item label="采购价" prop="purchase_price">
<el-input v-model="formData.purchase_price" clearable placeholder="请输入采购价" :readonly="true" />
</el-form-item>
<el-form-item label="比例" prop="purchase_lv">
<el-input v-model="formData.purchase_lv" clearable placeholder="请输入比例" :readonly="true" />
</el-form-item>
<el-form-item label="供货价" prop="purchase">
<el-input v-model="formData.purchase" clearable placeholder="请输入供货价" :readonly="true" />
</el-form-item>
<el-form-item label="比例" prop="cost_lv">
<el-input v-model="formData.cost_lv" clearable placeholder="请输入比例" :readonly="true" />
</el-form-item>
<el-form-item label="商户价" prop="cost">
<el-input v-model="formData.cost" clearable placeholder="请输入商户价" :readonly="true" />
</el-form-item>
<el-form-item label="比例" prop="price_lv">
<el-input v-model="formData.price_lv" clearable placeholder="请输入比例" :readonly="true" />
</el-form-item>
<el-form-item label="零售价" prop="price">
<el-input v-model="formData.price" clearable placeholder="请输入零售价" :readonly="true" />
</el-form-item>
<el-form-item label="会员价比例" prop="vip_lv">
<el-input v-model="formData.vip_lv" clearable placeholder="请输入会员价比例" :readonly="true" />
</el-form-item>
<el-form-item label="会员价" prop="vip_price">
<el-input v-model="formData.vip_price" clearable placeholder="请输入会员价" :readonly="true" />
</el-form-item>
<el-form-item label="价格配置" prop="price_config">
<el-input v-model="formData.price_config" clearable placeholder="请输入价格配置" :readonly="true" />
</el-form-item>
<el-form-item label="备注" prop="mark">
<el-input v-model="formData.mark" clearable placeholder="请输入备注" :readonly="true" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-input v-model="formData.status" clearable placeholder="请输入状态" :readonly="true" />
</el-form-item>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="storeProductPriceDETAILS">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiStoreProductPriceAdd, apiStoreProductPriceEdit, apiStoreProductPriceDetail } from '@/api/psi/store_product_price'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
//
const formData = reactive({
id: '',
bhoid: '',
offer_id: '',
warehouse_id: '',
warehouse_product_id: '',
product_id: '',
purchase_price: '',
purchase_lv: '',
purchase: '',
cost_lv: '',
cost: '',
price_lv: '',
price: '',
vip_lv: '',
vip_price: '',
price_config: '',
mark: '',
status: '',
})
//
const setFormData = async (data : Record<any, any>) => {
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key]
}
}
//@ts-ignore
formData.create_time = timeFormat(formData.create_time, 'yyyy-mm-dd hh:MM:ss')
}
const getDetail = async (row : Record<string, any>) => {
const data = await apiStoreProductPriceDetail({
id: row.id
})
setFormData(data)
}
//
const open = () => {
popupRef.value?.open()
}
//
const handleClose = () => {
emit('close')
}
defineExpose({
open,
setFormData,
getDetail
})
</script>

View File

@ -0,0 +1,183 @@
<template>
<div class="edit-popup">
<popup ref="popupRef" :title="popupTitle" :async="true" width="550px" @confirm="handleSubmit"
@close="handleClose">
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
<el-form-item label="商品名称" prop="store_name">
<el-input v-model="formData.store_name" clearable disabled />
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="供货价比例" prop="purchase_lv">
<el-input v-model="formData.purchase_lv" @change="changePriceRate('purchase', $event)"
clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="供货价" prop="purchase">
<el-input v-model="formData.purchase" @change="changePurchase" clearable />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="商户价比例" prop="cost_lv">
<el-input v-model="formData.cost_lv" @change="changePriceRate('cost', $event)" clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="商户价" prop="cost">
<el-input v-model="formData.cost" clearable />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="会员价比例" prop="vip_lv">
<el-input v-model="formData.vip_lv" @change="changePriceRate('vip_price', $event)"
clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="会员价" prop="vip_price">
<el-input v-model="formData.vip_price" clearable />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="零售价比例" prop="price_lv">
<el-input v-model="formData.price_lv" @change="changePriceRate('price', $event)"
clearable />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="零售价" prop="price">
<el-input v-model="formData.price" clearable />
</el-form-item>
</el-col>
</el-row>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="storeProductPriceEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiStoreProductPriceEdit, apiStoreProductPriceDetail } from '@/api/psi/store_product_price'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
//
const popupTitle = computed(() => {
return mode.value == 'edit' ? '编辑商品价格更改' : '新增商品价格更改'
})
//
const formData = reactive({
id: '',
purchase_price: '',
store_name: '',
purchase: '',
purchase_lv: '',
cost: '',
cost_lv: '',
price: '',
price_lv: '',
vip_price: '',
vip_lv: '',
price_config: []
})
//
const formRules = reactive<any>({})
const changePriceRate = (type, e) => {
let value = '0.00'
if (type == 'purchase') {
value = formData.purchase_price * e
} else {
value = formData.purchase * e
}
value = value.toFixed(2)
if (type == 'purchase') {
formData.purchase = value
formData.cost = (value * formData.cost_lv).toFixed(2)
formData.vip_price = (value * formData.vip_lv).toFixed(2)
formData.price = (value * formData.price_lv).toFixed(2)
} else if (type == 'cost') {
formData.cost = value
} else if (type == 'vip_price') {
formData.vip_price = value
} else {
formData.price = value
}
}
const changePurchase = (value) => {
formData.cost = (value * formData.cost_lv).toFixed(2)
formData.vip_price = (value * formData.vip_lv).toFixed(2)
formData.price = (value * formData.price_lv).toFixed(2)
}
//
const setFormData = async (data : Record<any, any>) => {
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key]
}
}
//@ts-ignore
formData.create_time = timeFormat(formData.create_time, 'yyyy-mm-dd hh:MM:ss')
}
const getDetail = async (row : Record<string, any>) => {
const data = await apiStoreProductPriceDetail({
id: row.id
})
setFormData(data)
}
//
const handleSubmit = async () => {
await formRef.value?.validate()
const data = { ...formData, }
await apiStoreProductPriceEdit(data)
popupRef.value?.close()
emit('success')
}
//
const open = (type = 'add') => {
mode.value = type
popupRef.value?.open()
}
//
const handleClose = () => {
emit('close')
}
defineExpose({
open,
setFormData,
getDetail
})
</script>

View File

@ -0,0 +1,216 @@
<template>
<div>
<el-card class="!border-none mb-4" shadow="never">
<el-form class="mb-[-16px]" :model="queryParams" inline>
<el-form-item label="商品" prop="store_name">
<el-input class="w-[280px]" v-model="queryParams.store_name" clearable placeholder="请输入商品" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择状态" style="width: 240px">
<el-option :value="0" label="未设置"></el-option>
<el-option :value="1" label="已设置"></el-option>
</el-select>
</el-form-item>
<el-form-item label="日期" prop="timeScope">
<el-date-picker v-model="queryParams.timeScope" type="daterange" range-separator=""
start-placeholder="开始日期" end-placeholder="结束日期" unlink-panels :shortcuts="shortcuts"
@change="changeStartEndTime" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button>
<el-button @click="xlsx()">导出</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
<div class="mt-4">
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column label="溯源" width="150">
<template #default="{ row }">
<div>id: {{ row.id }}</div>
<div>预订单id: {{ row.bhoid }}</div>
<div>采购源id: {{ row.offer_id }}</div>
</template>
</el-table-column>
<el-table-column label="仓库" prop="warehouse" show-overflow-tooltip />
<el-table-column label="商品信息" width="150" show-overflow-tooltip>
<template #default="{ row }">
<div>商品名称: {{ row.store_name }}</div>
<div>单位: {{ row.unit_name }}</div>
</template>
</el-table-column>
<el-table-column label="规格" prop="store_info" show-overflow-tooltip />
<el-table-column label="商品图片" prop="image" width="120">
<template #default="{ row }">
<el-image style="width: 50px; height: 50px" :src="row.image" :preview-teleported="true" />
</template>
</el-table-column>
<el-table-column label="采购价" prop="purchase_price" show-overflow-tooltip>
<template #default="{ row }">
<div @click="chartPop(row.product_id)" style="color: red">{{ row.purchase_price }}</div>
</template>
</el-table-column>
<el-table-column label="供货价" prop="purchase" show-overflow-tooltip>
<template #default="{ row }">
<div>设置价:{{ row.purchase }}|{{ row.purchase_lv }}%</div>
<div>当前价:{{ row.current_purchase }}</div>
</template>
</el-table-column>
<el-table-column label="商户价" prop="cost" show-overflow-tooltip>
<template #default="{ row }">
<div>设置价:{{ row.cost }}|{{ row.cost_lv }}%</div>
<div>当前价:{{ row.current_cost }}</div>
</template>
</el-table-column>
<el-table-column label="零售价" prop="price" show-overflow-tooltip>
<template #default="{ row }">
<div>设置价:{{ row.price }}|{{ row.price_lv }}%</div>
<div>当前价:{{ row.current_price }}</div>
</template>
</el-table-column>
<el-table-column label="状态" prop="status_name" show-overflow-tooltip />
<el-table-column label="时间" prop="create_time" show-overflow-tooltip width="180" />
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
<el-button v-perms="['store_product_price.store_product_price/edit']" type="primary" link
@click="handleEdit(row)">
编辑
</el-button>
<el-button v-perms="['store_product_price.store_product_price/delete']" type="danger" link
@click="handleEnter(row)" v-if="row.status == 0">
确认
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="flex mt-4 justify-end">
<pagination v-model="pager" @change="getLists" />
</div>
</el-card>
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
<el-dialog v-model="showChart" title="价格走势" width="70%">
<price-chart ref="priceChartRef" :key="chartKey" :type="1" :productId="chartId"></price-chart>
</el-dialog>
</div>
</template>
<script lang="ts" setup name="storeProductPriceLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import {
apiStoreProductPriceLists,
apiStoreProductPriceDelete,
apiStoreProductPriceExport,
apiStoreProductPriceEnterPrice
} from '@/api/psi/store_product_price'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
import moment from 'moment'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
//
const showEdit = ref(false)
//
const queryParams = reactive({
store_name: '',
status: '',
start_time: '',
end_time: '',
timeScope: [],
})
const showChart = ref(false)
const chartId = ref('')
const chartKey = ref(0)
const chartPop = (id) => {
showChart.value = true
chartId.value = id
chartKey.value++
}
//
const selectData = ref<any[]>([])
const shortcuts = [
{
text: '近一周',
value: () => {
const end = new Date()
const start = new Date()
start.setDate(start.getDate() - 7)
return [start, end]
}
},
{
text: '近一月',
value: () => {
const end = new Date()
const start = new Date()
start.setMonth(start.getMonth() - 1)
return [start, end]
}
},
{
text: '近三月',
value: () => {
const end = new Date()
const start = new Date()
start.setMonth(start.getMonth() - 3)
return [start, end]
}
}
]
const changeStartEndTime = () => {
if (queryParams.timeScope[0] && queryParams.timeScope[1]) {
queryParams.start_time = moment(queryParams.timeScope[0]).format('YYYY-MM-DD') + ' 00:00:00'
queryParams.end_time = moment(queryParams.timeScope[1]).format('YYYY-MM-DD') + ' 23:59:59'
} else {
queryParams.start_time = ''
queryParams.end_time = ''
}
}
//
const handleSelectionChange = (val : any[]) => {
selectData.value = val.map(({ id }) => id)
}
//
const { dictData } = useDictData('')
//
const { pager, getLists, resetParams, resetPage } = usePaging({
fetchFun: apiStoreProductPriceLists,
params: queryParams
})
//
const handleEdit = async (data : any) => {
showEdit.value = true
await nextTick()
editRef.value?.open('edit')
editRef.value?.setFormData(data)
}
const handleEnter = async (data : any) => {
await feedback.confirm('是否改价:' + data.store_name)
await apiStoreProductPriceEnterPrice({ id: data.id })
getLists()
}
const xlsx = () => {
apiStoreProductPriceExport(queryParams).then((res) => {
window.open(res.url, '_blank')
ElMessage.success('导出成功')
})
}
getLists()
</script>