Blame view
src/pages/address/addAddress.vue
6.91 KB
7d6833f2c 地址列表 |
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 |
<template> <form class="wrap" @submit="formSubmit" @reset="formReset" > <view class="content"> <view class="item,name"> <text class="itemText">姓名</text> <input placeholder="收货人姓名(真实姓名)" placeholder-style="color:#B8B8B8" name="name" :value="name" /> </view> <view class="item,phone"> <text class="itemText">电话</text> <input placeholder="手机号" type="digit" placeholder-style="color:#B8B8B8" name="mobile" v-model="mobile" /> </view> <view class="item,phone"> <text class="itemText">性别</text> <picker @change="bindPickerChange" :value="index" :range="sexArray" name="sex" > <view class="uni-input">{{sexArray[sexIndex]}}</view> </picker> </view> <view class="item,area"> <text class="itemText">地区</text> <view class="btn" v-if="pickerText===''" @tap="openAddres" >选择省/市/区</view> <view class="btn" v-else @tap="openAddres" >{{pickerText}}</view> <simple-address ref="SimpleAddress" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm" themeColor="#007AFF" name="address" ></simple-address> </view> <view class="item,address"> <text class="itemText">详细地址</text> <input placeholder="街道、小区门牌等详细地址" name="addDetail" :value="addDetial" /> </view> <view class="item,check"> <text class="itemText">设为默认地址</text> <switch :checked="isDefalutAddress" color="#FF6B4A" style="transform:scale(0.6)" @change="changeDefalutAddress" name="isDefault" /> </view> <input /> </view> <button form-type="submit" |
f112b6434 全面屏适配 |
80 81 82 |
class="button" v-if="addId" >编辑</button> |
4e9d88ff7 新建地址修改 |
83 84 |
<button form-type="submit" |
7d6833f2c 地址列表 |
85 |
class="button" |
4e9d88ff7 新建地址修改 |
86 |
v-else |
7d6833f2c 地址列表 |
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
>保存并使用</button> </form> </template> <script> import SimpleAddress from '@/components/SimpleAddress/SimpleAddress.vue' import store from '@/store' export default { data () { return { cityPickerValueDefault: [0, 0, 1], pickerText: '', isDefalutAddress: true, sexArray: ['男', '女'], sexIndex: 0, flag: 0, addId: undefined, name: '', mobile: '', addDetial: '', |
f112b6434 全面屏适配 |
108 |
isDefault: 0, |
7d6833f2c 地址列表 |
109 110 111 112 113 114 115 |
} }, onLoad (option) { const { addId } = option if (addId) { this.addId = addId store.dispatch('address/details', { |
f112b6434 全面屏适配 |
116 |
add_id: addId, |
7d6833f2c 地址列表 |
117 118 |
}).then(() => { uni.setNavigationBarTitle({ |
f112b6434 全面屏适配 |
119 |
title: '编辑地址', |
7d6833f2c 地址列表 |
120 |
}) |
f112b6434 全面屏适配 |
121 |
const { name, mobile, sex, add_detail: addDetial, default: isDefault, address } = this.$store.state.address.details |
7d6833f2c 地址列表 |
122 123 |
console.log('---', this.$store.state.address.details) const index = this.$refs.SimpleAddress.queryIndex(this.$store.state.address.details.address.split('-'), 'label') |
f112b6434 全面屏适配 |
124 |
console.log(index) |
7d6833f2c 地址列表 |
125 126 127 128 129 130 |
this.cityPickerValueDefault = index.index this.name = name this.mobile = Number(mobile) this.sexIndex = sex this.addDetial = addDetial this.isDefalutAddress = !!Number(isDefault) |
f112b6434 全面屏适配 |
131 |
this.pickerText = address |
7d6833f2c 地址列表 |
132 133 134 135 |
}) } }, components: { |
f112b6434 全面屏适配 |
136 |
SimpleAddress, |
7d6833f2c 地址列表 |
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
}, methods: { openAddres () { this.cityPickerValueDefault = [0, 0, 1] this.$refs.SimpleAddress.open() }, onConfirm (e) { this.pickerText = e.label console.log('lll', e, this.pickerText) }, changeDefalutAddress (e) { this.isDefalutAddress = e.target.value }, bindPickerChange (e) { console.log('picker发送选择改变,携带值为', e.target.value) this.sexIndex = e.target.value }, formValidation (formdata) { const { name, mobile, addDetail } = formdata this.flag = false if (name === '') { uni.showModal({ content: '请输入姓名', |
f112b6434 全面屏适配 |
160 |
showCancel: false, |
7d6833f2c 地址列表 |
161 162 163 164 165 166 |
}) return 0 } if (!(/^1[3456789]\d{9}$/.test(mobile))) { uni.showModal({ content: '请输入正确的手机号', |
f112b6434 全面屏适配 |
167 |
showCancel: false, |
7d6833f2c 地址列表 |
168 169 170 171 172 173 |
}) return 0 } if (this.pickerText === '') { uni.showModal({ content: '请选择收货地区', |
f112b6434 全面屏适配 |
174 |
showCancel: false, |
7d6833f2c 地址列表 |
175 176 177 178 179 180 |
}) return 0 } if (addDetail === '') { uni.showModal({ content: '请输入收货详细地址', |
f112b6434 全面屏适配 |
181 |
showCancel: false, |
7d6833f2c 地址列表 |
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
}) return 0 } this.flag = true }, formSubmit (e) { const formdata = e.detail.value this.formValidation(formdata) const { name, mobile, addDetail, isDefault } = formdata if (this.flag === true) { const params = { sex: this.sexIndex, name, address: this.pickerText, mobile, default: isDefault ? 1 : 0, add_detail: addDetail, |
323398550 若干功能添加 |
200 |
longitude: 1, |
f112b6434 全面屏适配 |
201 |
latitude: 1, |
7d6833f2c 地址列表 |
202 203 204 205 |
} if (this.addId) { params.add_id = this.addId } |
4e9d88ff7 新建地址修改 |
206 |
store.dispatch('address/edit', params).then(() => { |
f112b6434 全面屏适配 |
207 |
console.log('fanhui') |
4e9d88ff7 新建地址修改 |
208 |
uni.navigateBack({ |
f112b6434 全面屏适配 |
209 |
delta: 1, |
4e9d88ff7 新建地址修改 |
210 211 |
}) }) |
7d6833f2c 地址列表 |
212 |
} |
f112b6434 全面屏适配 |
213 214 |
}, }, |
7d6833f2c 地址列表 |
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
} </script> <style lang="scss"> .wrap { height: 100vh; background-color: #f2f2f2; font-family: PingFangSC-Regular; letter-spacing: -0.23px; padding-top: 19rpx; } .content { background-color: #ffffff; border-radius: 8px; border-radius: 8px; padding: 40rpx 56rpx; margin-left: 40rpx; width: 670rpx; box-sizing: border-box; .item { display: flex; justify-content: flex-start; font-size: 14px; align-items: center; height: 112rpx; border-bottom: 1rpx solid #e9e9e9; .itemText { width: 162rpx; font-family: PingFangSC-Regular; letter-spacing: -0.26px; } .btn { color: #333333 !important; } } .check { justify-content: space-between; } } .button { position: fixed; bottom: 0; left: 0; |
f112b6434 全面屏适配 |
258 |
height: 120rpx; |
7d6833f2c 地址列表 |
259 260 261 262 263 264 265 266 |
width: 100%; background: #ff6b4a; display: flex; justify-content: center; align-items: center; font-size: 16px; color: #ffffff; letter-spacing: -0.3px; |
f112b6434 全面屏适配 |
267 268 269 270 271 |
/* iphonex 等安全区设置,底部安全区适配 */ /* #ifndef APP-NVUE */ padding-bottom: constant(safe-area-inset-bottom); padding-bottom: env(safe-area-inset-bottom); /* #endif */ |
7d6833f2c 地址列表 |
272 273 |
} </style> |