uniapp 微信小程序 自定义弹框+picker下拉选择列表+输入表单:拒绝-选择理由弹窗

效果:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

1、template

<!-- 拒绝-选择理由弹窗-->
<view class="reason-popover" v-if="showReasonDialog">
	<view class="reason-modal">
		<view class="reason-title">
			<text>请选择拒绝理由</text>
		</view>
		<view class="reason-bd">
			<view class="select-picker">
				<picker @change="bindPickerChangeReason" :value="itemIndex" :range="listArray"
					range-key="dictLabel">
					<input class="select-input" type="text" placeholder="请选择" disabled="disabled"
						v-if="itemIndex == -1"></input>
					<view class="select-input" v-else :value="listArray[itemIndex].dictLabel">
						{{listArray[itemIndex].dictLabel}}
					</view>
				</picker>
			</view>
			<textarea placeholder="请填写理由" v-model="otherReason" class="other-reason"
				v-if="showOther"></textarea>
			<text class="tips">每月可拒绝3次,超过将进行监管</text>
		</view>
		<view class="reason-bottom-btn">
			<view class="common-btn" @click="closeReasonDialog">取消</view>
			<view class="common-btn confirm-btn" @click="toConfirm">确定</view>
		</view>
	</view>
</view>

2、data:

data() {
	return {
		// 拒绝理由
		itemIndex: -1,
		listArray: [],
		reasonName:'',//理由文本
		showReasonDialog: false, //是否显示拒绝弹框
		otherReason: '', //输入的理由
		showOther: false, //是否显示输入文本框
	}
}

3、methods:

// 点击拒绝-请求拒绝理由列表接口
toCancel: function() {
	uni.showLoading();
	var params = {
		url: "/***/***",
		method: "GET",
		data: {},
		callBack: res => {
			uni.hideLoading()
			this.listArray = res.data
			this.showReasonDialog = true //显示拒绝弹框
		}
	};
	http.request(params);
},
// 理由下拉列表
bindPickerChangeReason: function(e) {
	this.itemIndex = e.detail.value
	this.reasonIds = this.listArray[this.itemIndex].dictValue
	this.reasonName = this.listArray[this.itemIndex].dictLabel
	//当选择其他时,文本输入框显示,当选择非其他时输入框隐藏
	if (this.reasonName == "其他") {
		this.showOther = true
	}else{
		this.showOther = false 
	}
},
// 拒绝点击确定
toConfirm: function() {
	if (this.reasonName.length == 0) {
		uni.showToast({
			icon: 'none',
			title: "请选择拒绝理由",
		})
		return
	}
	//当选择其他时,如果未输入文本,则理由默认传“其他”,否则就传输入的文本值
	if (this.reasonName == "其他") {
		if(!this.otherReason){
			this.reasonName = "其他"
		}else{
			this.reasonName = this.otherReason
		}
	}
	
	uni.showLoading();
	var params = {
		url: "/****/****",
		method: "PUT",
		data: {
			orderId: this.orderId,
			driverRefuseReason: this.reasonName
		},
		callBack: res => {
			uni.hideLoading()
			this.showReasonDialog = false
			uni.showModal({
				title: "拒绝成功",
				content: "",
				confirmText: "确定",
				showCancel: false,
				success: (res) => {
					if (res.confirm) {
						//拒绝成功跳转订单列表页
						uni.reLaunch({
							url: '/pages/order/order'
						})
					}
				}
			})
		}
	};
	http.request(params);
},
// 关闭弹框
closeReasonDialog() {
	this.showReasonDialog = false
},

4、style

.reason-popover {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 10000;
	display: flex;
	display: -webkit-flex;
	justify-content: center;
	align-items: center;
	background-color: rgba(0, 0, 0, 0.5);
}

.reason-popover .reason-modal {
	position: relative;
	width: 640rpx;
	/* height: 575rpx; */
	border-radius: 16rpx;
	background: #fff;
	margin: 0 auto;
	padding: 64rpx 48rpx 112rpx 48rpx;
	box-sizing: border-box;
}

