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
<template>
<view class="content">
<view class="cell">
<text>收件人</text>
<u-input v-model="address.name" :type="type" :border="border" placeholder="请输入收件人姓名" :clearable="false" />
</view>
<view class="cell">
<text>联系电话</text>
<u-input v-model="address.phone" :type="type" :border="border" placeholder="请输入联系电话" :clearable="false" />
</view>
<view class="cell">
<text>收货地址</text>
<u-input v-model="address.address" :type="type" :border="border" placeholder="请输入收货地址" :clearable="false" />
</view>
<view style="margin: 100upx auto;width: 30%;">
<u-button type="success" @click="baocun">保存</u-button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
isAdd:"",//判断是否为新增
address: {
name: "", //姓名
phone: "", //联系电话
address: "" //地址
} //地址信息
}
},
onLoad(opction) { //代替 vue 里面的 created
this.address = opction
if(JSON.stringify(opction) === '{}'){
this.isAdd=true
}else{
this.isAdd=false
}
console.log(this.isAdd);
},
onReady() { //代替 vue 里面的 mounted
},
methods: {
baocun() { //保存收货地址
if(this.isAdd){
if (this.$u.test.mobile(this.address.phone)) { //手机号验证
let data = {
name: this.address.name,
phone: this.address.phone,
address: this.address.address,
openid: uni.getStorageSync('openid'),
credentialNumber:"500226199407035525",
credentialType:1,
category:0
}
this.$request('wechatUser/contact/saveContact', data).then(res => {
if (res.code == '00') { //保存成功后跳转
this.$u.route("pages/vlog/orderPay/orderPay")
uni.showToast({
title: '保存成功',
duration: 1000
});
}else{
uni.showModal({
showCancel: false,
title: '提示',
content: res.message,
});
}
})
} else {
uni.showModal({
showCancel: false,
title: '提示',
content: "请正确输入手机号!",
});
}
}else{
if (this.$u.test.mobile(this.address.phone)) { //手机号验证
let data = {
id: this.address.id,
name: this.address.name,
phone: this.address.phone,
address: this.address.address,
openid: uni.getStorageSync('openid')
}
this.$request('wechatUser/contact/updateContact', data).then(res => {
if (res.code == '00') { //保存成功后跳转
this.$u.route("pages/vlog/orderPay/orderPay")
uni.showToast({
title: '保存成功',
duration: 1000
});
}else{
uni.showModal({
showCancel: false,
title: '提示',
content: res.message,
});
}
})
} else {
uni.showModal({
showCancel: false,
title: '提示',
content: "请正确输入手机号!",
});
}
}
},
}
}
</script>
<style lang="scss" scoped>
.content {
padding: 0 20rpx;
box-sizing: border-box;
margin: 0 auto;
}
.cell {
display: flex;
align-items: center;
height: 80upx;
line-height: 80upx;
border-bottom: 1upx solid #ccc;
text {
width: 20%;
margin-left: 30upx;
}
}
</style>