完成卡信息修改功能

This commit is contained in:
范鹏 2025-02-13 16:56:54 +08:00
parent ebcf510915
commit 8b8b3ccf0b
9 changed files with 571 additions and 36 deletions

View File

@ -37,3 +37,21 @@ export function addCardRequest(data) {
data
})
}
// 更新卡片
export function updateCardRequest(data) {
return request({
url: '/identityCard/update',
method: 'POST',
data
})
}
// 卡详情
export function getCardRequest(data) {
return request({
url: '/identityCard/detail',
method: 'POST',
data
})
}

View File

@ -0,0 +1,72 @@
<template>
<view>
<up-popup :show="show" mode="center" round="32rpx" @close="close" :safeAreaInsetBottom="false">
<view class="bg-#f3f3f3 rounded-2xl">
<view class="py-4 text-center font-bold text-lg">{{ title }}</view>
<view class="px-4">
<input
class="bg-white border-none outline-none rounded-md h-80 w-450 text-base px-4"
placeholder-class="text-base line-height-[80rpx]"
:focus="show"
:placeholder="placeholder"
:value="text"
@change="change"
/>
</view>
<view
class="flex justify-between items-center border-t-solid border-t-2 text-base font-bold border-t-gray-200 mt-4 text-#63b8af"
>
<view
@click="close"
class="text-center border-r-solid border-r-2 border-e-gray-200 w-50% box-border py-2"
>取消</view
>
<view @click="confirm" class="text-center w-50% py-2">确定</view>
</view>
</view>
</up-popup>
</view>
</template>
<script setup>
import { ref } from 'vue'
const show = ref(false)
const text = ref('')
const props = defineProps({
title: { type: String, default: '请输入' },
placeholder: { type: String, default: '请输入' },
value: { type: String, default: '' },
autoClose: { type: Boolean, default: true }
})
const emits = defineEmits(['confirm'])
const open = () => {
text.value = props.value
show.value = true
}
const close = () => {
show.value = false
}
const change = e => {
text.value = e.target.value
}
const confirm = () => {
emits('confirm', text.value)
if (props.autoClose) {
show.value = false
}
}
defineExpose({
open,
close
})
</script>
<style scoped lang="scss"></style>

View File

