wx-starlock/pages/feature/cardDetail.vue
2025-04-02 18:40:56 +08:00

297 lines
8.5 KiB
Vue

<template>
<view>
<view v-if="info">
<view class="item">
<view class="item-title">卡号</view>
<view class="item-content">{{ info.cardNumber }}</view>
</view>
<view class="item" style="margin-top: 2rpx" @click="() => $refs.modalInput.open()">
<view class="item-title">姓名</view>
<view class="flex items-center">
<view class="item-content mr-2 max-w-550 break-all">{{ info.cardName }}</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
<view class="item" style="margin-top: 2rpx" @click="updateTime">
<view class="item-title">有效期</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" @click="updateTime">
<view class="item-title">有效日</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" @click="updateTime">
<view class="item-title">有效时间</view>
<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">
<view class="item-title">添加者</view>
<view class="item-content">{{ info.senderUsername }}</view>
</view>
<view class="item" style="margin-top: 2rpx">
<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>
<script setup>
import { getCurrentInstance, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
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)
}
})
const toRecordList = async () => {
$basic.routeJump({
name: 'typeRecordList',
params: {
name: info.value.cardName,
key: 'cardId',
id: info.value.cardId
}
})
}
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 () => {
const netWork = await $basic.getNetworkType()
if (!netWork) {
return
}
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', {})
}
</script>
<style lang="scss">
page {
background-color: $uni-bg-color-grey;
}
</style>
<style lang="scss" scoped>
.item-title {
width: 350rpx;
}
.item {
padding: 24rpx 32rpx;
background-color: #ffffff;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 32rpx;
font-weight: 500;
}
.tips {
padding: 24rpx 32rpx;
font-size: 24rpx;
color: #999999;
}
.button {
margin: 32rpx;
width: 686rpx;
height: 88rpx;
background-color: #df282d;
color: white;
text-align: center;
line-height: 88rpx;
border-radius: 44rpx;
font-weight: bold;
}
</style>