addressCom.vue
5.83 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<template>
<el-drawer ref="drawerRef" class="shoppingCartDrawerCon" v-bind="$attrs" title="收货地址管理" size="774px" :direction="direction" :before-close="cancel">
<glsx-combi-form class="edit-form-container" ref="editFormRef" labelWidth="154px" defaultWidth="432px" :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule">
<span slot="provincesAndCities">
<el-cascader v-model="editForm.provincesAndCities" size="mini" ref="cascader" placeholder="请选择 省/市/区" style="width: 432px" :options="provincesAndCities_options" :props="{ label: 'name', value: 'code', children: 'childrenList' }" />
</span>
</glsx-combi-form>
<div class="footer-btn">
<span class="btn">
<el-button size="small" @click="cancel">取消</el-button>
<el-button size="small" @click="submit" type="primary">保存</el-button>
</span>
</div>
</el-drawer>
</template>
<script>
import glsxCombiForm from '@/components/glsx-combi-form'
export default {
name: 'AddressCom',
components: { glsxCombiForm },
props: {
addressInfo: {
type: Object,
default: () => {
return {}
}
}
},
data() {
let checkPhone = (rule, value, callback) => {
if (!this.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: 'provincesAndCities',
type: 'other',
addHtml: 'provincesAndCities'
},
{
label: '',
name: 'contactAddress',
type: 'input',
maxlength: 50,
placeholder: '请输入收货地址',
inputType: 'textarea',
rows: 3,
style: {
'padding-left': '154px'
}
}
],
editForm: {
contactName: '',
contactPhone: '',
contactAddress: '',
provincesAndCities: []
},
provincesAndCities_options: [],
editRule: {
contactName: [{ required: true, message: '请输入姓名', trigger: 'change' }],
contactPhone: [
{ required: true, message: '请输入电话号码', trigger: 'change' },
{ validator: checkPhone, trigger: 'blur' }
],
contactAddress: [{ required: true, message: '请输入收货地址', trigger: 'change' }],
provincesAndCities: [{ required: true, message: '请选择省市区', trigger: 'change' }]
},
editChildRef: 'editChildRef'
}
},
watch: {
addressInfo: {
immediate: true,
handler(val) {
if (val) {
this.editForm = this.$common.utils.deepClone(this.addressInfo)
this.editForm.provincesAndCities = [String(this.editForm.provinceId), String(this.editForm.cityId), String(this.editForm.areaId)]
} else {
this.editForm = {}
}
}
}
},
created() {
this.getAreaInfo()
},
methods: {
// 获取省市区信息
getAreaInfo() {
this.$apis.purchase.getAreaInfoApi({ areaType: '2' }).then(res => {
this.provincesAndCities_options = res.areaList
})
},
getProvincesAndCities() {
const nodesInfo = this.$refs.cascader.getCheckedNodes()
if (nodesInfo.length == 0 || Object.prototype.toString.call(nodesInfo[0]) != '[object Object]') {
return
}
this.editForm.provinceId = nodesInfo[0].pathNodes[0].value
this.editForm.provinceName = nodesInfo[0].pathNodes[0].label
this.editForm.cityId = nodesInfo[0].pathNodes[1].value
this.editForm.cityName = nodesInfo[0].pathNodes[1].label
this.editForm.areaId = nodesInfo[0].pathNodes[2].value
this.editForm.areaName = nodesInfo[0].pathNodes[2].label
},
submit() {
this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) {
this.getProvincesAndCities()
let { merchantId, accountName, merchantName } = this.$globalState.session
const params = this.$common.utils.deepClone(this.editForm)
params.merchantId = merchantId
params.merchantName = merchantName
params.updatedBy = accountName
delete params.provincesAndCities
this.$apis.purchase
.addressSave(params)
.then(result => {
this.$notify({
type: 'success',
title: '保存成功'
})
this.$parent.addressComVisible = false
this.$emit('handleConfirmAddress')
})
.catch(err => {})
}
})
},
cancel() {
this.$parent.addressComVisible = false
},
validPhone(mobile) {
const myreg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/
return myreg.test(mobile)
}
}
}
</script>
<style lang="scss" scoped>
.shoppingCartDrawerCon {
// position: relative;
/deep/ .el-drawer__header {
border-bottom: 1px solid #e7eaec;
margin-bottom: 20px;
padding-bottom: 10px;
font-weight: 600;
font-size: 20px;
}
/deep/ .el-textarea {
width: 580px !important;
.el-textarea__inner {
height: auto !important;
}
}
.footer-btn {
width: 774px;
height: 64px;
border-radius: 4px;
border-top: 1px solid #e5e5e5;
position: fixed;
bottom: 0;
text-align: right;
line-height: 64px;
.btn {
text-align: right;
margin-right: 20px;
}
}
}
</style>