|
@@ -19,10 +19,28 @@
|
|
|
|
|
|
<CtDialog :visible="showDialog" titleClass="text-h6" :footer="true" :widthType="3" :title="isAdd ? '新增收货地址' : '编辑收货地址'" @submit="handleSubmit" @close="handleClose">
|
|
<CtDialog :visible="showDialog" titleClass="text-h6" :footer="true" :widthType="3" :title="isAdd ? '新增收货地址' : '编辑收货地址'" @submit="handleSubmit" @close="handleClose">
|
|
<CtForm ref="CtFormRef" :items="formItems">
|
|
<CtForm ref="CtFormRef" :items="formItems">
|
|
|
|
+ <template #areaId="{ item }">
|
|
|
|
+ <div class="d-flex" style="width: 100%;">
|
|
|
|
+ <div class="mt-2" style="color: #777; width: 100px;">省市区 *</div>
|
|
|
|
+ <el-cascader
|
|
|
|
+ ref="cascaderAddr"
|
|
|
|
+ v-model="item.value"
|
|
|
|
+ size="large"
|
|
|
|
+ clearable
|
|
|
|
+ class="mb-5"
|
|
|
|
+ placeholder="省市区 *"
|
|
|
|
+ style="flex: 1;"
|
|
|
|
+ :props="{ value: 'id', label: 'name', emitPath: false }"
|
|
|
|
+ :options="item.items"
|
|
|
|
+ @change="handleChangeArea(item)"
|
|
|
|
+ @clear="item.labelValue = ''"
|
|
|
|
+ ></el-cascader>
|
|
|
|
+ </div>
|
|
|
|
+ </template>
|
|
<template #defaultStatus="{ item }">
|
|
<template #defaultStatus="{ item }">
|
|
<div class="d-flex align-center">
|
|
<div class="d-flex align-center">
|
|
<span class="color-666 mr-5">设为默认地址</span>
|
|
<span class="color-666 mr-5">设为默认地址</span>
|
|
- <v-switch v-model="item.value" label="" hide-details color="primary" inset></v-switch>
|
|
|
|
|
|
+ <v-switch v-model="item.value" hide-details color="primary"></v-switch>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
</CtForm>
|
|
</CtForm>
|
|
@@ -38,6 +56,7 @@ import { getDict } from '@/hooks/web/useDictionaries'
|
|
import Snackbar from '@/plugins/snackbar'
|
|
import Snackbar from '@/plugins/snackbar'
|
|
|
|
|
|
const isAdd = ref(true)
|
|
const isAdd = ref(true)
|
|
|
|
+const editId = ref(null)
|
|
const showDialog = ref(false)
|
|
const showDialog = ref(false)
|
|
const items = ref([])
|
|
const items = ref([])
|
|
const headers = [
|
|
const headers = [
|
|
@@ -48,6 +67,7 @@ const headers = [
|
|
{ title: '是否默认', key: 'defaultStatus', sortable: false, value: item => item.defaultStatus ? '是' : '否' },
|
|
{ title: '是否默认', key: 'defaultStatus', sortable: false, value: item => item.defaultStatus ? '是' : '否' },
|
|
{ title: '操作', key: 'actions', sortable: false }
|
|
{ title: '操作', key: 'actions', sortable: false }
|
|
]
|
|
]
|
|
|
|
+const cascaderAddr = ref()
|
|
const CtFormRef = ref()
|
|
const CtFormRef = ref()
|
|
const formItems = ref({
|
|
const formItems = ref({
|
|
options: [
|
|
options: [
|
|
@@ -70,16 +90,11 @@ const formItems = ref({
|
|
rules: [v => !!v || '请填写收货人联系电话']
|
|
rules: [v => !!v || '请填写收货人联系电话']
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- type: 'cascade',
|
|
|
|
|
|
+ slotName: 'areaId',
|
|
key: 'areaId',
|
|
key: 'areaId',
|
|
- value: [],
|
|
|
|
- default: [],
|
|
|
|
- label: '省市区',
|
|
|
|
- itemText: 'name',
|
|
|
|
- itemValue: 'id',
|
|
|
|
- required: true,
|
|
|
|
- clearable: false,
|
|
|
|
- emitPath: true,
|
|
|
|
|
|
+ labelValue: '',
|
|
|
|
+ value: null,
|
|
|
|
+ default: null,
|
|
items: []
|
|
items: []
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -93,8 +108,9 @@ const formItems = ref({
|
|
{
|
|
{
|
|
slotName: 'defaultStatus',
|
|
slotName: 'defaultStatus',
|
|
key: 'defaultStatus',
|
|
key: 'defaultStatus',
|
|
- value: false
|
|
|
|
- }
|
|
|
|
|
|
+ value: false,
|
|
|
|
+ default: false,
|
|
|
|
+ }
|
|
]
|
|
]
|
|
})
|
|
})
|
|
getDict('areaTreeData', null, 'areaTreeData').then(({ data }) => {
|
|
getDict('areaTreeData', null, 'areaTreeData').then(({ data }) => {
|
|
@@ -111,10 +127,18 @@ getAddressList()
|
|
|
|
|
|
// 新增
|
|
// 新增
|
|
const handleAdd = () => {
|
|
const handleAdd = () => {
|
|
|
|
+ formItems.value.options.forEach(e => e.value = e.default)
|
|
showDialog.value = true
|
|
showDialog.value = true
|
|
isAdd.value = true
|
|
isAdd.value = true
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 地区选择
|
|
|
|
+const handleChangeArea = (item) => {
|
|
|
|
+ const node = cascaderAddr.value.getCheckedNodes() ? cascaderAddr.value.getCheckedNodes()[0] : null
|
|
|
|
+ if (!node) return
|
|
|
|
+ item.labelValue = node.pathLabels.join(' ')
|
|
|
|
+}
|
|
|
|
+
|
|
// 设置为默认地址
|
|
// 设置为默认地址
|
|
const handleSetDefault = async (item) => {
|
|
const handleSetDefault = async (item) => {
|
|
Confirm('系统提示', '是否确定设置该地址为默认收货地址?').then(async () => {
|
|
Confirm('系统提示', '是否确定设置该地址为默认收货地址?').then(async () => {
|
|
@@ -127,24 +151,34 @@ const handleSetDefault = async (item) => {
|
|
// 编辑
|
|
// 编辑
|
|
const handleEdit = (item) => {
|
|
const handleEdit = (item) => {
|
|
isAdd.value = false
|
|
isAdd.value = false
|
|
|
|
+ editId.value = item.id
|
|
formItems.value.options.forEach(e => e.value = item[e.key])
|
|
formItems.value.options.forEach(e => e.value = item[e.key])
|
|
showDialog.value = true
|
|
showDialog.value = true
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 提交
|
|
|
|
+const handleClose = () => {
|
|
|
|
+ showDialog.value = false
|
|
|
|
+ editId.value = null
|
|
|
|
+}
|
|
|
|
+
|
|
const handleSubmit = async () => {
|
|
const handleSubmit = async () => {
|
|
const { valid } = await CtFormRef.value.formRef.validate()
|
|
const { valid } = await CtFormRef.value.formRef.validate()
|
|
if (!valid) return
|
|
if (!valid) return
|
|
const obj = {}
|
|
const obj = {}
|
|
- formItems.value.options.forEach(e => obj[e.key] = e.value)
|
|
|
|
- console.log(obj, 'submit')
|
|
|
|
- // try {
|
|
|
|
- // isAdd.value ? await createMallUserAddress(obj) : await updateMallUserAddress(obj)
|
|
|
|
- // } catch {}
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const handleClose = () => {
|
|
|
|
- showDialog.value = false
|
|
|
|
-
|
|
|
|
|
|
+ formItems.value.options.forEach(e => {
|
|
|
|
+ if (e.key === 'areaId') {
|
|
|
|
+ obj.areaId = e.value
|
|
|
|
+ obj.areaName = e.labelValue
|
|
|
|
+ } else obj[e.key] = e.value
|
|
|
|
+ })
|
|
|
|
+ if (!obj.areaId && !obj.areaName) return Snackbar.warning('请将必填项填写完整')
|
|
|
|
+ try {
|
|
|
|
+ isAdd.value ? await createMallUserAddress(obj) : await updateMallUserAddress(obj)
|
|
|
|
+ Snackbar.success(isAdd.value ? '新增成功' : '编辑成功')
|
|
|
|
+ handleClose()
|
|
|
|
+ getAddressList()
|
|
|
|
+ } catch {}
|
|
}
|
|
}
|
|
|
|
|
|
// 删除
|
|
// 删除
|