@ -330,6 +330,13 @@
"navigationBarTitleText": "有效期",
"disableScroll": true
}
},
{
"path": "pages/temporaryDate/temporaryDate",
"style": {
"navigationBarTitleText": "修改有效期",
"disableScroll": true
}
}
],
"globalStyle": {

View File

@ -59,6 +59,8 @@
cardUserNo: String(data.cardNumber),
cardType: params.cardType,
addType: 1,
startTime: params.startDate,
endTime: params.endDate,
weekDay: params.weekDays,
cardRight: params.isAdmin,
isCoerced: params.isForce === 1 ? 2 : 1

View File

@ -5,30 +5,44 @@
<view class="item-title">卡号</view>
<view class="item-content">{{ info.cardNumber }}</view>
</view>
<view class="item" style="margin-top: 2rpx">
<view class="item" style="margin-top: 2rpx" @click="() => $refs.modalInput.open()">
<view class="item-title">姓名</view>
<view class="item-content">{{ info.cardName }}</view>
<view class="flex items-center">
<view class="item-content mr-2">{{ info.cardName }}</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
<view class="item" style="margin-top: 2rpx">
<view class="item" style="margin-top: 2rpx" @click="updateTime">
<view class="item-title">有效期</view>
<view v-if="info.cardType === 1">永久</view>
<view v-else-if="info.cardType === 2">
<view class="item-content">{{ timeFormat(info.startDate, 'yyyy-mm-dd h:M') }}</view>
<view class="item-content">{{ timeFormat(info.endDate, 'yyyy-mm-dd h:M') }}</view>
</view>
<view v-else>
<view class="item-content">{{ timeFormat(info.startDate, 'yyyy-mm-dd') }}</view>
<view class="item-content">{{ timeFormat(info.endDate, 'yyyy-mm-dd') }}</view>
<view class="flex items-center">
<view v-if="info.cardType === 1" class="mr-2">永久</view>
<view v-else-if="info.cardType === 2" class="mr-2 w-400 text-right">
<view class="item-content">{{ timeFormat(info.startDate, 'yyyy-mm-dd h:M') }}</view>
<view class="item-content">{{ timeFormat(info.endDate, 'yyyy-mm-dd h:M') }}</view>
</view>
<view v-else class="mr-2">
<view class="item-content">{{ timeFormat(info.startDate, 'yyyy-mm-dd') }}</view>
<view class="item-content">{{ timeFormat(info.endDate, 'yyyy-mm-dd') }}</view>
</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
<view class="item" style="margin-top: 2rpx" v-if="info.cardType === 4">
<view class="item" style="margin-top: 2rpx" v-if="info.cardType === 4" @click="updateTime">
<view class="item-title">有效日</view>
<view class="item-content">{{ $lock.convertWeekDaysToChineseString(info.weekDay) }}</view>
<view class="flex items-center">
<view class="item-content mr-2">{{
$lock.convertWeekDaysToChineseString(info.weekDay)
}}</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
<view class="item" style="margin-top: 2rpx" v-if="info.cardType === 4">
<view class="item" style="margin-top: 2rpx" v-if="info.cardType === 4" @click="updateTime">
<view class="item-title">有效时间</view>
<view class="item-content">
{{ timeFormat(info.startDate, 'h:M') }} - {{ timeFormat(info.endDate, 'h:M') }}
<view class="flex items-center">
<view class="item-content mr-2">
{{ timeFormat(info.startDate, 'h:M') }} - {{ timeFormat(info.endDate, 'h:M') }}
</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
<view class="item" style="margin-top: 20rpx">
@ -39,11 +53,39 @@
<view class="item-title">添加时间</view>
<view class="item-content">{{ timeFormat(info.createDate, 'yyyy-mm-dd h:M') }}</view>
</view>
<view class="item !py-2" style="margin-top: 20rpx">
<view class="item-title">胁迫卡</view>
<switch
:checked="info.isCoerced === 2"
class="transform-scale-90"
@click="changeCoerced"
:disabled="true"
color="#002ce5"
/>
</view>
<view class="item !py-2" style="margin-top: 2rpx">
<view class="item-title">是否为管理员</view>
<switch
@click="disabled"
:checked="info.cardRight"
class="transform-scale-90"
:disabled="true"
color="#002ce5"
/>
</view>
<view class="item" style="margin-top: 20rpx" @click="toRecordList">
<view class="item-title">操作记录</view>
<up-icon name="arrow-right"></up-icon>
</view>
<view class="button" @click="deletePassword">删除</view>
<ModalInput
ref="modalInput"
title="请输入姓名"
:autoClose="false"
placeholder="请输入姓名"
:value="info.cardName"
@confirm="changeName"
/>
</view>
</view>
</template>
@ -54,19 +96,27 @@
import { timeFormat } from 'uview-plus'
import { useLockStore } from '@/stores/lock'
import { useBasicStore } from '@/stores/basic'
import { getCardRequest, updateCardRequest } from '@/api/card'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useUserStore } from '@/stores/user'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
const $lock = useLockStore()
const $basic = useBasicStore()
const $bluetooth = useBluetoothStore()
const $user = useUserStore()
const info = ref(null)
const modalInput = ref(null)
const pending = ref(false)
onLoad(options => {
if (options.info) {
info.value = JSON.parse(options.info)
console.log(info.value)
}
})
@ -81,6 +131,121 @@
})
}
const disabled = () => {
uni.showToast({
title: '暂不支持修改',
icon: 'none'
})
}
const updateTime = () => {
$basic.routeJump({
name: info.value.cardType === 1 || info.value.cardType === 2 ? 'temporaryDate' : 'cycleDate',
params: {
info: JSON.stringify({ ...info.value, type: 'card' })
},
events: {
refresh() {
eventChannel.emit('refresherList', {})
getCardRequest({
cardId: info.value.cardId
}).then(res => {
info.value = res.data
})
}
}
})
}
const changeName = async name => {
if (!name) {
uni.showToast({
title: '请输入姓名',
icon: 'none'
})
return
}
if (pending.value) return
pending.value = true
const { code, message } = await updateCardRequest({
lockId: $bluetooth.currentLockInfo.lockId,
cardId: info.value.cardId,
cardType: info.value.cardType,
cardName: name,
changeType: 1
})
pending.value = false
if (code === 0) {
modalInput.value.close()
eventChannel.emit('refresherList', {})
info.value.cardName = name
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
}
const changeCoerced = async () => {
if (pending.value) return
pending.value = true
uni.showLoading({
title: '更新中'
})
const { code } = await $bluetooth.registerAuthentication({
type: 'card',
operate: 1,
isAdmin: info.value.isAdmin,
isForce: info.value.isCoerced === 2 ? 0 : 1,
isRound: info.value.cardType === 4 ? 1 : 0,
weekDays: info.value.weekDay,
no: info.value.cardNumber,
userCountLimit: 0xffff,
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString(),
startDate: info.value.startDate,
endDate: info.value.endDate,
startTime: info.value.cardType === 4 ? timeFormat(info.value.startDate, 'h:M') : '00:00',
endTime: info.value.cardType === 4 ? timeFormat(info.value.endDate, 'h:M') : '00:00'
})
if (code === 0) {
const { code, message } = await updateCardRequest({
lockId: $bluetooth.currentLockInfo.lockId,
cardId: info.value.cardId,
cardType: info.value.cardType,
isCoerced: info.value.isCoerced === 2 ? 1 : 2,
changeType: 1
})
pending.value = false
uni.hideLoading()
if (code === 0) {
info.value.isCoerced = info.value.isCoerced === 2 ? 1 : 2
eventChannel.emit('refresherList', {})
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
} else {
pending.value = false
uni.hideLoading()
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
})
}
}
const deletePassword = async () => {
eventChannel.emit('delete', {})
}