.reason-popover .reason-title {
	/* width: 313rpx;
	height: 90rpx; */
	margin: 0 auto;
	font-size: 32rpx;
	/* line-height: 45rpx; */
	text-align: center;
	color: #000;
	margin-bottom: 32rpx;
}

/* .close-img {
	position: absolute;
	top: 12rpx;
	right: 12rpx;
	width: 44rpx;
	height: 44rpx;
}

.close-img image {
	width: 100%;
	height: 100%;
} */
.reason-bd{
	/* width: 420rpx; */
	width: 100%;
	/* height: 640rpx; */
	margin: 0 auto;
	margin-bottom: 64rpx;
	
	/* line-height: 36rpx; */
	
}
.reason-bd .bd-title{
	color: #3DB86D;
}
.tips{
	margin: 0 auto;
	font-size: 36rpx;
	color: #3D3D3D;
	margin-top: 64rpx;
}
.reason-bd text{
	display: block;
}
.reason-bottom-btn{
	width: 100%;
	border-top:1rpx solid #E7E7E7;
	position: absolute;
	left: 0;
	bottom: 0;
	display: flex;
	justify-content: space-around;
	height: 112rpx;
	line-height: 112rpx;
	text-align: center;
}
.common-btn{
	width:320rpx;
	
}
.confirm-btn {
	border-left: 1rpx solid #E7E7E7;
	color: #5b6987;
	box-sizing: border-box;
}
.other-reason{
	width: 100%;
	height: 147rpx;
	border-radius: 8rpx;
	background: #F3F3F3;
	padding: 24rpx 24rpx 27rpx 24rpx;
	box-sizing: border-box;
	color: #3D3D3D;
	font-size: 32rpx;
	margin-top:20rpx;
}
.select-input{
	width:100%;
	height: 88rpx;
	line-height: 88rpx;
	border-radius: 10rpx;
	border: 1rpx solid #BDBDBD;
	padding-left: 22rpx;
	box-sizing:border-box;
}
.select-picker{
	border: 1rpx solid #BDBDBD;
}
.select-picker .select-input{
	border:none !important
}
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在uni-app中实现一个点击关闭弹框的功能,可以使用uni-app提供的组件来实现。以下是一个简单的例子: 在页面中添加一个弹框: ``` <view class="dialog"> <view class="close-button" @click="closeDialog">x</view> <view class="dialog-content"> 这是弹框的内容。 </view> </view> ``` 在样式中定义弹框和关闭按钮的样式: ``` .dialog { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999; background-color: rgba(0, 0, 0, 0.5); display: flex; justify-content: center; align-items: center; } .dialog-content { background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); } .close-button { position: absolute; top: 10px; right: 10px; font-size: 20px; cursor: pointer; } ``` 在页面的methods中添加一个方法来处理关闭事件: ``` methods: { closeDialog() { this.$emit('close'); } } ``` 在父组件中引用弹框组件,并使用`v-if`来控制弹框的显示和隐藏,同时监听弹框组件的`close`事件,来关闭弹框: ``` <template> <view> <button @click="showDialog">打开弹框</button> <dialog :show="dialogVisible" @close="closeDialog"></dialog> </view> </template> <script> import Dialog from '@/components/dialog.vue'; export default { components: { Dialog }, data() { return { dialogVisible: false }; }, methods: { showDialog() { this.dialogVisible = true; }, closeDialog() { this.dialogVisible = false; } } }; </script> ``` 在这个例子中,我们使用了uni-app提供的组件`<view>`来实现弹框,并使用了CSS来设置弹框和关闭按钮的样式。在methods中,我们添加了一个方法`closeDialog`来处理关闭按钮的点击事件,并使用`$emit`来触发`close`事件。在父组件中,我们使用了`v-if`来控制弹框的显示和隐藏,并监听弹框组件的`close`事件,来关闭弹框。 需要注意的是,这个例子中的弹框是在页面中的,如果你想要在小程序中实现全局弹框的功能,可以使用小程序原生的API`wx.showToast()`或`wx.showModal()`来实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值