331 lines
8.0 KiB
Vue
331 lines
8.0 KiB
Vue
<template>
|
|
<view>
|
|
<view class="tabs">
|
|
<up-tabs
|
|
:list="tabs"
|
|
lineWidth="40rpx"
|
|
lineHeight="5rpx"
|
|
:current="currentIndex"
|
|
lineColor="#63b8af"
|
|
@click="clickTab"
|
|
:inactiveStyle="{ color: '#a3a3a3', fontSize: '32rpx', fontWeight: 'bold' }"
|
|
:activeStyle="{ color: '#63b8af', fontSize: '32rpx', fontWeight: 'bold' }"
|
|
>
|
|
</up-tabs>
|
|
</view>
|
|
<swiper
|
|
:style="{ height: deviceInfo.screenHeight - deviceInfo.safeArea.top - 44 + 'px' }"
|
|
v-if="deviceInfo"
|
|
:list="tabs"
|
|
:autoplay="false"
|
|
:circular="true"
|
|
:current="currentIndex"
|
|
@change="changeSwiper"
|
|
>
|
|
<swiper-item>
|
|
<LockInput
|
|
:value="permanentName"
|
|
title="姓名"
|
|
placeholder="请输入"
|
|
@change-input="changeName('permanent', $event)"
|
|
></LockInput>
|
|
<view class="button mt-5" @click="create('permanent')">下一步</view>
|
|
</swiper-item>
|
|
<swiper-item>
|
|
<LockInput
|
|
:value="temporaryName"
|
|
title="姓名"
|
|
placeholder="请输入"
|
|
@change-input="changeName('temporary', $event)"
|
|
></LockInput>
|
|
<view class="mt-3">
|
|
<LockDatetimePicker
|
|
title="生效时间"
|
|
:value="temporaryStartTime"
|
|
:minDate="minDate"
|
|
:maxDate="maxDate"
|
|
@change-time="changeDate('temporaryStartTime', $event)"
|
|
></LockDatetimePicker>
|
|
</view>
|
|
<view class="mt-3">
|
|
<LockDatetimePicker
|
|
title="失效时间"
|
|
:value="temporaryEndTime"
|
|
:minDate="minDate"
|
|
:maxDate="maxDate"
|
|
@change-time="changeDate('temporaryEndTime', $event)"
|
|
></LockDatetimePicker>
|
|
</view>
|
|
<view class="button mt-5" @click="create('temporary')">下一步</view>
|
|
</swiper-item>
|
|
|
|
<swiper-item>
|
|
<LockInput
|
|
:value="cycleName"
|
|
title="姓名"
|
|
placeholder="请输入"
|
|
@change-input="changeName('cycle', $event)"
|
|
></LockInput>
|
|
<view class="mt-3">
|
|
<LockCycle @change="changeCycle"></LockCycle>
|
|
</view>
|
|
<view class="button mt-5" @click="create('cycle')">下一步</view>
|
|
</swiper-item>
|
|
</swiper>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { getCurrentInstance, ref } from 'vue'
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
import { timeFormat } from 'uview-plus'
|
|
import { useBasicStore } from '@/stores/basic'
|
|
import { useUserStore } from '@/stores/user'
|
|
import { useBluetoothStore } from '@/stores/bluetooth'
|
|
import { checkRemoteNameRequest } from '@/api/remote'
|
|
|
|
const instance = getCurrentInstance().proxy
|
|
const eventChannel = instance.getOpenerEventChannel()
|
|
|
|
const $basic = useBasicStore()
|
|
const $bluetooth = useBluetoothStore()
|
|
const $user = useUserStore()
|
|
|
|
const tabs = [
|
|
{
|
|
name: '永久'
|
|
},
|
|
{
|
|
name: '限时'
|
|
},
|
|
{
|
|
name: '循环'
|
|
}
|
|
]
|
|
|
|
const permanentName = ref('')
|
|
|
|
const temporaryName = ref('')
|
|
const temporaryStartTime = ref(Number(new Date()))
|
|
const temporaryEndTime = ref(Number(new Date()))
|
|
|
|
const cycleName = ref('')
|
|
const cycleStartTime = ref(null)
|
|
const cycleEndTime = ref(null)
|
|
const weekDays = ref([])
|
|
|
|
const minDate = ref(Number(new Date()))
|
|
const maxDate = ref(Number(4133951940000))
|
|
const currentIndex = ref(0)
|
|
const deviceInfo = ref(null)
|
|
|
|
onLoad(async () => {
|
|
deviceInfo.value = await $basic.getDeviceInfo()
|
|
temporaryStartTime.value = setTime()
|
|
temporaryEndTime.value = setTime()
|
|
minDate.value = Number(getNextFullHour())
|
|
maxDate.value = Number(getFutureTimestamp())
|
|
})
|
|
|
|
const changeCycle = data => {
|
|
cycleStartTime.value = data.startDate
|
|
cycleEndTime.value = data.endDate
|
|
weekDays.value = data.weekDays
|
|
}
|
|
|
|
const getNextFullHour = () => {
|
|
const now = new Date()
|
|
const currentHour = now.getHours()
|
|
now.setHours(currentHour)
|
|
now.setMinutes(0)
|
|
now.setSeconds(0)
|
|
now.setMilliseconds(0)
|
|
|
|
return now
|
|
}
|
|
|
|
const getFutureTimestamp = () => {
|
|
const currentDate = new Date()
|
|
|
|
const year = currentDate.getFullYear()
|
|
const month = currentDate.getMonth()
|
|
const day = currentDate.getDate()
|
|
|
|
const futureDate = new Date(year + 3, month, day, 23, 0, 0)
|
|
|
|
return futureDate.getTime()
|
|
}
|
|
|
|
const setTime = () => {
|
|
const now = new Date()
|
|
now.setMinutes(0, 0, 0)
|
|
|
|
return now.getTime()
|
|
}
|
|
|
|
const create = async type => {
|
|
if (
|
|
(type === 'temporary' && temporaryName.value === '') ||
|
|
(type === 'permanent' && permanentName.value === '') ||
|
|
(type === 'cycle' && cycleName.value === '')
|
|
) {
|
|
uni.showToast({
|
|
title: '名称不能为空',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
|
|
if (type === 'temporary' && temporaryStartTime.value >= temporaryEndTime.value) {
|
|
uni.showToast({
|
|
title: '失效时间要大于生效时间',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
|
|
if (type === 'cycle' && weekDays.value.length === 0) {
|
|
uni.showToast({
|
|
title: '请选择有效期',
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
|
|
const netWork = await $basic.getNetworkType()
|
|
if (!netWork) {
|
|
return
|
|
}
|
|
|
|
let params = {
|
|
type: 'remote',
|
|
keyId: $bluetooth.keyId.toString(),
|
|
uid: $user.userInfo.uid.toString(),
|
|
no: 0,
|
|
operate: 0,
|
|
userCountLimit: 0xffff
|
|
}
|
|
|
|
if (type === 'permanent') {
|
|
params = {
|
|
...params,
|
|
remoteName: permanentName.value,
|
|
weekDays: [],
|
|
isRound: 0,
|
|
startDate: 0,
|
|
remoteType: 1,
|
|
endDate: 0,
|
|
startTime: '00:00',
|
|
endTime: '00:00'
|
|
}
|
|
} else if (type === 'temporary') {
|
|
params = {
|
|
...params,
|
|
remoteName: temporaryName.value,
|
|
weekDays: [],
|
|
remoteType: 2,
|
|
isRound: 0,
|
|
startDate: temporaryStartTime.value,
|
|
endDate: temporaryEndTime.value,
|
|
startTime: '00:00',
|
|
endTime: '00:00'
|
|
}
|
|
} else {
|
|
params = {
|
|
...params,
|
|
remoteName: cycleName.value,
|
|
weekDays: weekDays.value,
|
|
remoteType: 4,
|
|
isRound: 1,
|
|
startDate: cycleStartTime.value,
|
|
endDate: cycleEndTime.value,
|
|
startTime: timeFormat(new Date(cycleStartTime.value), 'h:M'),
|
|
endTime: timeFormat(new Date(cycleEndTime.value), 'h:M')
|
|
}
|
|
}
|
|
|
|
const { code, message } = await checkRemoteNameRequest({
|
|
lockId: $bluetooth.currentLockInfo.lockId,
|
|
remoteName: params.remoteName
|
|
})
|
|
if (code === 0) {
|
|
$basic.routeJump({
|
|
name: 'bindRemote',
|
|
params: {
|
|
info: JSON.stringify(params)
|
|
},
|
|
events: {
|
|
refresherList() {
|
|
eventChannel.emit('refresherList', {})
|
|
}
|
|
}
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title: message,
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}
|
|
|
|
const changeName = (type, event) => {
|
|
if (type === 'permanent') {
|
|
permanentName.value = event
|
|
} else if (type === 'temporary') {
|
|
temporaryName.value = event
|
|
} else {
|
|
cycleName.value = event
|
|
}
|
|
}
|
|
|
|
const changeDate = (type, event) => {
|
|
if (type === 'temporaryStartTime') {
|
|
temporaryStartTime.value = event
|
|
} else {
|
|
temporaryEndTime.value = event
|
|
}
|
|
}
|
|
|
|
const clickTab = data => {
|
|
currentIndex.value = data.index
|
|
}
|
|
|
|
const changeSwiper = e => {
|
|
currentIndex.value = e.detail.current
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
page {
|
|
background-color: $uni-bg-color-grey;
|
|
}
|
|
</style>
|
|
|
|
<style lang="scss" scoped>
|
|
.tabs {
|
|
display: flex;
|
|
justify-content: center;
|
|
}
|
|
|
|
.text {
|
|
margin-top: 40rpx;
|
|
margin-bottom: 50rpx;
|
|
color: #262626;
|
|
font-size: 26rpx;
|
|
padding: 0 32rpx;
|
|
}
|
|
|
|
.button {
|
|
border-radius: 64rpx;
|
|
width: 686rpx;
|
|
margin-left: 32rpx;
|
|
height: 100rpx;
|
|
line-height: 100rpx;
|
|
text-align: center;
|
|
background-color: #63b8af;
|
|
color: #fff;
|
|
font-size: 32rpx;
|
|
font-weight: bold;
|
|
}
|
|
</style>
|