Commit 4fbb7ab7 by linjinhong

修改编辑

parent ef6bb62a
...@@ -9,7 +9,7 @@ interface Ikey { ...@@ -9,7 +9,7 @@ interface Ikey {
[key: string]: unknown [key: string]: unknown
} }
interface ILogisticsParams { interface ILogisticsParams {
logType: 'logistics_way' | 'logistics_address' logType: string
relaId: number | string relaId: number | string
} }
//获取日志 //获取日志
......
...@@ -539,7 +539,7 @@ async function showLog(row) { ...@@ -539,7 +539,7 @@ async function showLog(row) {
logDialogVisible.value = true logDialogVisible.value = true
try { try {
const { data } = await getLogisticsLog({ const { data } = await getLogisticsLog({
logType: 'logistics_way', logType: 'logistics_customs_rule',
relaId: row.id, relaId: row.id,
}) })
logList.value = data logList.value = data
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
<SearchForm <SearchForm
:config="searchConfig" :config="searchConfig"
@search="search" @search="search"
@add="addDialog"
:isAddBtn="false" :isAddBtn="false"
@delete="deleteFn" @delete="deleteFn"
v-model="searchForm" v-model="searchForm"
...@@ -47,29 +46,6 @@ ...@@ -47,29 +46,6 @@
</div> </div>
</div> </div>
</div> </div>
<LogDialog
:title="editForm.id ? '编辑物流方式' : '新增物流方式'"
dialogWidth="1000px"
v-model="dialogVisible"
@close="cancelFn"
>
<CustomizeForm
ref="editFormRef"
v-model="editForm"
:config="formConfig"
formItemWidth="100%"
>
</CustomizeForm>
<template #footer>
<div style="text-align: center">
<ElButton @click="cancelFn">取消</ElButton>
<ElButton type="primary" @click="save">保存</ElButton>
</div>
</template>
</LogDialog>
</template> </template>
<script setup lang="tsx"> <script setup lang="tsx">
...@@ -133,171 +109,43 @@ const searchConfig = ref([ ...@@ -133,171 +109,43 @@ const searchConfig = ref([
}, },
]) ])
const formConfig = ref([
{ title: '物流基础信息' },
{
prop: 'zone1',
type: 'input',
label: 'ZONE 1',
attrs: {
placeholder: '请输入ZONE 1',
},
},
{
prop: 'zone2',
type: 'input',
label: 'ZONE 2',
attrs: {
placeholder: '请输入ZONE 2',
},
},
{
prop: 'zone3',
type: 'input',
label: 'ZONE 3',
attrs: {
placeholder: '请输入ZONE 3',
},
},
{
prop: 'zone4',
type: 'input',
label: 'ZONE 4',
attrs: {
placeholder: '请输入ZONE 4',
},
},
{
prop: 'zone5',
type: 'input',
label: 'ZONE 5',
attrs: {
placeholder: '请输入ZONE 5',
},
},
{
prop: 'zone6',
type: 'input',
label: 'ZONE 6',
attrs: {
placeholder: '请输入ZONE 6',
},
},
{
prop: 'zone7',
type: 'input',
label: 'ZONE 7',
attrs: {
placeholder: '请输入ZONE 7',
},
},
{
prop: 'zone8',
type: 'input',
label: 'ZONE 8',
attrs: {
placeholder: '请输入ZONE 8',
},
},
{
prop: 'zone9',
type: 'input',
label: 'ZONE 9',
attrs: {
placeholder: '请输入ZONE 9',
},
},
])
const tableConfig = ref([]) const tableConfig = ref([])
onMounted(() => { onMounted(() => {
// loading.value = true
getAllList() getAllList()
}) })
/**
* @description: 搜索
*/
async function search() { async function search() {
await getList(searchForm.value) await getList(searchForm.value)
setCellStyle() setCellStyle()
} }
/**
* @description: 转换表格数据
*/
function getTableData(arr) { function getTableData(arr) {
// 防御式编程:处理非数组或空输入
if (!Array.isArray(arr) || arr.length === 0) return [] if (!Array.isArray(arr) || arr.length === 0) return []
// 使用 map 替代 forEach 实现不可变数据
return arr.map((parentItem) => { return arr.map((parentItem) => {
// 使用可选链 + 空值合并运算符处理嵌套数据
const quotationList = parentItem.logisticsZoneList ?? [] const quotationList = parentItem.logisticsZoneList ?? []
// 使用 Object.fromEntries 优化属性合并
quotationList?.forEach((el) => { quotationList?.forEach((el) => {
parentItem[el.logistics] = { parentItem[el.logistics] = {
codePrefix: el.codePrefix || '', codePrefix: el.codePrefix || '',
highlight: el.highlight, highlight: el.highlight,
logisticsId: el.logisticsId,
} }
}) })
// 返回新对象保持不可变性
return { return {
...parentItem, // 保留原属性 ...parentItem,
} }
}) })
} }
function cancelFn() { /**
dialogVisible.value = false * @description: 删除按钮
editFormRef.value?.resetFields() */
resetEditForm()
}
async function checkData() {
const [isValid, postData] = await Promise.all([
new Promise<boolean>((resolve) => {
editFormRef.value
?.validate()
.then(() => resolve(true))
.catch((err) => {
resolve(false)
console.log(err)
})
}),
new Promise<any>((resolve) => {
const params = { ...editForm.value }
resolve(params)
}),
])
console.log(isValid, postData)
return { isValid, postData }
}
const save = debounce(async () => {
const { isValid, postData } = await checkData()
if (isValid) {
try {
if (!postData.id) {
await addLogisticsZone({
...postData,
})
}
ElMessage({
message: '保存成功',
type: 'success',
offset: window.innerHeight / 2,
})
cancelFn()
search()
} catch (e) {
return
}
}
}, 400)
function addDialog() {
dialogVisible.value = true
}
async function deleteFn() { async function deleteFn() {
if (!selection.value.length) { if (!selection.value.length) {
return ElMessage({ return ElMessage({
...@@ -342,8 +190,13 @@ async function deleteFn() { ...@@ -342,8 +190,13 @@ async function deleteFn() {
// showError(e) // showError(e)
} }
} }
const loading = ref(false) const loading = ref(false)
const editParams = ref({}) const editParams = ref({})
/**
* @description: 获取列表
*/
async function getList(data?) { async function getList(data?) {
loading.value = true loading.value = true
try { try {
...@@ -352,61 +205,61 @@ async function getList(data?) { ...@@ -352,61 +205,61 @@ async function getList(data?) {
}) })
tableData.value = [...res.data] tableData.value = [...res.data]
try {
const arr = await getTableData(tableData.value)
const whiteList = ['logisticsZoneList', 'zoneName'] const arr = await getTableData(tableData.value)
const oldConfig = [
{ const whiteList = ['logisticsZoneList', 'zoneName']
prop: 'zoneName', const oldConfig = [
label: '分区', {
}, prop: 'zoneName',
] label: '分区',
const newConfig = [] },
if (arr.length) { ]
for (const key in arr[0]) { const newConfig = []
if (!whiteList.includes(key)) { if (arr.length) {
newConfig.push({ for (const key in arr[0]) {
prop: key, if (!whiteList.includes(key)) {
label: key, newConfig.push({
prop: key,
render: { label: key,
edit: ({ row }) => {
return ( render: {
<div> edit: ({ row }) => {
<ElInput return (
style={{ height: '24px' }} <div>
modelValue={row[key]?.codePrefix} <ElInput
onInput={(e) => { style={{ height: '24px' }}
row[key].codePrefix = e modelValue={row[key]?.codePrefix}
editParams.value = { onInput={(e) => {
zoneName: row.zoneName, console.log(233, row)
logistics: key, row[key].codePrefix = e
codePrefix: e || '', editParams.value = {
} zoneName: row.zoneName,
}} logistics: key,
/> codePrefix: e || '',
</div> logisticsId: row[key].logisticsId,
) }
}, }}
default: ({ row }) => { />
return ( </div>
<span )
class={row[key]?.highlight ? 'tableCell' : 'primaryCell'} },
> default: ({ row }) => {
{row[key]?.codePrefix} return (
</span> <span
) class={row[key]?.highlight ? 'tableCell' : 'primaryCell'}
}, >
{row[key]?.codePrefix}
</span>
)
}, },
}) },
} })
} }
} }
tableConfig.value = [...oldConfig, ...newConfig]
} catch (e) {
console.log(e)
} }
tableConfig.value = [...oldConfig, ...newConfig]
console.log(545, tableConfig.value)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} finally { } finally {
...@@ -414,17 +267,21 @@ async function getList(data?) { ...@@ -414,17 +267,21 @@ async function getList(data?) {
} }
} }
/**
* @description: 处理复选框
*/
function handleCheckboxRecords(value: never[]) { function handleCheckboxRecords(value: never[]) {
console.log(351, value) console.log(351, value)
selection.value = value selection.value = value
} }
/**
* @description: 设置单元格样式
*/
function setCellStyle() { function setCellStyle() {
const [cell, primaryCell] = ['.tableCell', '.primaryCell'].map((selector) => const [cell, primaryCell] = ['.tableCell', '.primaryCell'].map((selector) =>
document.querySelectorAll(selector), document.querySelectorAll(selector),
) )
console.log(404, cell)
const getAncestor = (element, level = 2) => { const getAncestor = (element, level = 2) => {
let current = element let current = element
while (level-- > 0 && current) { while (level-- > 0 && current) {
...@@ -452,17 +309,21 @@ function setCellStyle() { ...@@ -452,17 +309,21 @@ function setCellStyle() {
} }
} }
/**
* @description: 获取物流方式列表
*/
async function getAllList() { async function getAllList() {
try { try {
const res = await Promise.all([getlogisticsWayAllList(), getList()]) const res = await Promise.all([getlogisticsWayAllList(), getList()])
// console.log(545, res)
searchConfig.value[0].attrs!.options = [...(res[0]?.data || [])] searchConfig.value[0].attrs!.options = [...(res[0]?.data || [])]
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
} }
/**
* @description: 上传文件
*/
function onBeforeUploadImage(file) { function onBeforeUploadImage(file) {
const isIMAGE = const isIMAGE =
file.type == file.type ==
...@@ -474,16 +335,15 @@ function onBeforeUploadImage(file) { ...@@ -474,16 +335,15 @@ function onBeforeUploadImage(file) {
return isIMAGE return isIMAGE
} }
/**
* @description: 下载模版
*/
async function downloadExcel() { async function downloadExcel() {
try { try {
const res = await exportExcelLogisticsZone() const res = await exportExcelLogisticsZone()
// console.log(483, data)
const blob = new Blob([res]) const blob = new Blob([res])
// 2. 解析文件名(从响应头或自定义)
const filename = '物流分区模版.xlsx' const filename = '物流分区模版.xlsx'
// 3. 创建临时链接并触发下载
const link = document.createElement('a') const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob) link.href = window.URL.createObjectURL(blob)
link.download = filename link.download = filename
...@@ -492,6 +352,10 @@ async function downloadExcel() { ...@@ -492,6 +352,10 @@ async function downloadExcel() {
console.log(error) console.log(error)
} }
} }
/**
* @description: 导入
*/
async function exportExcel(file) { async function exportExcel(file) {
try { try {
const formData = new FormData() const formData = new FormData()
...@@ -507,6 +371,9 @@ async function exportExcel(file) { ...@@ -507,6 +371,9 @@ async function exportExcel(file) {
} }
} }
/**
* @description: table编辑关闭事件
*/
async function editClosed() { async function editClosed() {
console.log(1111111, editParams.value) console.log(1111111, editParams.value)
try { try {
......
...@@ -94,6 +94,17 @@ ...@@ -94,6 +94,17 @@
</div> </div>
</template> </template>
</LogDialog> </LogDialog>
<LogDialog
title="操作日志"
v-model="logDialogVisible"
@close="logDialogVisible = false"
>
<div v-for="item in logList" :key="item.id" style="margin-bottom: 8px">
<span style="margin-right: 10px">{{ item.createTime }}</span>
<span>{{ item.description }}</span>
</div>
</LogDialog>
</template> </template>
<script setup lang="tsx"> <script setup lang="tsx">
...@@ -108,6 +119,7 @@ import { ...@@ -108,6 +119,7 @@ import {
deleteLogisticsQuotation, deleteLogisticsQuotation,
importLogisticsQuotation, importLogisticsQuotation,
downloadLogisticsQuotationTemplate, downloadLogisticsQuotationTemplate,
getLogisticsLog,
} from '@/api/logistics' } from '@/api/logistics'
import type { LogisticsMethod } from '@/types/api/logistics' import type { LogisticsMethod } from '@/types/api/logistics'
import SearchForm from '@/components/SearchForm.tsx' import SearchForm from '@/components/SearchForm.tsx'
...@@ -118,7 +130,7 @@ import type { VxeTablePropTypes } from 'vxe-table' ...@@ -118,7 +130,7 @@ import type { VxeTablePropTypes } from 'vxe-table'
import usePageList from '@/utils/hooks/usePageList' import usePageList from '@/utils/hooks/usePageList'
import { useValue } from './hooks/useValue' import { useValue } from './hooks/useValue'
import { showConfirm } from '@/utils/ui' import { showConfirm } from '@/utils/ui'
import { Edit } from '@element-plus/icons-vue' import { Edit, List } from '@element-plus/icons-vue'
import { debounce } from 'lodash-es' import { debounce } from 'lodash-es'
const [searchForm] = useValue({ logisticsIdList: [] }) const [searchForm] = useValue({ logisticsIdList: [] })
...@@ -373,6 +385,15 @@ const tableConfig = ref([ ...@@ -373,6 +385,15 @@ const tableConfig = ref([
> >
<Edit /> <Edit />
</el-icon> </el-icon>
<el-icon
size="24"
title="日志"
color="#008aff"
style="cursor: pointer; vertical-align: middle"
onclick={() => showLog(row)}
>
<List />
</el-icon>
</div> </div>
), ),
}, },
...@@ -568,11 +589,7 @@ async function downloadExcel() { ...@@ -568,11 +589,7 @@ async function downloadExcel() {
const res = await downloadLogisticsQuotationTemplate() const res = await downloadLogisticsQuotationTemplate()
console.log(483, data) console.log(483, data)
const blob = new Blob([res]) const blob = new Blob([res])
// 2. 解析文件名(从响应头或自定义)
const filename = '物流报价模版.xlsx' const filename = '物流报价模版.xlsx'
// 3. 创建临时链接并触发下载
const link = document.createElement('a') const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob) link.href = window.URL.createObjectURL(blob)
link.download = filename link.download = filename
...@@ -612,15 +629,20 @@ async function updateExcel(file) { ...@@ -612,15 +629,20 @@ async function updateExcel(file) {
} }
} }
watch( const logList = ref([])
() => editForm.value, const logDialogVisible = ref(false)
(val) => { async function showLog(row) {
console.log('editForm', val) logDialogVisible.value = true
const bool = editForm.value?.['id'] ? true : false try {
console.log('bool', bool) const { data } = await getLogisticsLog({
}, logType: 'logistics_quotation',
{ deep: true, immediate: true }, relaId: row.id,
) })
logList.value = data
} catch (error) {
console.log(error)
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment