<template>
	<view class="content">
		<!-- #ifndef MP-WEIXIN -->
		<view class="address-list" v-for="(item,index) in list" :key='index'>
			<view @tap='goBackByAddress(item.addressId)' class="flex align-center">
				<view class="address-list-img">
					<image src="../../static/bbn.png" mode=""></image>
				</view>
				<view style="margin-left: 20rpx;flex: 1;">
					<view style="color: #333333;font-size: 31rpx;font-weight: bold;">
						{{item.name}}
						<text class="margin-left-sm" style="font-weight: normal;color: #999;">{{item.phone}}</text>
					</view>
					<view class="" style="color: #999;margin-top: 8rpx;font-size: 26rpx;">
						{{item.province}}{{item.city}}{{item.district}} {{item.detailsAddress}}
					</view>
				</view>
			</view>
			<view style="margin-top: 30rpx;height: 1rpx;background-color: #f7f7f7;margin-bottom: 10upx;"></view>
			<view style="display: flex;padding: 0 5upx 0 0;font-size: 26upx;">
				<radio-group name="openWay" style="text-align: left;width: 70%; margin-top:15rpx;">
					<label class="tui-radio">
						<radio :checked="item.isDefault == 1 ? true : false" color="#019c88" :disabled='item.isDefault == 1 ? false : true'
							style="transform:scale(0.6);" />
						<text style="font-size: 26upx;margin-left: 8upx;">默认地址</text>
					</label>
				</radio-group>
				<view style="display: flex;margin-left: 80upx;margin-top: 10rpx;width: 40%;text-align: right;">
					<view class="delete-view" @tap='deleteAddressList(item.addressId)'>删除</view>
					<view class="delete-view delete-btn" @tap='goAddress(item.addressId)'>编辑</view>
				</view>
			</view>
		</view>
		<view style="position: fixed;bottom: 0rpx;left: 0;right: 0;background: #FFFFFF;height: 110rpx;line-height: 110rpx;z-index: 999;">
			<button class="shouhuo" @tap="goAddress('')">
				新增地址
			</button>
		</view>
		<empty v-if="list.length == 0" :noneData="noneData"></empty>
		<!-- #endif -->
		<!-- 悬浮上拉 -->
		<!-- <view class="scroll_top" @tap="topScrollTap" v-bind:class="[scrollTop ? 'active' : '', '']"
			style="bottom: 56px;"><text class="iconfont icon-shangla"></text></view> -->
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty,
		},
		data() {
			return {
				openWay: 0,
				list: [],
				// loadingType: 0,
				type: 1,
				scrollTop: true,
				page: 1,
				limit: 5,
				address: '',
				isfa: '',
				noneData:'地址',
				orderXm:[]
			}
		},
		onShow() {
			let userId = this.$queue.getData('userId');
			if (userId) {
				this.getAddressList();
			}
		},
		onLoad(e) {
			this.isfa = e.id

			
			let userId = this.$queue.getData('userId');
			if (userId) {
				this.getAddressList();
			}
		},
		methods: {
			goBackByAddress(addressId) {
				// console.log("addressId",addressId)
				this.$queue.setData('EditAddress', addressId);
				if (this.isfa == 0) {
					console.log('1111111')
				}else if (this.isfa ==1 ) {
					this.updateaddress()
				}else if (this.isfa == 2) {
					uni.reLaunch({
						url:'/my/order/payModify'
					})
				}else if (this.isfa == '104') {
					uni.reLaunch({
						url:'/my/order/payModifyTc'
					})
				}else if (this.isfa == '105') {
					uni.reLaunch({
						url:'/my/order/payModifyCi'
					})
				}else if (this.isfa == '106') {
					uni.reLaunch({
						url:'/my/order/payModifyLiao'
					})
				} else if (this.isfa == 3) {
					this.updateaddress()
				}else if (this.isfa == 4) {
					uni.reLaunch({
						url:'/my/order/payModifyTcMy'
					})
				}else if (this.isfa == 6) {
					uni.reLaunch({
						url:'/my/order/payModifyJsDetail'
					})
				}else if (this.isfa == 5) {//项目待补单
					uni.reLaunch({
						url:'/my/order/payModifyDd'
					})
				}

			},
			updateaddress() {
				let addressId = this.$queue.getData('EditAddress')
				let data = {
					ordersId: this.isfa.order,
					addressId: addressId
				}
				this.$Request.post('/app/orders/updateOrdersAddress', data).then(res => {
					console.log(res)
					if (res.code == 0) {
						uni.showToast({
							title: '修改成功',
							icon: 'none'
						})
						uni.navigateBack();
					}
				})

			},
			deleteAddressList(id) {
				console.log(id)
				var id = id
				let data = {
					addressId: id,
				}
				uni.showModal({
					title: '温馨提示',
					content: '您确定要删除此地址信息吗?',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						if (res.confirm) {
							this.$Request.postT('/app/address/deleteAddress', data).then(res => {
								console.log(res)
								if (res.code == 0) {
									this.$queue.showToast("删除成功！");
									this.getAddressList();
								} else {
									this.$queue.showToast(res.msg);
								}
							});
						}
					}
				});
			},
			getAddressList() {
				uni.showLoading({
					title: '加载中...'
				});
				let userId = this.$queue.getData('userId');
				let data = {
					userId: userId,
					page: this.page,
					limit: this.limit
				}
				this.$Request.getT('/app/address/selectAddressListById', data).then(res => {
					uni.hideLoading();
					uni.stopPullDownRefresh();
					if (res.code == 0) {
						if (this.page == 1) this.list = []
						this.list = [...this.list, ...res.data.list]; //追加新数据
						console.log("数据",this.list)
					}
				});
			},
			goAddress(id) {
				uni.navigateTo({
					url: '/my/address/Endaddress?id=' + id
				});
			},
			tabSlect(item) {
				this.tabIndex = item.id;
			},
			selectWay(id) {
				this.openWay = id;
			},
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getAddressList();
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getAddressList();
		}

	}
</script>

<style lang="less" scoped>
	.delete-btn{
		margin-left: 10px;
	}
	.delete-view{
		width: 120rpx;
		text-align: center;
		background: #ecfbf8;
		border-radius: 30rpx;
		border: 1px solid #8ccfc5;
		font-weight: 400;
		font-size: 30rpx;
		color: #20a391;
		padding: 8rpx 10rpx;
	}
	.address-list-img{
		width: 91rpx;
		height: 91rpx;
	}
	.address-list-img image{
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}
	.address-list{
		width: 95%;
		margin: 12rpx auto;
		height: 246rpx;
		background: linear-gradient(to right, #ffffff, #fbffff,#ffffff);
		border-radius: 24rpx;
		height: max-content;
		padding: 30upx;
		display: flex;
		flex-direction: column;
		border: 1px solid #d7f2ee;
	}
	.content{
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background-color: #f7f7f7;
	}
	// @import '../../../static/less/index.less';
	// @import '../../../static/css/index.css';
	.shouhuo{
		margin: 16rpx 30upx;
		position: fixed;
		bottom: -2upx;
		width: 92%;
		height: 80rpx;
		background: linear-gradient(90deg, #019C88, #28BA92, #35C495);
		border-radius: 46rpx;
		line-height: 80rpx;
		font-weight: 400;
		font-size: 36rpx;
		color: #FFFFFF;
	}
	page {
		background: #f7f7f7;
	}

	.tui-line-cell {
		width: 100%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 2upx solid #f2f2f2;
		padding: 0 0 16upx 0;
	}

	.tui-title {
		line-height: 32rpx;
		min-width: 120rpx;
		flex-shrink: 0;
	}

	.tui-input {
		font-size: 32rpx;
		color: #333;
		padding-left: 20rpx;
		flex: 1;
	}
</style>
