| | |
| | | <el-option v-for="supplier in supplierList" :key="supplier.id" :label="supplier.name" :value="supplier.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="价格状态:"> |
| | | <el-select v-model="searchForm.priceStatus" placeholder="请选择状态" clearable style="width: 150px"> |
| | | <el-option label="有效" value="active" /> |
| | | <el-option label="待生效" value="pending" /> |
| | | <el-option label="已过期" value="expired" /> |
| | | <el-option label="已暂停" value="suspended" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" @click="handleSearch" :loading="loading"> |
| | | <el-icon><Search /></el-icon> |
| | |
| | | <el-button type="success" @click="openBatchDiscountDialog"> |
| | | <el-icon><Discount /></el-icon> |
| | | 批量折扣 |
| | | </el-button> |
| | | <el-button type="warning" @click="openPriceControlDialog"> |
| | | <el-icon><Setting /></el-icon> |
| | | 价格控制 |
| | | </el-button> |
| | | <el-button type="info" @click="exportData"> |
| | | <el-icon><Download /></el-icon> |
| | |
| | | <el-table-column label="供应商" prop="supplierName" width="150" /> |
| | | <el-table-column label="基础价格" width="120" align="right"> |
| | | <template #default="{ row }"> |
| | | <span class="price-text">¥{{ row.basePrice.toFixed(2) }}</span> |
| | | <span class="price-text">¥{{ row.basePrice }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="折扣信息" width="150"> |
| | |
| | | </el-table-column> |
| | | <el-table-column label="实际价格" width="120" align="right"> |
| | | <template #default="{ row }"> |
| | | <span class="final-price">¥{{ calculateFinalPrice(row).toFixed(2) }}</span> |
| | | <span class="final-price">¥{{ calculateFinalPrice(row) }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="价格控制" width="120"> |
| | | <template #default="{ row }"> |
| | | <div class="price-control"> |
| | | <div v-if="row.priceControl?.minPrice" class="control-item"> |
| | | 最低: ¥{{ row.priceControl.minPrice.toFixed(2) }} |
| | | <div v-if="row.minPrice" class="control-item"> |
| | | 最低: ¥{{ row.minPrice }} |
| | | </div> |
| | | <div v-if="row.priceControl?.maxPrice" class="control-item"> |
| | | 最高: ¥{{ row.priceControl.maxPrice.toFixed(2) }} |
| | | <div v-if="row.maxPrice" class="control-item"> |
| | | 最高: ¥{{ row.maxPrice }} |
| | | </div> |
| | | </div> |
| | | </template> |
| | |
| | | <el-icon><Edit /></el-icon> |
| | | 编辑 |
| | | </el-button> |
| | | <el-button type="success" link @click="openDiscountDialog(row)"> |
| | | <el-icon><Discount /></el-icon> |
| | | 折扣 |
| | | </el-button> |
| | | <el-button type="danger" link @click="handleDelete(row)"> |
| | | <el-icon><Delete /></el-icon> |
| | | 删除 |
| | |
| | | <!-- 分页 --> |
| | | <div class="pagination-wrapper"> |
| | | <el-pagination |
| | | v-model:current-page="pagination.currentPage" |
| | | v-model:page-size="pagination.pageSize" |
| | | v-model:current-page="pagination.current" |
| | | v-model:page-size="pagination.size" |
| | | :page-sizes="[10, 20, 50, 100]" |
| | | :total="pagination.total" |
| | | :total="total" |
| | | layout="total, sizes, prev, pager, next, jumper" |
| | | @size-change="handleSizeChange" |
| | | @current-change="handleCurrentChange" |
| | |
| | | <el-option label="无折扣" value="" /> |
| | | <el-option label="百分比折扣" value="percentage" /> |
| | | <el-option label="固定金额" value="fixed" /> |
| | | <el-option label="阶梯折扣" value="tiered" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <!-- 阶梯折扣设置 --> |
| | | <div v-if="formData.discountType === 'tiered'"> |
| | | <el-form-item label="阶梯折扣"> |
| | | <el-table :data="formData.tieredDiscount" border size="small"> |
| | | <el-table-column label="最小数量" width="120"> |
| | | <template #default="{ row, $index }"> |
| | | <el-input-number v-model="row.minQty" :min="0" size="small" /> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="最大数量" width="120"> |
| | | <template #default="{ row, $index }"> |
| | | <el-input-number v-model="row.maxQty" :min="0" size="small" /> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="折扣率(%)" width="120"> |
| | | <template #default="{ row, $index }"> |
| | | <el-input-number v-model="row.discount" :min="0" :max="100" :precision="2" size="small" /> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="操作" width="80"> |
| | | <template #default="{ row, $index }"> |
| | | <el-button type="danger" link @click="removeTieredRow($index)">删除</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <el-button type="primary" link @click="addTieredRow" class="mt-2">添加阶梯</el-button> |
| | | </el-form-item> |
| | | </div> |
| | | |
| | | <!-- 价格控制 --> |
| | | <el-divider content-position="left">价格控制</el-divider> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, reactive, computed, onMounted } from 'vue' |
| | | import {ref, reactive, computed, onMounted, getCurrentInstance} from 'vue' |
| | | import { ElMessage, ElMessageBox } from 'element-plus' |
| | | import { |
| | | Search, Refresh, Plus, Discount, Setting, Download, Delete, Edit, |
| | | Warning |
| | | } from '@element-plus/icons-vue' |
| | | import { listPage, update, del, add } from '@/api/procurementManagement/advancedPriceManagement' |
| | | |
| | | // 响应式数据 |
| | | const loading = ref(false) |
| | |
| | | // 搜索表单 |
| | | const searchForm = reactive({ |
| | | productName: '', |
| | | supplierId: '', |
| | | priceStatus: '' |
| | | supplierId: '' |
| | | }) |
| | | |
| | | const total = ref(0) |
| | | |
| | | // 分页 |
| | | const pagination = reactive({ |
| | | currentPage: 1, |
| | | pageSize: 20, |
| | | total: 0 |
| | | current: 1, |
| | | size: 20 |
| | | }) |
| | | |
| | | |
| | |
| | | reason: '', |
| | | remark: '' |
| | | }) |
| | | |
| | | const tableData = ref([]) |
| | | |
| | | // 批量折扣表单 |
| | | const batchDiscountForm = reactive({ |
| | |
| | | reason: [{ required: true, message: '请选择调价原因', trigger: 'change' }] |
| | | } |
| | | |
| | | // 模拟数据 |
| | | const tableData = ref([ |
| | | { |
| | | id: 1, |
| | | productName: '高强度螺栓', |
| | | productCode: 'HQ001', |
| | | specification: 'M12×80', |
| | | supplierName: '优质五金供应商', |
| | | basePrice: 2.50, |
| | | discountType: 'percentage', |
| | | discountValue: 10, |
| | | priceControl: { minPrice: 2.00, maxPrice: 3.00 }, |
| | | status: 'active', |
| | | effectiveTime: '2025-01-01 00:00:00', |
| | | updateTime: '2025-09-17 10:30:00', |
| | | unit: '个', |
| | | reason: 'market', |
| | | remark: '市场价格调整' |
| | | }, |
| | | { |
| | | id: 2, |
| | | productName: '不锈钢管', |
| | | productCode: 'BXG002', |
| | | specification: 'Φ25×2.0', |
| | | supplierName: '钢材贸易公司', |
| | | basePrice: 45.80, |
| | | discountType: 'fixed', |
| | | discountValue: 5, |
| | | priceControl: { minPrice: 40.00, maxPrice: 50.00 }, |
| | | status: 'pending', |
| | | effectiveTime: '2025-10-01 00:00:00', |
| | | updateTime: '2025-09-16 14:20:00', |
| | | unit: '米', |
| | | reason: 'cost', |
| | | remark: '原材料成本上涨' |
| | | } |
| | | ]) |
| | | |
| | | const supplierList = ref([ |
| | | { id: 1, name: '优质五金供应商' }, |
| | | { id: 2, name: '钢材贸易公司' }, |
| | |
| | | { id: 3, name: '铝合金型材' } |
| | | ]) |
| | | |
| | | |
| | | // 计算属性 |
| | | const finalTableData = computed(() => { |
| | | return tableData.value.filter(item => { |
| | | if (searchForm.productName && !item.productName.includes(searchForm.productName)) return false |
| | | if (searchForm.supplierId && item.supplierId !== searchForm.supplierId) return false |
| | | if (searchForm.priceStatus && item.status !== searchForm.priceStatus) return false |
| | | |
| | | return true |
| | | }) |
| | | }) |
| | | |
| | | // 方法 |
| | | const calculateFinalPrice = (row) => { |
| | |
| | | const getDiscountText = (discountType) => { |
| | | const textMap = { |
| | | percentage: '百分比', |
| | | fixed: '固定金额', |
| | | tiered: '阶梯折扣' |
| | | fixed: '固定金额' |
| | | } |
| | | return textMap[discountType] || '未知' |
| | | } |
| | |
| | | const statusMap = { |
| | | active: 'success', |
| | | pending: 'warning', |
| | | expired: 'info', |
| | | suspended: 'danger' |
| | | expired: 'info' |
| | | } |
| | | return statusMap[status] || 'info' |
| | | } |
| | |
| | | const statusMap = { |
| | | active: '有效', |
| | | pending: '待生效', |
| | | expired: '已过期', |
| | | suspended: '已暂停' |
| | | expired: '已过期' |
| | | } |
| | | return statusMap[status] || '未知' |
| | | } |
| | |
| | | const handleSearch = () => { |
| | | loading.value = true |
| | | // 模拟API调用 |
| | | setTimeout(() => { |
| | | listPage({ ...searchForm, ...pagination}).then(res => { |
| | | tableData.value = res.data.records |
| | | total.value = res.data.total |
| | | loading.value = false |
| | | }, 500) |
| | | }) |
| | | } |
| | | |
| | | const resetSearch = () => { |
| | | Object.assign(searchForm, { |
| | | productName: '', |
| | | supplierId: '', |
| | | priceStatus: '' |
| | | supplierId: '' |
| | | }) |
| | | handleSearch() |
| | | } |
| | |
| | | await formRef.value.validate() |
| | | submitLoading.value = true |
| | | |
| | | // 模拟API调用 |
| | | setTimeout(() => { |
| | | if (dialogType.value === 'add') { |
| | | const newItem = { |
| | | id: Date.now(), |
| | | ...formData, |
| | | priceControl: { |
| | | minPrice: formData.minPrice, |
| | | maxPrice: formData.maxPrice |
| | | }, |
| | | status: 'pending', |
| | | updateTime: new Date().toLocaleString() |
| | | } |
| | | tableData.value.unshift(newItem) |
| | | add(formData).then(res => { |
| | | if (res.code === 200){ |
| | | ElMessage.success('新增成功') |
| | | handleSearch() |
| | | } |
| | | }) |
| | | } else { |
| | | // 编辑逻辑 |
| | | update(formData).then(res => { |
| | | if (res.code === 200){ |
| | | ElMessage.success('编辑成功') |
| | | handleSearch() |
| | | } |
| | | }) |
| | | } |
| | | |
| | | dialogVisible.value = false |
| | | submitLoading.value = false |
| | | }, 1000) |
| | | } catch (error) { |
| | | console.error('表单验证失败:', error) |
| | | }finally { |
| | | dialogVisible.value = false |
| | | submitLoading.value = false |
| | | } |
| | | } |
| | | |
| | |
| | | selectedRows.value.forEach(row => { |
| | | row.discountType = batchDiscountForm.discountType |
| | | row.discountValue = batchDiscountForm.discountValue |
| | | update(row).then(res => { |
| | | handleSearch() |
| | | }) |
| | | |
| | | ElMessage.success(`已为 ${selectedRows.value.length} 个商品设置折扣`) |
| | | }) |
| | | ElMessage.success('折扣设置成功') |
| | | batchDiscountVisible.value = false |
| | | |
| | | } |
| | | |
| | | const openPriceControlDialog = () => { |
| | |
| | | priceControlVisible.value = false |
| | | } |
| | | |
| | | const openDiscountDialog = (row) => { |
| | | // 单个商品折扣设置 |
| | | openDialog('edit', row) |
| | | } |
| | | |
| | | |
| | | const handleDelete = (row) => { |
| | | ElMessageBox.confirm('确定要删除这条记录吗?', '提示', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }).then(() => { |
| | | const index = tableData.value.findIndex(item => item.id === row.id) |
| | | if (index !== -1) { |
| | | tableData.value.splice(index, 1) |
| | | let ids = [row.id] |
| | | del(ids).then(res => { |
| | | if(res.code === 200){ |
| | | ElMessage.success('删除成功') |
| | | handleSearch() |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | | }).then(() => { |
| | | selectedRows.value.forEach(row => { |
| | | const index = tableData.value.findIndex(item => item.id === row.id) |
| | | if (index !== -1) { |
| | | tableData.value.splice(index, 1) |
| | | del(selectedRows.value.map(item => item.id)).then(i =>{ |
| | | if(i.code === 200){ |
| | | ElMessage.success('删除成功') |
| | | handleSearch() |
| | | } |
| | | }) |
| | | ElMessage.success('批量删除成功') |
| | | selectedRows.value = [] |
| | | }) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | const handleSizeChange = (size) => { |
| | | pagination.pageSize = size |
| | | pagination.size = size |
| | | handleSearch() |
| | | } |
| | | |
| | | const handleCurrentChange = (page) => { |
| | | pagination.currentPage = page |
| | | pagination.current = page |
| | | handleSearch() |
| | | } |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | | const exportData = () => { |
| | | ElMessage.success('数据导出功能开发中...') |
| | | ElMessageBox.confirm("内容将被导出,是否确认导出?", "导出", { |
| | | confirmButtonText: "确认", |
| | | cancelButtonText: "取消", |
| | | type: "warning", |
| | | }) |
| | | .then(() => { |
| | | proxy.download("/procurementPriceManagement/export", {}, "采购价格管理.xlsx"); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msg("已取消"); |
| | | }); |
| | | } |
| | | |
| | | // 生命周期 |