确认弹框组件

This commit is contained in:
bb_pan 2025-09-03 21:30:31 +08:00
parent ba88efd56a
commit d618c4feaf
2 changed files with 204 additions and 62 deletions

View File

@ -0,0 +1,129 @@
<template>
<div>
<!-- 弹框确认组件 -->
<uni-popup ref="popupDialog" type="dialog" :mask-click="false">
<view class="popup-content">
<view class="popup-title">{{ title }}</view>
<view class="popup-message" v-if="!showRemark">{{ content }}</view>
<uni-easyinput v-else type="textarea" v-model="remark" placeholder="请输入" autoHeight />
<view class="popup-btns">
<view class="btn cancel" v-if="showClose" @click="closePopup">{{ leftBtn }}</view>
<view class="btn confirm" :class="{ disabled: countdown > 0 }" @click="confirm">
<span>{{ rightBtn }}</span>
{{ countdown > 0 ? '(' + countdown + ')' : '' }}
</view>
</view>
</view>
</uni-popup>
</div>
</template>
<script setup>
import { ref } from 'vue'
const props = defineProps({
title: { type: String, default: '提示' },
content: { type: String, default: '是否确定?' },
showClose: { type: Boolean, default: true },
leftBtn: { type: String, default: '取 消' },
rightBtn: { type: String, default: '确 定' },
showRemark: { type: Boolean, default: false },
})
const emit = defineEmits(['confirm'])
const popupDialog = ref(null)
const remark = ref('')
const timer = ref(null)
const countdown = ref(0)
let resolvePromise = null // Promise resolve
// Promise
const openPopup = () => {
return new Promise((resolve) => {
resolvePromise = resolve // resolve
popupDialog.value.open()
remark.value = '' //
//
if (timer.value) clearInterval(timer.value)
countdown.value = 3
timer.value = setInterval(() => {
if (countdown.value > 0) {
countdown.value--
} else {
clearInterval(timer.value)
timer.value = null
countdown.value = 0
}
}, 1000)
})
}
//
const closePopup = () => {
popupDialog.value.close()
if (resolvePromise) resolvePromise({ data: false })
resolvePromise = null
}
//
const confirm = () => {
if (countdown.value > 0) return
popupDialog.value.close()
const params = {
data: true,
remark: remark.value,
}
if (!remark.value) delete params.remark
if (resolvePromise) resolvePromise(params)
resolvePromise = null
}
//
defineExpose({ openPopup })
</script>
<style lang="scss" scoped>
.popup-content {
padding: 20rpx;
background-color: #fff;
border-radius: 10rpx;
width: 80vw;
}
.popup-title {
font-size: 32rpx;
font-weight: bold;
margin-bottom: 20rpx;
}
.popup-message {
font-size: 36rpx;
font-weight: bold;
margin: 30px 0;
text-align: center;
}
.popup-btns {
display: flex;
border-top: 1px solid #eee;
height: 88rpx;
line-height: 88rpx;
text-align: center;
}
.btn {
margin-top: 3px;
flex: 1;
font-size: 34rpx;
}
.cancel {
color: #666;
border-right: 1px solid #eee;
}
.confirm {
color: #007aff;
font-weight: 500;
&.disabled {
color: #999;
}
}
</style>

View File

@ -90,6 +90,7 @@
</view>
</scroll-view>
</view>
<PopupConfirm ref="popupConfirm" :content="content" />
</template>
<script setup>
@ -98,7 +99,10 @@ import { onLoad, onShow } from '@dcloudio/uni-app'
import { debounce } from 'lodash-es'
import { getPurchaseList } from '@/services/purchase.js'
import { getQrCodeBoxListApi,appReceiveApi,appTransferRejectApi } from '@/services/standard.js'
import PopupConfirm from '@/components/PopupConfirm'
const popupConfirm = ref(null)
const content = ref('')
const swipeRef = ref(null)
const total = ref(0) //
const active = ref(1) // tap
@ -127,6 +131,7 @@ const onChangeDate = (val) => {
//
const onClick=(e,item, itemIndex)=> {
console.log('🚀 ~ onClick ~ item:', item)
if(item.status==4){
if(e.index==0){
uni.navigateTo({ url: `/pages/standardBox/codeView?boxInfo=${JSON.stringify(item)}` })
@ -134,16 +139,29 @@ const onClick=(e,item, itemIndex)=> {
}else{
if(e.index==0){
uni.navigateTo({ url: `/pages/standardBox/codeView?boxInfo=${JSON.stringify(item)}` })
}else if(e.index==1){//
console.log(item)
setTimeout(() => {
uni.showModal({
title: '提示',
content: '是否确认接收?',
confirmText: '确定',
cancelText: '取消',
success: async (modalRes) => {
if (modalRes.confirm) {
}else if(e.index==1){
//
content.value = '是否确认接收?'
popupConfirm.value.openPopup().then((res) => {
console.log('🚀 ~ Popup ~ res:', res)
if (res.data) handleReceive(item)
})
}else{
//
content.value = '是否确认驳回?'
popupConfirm.value.openPopup().then((res) => {
console.log('🚀 ~ Popup ~ res:', res)
if (res.data) handleReject(item)
})
}
}
swipeRef.value[itemIndex].closeAll()
}
//
const handleReceive = async (item) => {
try {
uni.showLoading({ title: '操作中...', mask: true })
let param = {
boxId:item.boxId
}
@ -162,20 +180,17 @@ const onClick=(e,item, itemIndex)=> {
console.log("xxxxxxxxxxxxxxxxxxxxxxxxx")
uni.showToast({ title: '接收失败', icon: 'none' })
}
} catch (error) {
console.log('🚀 ~ handleReceive ~ error:', error)
} finally {
uni.hideLoading()
}
}
})
}, 500)
}else{//
console.log(item)
setTimeout(() => {
uni.showModal({
title: '提示',
content: '是否确认驳回移交?',
confirmText: '确定',
cancelText: '取消',
success: async (resp) => {
if (resp.confirm) {
//
const handleReject = async (item) => {
try {
uni.showLoading({ title: '操作中...', mask: true })
let param = {
boxId:item.boxId
}
@ -192,14 +207,12 @@ const onClick=(e,item, itemIndex)=> {
}else{
uni.showToast({ title: '驳回失败', icon: 'none' })
}
} catch (error) {
console.log('🚀 ~ handleReject ~ error:', error)
} finally {
uni.hideLoading()
}
}
})
}, 500)
}
}
swipeRef.value[itemIndex].closeAll()
}
//1
const swipeOptions = ref([