• uniapp选择地址弹窗组件


    1.效果
    在这里插入图片描述
    2.子组件在components里面创建组件AddreessWindow

    <template>
    	<view style="position: relative;z-index: 999999 !important;">
    		<view class="address-window" :class="value === true ? 'on' : ''">
    			<view class="title">
    				<view>选择地址
    				view>
    				<view style="position: absolute;right: 20rpx;top: 39rpx;">
    					<u-icon name="close" color="#666" size="20" @click="closeAddress">u-icon>
    				view>
    			view>
    			<view class="list" v-if="addressList.length">
    				<view class="item acea-row row-between-wrapper" :class="item.id === checked ? 'font-color-green' : ''"
    					v-for="(item, addressIndex) in addressList" @click="tapAddress(addressIndex)" :key="addressIndex">
    					<u-icon name="map" :color="item.id === checked?'#99CC00':'#000'" size="20">u-icon>
    					
    					<view class="addressTxt">
    						<view class="name" :class="item.id === checked ? 'font-color-green' : ''">
    							{{ item.realName }}
    							<text class="phone">{{ item.phone }}text>
    						view>
    						<view class="line1"> {{ item.province }}{{ item.city }}{{ item.district }}{{ item.detail }}
    						view>
    					view>
    					
    					<u-icon name="checkmark" v-if="item.id === checked" color="#99CC00" size="20">u-icon>
    				view>
    			view>
    			<view class="pictrue" v-if="addressList.length < 1">
    				
    				<u-empty textSize='36rpx' text="空空如也" textColor='#A8D61E' width='512' height='251' mode="list"
    					:icon="`${imgUrl}empty.png`">u-empty>
    			view>
    			<view class="addressBnt bg-color-red"
    				style="background-color:#99CC00 !important;color: #FFFFFF !important; font-size: 31rpx !important;"
    				@click="goAddressPages">新加地址view>
    		view>
    		<view class="mask" @touchmove.prevent :hidden="value === false" @click="closeAddress">view>
    	view>
    template>
    <script>
    	// import { getAddressList } from '@/api/dsIndexApi.js'
    
    	export default {
    		name: 'AddressWindow',
    		props: {
    			value: Boolean,
    			checked: Number,
    			timer: Number
    		},
    		data: function() {
    			return {
    				imgUrl: '',
    				addressList: [],
    				current: 0,
    				cartId: 0,
    				pinkId: 0,
    				couponId: 0,
    			}
    		},
    		mounted: function() {
    			this.imgUrl = this.$VUE_APP_IMG_URL;
    		},
    		created() {
    			// console.
    		},
    		methods: {
    			getAddressList: function() {
    				let that = this;
    				that.addressList = [{
    						id: 1,
    						realName: '哈哈嗝',
    						phone: '14708291001',
    						province: "四川省",
    						city: "成都市",
    						district: "武侯区",
    						detail: "阳光大道",
    
    					},
    					{
    						id: 2,
    						realName: '张三',
    						phone: '14708291000',
    						province: "四川省",
    						city: "成都市",
    						district: "武侯区",
    						detail: "大悦城",
    
    					}
    				]
    				//   getAddressList().then(res => {
    				// // console.log('获取地址额列表',res)
    				//     that.addressList = res.data;
    				//   })
    			},
    
    			closeAddress() {
    				this.$emit('input', false)
    			},
    			goAddressPages: function() {
    				uni.navigateTo({
    					url: '/pages/address/address'
    				})
    				this.$emit('redirect')
    			},
    			tapAddress: function(index) {
    				this.$emit('checked', this.addressList[index])
    				this.$emit('input', false)
    			},
    		},
    		watch: {
    			timer(e, v) {
    				console.log(e, v, '变换了')
    				this.getAddressList()
    			},
    		},
    	}
    script>
    <style lang="scss">
    	.font-color-green {
    		color: #99CC00 !important;
    	}
    
    	.mask {
    		display: flex;
    		align-items: flex-end;
    		position: fixed;
    		left: 0;
    		top: 0px;
    		bottom: 0;
    		width: 100%;
    		background: rgba(0, 0, 0, 0.6);
    		z-index: 9995;
    		transition: .3s;
    	}
    
    	/*地址弹窗*/
    	.address-window {
    		background-color: #fff;
    		position: fixed;
    		bottom: 0;
    		left: 0;
    		width: 100%;
    		z-index: 10000;
    		transform: translate3d(0, 100%, 0);
    		transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
    	}
    
    	.address-window.on {
    		transform: translate3d(0, 0, 0);
    	}
    
    	.address-window .title {
    		font-size: 0.32 * 100rpx;
    		font-weight: bold;
    		text-align: center;
    		height: 1.23 * 100rpx;
    		line-height: 1.23 * 100rpx;
    		position: relative;
    		color: #333;
    		display: flex;
    		align-items: center;
    		justify-content: center;
    	}
    
    	.address-window .title .iconfont {
    		position: absolute;
    		right: 0.3 * 100rpx;
    		color: #8a8a8a;
    		font-size: 0.35 * 100rpx;
    	}
    
    	.address-window .list {
    		max-height: 6 * 100rpx;
    		overflow-y: auto;
    		overflow-x: hidden;
    	}
    
    	.address-window .list .item {
    		margin-left: 0.3 * 100rpx;
    		padding-right: 0.3 * 100rpx;
    		border-bottom: 1px solid #eee;
    		height: 1.29 * 100rpx;
    		font-size: 0.25 * 100rpx;
    		color: #333;
    		display: flex;
    		align-items: center;
    	}
    
    	.address-window .list .item .iconfont {
    		font-size: 0.37 * 100rpx;
    		color: #2c2c2c;
    	}
    
    	.address-window .list .item .iconfont.icon-complete {
    		font-size: 0.3 * 100rpx;
    		color: #fff;
    	}
    
    	.address-window .list .item .addressTxt {
    		width: 5.6 * 100rpx;
    	}
    
    	.address-window .list .item .addressTxt .name {
    		font-size: 0.28 * 100rpx;
    		font-weight: bold;
    		color: #282828;
    		margin-bottom: 0.04 * 100rpx;
    	}
    
    	.address-window .list .item .addressTxt .name .phone {
    		margin-left: 0.18 * 100rpx;
    	}
    
    	.address-window .addressBnt {
    		font-size: 0.3 * 100rpx;
    		font-weight: bold;
    		color: #fff;
    		width: 6.9 * 100rpx;
    		height: 0.86 * 100rpx;
    		border-radius: 0.43 * 100rpx;
    		text-align: center;
    		line-height: 0.86 * 100rpx;
    		margin: 0.85 * 100rpx auto;
    	}
    
    	.address-window .pictrue {
    		width: 4.14 * 100rpx;
    		height: 3.36 * 100rpx;
    		margin: 0.8 * 100rpx auto;
    	}
    
    	.address-window .pictrue .image {
    		width: 100%;
    		height: 100%;
    	}
    style>
    
    
    • 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
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237

    3.父组件

    <template>
    	<view class="container">
    	<view @click="skipAddress">选择地址view>
    		
    		<AddressWindow :timer="timer" @checked="changeAddress" @redirect="addressRedirect" v-model="showAddress"
    			:checked="addressInfo.id" ref="mychild">AddressWindow>
       view>
       template>
       <script>
    	export default {
    		data() {
    		return {
    				addressInfo: {},
    				addressLoaded: false,
    				timer: '',
    				showAddress: false,
    				}
    		},
    		methods:{
    		//选地址
    			skipAddress() {
    					this.timer = new Date().getTime();
    					this.showAddress = true;
    					if (!this.addressLoaded) {
    						this.addressLoaded = true
    						this.$refs.mychild.getAddressList()
    					}
    			},
    			// 控制地址弹框
    			addressRedirect() {
    				// this.addressLoaded = false
    				this.showAddress = false;
    			},
    			// 地址选择
    			changeAddress(addressInfo) {
    				this.addressInfo = addressInfo
    				// this.addressInfo.id = addressInfo.id;
    				console.log('地址栏11111', this.addressInfo)
    				//计算订单金额
    				// this.orderComputedAPi(this.addressInfo.id)
    		    	},
    			}
    		}
    		script>
    
    • 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
  • 相关阅读:
    java+mysql基于SSM的大学生兼职信息系统-计算机毕业设计
    vue3源码分析——实现createRenderer,增加runtime-test
    Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
    画布入门—由浅至深
    24个写出漂亮代码的小技巧
    前端开发中经常使用到的颜色:
    [附源码]SSM计算机毕业设计小说网站的设计与实现1JAVA
    中级C++:红黑树
    Vue2利用创建a标签实现下载本地静态文件到本地电脑上的功能
    深度学习基础学习-1x1卷积核的作用(CNN中)
  • 原文地址:https://blog.csdn.net/oneya1/article/details/133128075