Commit 4fbb7ab7 by linjinhong

修改编辑

parent ef6bb62a
......@@ -9,7 +9,7 @@ interface Ikey {
[key: string]: unknown
}
interface ILogisticsParams {
logType: 'logistics_way' | 'logistics_address'
logType: string
relaId: number | string
}
//获取日志
......
......@@ -539,7 +539,7 @@ async function showLog(row) {
logDialogVisible.value = true
try {
const { data } = await getLogisticsLog({
logType: 'logistics_way',
logType: 'logistics_customs_rule',
relaId: row.id,
})
logList.value = data
......
......@@ -4,7 +4,6 @@
<SearchForm
:config="searchConfig"
@search="search"
@add="addDialog"
:isAddBtn="false"
@delete="deleteFn"
v-model="searchForm"
......@@ -47,29 +46,6 @@
</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>
<script setup lang="tsx">
......@@ -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([])
onMounted(() => {
// loading.value = true
getAllList()
})
/**
* @description: 搜索
*/
async function search() {
await getList(searchForm.value)
setCellStyle()
}
/**
* @description: 转换表格数据
*/
function getTableData(arr) {
// 防御式编程:处理非数组或空输入
if (!Array.isArray(arr) || arr.length === 0) return []
// 使用 map 替代 forEach 实现不可变数据
return arr.map((parentItem) => {
// 使用可选链 + 空值合并运算符处理嵌套数据
const quotationList = parentItem.logisticsZoneList ?? []
// 使用 Object.fromEntries 优化属性合并
quotationList?.forEach((el) => {
parentItem[el.logistics] = {
codePrefix: el.codePrefix || '',
highlight: el.highlight,
logisticsId: el.logisticsId,
}
})
// 返回新对象保持不可变性
return {
...parentItem, // 保留原属性
...parentItem,
}
})
}
function cancelFn() {
dialogVisible.value = false
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
}
/**
* @description: 删除按钮
*/
async function deleteFn() {
if (!selection.value.length) {
return ElMessage({
......@@ -342,8 +190,13 @@ async function deleteFn() {
// showError(e)
}
}
const loading = ref(false)
const editParams = ref({})
/**
* @description: 获取列表
*/
async function getList(data?) {
loading.value = true
try {
......@@ -352,7 +205,7 @@ async function getList(data?) {
})
tableData.value = [...res.data]
try {
const arr = await getTableData(tableData.value)
const whiteList = ['logisticsZoneList', 'zoneName']
......@@ -378,11 +231,13 @@ async function getList(data?) {
style={{ height: '24px' }}
modelValue={row[key]?.codePrefix}
onInput={(e) => {
console.log(233, row)
row[key].codePrefix = e
editParams.value = {
zoneName: row.zoneName,
logistics: key,
codePrefix: e || '',
logisticsId: row[key].logisticsId,
}
}}
/>
......@@ -404,9 +259,7 @@ async function getList(data?) {
}
}
tableConfig.value = [...oldConfig, ...newConfig]
} catch (e) {
console.log(e)
}
console.log(545, tableConfig.value)
} catch (error) {
console.log(error)
} finally {
......@@ -414,17 +267,21 @@ async function getList(data?) {
}
}
/**
* @description: 处理复选框
*/
function handleCheckboxRecords(value: never[]) {
console.log(351, value)
selection.value = value
}
/**
* @description: 设置单元格样式
*/
function setCellStyle() {
const [cell, primaryCell] = ['.tableCell', '.primaryCell'].map((selector) =>
document.querySelectorAll(selector),
)
console.log(404, cell)
const getAncestor = (element, level = 2) => {
let current = element
while (level-- > 0 && current) {
......@@ -452,17 +309,21 @@ function setCellStyle() {
}
}
/**
* @description: 获取物流方式列表
*/
async function getAllList() {
try {
const res = await Promise.all([getlogisticsWayAllList(), getList()])
// console.log(545, res)
searchConfig.value[0].attrs!.options = [...(res[0]?.data || [])]
} catch (error) {
console.log(error)
}
}
/**
* @description: 上传文件
*/
function onBeforeUploadImage(file) {
const isIMAGE =
file.type ==
......@@ -474,16 +335,15 @@ function onBeforeUploadImage(file) {
return isIMAGE
}
/**
* @description: 下载模版
*/
async function downloadExcel() {
try {
const res = await exportExcelLogisticsZone()
// console.log(483, data)
const blob = new Blob([res])
// 2. 解析文件名(从响应头或自定义)
const filename = '物流分区模版.xlsx'
// 3. 创建临时链接并触发下载
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = filename
......@@ -492,6 +352,10 @@ async function downloadExcel() {
console.log(error)
}
}
/**
* @description: 导入
*/
async function exportExcel(file) {
try {
const formData = new FormData()
......@@ -507,6 +371,9 @@ async function exportExcel(file) {
}
}
/**
* @description: table编辑关闭事件
*/
async function editClosed() {
console.log(1111111, editParams.value)
try {
......
......@@ -94,6 +94,17 @@
</div>
</template>
</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>
<script setup lang="tsx">
......@@ -108,6 +119,7 @@ import {
deleteLogisticsQuotation,
importLogisticsQuotation,
downloadLogisticsQuotationTemplate,
getLogisticsLog,
} from '@/api/logistics'
import type { LogisticsMethod } from '@/types/api/logistics'
import SearchForm from '@/components/SearchForm.tsx'
......@@ -118,7 +130,7 @@ import type { VxeTablePropTypes } from 'vxe-table'
import usePageList from '@/utils/hooks/usePageList'
import { useValue } from './hooks/useValue'
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'
const [searchForm] = useValue({ logisticsIdList: [] })
......@@ -373,6 +385,15 @@ const tableConfig = ref([
>
<Edit />
</el-icon>
<el-icon
size="24"
title="日志"
color="#008aff"
style="cursor: pointer; vertical-align: middle"
onclick={() => showLog(row)}
>
<List />
</el-icon>
</div>
),
},
......@@ -568,11 +589,7 @@ async function downloadExcel() {
const res = await downloadLogisticsQuotationTemplate()
console.log(483, data)
const blob = new Blob([res])
// 2. 解析文件名(从响应头或自定义)
const filename = '物流报价模版.xlsx'
// 3. 创建临时链接并触发下载
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = filename
......@@ -612,15 +629,20 @@ async function updateExcel(file) {
}
}
watch(
() => editForm.value,
(val) => {
console.log('editForm', val)
const bool = editForm.value?.['id'] ? true : false
console.log('bool', bool)
},
{ deep: true, immediate: true },
)
const logList = ref([])
const logDialogVisible = ref(false)
async function showLog(row) {
logDialogVisible.value = true
try {
const { data } = await getLogisticsLog({
logType: 'logistics_quotation',
relaId: row.id,
})
logList.value = data
} catch (error) {
console.log(error)
}
}
</script>
<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