addAddress.vue
4.62 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
<template>
<div class="editAddressBox">
<div class="editArea itemStyle">
<span><i>*</i>所在地区:</span>
<div class="rightForm">
<el-cascader
size="large"
:options="options"
v-model="$store.state.areaCode"
@change="addressChange">
</el-cascader>
</div>
</div>
<div class="itemStyle">
<span><i>*</i>详细地址:</span>
<div class="rightForm">
<el-input
type="textarea"
:rows="2"
placeholder="请输入地址"
resize="none"
v-model="newAddress.address">
</el-input>
</div>
</div>
<div class="itemStyle">
<span><i>*</i>收货人姓名:</span>
<div class="rightForm">
<el-input v-model="newAddress.receiveName" placeholder="请输入内容"></el-input>
</div>
</div>
<div class="itemStyle">
<span><i>*</i>手机号码:</span>
<div class="rightForm">
<el-input v-model="newAddress.receivePhone" placeholder="请输入内容"></el-input>
</div>
</div>
<div class="itemStyle">
<span></span>
<div class="rightForm">
<el-checkbox :false-label="0" :true-label="1" v-model="newAddress.ifDefault">设置为默认收货地址</el-checkbox>
</div>
</div>
<div class="dialogFooter">
<el-button @click="cancelAdd">取 消</el-button>
<el-button class="saveBtn" @click="newAddressData">确 定</el-button>
</div>
</div>
</template>
<script>
import { regionData, CodeToText } from 'element-china-area-data'
import { mapGetters, mapMutations } from 'vuex'
// import selectData from '@/assets/data.js'
export default {
name: 'addAddress',
data () {
return {
options: regionData,
areaData: ''
}
},
computed: {
...mapGetters([
'newAddress' // 新增修改收货地址
])
},
methods: {
...mapMutations({
seNewAddress: 'SET_NEWADDRESS', // 新增修改收货地址
setAreacode: 'SET_AREACODE' // 新增地区编码
}),
addressChange (arr) {
this.areaData = `${CodeToText[arr[0]]}-${CodeToText[arr[1]]}-${CodeToText[arr[2]]}`
},
newAddressData () {
if (this.newAddress.receiveAdress !== '') {
if (this.newAddress.address === '') {
this.$message.error('请填写详细地址!')
} else if (this.newAddress.receiveName === '') {
this.$message.error('请填写收件人姓名!')
} else if (this.newAddress.receivePhone === '') {
this.$message.error('请填写手机号码!')
} else {
let reg = /^1[13456789]\d{9}$/
if (!reg.test(this.newAddress.receivePhone)) {
this.$message.error('手机号格式错误')
return
}
this.newAddress.receiveAdress = this.areaData
this.$emit('hideAddDialog')
}
} else {
if (this.areaData === '') {
this.$message.error('请选择地区!')
} else if (this.newAddress.address === '') {
this.$message.error('请填写详细地址!')
} else if (this.newAddress.receiveName === '') {
this.$message.error('请填写收件人姓名!')
} else if (this.newAddress.receivePhone === '') {
this.$message.error('请填写手机号码!')
} else {
let reg = /^1[13456789]\d{9}$/
if (!reg.test(this.newAddress.receivePhone)) {
this.$message.error('手机号格式错误')
return
}
this.newAddress.receiveAdress = this.areaData
this.$emit('hideAddDialog')
}
}
},
cancelAdd () {
this.$emit('cancelAdd')
}
}
}
</script>
<style lang="scss" scoped>
.editAddressBox {
padding: 0 100px;
.itemStyle {
display: flex;
margin-bottom: 20px;
span {
width: 100px;
margin-right: 20px;
text-align: right;
padding-top: 5px;
}
i {
color: red;
margin-right: 3px;
}
.rightForm {
flex: 1;
>>> .el-cascader {
width: 100%;
}
>>> .el-checkbox__label {
font-size: 12px;
font-family: Microsoft YaHei;
color: #C5AA7B;
}
}
}
.dialogFooter {
display: flex;
justify-content: center;
width: 100%;
.el-button{
width: 200px;
height: 50px;
background: #F3F4F5;
border-radius: 0px;
padding: 0;
}
.saveBtn{
color: $mainGlod;
background-color: #333333;
border: 1px solid transparent;
}
}
}
</style>