|
|
@@ -1,31 +1,38 @@
|
|
1
|
1
|
<template>
|
|
2
|
|
- <nut-form :model-value="formData" ref="ruleForm">
|
|
3
|
|
- <nut-form-item label="联系人" prop="name"
|
|
4
|
|
- required
|
|
5
|
|
- :rules="[{ required: true, message: '请填写姓名' }]">
|
|
6
|
|
- <nut-input class="nut-input-text" @blur="customBlurValidate('name')"
|
|
7
|
|
- v-model="formData.name"
|
|
8
|
|
- placeholder="请输入姓名" type="text" />
|
|
|
2
|
+ <nut-form :model-value="state.userAddress" ref="ruleForm">
|
|
|
3
|
+ <nut-form-item label="联系人" prop="real_name"
|
|
|
4
|
+ required>
|
|
|
5
|
+ <nut-input class="nut-input-text"
|
|
|
6
|
+ v-model="state.userAddress.real_name"
|
|
|
7
|
+ placeholder="请输入姓名" type="text"/>
|
|
9
|
8
|
</nut-form-item>
|
|
10
|
9
|
|
|
11
|
|
- <nut-form-item label="手机号码" prop="phone" required :rules="[
|
|
12
|
|
- { required: true, message: '请填写联系电话' },
|
|
13
|
|
- { validator: asyncValidator, message: '电话格式不正确' }
|
|
14
|
|
- ]">
|
|
15
|
|
- <nut-input class="nut-input-text" v-model="formData.phone" placeholder="请填写手机号码" type="text" />
|
|
|
10
|
+ <nut-form-item label="手机号码" prop="phone" required>
|
|
|
11
|
+ <nut-input class="nut-input-text" v-model="state.userAddress.phone" placeholder="请填写手机号码" type="text"/>
|
|
16
|
12
|
</nut-form-item>
|
|
17
|
13
|
<nut-form-item label="收货地址"
|
|
18
|
14
|
required
|
|
19
|
15
|
prop="address"
|
|
20
|
|
- :rules="[{ required: true, message: '请选择收货地址' }]"
|
|
21
|
16
|
>
|
|
22
|
|
- <div class="nut-input-text"
|
|
23
|
|
- @click="addressData.visible = true"
|
|
24
|
|
- >
|
|
25
|
|
- {{formData.address.toString() === '' ? '省市区县、省镇等' : formData.address.toString()}}
|
|
26
|
|
- </div>
|
|
|
17
|
+<!-- <div class="nut-input-text"-->
|
|
|
18
|
+<!-- @click="addressData.visible = true"-->
|
|
|
19
|
+<!-- >-->
|
|
|
20
|
+<!-- </div>-->
|
|
27
|
21
|
|
|
|
22
|
+ <picker mode="multiSelector" @change="bindRegionChange"
|
|
|
23
|
+ @columnchange="bindMultiPickerColumnChange" :value="state.valueRegion" :range="state.multiArray">
|
|
|
24
|
+ <view class=" flex ">
|
|
|
25
|
+ <view class="picker" v-if="state.region[3]">
|
|
|
26
|
+ {{ state.region[0] }},{{ state.region[1] }},{{ state.region[2] }},{{ state.region[3] }}
|
|
|
27
|
+ </view>
|
|
|
28
|
+ <view class="picker" v-else>
|
|
|
29
|
+ {{ state.region[0] }},{{ state.region[1] }},{{ state.region[2] }}
|
|
|
30
|
+ </view>
|
|
|
31
|
+ <view class="iconfont icon-dizhi font-color"></view>
|
|
|
32
|
+ </view>
|
|
|
33
|
+ </picker>
|
|
28
|
34
|
|
|
|
35
|
+ <!--
|
|
29
|
36
|
<nut-cascader
|
|
30
|
37
|
title="地址选择"
|
|
31
|
38
|
v-model:visible="addressData.visible"
|
|
|
@@ -40,9 +47,10 @@
|
|
40
|
47
|
lazy
|
|
41
|
48
|
:lazyLoad="addressData.lazyLoad"
|
|
42
|
49
|
></nut-cascader>
|
|
|
50
|
+ -->
|
|
43
|
51
|
</nut-form-item>
|
|
44
|
52
|
<nut-form-item label="详细地址" prop="detail" required :rules="[{ required: true, message: '请填写详细地址' }]">
|
|
45
|
|
- <nut-input class="nut-input-text" v-model="formData.detail" placeholder="街道、楼牌号等" type="text" />
|
|
|
53
|
+ <nut-input class="nut-input-text" v-model="state.userAddress.detail" placeholder="街道、楼牌号等" type="text"/>
|
|
46
|
54
|
</nut-form-item>
|
|
47
|
55
|
<div class="p-4">
|
|
48
|
56
|
<div class="flex items-center justify-between">
|
|
|
@@ -50,34 +58,74 @@
|
|
50
|
58
|
<div>设置为默认地址</div>
|
|
51
|
59
|
<div class="text-xs text-gray">提醒:下单会优先使用该地址</div>
|
|
52
|
60
|
</div>
|
|
53
|
|
- <nut-switch v-model="formData.is_default"></nut-switch>
|
|
|
61
|
+ <nut-switch v-model="state.userAddress.is_default"></nut-switch>
|
|
54
|
62
|
|
|
55
|
63
|
</div>
|
|
56
|
64
|
</div>
|
|
57
|
65
|
|
|
58
|
66
|
<div class="fixed bottom-0 p-safe w-full ">
|
|
59
|
|
- <div class="px-3">
|
|
|
67
|
+ <div class="px-3" v-if="state.addNew == 1">
|
|
|
68
|
+ <nut-button block type="primary" @click="submit">保存</nut-button>
|
|
|
69
|
+ </div>
|
|
|
70
|
+
|
|
|
71
|
+ <div class="px-3 flex flex-col gap-3" v-else>
|
|
60
|
72
|
<nut-button block type="primary" @click="submit">保存</nut-button>
|
|
|
73
|
+ <nut-button block type="default" @click="handleDelete">删除</nut-button>
|
|
61
|
74
|
</div>
|
|
62
|
75
|
</div>
|
|
63
|
76
|
</nut-form>
|
|
64
|
77
|
</template>
|
|
65
|
78
|
<script lang="ts">
|
|
66
|
|
-import { ref,reactive } from 'vue';
|
|
|
79
|
+import {ref, reactive} from 'vue';
|
|
67
|
80
|
import type {FormItemRuleWithoutValidator} from "uniapp-nutui";
|
|
68
|
|
-import {addressNewCreate, getCityList, getCityNewFiveList} from "~/apis/user";
|
|
|
81
|
+import {addressNewCreate, deleteAddress, getCityList, getCityNewFiveList, getUserAddressDetail} from "~/apis/user";
|
|
69
|
82
|
import FSwitch from "~/components/FSwitch/FSwitch.vue";
|
|
|
83
|
+
|
|
70
|
84
|
export default {
|
|
71
|
85
|
components: {FSwitch},
|
|
72
|
|
- setup(){
|
|
|
86
|
+ setup() {
|
|
|
87
|
+ const userStore = useUserStore()
|
|
|
88
|
+
|
|
73
|
89
|
const formData = reactive({
|
|
|
90
|
+ address_id: 0,
|
|
74
|
91
|
name: '',
|
|
75
|
92
|
detail: '',
|
|
76
|
93
|
phone: '',
|
|
77
|
94
|
address: [],
|
|
78
|
95
|
is_default: false,
|
|
|
96
|
+
|
|
|
97
|
+ city_id: null,
|
|
|
98
|
+ code_list: '',
|
|
|
99
|
+ province: '',
|
|
|
100
|
+ city: '',
|
|
|
101
|
+ district: ''
|
|
79
|
102
|
});
|
|
80
|
103
|
|
|
|
104
|
+ const state = reactive({
|
|
|
105
|
+ cartId: '', // 购物车 id
|
|
|
106
|
+ pinkId: 0, // 拼团 id
|
|
|
107
|
+ couponId: 0, // 优惠劵 id
|
|
|
108
|
+ addressId: 0, // 地址 id
|
|
|
109
|
+ userAddress: {
|
|
|
110
|
+ is_default: false
|
|
|
111
|
+ },
|
|
|
112
|
+ addNew: 0,
|
|
|
113
|
+ region: ['省', '市', '区', '县'],
|
|
|
114
|
+ valueRegion: [0, 0, 0, 0],
|
|
|
115
|
+ defaultRegion: ['广东省', '广州市', '番禺区'],
|
|
|
116
|
+ defaultRegionCode: '440113',
|
|
|
117
|
+ district: [],
|
|
|
118
|
+ multiArray: [],
|
|
|
119
|
+ multiIndex: [0, 0, 0, 0],
|
|
|
120
|
+ wikmn: [],
|
|
|
121
|
+ wikmns: ['', 439, ''],
|
|
|
122
|
+ // cityId: city
|
|
|
123
|
+ cityId: 0,
|
|
|
124
|
+
|
|
|
125
|
+ dxz: '',
|
|
|
126
|
+ dhy: '',
|
|
|
127
|
+ ljq: '',
|
|
|
128
|
+ })
|
|
81
|
129
|
const basicData = reactive({
|
|
82
|
130
|
addressObject: [],
|
|
83
|
131
|
isDefaultVal: true,
|
|
|
@@ -106,68 +154,326 @@ export default {
|
|
106
|
154
|
}
|
|
107
|
155
|
})
|
|
108
|
156
|
|
|
109
|
|
- onLoad(() => {
|
|
|
157
|
+ onLoad((options) => {
|
|
|
158
|
+ if (userStore.uid) {
|
|
|
159
|
+ state.cartId = options.cartId || ''
|
|
|
160
|
+ state.pinkId = options.pinkId || 0
|
|
|
161
|
+ state.couponId = options.couponId || 0
|
|
|
162
|
+ state.addressId = options.id || 0
|
|
|
163
|
+ state.addNew = options.add || 1
|
|
110
|
164
|
|
|
111
|
|
- getCityNewFiveList(0).then(res => {
|
|
112
|
|
- // addressData.options.push()
|
|
113
|
|
- // province.forEach()
|
|
114
|
|
- res.forEach(province => {
|
|
115
|
|
- addressData.options.push(province)
|
|
116
|
|
- })
|
|
117
|
|
- })
|
|
118
|
|
- // getCityList().then(res => {
|
|
119
|
|
- // res.forEach((province) => {
|
|
|
165
|
+
|
|
|
166
|
+ uni.setNavigationBarTitle({
|
|
|
167
|
+ title: options.id ? '修改地址' : '新增收货地址'
|
|
|
168
|
+ });
|
|
|
169
|
+
|
|
|
170
|
+ getUserAddress()
|
|
|
171
|
+ loadCityList()
|
|
|
172
|
+
|
|
|
173
|
+ } else {
|
|
|
174
|
+ // LOGIN
|
|
|
175
|
+ // userStore.logout()
|
|
|
176
|
+ }
|
|
|
177
|
+ // getCityNewFiveList(0).then(res => {
|
|
|
178
|
+ // // addressData.options.push()
|
|
|
179
|
+ // // province.forEach()
|
|
|
180
|
+ // res.forEach(province => {
|
|
120
|
181
|
// addressData.options.push(province)
|
|
121
|
182
|
// })
|
|
122
|
183
|
// })
|
|
123
|
184
|
})
|
|
|
185
|
+
|
|
|
186
|
+ const loadCityList = () => {
|
|
|
187
|
+ uni.showLoading({
|
|
|
188
|
+ title: '加载中',
|
|
|
189
|
+ duration: 3000,
|
|
|
190
|
+ mask: true
|
|
|
191
|
+ })
|
|
|
192
|
+ getCityList().then(res => {
|
|
|
193
|
+ if (res) {
|
|
|
194
|
+ state.district = res
|
|
|
195
|
+ // console.log(res)
|
|
|
196
|
+ // 初始化
|
|
|
197
|
+ initializePickerValue()
|
|
|
198
|
+ }
|
|
|
199
|
+ uni.hideLoading()
|
|
|
200
|
+ }).catch(error => {
|
|
|
201
|
+ uni.hideLoading()
|
|
|
202
|
+ console.error(error)
|
|
|
203
|
+ })
|
|
|
204
|
+ }
|
|
|
205
|
+
|
|
|
206
|
+ const getUserAddress = () => {
|
|
|
207
|
+ if (!state.addressId) return false
|
|
|
208
|
+
|
|
|
209
|
+ getUserAddressDetail(state.addressId).then(res => {
|
|
|
210
|
+ let region = [res.province, res.city, res.district]
|
|
|
211
|
+ state.userAddress = res
|
|
|
212
|
+ state.region = region
|
|
|
213
|
+ state.cityId = res.city_id
|
|
|
214
|
+ })
|
|
|
215
|
+ }
|
|
|
216
|
+ const initializePickerValue = () => {
|
|
|
217
|
+ let province = []
|
|
|
218
|
+ let city = []
|
|
|
219
|
+ let area = []
|
|
|
220
|
+ let xian = []
|
|
|
221
|
+ if (state.district.length) {
|
|
|
222
|
+ let cityChildren = state.district[0].children || []
|
|
|
223
|
+ let areaChildren = cityChildren.length ? cityChildren[0].children || [] : []
|
|
|
224
|
+ let xianChildren = areaChildren.length ? areaChildren[0].children || [] : []
|
|
|
225
|
+
|
|
|
226
|
+ state.district.forEach((item => {
|
|
|
227
|
+ province.push(item.name)
|
|
|
228
|
+ }))
|
|
|
229
|
+ cityChildren.forEach((item) => {
|
|
|
230
|
+ city.push(item.name)
|
|
|
231
|
+ })
|
|
|
232
|
+ areaChildren.forEach((item) => {
|
|
|
233
|
+ area.push(item.name)
|
|
|
234
|
+ })
|
|
|
235
|
+ if (xianChildren.length) {
|
|
|
236
|
+ xianChildren.forEach((item) => {
|
|
|
237
|
+ xian.push(item.name)
|
|
|
238
|
+ })
|
|
|
239
|
+ }
|
|
|
240
|
+
|
|
|
241
|
+ state.multiArray = [province, city, area, xian]
|
|
|
242
|
+ }
|
|
|
243
|
+ }
|
|
|
244
|
+
|
|
|
245
|
+ const bindRegionChange = (e) => {
|
|
|
246
|
+ console.log(e)
|
|
|
247
|
+ let multiIndex = state.multiIndex
|
|
|
248
|
+ let province = state.district[multiIndex[0]] || {children: []}
|
|
|
249
|
+ let city = province.children[multiIndex[1]] || {city_id: 0}
|
|
|
250
|
+ let multiArray = state.multiArray
|
|
|
251
|
+ let value = e.detail.value
|
|
|
252
|
+ let wikmnss = state.wikmn
|
|
|
253
|
+ console.log(multiArray)
|
|
|
254
|
+ console.log(multiArray[0][value[0]])
|
|
|
255
|
+ state.region = [multiArray[0][value[0]], multiArray[1][value[1]], multiArray[2][value[2]], multiArray[3]
|
|
|
256
|
+ [value[3]]
|
|
|
257
|
+ ]
|
|
|
258
|
+ state.wikmns = [wikmnss[3][value[3]], wikmnss[2][value[2]]]
|
|
|
259
|
+
|
|
|
260
|
+ // console.log(wikmnss)
|
|
|
261
|
+ // state.wikmns = [wikmnss[3][value[3]], wikmnss[2][value[2]]]
|
|
|
262
|
+ // console.log(province.children[multiArray[1]])
|
|
|
263
|
+ state.cityId = city.city_id
|
|
|
264
|
+ // 表示选择了 range 中的第几个(下标从 0 开始)
|
|
|
265
|
+ // state.valueRegion = [0, 0, 0, 0]
|
|
|
266
|
+ // state.valueRegion = [5, 0, 0, 0]
|
|
|
267
|
+
|
|
|
268
|
+ initializePickerValue()
|
|
|
269
|
+ }
|
|
|
270
|
+
|
|
|
271
|
+ /// 来自-原小程序代码转换
|
|
|
272
|
+ const bindMultiPickerColumnChange = (e) => {
|
|
|
273
|
+ let column = e.detail.column
|
|
|
274
|
+ let value = e.detail.value
|
|
|
275
|
+ let currentCity = state.district[value] || {children: []}
|
|
|
276
|
+ let multiArray = state.multiArray
|
|
|
277
|
+ let multiIndex = state.multiIndex
|
|
|
278
|
+ let wikmns = state.wikmn
|
|
|
279
|
+ multiIndex[column] = value
|
|
|
280
|
+
|
|
|
281
|
+ switch (column) {
|
|
|
282
|
+ case 0:
|
|
|
283
|
+ let areaList = currentCity.children[0] || {
|
|
|
284
|
+ children: []
|
|
|
285
|
+ };
|
|
|
286
|
+ console.log(currentCity.id, currentCity.name, '省')
|
|
|
287
|
+ state.cityId = currentCity.id
|
|
|
288
|
+ // console.log(areaList.id, areaList.name, '市')
|
|
|
289
|
+ state.dxz = areaList.id
|
|
|
290
|
+ let isareaList = areaList.children[0] || {
|
|
|
291
|
+ children: []
|
|
|
292
|
+ };
|
|
|
293
|
+
|
|
|
294
|
+ // console.log(isareaList.id, isareaList.name, '区')
|
|
|
295
|
+ state.dhy = isareaList.id
|
|
|
296
|
+ let isareaListssssss = areaList.children[0] || {
|
|
|
297
|
+ children: []
|
|
|
298
|
+ };
|
|
|
299
|
+ let xianshi = isareaListssssss.children[0] || {
|
|
|
300
|
+ children: []
|
|
|
301
|
+ };
|
|
|
302
|
+ // console.log(xianshi.id, xianshi.name, '县')
|
|
|
303
|
+ state.ljq = xianshi.id
|
|
|
304
|
+ multiArray[1] = currentCity.children.map(item => {
|
|
|
305
|
+ return item.name;
|
|
|
306
|
+ });
|
|
|
307
|
+
|
|
|
308
|
+ multiArray[2] = areaList.children.map(item => {
|
|
|
309
|
+ return item.name;
|
|
|
310
|
+ });
|
|
|
311
|
+ if (areaList.children) {
|
|
|
312
|
+ wikmns[2] = areaList.children.map(item => {
|
|
|
313
|
+ return item.id;
|
|
|
314
|
+ });
|
|
|
315
|
+
|
|
|
316
|
+ } else {
|
|
|
317
|
+ wikmns[2] = []
|
|
|
318
|
+ }
|
|
|
319
|
+
|
|
|
320
|
+ if (isareaList.children) {
|
|
|
321
|
+ multiArray[3] = isareaList.children.map(item => {
|
|
|
322
|
+ return item.name;
|
|
|
323
|
+ });
|
|
|
324
|
+ } else {
|
|
|
325
|
+ multiArray[3] = []
|
|
|
326
|
+ }
|
|
|
327
|
+ if (isareaListssssss.children) {
|
|
|
328
|
+ wikmns[3] = isareaListssssss.children.map(item => {
|
|
|
329
|
+ return item.id;
|
|
|
330
|
+ });
|
|
|
331
|
+ } else {
|
|
|
332
|
+ multiArray[3] = []
|
|
|
333
|
+ }
|
|
|
334
|
+ state.multiArray = multiArray
|
|
|
335
|
+ break;
|
|
|
336
|
+ case 1:
|
|
|
337
|
+ let cityList = state.district[multiIndex[0]].children[multiIndex[1]].children || [];
|
|
|
338
|
+ multiArray[2] = cityList.map(item => {
|
|
|
339
|
+ return item.name;
|
|
|
340
|
+ });
|
|
|
341
|
+
|
|
|
342
|
+ let cityListssaaa = state.district[multiIndex[0]].children[multiIndex[1]].children || [];
|
|
|
343
|
+ if (cityListssaaa) {
|
|
|
344
|
+ wikmns[2] = cityListssaaa.map(item => {
|
|
|
345
|
+ return item.id;
|
|
|
346
|
+ });
|
|
|
347
|
+ }
|
|
|
348
|
+ state.cityId = state.district[multiIndex[0]].id
|
|
|
349
|
+ state.dxz = state.district[multiIndex[0]].children[multiIndex[1]].id
|
|
|
350
|
+ state.dhy = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]].id
|
|
|
351
|
+ state.ljq = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]].children[multiIndex[3]].id
|
|
|
352
|
+
|
|
|
353
|
+
|
|
|
354
|
+ let cityListss = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[
|
|
|
355
|
+ 2]] || [];
|
|
|
356
|
+ if (cityListss.children) {
|
|
|
357
|
+ multiArray[3] = cityListss.children.map(item => {
|
|
|
358
|
+ return item.name;
|
|
|
359
|
+ });
|
|
|
360
|
+ } else {
|
|
|
361
|
+ multiArray[3] = []
|
|
|
362
|
+ }
|
|
|
363
|
+ let cityListssssssssssss = state.district[multiIndex[0]].children[multiIndex[1]].children[
|
|
|
364
|
+ multiIndex[
|
|
|
365
|
+ 2]] || [];
|
|
|
366
|
+ if (cityListssssssssssss.children) {
|
|
|
367
|
+ wikmns[3] = cityListssssssssssss.children.map(item => {
|
|
|
368
|
+ return item.id;
|
|
|
369
|
+ });
|
|
|
370
|
+ } else {
|
|
|
371
|
+ wikmns[3] = []
|
|
|
372
|
+ }
|
|
|
373
|
+ break;
|
|
|
374
|
+ case 2:
|
|
|
375
|
+ let cityLists = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]]
|
|
|
376
|
+ .children || [];
|
|
|
377
|
+ multiArray[3] = cityLists.map(item => {
|
|
|
378
|
+ return item.name;
|
|
|
379
|
+ });
|
|
|
380
|
+ state.cityId = state.district[multiIndex[0]].id
|
|
|
381
|
+ state.dxz = state.district[multiIndex[0]].children[multiIndex[1]].id
|
|
|
382
|
+ state.dhy = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]].id
|
|
|
383
|
+ state.ljq = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]].children[multiIndex[3]].id
|
|
|
384
|
+ let cityListsss = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]]
|
|
|
385
|
+ .children || [];
|
|
|
386
|
+ wikmns[3] = cityListsss.map(item => {
|
|
|
387
|
+ return item.id;
|
|
|
388
|
+ });
|
|
|
389
|
+ break;
|
|
|
390
|
+ case 3:
|
|
|
391
|
+ let cityListsw = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]]
|
|
|
392
|
+ .children || [];
|
|
|
393
|
+ multiArray[3] = cityListsw.map(item => {
|
|
|
394
|
+ return item.name;
|
|
|
395
|
+ });
|
|
|
396
|
+ state.cityId = state.district[multiIndex[0]].id
|
|
|
397
|
+ state.dxz = state.district[multiIndex[0]].children[multiIndex[1]].id
|
|
|
398
|
+ state.dhy = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]].id
|
|
|
399
|
+ state.ljq = state.district[multiIndex[0]].children[multiIndex[1]].children[multiIndex[2]].children[multiIndex[3]].id
|
|
|
400
|
+
|
|
|
401
|
+ break;
|
|
|
402
|
+
|
|
|
403
|
+ }
|
|
|
404
|
+ // console.log(multiArray)
|
|
|
405
|
+ // state.multiArray = multiArray
|
|
|
406
|
+ state.multiArray[0] = multiArray[0]
|
|
|
407
|
+ state.multiArray[1] = multiArray[1]
|
|
|
408
|
+ state.multiArray[2] = multiArray[2]
|
|
|
409
|
+ state.multiIndex = multiIndex
|
|
|
410
|
+
|
|
|
411
|
+ }
|
|
124
|
412
|
const validate = (item: any) => {
|
|
125
|
413
|
console.log(item);
|
|
126
|
414
|
};
|
|
127
|
415
|
const ruleForm = ref<any>(null);
|
|
128
|
416
|
|
|
129
|
417
|
const submit = () => {
|
|
130
|
|
- ruleForm.value.validate().then(({ valid, errors }: any) => {
|
|
|
418
|
+ ruleForm.value.validate().then(({valid, errors}: any) => {
|
|
131
|
419
|
if (valid) {
|
|
132
|
|
- console.log('success', formData);
|
|
133
|
|
- const province = formData.address[0]
|
|
134
|
|
- const city = formData.address[1]
|
|
135
|
|
- const district = formData.address[2]
|
|
136
|
|
- // const village = formData.address[3]
|
|
137
|
|
-
|
|
138
|
|
- // IDs
|
|
139
|
|
- const provinceId = basicData.addressObject[0].id
|
|
140
|
|
- const cityId = basicData.addressObject[1].id
|
|
141
|
|
- // const countryId = basicData.addressObject[2].id
|
|
142
|
|
- const districtId = basicData.addressObject[2].id
|
|
143
|
|
- const countryId = basicData.addressObject[3].id
|
|
144
|
|
- let villageId = ''
|
|
145
|
|
- let village = ''
|
|
146
|
|
- // const province =
|
|
147
|
|
- let code_list = ''
|
|
148
|
|
- if (formData.address[3]) {
|
|
149
|
|
- // codeList = mProvinceId + "," + mCityId + "," + mCountyId + "," + mVillageId;
|
|
150
|
|
- code_list = provinceId + ',' + cityId + ',' + districtId + ',' + countryId
|
|
151
|
|
- } else {
|
|
152
|
|
- code_list = provinceId + ',' + cityId + ',' + districtId
|
|
|
420
|
+ let formValue: any = {}
|
|
|
421
|
+
|
|
|
422
|
+ if (!state.userAddress.real_name) {
|
|
|
423
|
+ return uni.showToast({
|
|
|
424
|
+ title: '请输入收货人的姓名'
|
|
|
425
|
+ })
|
|
|
426
|
+ }
|
|
|
427
|
+ if (!state.userAddress.phone) {
|
|
|
428
|
+ return uni.showToast({
|
|
|
429
|
+ title: '请输入手机号'
|
|
|
430
|
+ })
|
|
|
431
|
+ }
|
|
|
432
|
+ if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(state.userAddress.phone)) {
|
|
|
433
|
+ return uni.showToast({
|
|
|
434
|
+ title: '请输入正确的手机号码',
|
|
|
435
|
+ icon: 'none'
|
|
|
436
|
+ })
|
|
|
437
|
+ }
|
|
|
438
|
+ // console.log(state.region.toString())
|
|
|
439
|
+ if (JSON.stringify(state.region) === JSON.stringify(['省', '市', '区', '县'])) {
|
|
|
440
|
+ return uni.showToast({
|
|
|
441
|
+ title: '请选择收货地址',
|
|
|
442
|
+ icon: "none"
|
|
|
443
|
+ })
|
|
153
|
444
|
}
|
|
154
|
|
- if (formData.address[4]) {
|
|
155
|
|
- villageId = basicData.addressObject[4].id
|
|
156
|
|
- village = basicData.addressObject[4].value
|
|
|
445
|
+
|
|
|
446
|
+ if (!state.userAddress.detail) {
|
|
|
447
|
+ return uni.showToast({
|
|
|
448
|
+ title: '请填写详细地址',
|
|
|
449
|
+ icon: 'none'
|
|
|
450
|
+ })
|
|
157
|
451
|
}
|
|
|
452
|
+
|
|
|
453
|
+ formValue.real_name = state.userAddress.real_name
|
|
|
454
|
+ formValue.phone = state.userAddress.phone
|
|
|
455
|
+ formValue.detail = state.userAddress.detail
|
|
|
456
|
+
|
|
|
457
|
+ formValue.address_id = state.addressId
|
|
|
458
|
+ let regionArray = state.region
|
|
|
459
|
+ formValue.province = regionArray[0]
|
|
|
460
|
+ formValue.city = regionArray[1]
|
|
|
461
|
+ formValue.district = regionArray[2]
|
|
|
462
|
+
|
|
|
463
|
+ console.log(state.cityId)
|
|
|
464
|
+ if (state.cityId == undefined) {
|
|
|
465
|
+ // unPackageRegion.city_id = 1
|
|
|
466
|
+ formValue.city_id = 1
|
|
|
467
|
+ formValue.code_list = 1 + "," + 67449 + "," + 35 + "," + 493
|
|
|
468
|
+ } else {
|
|
|
469
|
+ formValue.city_id = state.cityId
|
|
|
470
|
+ formValue.code_list = state.cityId + ',' + state.dxz + ',' + state.dhy + ',' + state.ljq
|
|
|
471
|
+ }
|
|
|
472
|
+ formValue.is_default = state.userAddress.is_default ? 1 : 0
|
|
|
473
|
+
|
|
|
474
|
+
|
|
158
|
475
|
addressNewCreate({
|
|
159
|
|
- province,
|
|
160
|
|
- city,
|
|
161
|
|
- district,
|
|
162
|
|
- is_default: formData.is_default ? '1' : '0',
|
|
163
|
|
- phone: formData.phone,
|
|
164
|
|
- real_name: formData.name,
|
|
165
|
|
- detail: formData.detail,
|
|
166
|
|
- code_list,
|
|
167
|
|
- city_id: '2',
|
|
168
|
|
- village_id: villageId,
|
|
169
|
|
- village,
|
|
170
|
|
- // address_id
|
|
|
476
|
+ ...formValue
|
|
171
|
477
|
}).then(res => {
|
|
172
|
478
|
console.log(res)
|
|
173
|
479
|
if (res) {
|
|
|
@@ -175,20 +481,43 @@ export default {
|
|
175
|
481
|
title: '保存成功'
|
|
176
|
482
|
})
|
|
177
|
483
|
setTimeout(() => {
|
|
178
|
|
- uni.redirectTo({
|
|
179
|
|
- url: '/pages/user/address/index'
|
|
180
|
|
- })
|
|
181
|
|
- }, 500)
|
|
|
484
|
+ if (state.cartId) {
|
|
|
485
|
+ let cartId = state.cartId
|
|
|
486
|
+ let pinkId = state.pinkId
|
|
|
487
|
+ let couponId = state.couponId
|
|
|
488
|
+ state.cartId = ''
|
|
|
489
|
+ state.pinkId = ''
|
|
|
490
|
+ state.couponId = ''
|
|
|
491
|
+
|
|
|
492
|
+ uni.redirectTo({
|
|
|
493
|
+ url: '/pages/order-confirm/index?cartId=' +
|
|
|
494
|
+ cartId +
|
|
|
495
|
+ '&addressId=' +
|
|
|
496
|
+ (state.addressId ? state.addressId : res.address_id) +
|
|
|
497
|
+ '&pinkId=' +
|
|
|
498
|
+ '&couponId=' +
|
|
|
499
|
+ couponId
|
|
|
500
|
+ })
|
|
|
501
|
+ } else {
|
|
|
502
|
+ return uni.navigateBack({
|
|
|
503
|
+ delta: 1
|
|
|
504
|
+ })
|
|
|
505
|
+ }
|
|
|
506
|
+ // uni.redirectTo({
|
|
|
507
|
+ // url: '/pages/user/address/index'
|
|
|
508
|
+ // })
|
|
|
509
|
+ }, 1000)
|
|
182
|
510
|
}
|
|
183
|
511
|
}).catch(message => {
|
|
184
|
512
|
console.log(message)
|
|
|
513
|
+ uni.hideLoading()
|
|
185
|
514
|
uni.showToast({
|
|
186
|
515
|
icon: "none",
|
|
187
|
516
|
title: message
|
|
188
|
517
|
})
|
|
189
|
518
|
})
|
|
190
|
519
|
// formData.address
|
|
191
|
|
- console.log(formData.address.length)
|
|
|
520
|
+ // console.log(formData.address.length)
|
|
192
|
521
|
} else {
|
|
193
|
522
|
console.log('error submit!!', errors);
|
|
194
|
523
|
}
|
|
|
@@ -199,7 +528,7 @@ export default {
|
|
199
|
528
|
};
|
|
200
|
529
|
// 失去焦点校验
|
|
201
|
530
|
const customBlurValidate = (prop: string) => {
|
|
202
|
|
- ruleForm.value.validate(prop).then(({ valid, errors }: any) => {
|
|
|
531
|
+ ruleForm.value.validate(prop).then(({valid, errors}: any) => {
|
|
203
|
532
|
if (valid) {
|
|
204
|
533
|
console.log('success', formData);
|
|
205
|
534
|
|
|
|
@@ -233,16 +562,73 @@ export default {
|
|
233
|
562
|
console.log('pathChange', ...args);
|
|
234
|
563
|
},
|
|
235
|
564
|
};
|
|
236
|
|
- return { ruleForm, formData, basicData, addressData, events, validate, customValidator, customRulePropValidator, nameLengthValidator, asyncValidator, customBlurValidate, submit, reset };
|
|
|
565
|
+
|
|
|
566
|
+ function handleDelete() {
|
|
|
567
|
+ if (formData && formData.address_id) {
|
|
|
568
|
+ uni.showModal({
|
|
|
569
|
+ title: '温馨提示',
|
|
|
570
|
+ content: '是否删除该地址',
|
|
|
571
|
+ success: function (res) {
|
|
|
572
|
+ if (res.confirm) {
|
|
|
573
|
+ deleteAddress(formData.address_id).then(res => {
|
|
|
574
|
+ uni.showToast({
|
|
|
575
|
+ title: '删除成功',
|
|
|
576
|
+ icon: 'none'
|
|
|
577
|
+ })
|
|
|
578
|
+ setTimeout(() => {
|
|
|
579
|
+ uni.redirectTo({
|
|
|
580
|
+ url: '/pages/user/address/index'
|
|
|
581
|
+ })
|
|
|
582
|
+ }, 500)
|
|
|
583
|
+ }).catch(error => {
|
|
|
584
|
+ uni.showToast({
|
|
|
585
|
+ title: error,
|
|
|
586
|
+ icon: 'none'
|
|
|
587
|
+ })
|
|
|
588
|
+ })
|
|
|
589
|
+
|
|
|
590
|
+ }
|
|
|
591
|
+ }
|
|
|
592
|
+ })
|
|
|
593
|
+ }
|
|
|
594
|
+ }
|
|
|
595
|
+
|
|
|
596
|
+ return {
|
|
|
597
|
+ ruleForm,
|
|
|
598
|
+ formData,
|
|
|
599
|
+ basicData,
|
|
|
600
|
+ addressData,
|
|
|
601
|
+ events,
|
|
|
602
|
+ validate,
|
|
|
603
|
+ customValidator,
|
|
|
604
|
+ customRulePropValidator,
|
|
|
605
|
+ nameLengthValidator,
|
|
|
606
|
+ asyncValidator,
|
|
|
607
|
+ customBlurValidate,
|
|
|
608
|
+ submit,
|
|
|
609
|
+ reset,
|
|
|
610
|
+ state,
|
|
|
611
|
+ bindRegionChange,
|
|
|
612
|
+ bindMultiPickerColumnChange,
|
|
|
613
|
+ handleDelete,
|
|
|
614
|
+ };
|
|
237
|
615
|
}
|
|
238
|
616
|
}
|
|
|
617
|
+
|
|
|
618
|
+function bindMultiPickerColumnChange() {
|
|
|
619
|
+}
|
|
239
|
620
|
</script>
|
|
240
|
621
|
<style>
|
|
241
|
622
|
.nut-input-text {
|
|
242
|
623
|
color: #000 !important;
|
|
243
|
624
|
}
|
|
|
625
|
+
|
|
|
626
|
+.nut-cell-group__wrap {
|
|
|
627
|
+ background: none !important;
|
|
|
628
|
+ box-shadow: none !important;
|
|
|
629
|
+}
|
|
244
|
630
|
</style>
|
|
245
|
631
|
<route lang="yaml">
|
|
246
|
632
|
style:
|
|
247
|
|
- navigationBarTitleText: 收货地址
|
|
|
633
|
+navigationBarTitleText: 收货地址
|
|
248
|
634
|
</route>
|