View File

@ -353,6 +353,12 @@
events: {
delete() {
deleteItem({ ...item, back: true })
},
refresherList() {
pageNo.value = 1
getList({
pageNo: pageNo.value
})
}
}
})

View File

@ -137,10 +137,18 @@
import { timeFormat } from 'uview-plus'
import { computed, getCurrentInstance, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { updateCardRequest } from '@/api/card'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useUserStore } from '@/stores/user'
import { useBasicStore } from '@/stores/basic'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
const $bluetooth = useBluetoothStore()
const $user = useUserStore()
const $basic = useBasicStore()
const showStartDate = ref(false)
const showEndDate = ref(false)
const showStartTime = ref(false)
@ -150,6 +158,8 @@
const endDate = ref(null)
const weekDays = ref([])
const info = ref(null)
const startTimeText = ref(null)
const endTimeText = ref(null)
@ -172,16 +182,19 @@
onLoad(options => {
if (options.info) {
const info = JSON.parse(options.info)
if (info.startDate) {
weekDays.value = info.weekDays
startDate.value = info.startDate
endDate.value = info.endDate
const data = JSON.parse(options.info)
info.value = data
if (data.startDate) {
weekDays.value = data.weekDays || data.weekDay
startDate.value = data.startDate
endDate.value = data.endDate
defaultStartDate.value = info.startDate
defaultEndDate.value = info.endDate
startTimeText.value = timeFormat(info.startDate, 'h:M')
endTimeText.value = timeFormat(info.endDate, 'h:M')
defaultStartDate.value = data.startDate
defaultEndDate.value = data.endDate
startTimeText.value = timeFormat(data.startDate, 'h:M')
endTimeText.value = timeFormat(data.endDate, 'h:M')
defaultStartTime.value = timeFormat(data.startDate, 'h:M')
defaultEndTime.value = timeFormat(data.endDate, 'h:M')
} else {
defaultStartTime.value = timeFormat(new Date(), 'h:M')
defaultEndTime.value = timeFormat(new Date(), 'h:M')
@ -204,7 +217,7 @@
return date1 - date2
}
const save = () => {
const save = async () => {
if (!canSubmit.value) {
return
}
@ -222,16 +235,72 @@
})
return
}
const data = {
startDate: updateTime(startDate.value, startTimeText.value),
endDate: updateTime(endDate.value, endTimeText.value),
weekDays: weekDays.value.sort()
}
uni.navigateBack({
success() {
eventChannel.emit('change', data)
if (!info.value.type) {
const data = {
startDate: updateTime(startDate.value, startTimeText.value),
endDate: updateTime(endDate.value, endTimeText.value),
weekDays: weekDays.value.sort()
}
})
uni.navigateBack({
success() {
eventChannel.emit('change', data)
}
})
} else {
uni.showLoading({
title: '更新中'
})
const { code } = await $bluetooth.registerAuthentication({
type: info.value.type,
operate: 1,
isAdmin: info.value.type,
isForce: info.value.isForce,
isRound: 1,
weekDays: weekDays.value.sort(),
no: info.value[`${info.value.type}Number`],
userCountLimit: 0xffff,
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString(),
startDate: updateTime(startDate.value, startTimeText.value),
endDate: updateTime(endDate.value, endTimeText.value),
startTime: startTimeText.value,
endTime: endTimeText.value
})
if (code === 0) {
const { code, message } = await updateCardRequest({
lockId: $bluetooth.currentLockInfo.lockId,
cardId: info.value.cardId,
cardType: 4,
weekDay: weekDays.value.sort(),
startDate: updateTime(startDate.value, startTimeText.value),
endDate: updateTime(endDate.value, endTimeText.value),
startTime: updateTime(startDate.value, startTimeText.value),
endTime: updateTime(endDate.value, endTimeText.value),
changeType: 1
})
uni.hideLoading()
if (code === 0) {
eventChannel.emit('refresh', {})
$basic.backAndToast('更新成功')
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
} else {
uni.hideLoading()
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
})
}
}
}
const updateTime = (datetime, timeStr) => {

View File

@ -0,0 +1,191 @@
<template>
<view>
<view class="font-bold text-base bg-white">
<view class="border-b-solid border-b-1 border-b-gray-200" @click="showStartDate = true">
<view class="mx-3 flex items-center h-100">
<view class="w-168">生效时间</view>
<view class="ml-a flex items-center">
<view v-if="startDate" class="mr-2">
<view>{{ timeFormat(startDate, 'yyyy-mm-dd h:M') }}</view>
</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
</view>
<view>
<view class="mx-3 flex items-center h-100" @click="showEndDate = true">
<view class="w-168">失效时间</view>
<view class="ml-a flex items-center">
<view v-if="endDate" class="mr-2">
<view>{{ timeFormat(endDate, 'yyyy-mm-dd h:M') }}</view>
</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
</view>
</view>
<view
:class="[
canSubmit ? 'bg-[#5eb7ac]' : 'bg-[#9d9da3]',
'mx-4',
'h-100',
'text-white',
'text-center',
'font-bold',
'mt-4',
'flex',
'items-center',
'justify-center'
]"
style="border-radius: 50rpx"
@click="save"
>保存</view
>
<up-datetime-picker
:hasInput="false"
:show="showStartDate"
v-model="defaultStartDate"
mode="datetime"
closeOnClickOverlay
:visibleItemCount="5"
@close="showStartDate = false"
@confirm="confirmDate('start', $event)"
@cancel="showStartDate = false"
></up-datetime-picker>
<up-datetime-picker
:hasInput="false"
:show="showEndDate"
v-model="defaultEndDate"
mode="datetime"
closeOnClickOverlay
:visibleItemCount="5"
@close="showEndDate = false"
@confirm="confirmDate('end', $event)"
@cancel="showEndDate = false"
></up-datetime-picker>
</view>
</template>
<script setup>
import { timeFormat } from 'uview-plus'
import { computed, getCurrentInstance, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useUserStore } from '@/stores/user'
import { updateCardRequest } from '@/api/card'
import { useBasicStore } from '@/stores/basic'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
const $bluetooth = useBluetoothStore()
const $user = useUserStore()
const $basic = useBasicStore()
const showStartDate = ref(false)
const showEndDate = ref(false)
const info = ref(null)
const startDate = ref(null)
const endDate = ref(null)
const defaultStartDate = ref(0)
const defaultEndDate = ref(0)
const canSubmit = computed(() => {
return startDate.value && endDate.value
})
onLoad(options => {
if (options.info) {
const data = JSON.parse(options.info)
if (data.startDate) {
startDate.value = data.startDate
endDate.value = data.endDate
info.value = data
defaultStartDate.value = data.startDate
defaultEndDate.value = data.endDate
}
console.log(info.value)
}
})
const save = async () => {
if (!canSubmit.value) {
return
}
if (startDate.value > endDate.value) {
uni.showToast({
title: '失效日期需晚于生效日期',
icon: 'none'
})
return
}
uni.showLoading({
title: '更新中'
})
const { code } = await $bluetooth.registerAuthentication({
type: info.value.type,
operate: 1,
isAdmin: info.value.type,
isForce: info.value.isForce,
isRound: 0,
weekDays: [],
no: info.value[`${info.value.type}Number`],
userCountLimit: 0xffff,
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString(),
startDate: startDate.value,
endDate: endDate.value
})
if (code === 0) {
const { code, message } = await updateCardRequest({
lockId: $bluetooth.currentLockInfo.lockId,
cardId: info.value.cardId,
cardType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
uni.hideLoading()
if (code === 0) {
eventChannel.emit('refresh', {})
$basic.backAndToast('更新成功')
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
} else {
uni.hideLoading()
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
})
}
}
const confirmDate = (type, date) => {
if (type === 'start') {
startDate.value = date.value
showStartDate.value = false
} else {
endDate.value = date.value
showEndDate.value = false
}
}
</script>
<style lang="scss">
page {
background-color: $uni-bg-color-grey;
}
</style>

View File

@ -246,6 +246,11 @@ const pages = [
name: 'cycleDate',
path: '/pages/cycleDate/cycleDate',
tabBar: false
},
{
name: 'temporaryDate',
path: '/pages/temporaryDate/temporaryDate',
tabBar: false
}
]