guhongwei 2 lat temu
rodzic
commit
9addee882a
3 zmienionych plików z 18 dodań i 23 usunięć
  1. 1 1
      pages.json
  2. 5 0
      pagesMy/address/add.vue
  3. 12 22
      pagesMy/address/index.vue

+ 1 - 1
pages.json

@@ -158,7 +158,7 @@
 				{
 					"path": "address/add",
 					"style": {
-						"navigationBarTitleText": "修改地址"
+						"navigationBarTitleText": "新增地址"
 					}
 				},
 				{

+ 5 - 0
pagesMy/address/add.vue

@@ -103,6 +103,11 @@
 		onLoad: function(e) {
 			const that = this;
 			that.$set(that, `id`, e.id || '');
+			if (e.id) {
+				uni.setNavigationBarTitle({
+					title: '修改地址'
+				});
+			}
 			that.searchPor();
 			that.watchLogin();
 		},

+ 12 - 22
pagesMy/address/index.vue

@@ -6,7 +6,7 @@
 					<radio-group @change="addressChange">
 						<view class="list" v-for="(item,index) in list" :key="index">
 							<label class="radio" v-if="type=='shopping'">
-								<radio :value="item._id" :checked="index === address" />
+								<radio :value="item._id" :checked="item._id == address_id" />
 							</label>
 							<view class="list_1">
 								<view class="name">
@@ -52,6 +52,7 @@
 		data() {
 			return {
 				// 购物选地址
+				id: '',
 				type: '',
 				address_id: '',
 				// 系统设置
@@ -70,9 +71,9 @@
 		onLoad: function(e) {
 			const that = this;
 			that.$set(that, `type`, e && e.type || '');
-			that.$set(that, `id`, e && e.id || '');
+			that.$set(that, `address_id`, e && e.id || '');
 		},
-		onShow: async function() {
+		onShow: async function(e) {
 			const that = this;
 			that.searchConfig();
 			that.watchLogin();
@@ -134,15 +135,6 @@
 					let list = [...that.list, ...res.data];
 					that.$set(that, `list`, list);
 					that.$set(that, `total`, res.total)
-					if (list.length == 0) uni.$emit("id", '')
-					if (that.id) {
-						for (let i = 0; i < list.length; i++) {
-							if (list[i]._id === that.id) {
-								that.address_id = that.id;
-								break;
-							}
-						}
-					}
 				}
 			},
 			// 分页
@@ -174,16 +166,14 @@
 			// 选择收货地址
 			addressChange(e) {
 				const that = this;
-				for (let i = 0; i < that.list.length; i++) {
-					if (that.list[i]._id === e.detail.value) {
-						that.address_id = e.detail.value;
-						break;
-					}
+				let data = that.list.find((i) => i._id == e.detail.value);
+				if (data) {
+					that.address_id == data._id;
+					uni.$emit("id", e.detail.value);
+					uni.navigateBack({
+						delta: 1
+					});
 				}
-				uni.$emit("id", e.detail.value)
-				uni.navigateBack({
-					delta: 1
-				})
 			},
 			// 设置默认
 			toDefa(e) {
@@ -275,11 +265,11 @@
 						if (res.confirm) {
 							const arr = await that.$api(`/address/${e._id}`, 'DELETE');
 							if (arr.errcode == '0') {
-								if (that.address_id === e._id) uni.$emit("id", '')
 								uni.showToast({
 									title: '删除信息成功',
 									icon: 'none'
 								})
+								if (that.address_id == e._id) uni.$emit("id", '')
 								that.clearPage()
 								that.search()
 							} else {