addressCom.vue
3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template>
<el-drawer class="shoppingCartDrawerCon" title="收货地址管理" size="500px" :visible.sync="dialogShow" :direction="direction">
<glsx-combi-form class="edit-form-container" ref="editFormRef" label-width="100px" default-width="350px" :form-ref="editChildRef" :form-obj="editForm" :form-data="editFormData" :form-rules="editRule"></glsx-combi-form>
<div class="footer-btn">
<el-button @click="submit" type="primary">保存</el-button>
<el-button @click="dialogShow = false">取消</el-button>
</div>
</el-drawer>
</template>
<script>
import { checkPhone as validPhone } from '@/utils/index'
export default {
name: 'AddressCom',
props: {
visible: {
type: Boolean,
default: false
},
addressInfo: {
type: Object,
default: () => {
return {}
}
}
},
data() {
function checkPhone(rule, value, callback) {
if (!validPhone(value)) {
callback(new Error('请输入正确的手机号码'))
return false
}
callback()
}
return {
direction: 'rtl',
editFormData: [
{
label: '收货人',
name: 'contactName',
type: 'input',
maxlength: 10,
placeholder: '请输入姓名'
},
{
label: '收货人电话',
name: 'contactPhone',
type: 'input',
maxlength: 20,
placeholder: '请输入电话号码'
},
{
label: '收货地址',
name: 'contactAddress',
type: 'input',
maxlength: 50,
placeholder: '请输入收货地址',
inputType: 'textarea'
// tips: '如XX店车主关怀活动'
}
],
editForm: {
contactName: '',
contactPhone: '',
contactAddress: ''
},
editRule: {
contactName: [{ required: true, message: '请输入姓名', trigger: 'change' }],
contactPhone: [
{ required: true, message: '请输入电话号码', trigger: 'change' },
{ validator: checkPhone, trigger: 'blur' }
],
contactAddress: [{ required: true, message: '请输入收货地址', trigger: 'change' }]
},
editChildRef: 'editChildRef'
}
},
computed: {
dialogShow: {
get() {
return this.visible
},
set(val) {
this.$emit('update:visible', val)
}
}
},
watch: {
visible(val) {
if (val) {
this.editForm = this.addressInfo ? this.$common.utils.deepClone(this.addressInfo) : {}
}
}
},
methods: {
handleDetailClose() {},
handleOkFn() {
// console.log('您点击了确定')
},
handleRestFn() {
console.log('您点击了取消')
},
submit() {
this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) {
const params = this.$common.utils.deepClone(this.editForm)
this.$apis.purchaseShopping
.addressSave(params)
.then(result => {
this.$notify({
type: 'success',
title: '保存成功'
})
this.dialogShow = false
this.$emit('handleConfirmAddress')
})
.catch(err => {})
}
})
},
navBack() {}
}
}
</script>
<style lang="scss" scoped>
.shoppingCartDrawerCon {
// position: relative;
::v-deep .el-drawer__header {
border-bottom: 1px solid #e7eaec;
margin-bottom: 20px;
padding-bottom: 10px;
font-weight: 600;
font-size: 20px;
}
.footer-btn {
text-align: center;
}
}
</style>