diff --git a/api/card.js b/api/card.js index d0d2385..eec0878 100644 --- a/api/card.js +++ b/api/card.js @@ -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 + }) +} diff --git a/components/ModalInput/ModalInput.vue b/components/ModalInput/ModalInput.vue new file mode 100644 index 0000000..e9a7938 --- /dev/null +++ b/components/ModalInput/ModalInput.vue @@ -0,0 +1,72 @@ + + + + + diff --git a/pages.json b/pages.json index aa45846..2232296 100644 --- a/pages.json +++ b/pages.json @@ -330,6 +330,13 @@ "navigationBarTitleText": "有效期", "disableScroll": true } + }, + { + "path": "pages/temporaryDate/temporaryDate", + "style": { + "navigationBarTitleText": "修改有效期", + "disableScroll": true + } } ], "globalStyle": { diff --git a/pages/bindCard/bindCard.vue b/pages/bindCard/bindCard.vue index f80b393..cace36a 100644 --- a/pages/bindCard/bindCard.vue +++ b/pages/bindCard/bindCard.vue @@ -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 diff --git a/pages/cardDetail/cardDetail.vue b/pages/cardDetail/cardDetail.vue index f8038c1..e45fe34 100644 --- a/pages/cardDetail/cardDetail.vue +++ b/pages/cardDetail/cardDetail.vue @@ -5,30 +5,44 @@ 卡号 {{ info.cardNumber }} - + 姓名 - {{ info.cardName }} + + {{ info.cardName }} + + - + 有效期 - 永久 - - {{ timeFormat(info.startDate, 'yyyy-mm-dd h:M') }} - {{ timeFormat(info.endDate, 'yyyy-mm-dd h:M') }} - - - {{ timeFormat(info.startDate, 'yyyy-mm-dd') }} - {{ timeFormat(info.endDate, 'yyyy-mm-dd') }} + + 永久 + + {{ timeFormat(info.startDate, 'yyyy-mm-dd h:M') }} + {{ timeFormat(info.endDate, 'yyyy-mm-dd h:M') }} + + + {{ timeFormat(info.startDate, 'yyyy-mm-dd') }} + {{ timeFormat(info.endDate, 'yyyy-mm-dd') }} + + - + 有效日 - {{ $lock.convertWeekDaysToChineseString(info.weekDay) }} + + {{ + $lock.convertWeekDaysToChineseString(info.weekDay) + }} + + - + 有效时间 - - {{ timeFormat(info.startDate, 'h:M') }} - {{ timeFormat(info.endDate, 'h:M') }} + + + {{ timeFormat(info.startDate, 'h:M') }} - {{ timeFormat(info.endDate, 'h:M') }} + + @@ -39,11 +53,39 @@ 添加时间 {{ timeFormat(info.createDate, 'yyyy-mm-dd h:M') }} + + 胁迫卡 + + + + 是否为管理员 + + 操作记录 删除 + @@ -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', {}) } diff --git a/pages/cardList/cardList.vue b/pages/cardList/cardList.vue index a6ab2f5..d6a8af2 100644 --- a/pages/cardList/cardList.vue +++ b/pages/cardList/cardList.vue @@ -353,6 +353,12 @@ events: { delete() { deleteItem({ ...item, back: true }) + }, + refresherList() { + pageNo.value = 1 + getList({ + pageNo: pageNo.value + }) } } }) diff --git a/pages/cycleDate/cycleDate.vue b/pages/cycleDate/cycleDate.vue index 4df14db..b2774f9 100644 --- a/pages/cycleDate/cycleDate.vue +++ b/pages/cycleDate/cycleDate.vue @@ -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) => { diff --git a/pages/temporaryDate/temporaryDate.vue b/pages/temporaryDate/temporaryDate.vue new file mode 100644 index 0000000..fdc9fc4 --- /dev/null +++ b/pages/temporaryDate/temporaryDate.vue @@ -0,0 +1,191 @@ + + + + + diff --git a/stores/basic.js b/stores/basic.js index c0b254d..c6b3f23 100644 --- a/stores/basic.js +++ b/stores/basic.js @@ -246,6 +246,11 @@ const pages = [ name: 'cycleDate', path: '/pages/cycleDate/cycleDate', tabBar: false + }, + { + name: 'temporaryDate', + path: '/pages/temporaryDate/temporaryDate', + tabBar: false } ]