完成创建单次、循环电子钥匙功能
This commit is contained in:
parent
fee5aa62e3
commit
17e820fc62
@ -5,7 +5,7 @@
|
|||||||
:list="tabs"
|
:list="tabs"
|
||||||
lineWidth="40rpx"
|
lineWidth="40rpx"
|
||||||
lineHeight="5rpx"
|
lineHeight="5rpx"
|
||||||
:current="currnetIndex"
|
:current="current"
|
||||||
lineColor="#63b8af"
|
lineColor="#63b8af"
|
||||||
@click="clickTab"
|
@click="clickTab"
|
||||||
:inactiveStyle="{ color: '#a3a3a3', fontSize: '32rpx', fontWeight: 'bold' }"
|
:inactiveStyle="{ color: '#a3a3a3', fontSize: '32rpx', fontWeight: 'bold' }"
|
||||||
@ -19,7 +19,7 @@
|
|||||||
:list="tabs"
|
:list="tabs"
|
||||||
:autoplay="false"
|
:autoplay="false"
|
||||||
:circular="true"
|
:circular="true"
|
||||||
:current="currnetIndex"
|
:current="current"
|
||||||
@change="changeSwiper"
|
@change="changeSwiper"
|
||||||
>
|
>
|
||||||
<swiper-item>
|
<swiper-item>
|
||||||
@ -27,13 +27,13 @@
|
|||||||
:value="permanentAccount"
|
:value="permanentAccount"
|
||||||
title="接收者"
|
title="接收者"
|
||||||
placeholder="请输入手机号或邮箱"
|
placeholder="请输入手机号或邮箱"
|
||||||
@change-input="changePermanentAccountInput"
|
@change-input="changeAccount('permanent', $event)"
|
||||||
></LockInput>
|
></LockInput>
|
||||||
<LockInput
|
<LockInput
|
||||||
:value="permanentName"
|
:value="permanentName"
|
||||||
title="姓名"
|
title="姓名"
|
||||||
placeholder="请输入姓名"
|
placeholder="请输入姓名"
|
||||||
@change-input="changePermanentNameInput"
|
@change-input="changeName('permanent', $event)"
|
||||||
></LockInput>
|
></LockInput>
|
||||||
<view class="text" style="margin-top: 40rpx">接收者可使用此小程序开关锁</view>
|
<view class="text" style="margin-top: 40rpx">接收者可使用此小程序开关锁</view>
|
||||||
<view class="text" style="margin-bottom: 50rpx"
|
<view class="text" style="margin-bottom: 50rpx"
|
||||||
@ -41,30 +41,30 @@
|
|||||||
>
|
>
|
||||||
<view class="button" @click="createKey('permanent')">发送</view>
|
<view class="button" @click="createKey('permanent')">发送</view>
|
||||||
</swiper-item>
|
</swiper-item>
|
||||||
<swiper-item :style="{ height: deviceInfo.windowHeight - 44 + 'px' }">
|
<swiper-item>
|
||||||
<LockInput
|
<LockInput
|
||||||
:value="temporaryAccount"
|
:value="temporaryAccount"
|
||||||
title="接收者"
|
title="接收者"
|
||||||
placeholder="请输入手机号或邮箱"
|
placeholder="请输入手机号或邮箱"
|
||||||
@change-input="changeTemporaryAccountInput"
|
@change-input="changeAccount('temporary', $event)"
|
||||||
></LockInput>
|
></LockInput>
|
||||||
<LockInput
|
<LockInput
|
||||||
:value="temporaryName"
|
:value="temporaryName"
|
||||||
title="姓名"
|
title="姓名"
|
||||||
placeholder="请输入姓名"
|
placeholder="请输入姓名"
|
||||||
@change-input="changeTemporaryNameInput"
|
@change-input="changeName('temporary', $event)"
|
||||||
></LockInput>
|
></LockInput>
|
||||||
<view style="margin-top: 20rpx">
|
<view style="margin-top: 20rpx">
|
||||||
<LockDatetimePicker
|
<LockDatetimePicker
|
||||||
title="生效时间"
|
title="生效时间"
|
||||||
:value="temporaryValidTime"
|
:value="startDate"
|
||||||
:minDate="minDate"
|
:minDate="minDate"
|
||||||
@change-time="changeTemporaryValidTime"
|
@change-time="changeTemporaryValidTime"
|
||||||
:maxDate="maxDate"
|
:maxDate="maxDate"
|
||||||
></LockDatetimePicker>
|
></LockDatetimePicker>
|
||||||
<LockDatetimePicker
|
<LockDatetimePicker
|
||||||
title="失效时间"
|
title="失效时间"
|
||||||
:value="temporaryInvalidTime"
|
:value="endDate"
|
||||||
:minDate="minDate"
|
:minDate="minDate"
|
||||||
@change-time="changeTemporaryInvalidTime"
|
@change-time="changeTemporaryInvalidTime"
|
||||||
:maxDate="maxDate"
|
:maxDate="maxDate"
|
||||||
@ -76,6 +76,41 @@
|
|||||||
>
|
>
|
||||||
<view class="button" @click="createKey('temporary')">发送</view>
|
<view class="button" @click="createKey('temporary')">发送</view>
|
||||||
</swiper-item>
|
</swiper-item>
|
||||||
|
<swiper-item>
|
||||||
|
<LockInput
|
||||||
|
:value="singleAccount"
|
||||||
|
title="接收者"
|
||||||
|
placeholder="请输入手机号或邮箱"
|
||||||
|
@change-input="changeAccount('single', $event)"
|
||||||
|
></LockInput>
|
||||||
|
<LockInput
|
||||||
|
:value="singleName"
|
||||||
|
title="姓名"
|
||||||
|
placeholder="请输入姓名"
|
||||||
|
@change-input="changeName('single', $event)"
|
||||||
|
></LockInput>
|
||||||
|
<view class="text mt-5 mb-50rpx">单次钥匙有效期为1小时,只能使用一次</view>
|
||||||
|
<view class="button" @click="createKey('single')">发送</view>
|
||||||
|
</swiper-item>
|
||||||
|
<swiper-item>
|
||||||
|
<LockInput
|
||||||
|
:value="cycleAccount"
|
||||||
|
title="接收者"
|
||||||
|
placeholder="请输入手机号或邮箱"
|
||||||
|
@change-input="changeAccount('cycle', $event)"
|
||||||
|
></LockInput>
|
||||||
|
<LockInput
|
||||||
|
:value="cycleName"
|
||||||
|
title="姓名"
|
||||||
|
placeholder="请输入姓名"
|
||||||
|
@change-input="changeName('cycle', $event)"
|
||||||
|
></LockInput>
|
||||||
|
<view style="margin-top: 20rpx">
|
||||||
|
<LockCycle @change="changeCycle"></LockCycle>
|
||||||
|
</view>
|
||||||
|
<view class="text mt-5 mb-50rpx">接收者可以在有效期内的固定时间段里,不限次数使用</view>
|
||||||
|
<view class="button" @click="createKey('cycle')">发送</view>
|
||||||
|
</swiper-item>
|
||||||
</swiper>
|
</swiper>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
@ -103,17 +138,30 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '限时'
|
name: '限时'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '单次'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '循环'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
permanentName: '',
|
permanentName: '',
|
||||||
permanentAccount: '',
|
permanentAccount: '',
|
||||||
temporaryName: '',
|
temporaryName: '',
|
||||||
temporaryAccount: '',
|
temporaryAccount: '',
|
||||||
temporaryValidTime: Number(new Date()),
|
startDate: Number(new Date()),
|
||||||
temporaryInvalidTime: Number(new Date()),
|
endDate: Number(new Date()),
|
||||||
|
singleName: '',
|
||||||
|
singleAccount: '',
|
||||||
|
cycleName: '',
|
||||||
|
cycleAccount: '',
|
||||||
|
cycleStartTime: null,
|
||||||
|
cycleEndTime: null,
|
||||||
|
weekDays: [],
|
||||||
minDate: Number(new Date()),
|
minDate: Number(new Date()),
|
||||||
maxDate: Number(4133951940000),
|
maxDate: Number(4133951940000),
|
||||||
currnetIndex: 0,
|
current: 0,
|
||||||
deviceInfo: null,
|
deviceInfo: null,
|
||||||
pending: false
|
pending: false
|
||||||
}
|
}
|
||||||
@ -124,24 +172,24 @@
|
|||||||
},
|
},
|
||||||
async onLoad() {
|
async onLoad() {
|
||||||
this.deviceInfo = await this.getDeviceInfo()
|
this.deviceInfo = await this.getDeviceInfo()
|
||||||
// this.temporaryInvalidTime = this.setTime()
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(useBasicStore, ['getDeviceInfo', 'backAndToast', 'getNetworkType']),
|
...mapActions(useBasicStore, ['getDeviceInfo', 'backAndToast', 'getNetworkType']),
|
||||||
...mapActions(useLockStore, ['getKeyList', 'updateKeySearch']),
|
...mapActions(useLockStore, ['getKeyList', 'updateKeySearch']),
|
||||||
setTime() {
|
changeCycle(data) {
|
||||||
const now = new Date()
|
this.cycleStartTime = data.startDate
|
||||||
now.setMinutes(0, 0, 0)
|
this.cycleEndTime = data.endDate
|
||||||
now.setDate(now.getDate() + 3)
|
this.weekDays = data.weekDays
|
||||||
|
|
||||||
return now.getTime()
|
|
||||||
},
|
},
|
||||||
async createKey(type, createUser = false) {
|
async createKey(type, createUser = false) {
|
||||||
if (
|
if (
|
||||||
(type === 'temporary' &&
|
(type === 'temporary' &&
|
||||||
!(test.email(this.temporaryAccount) || test.mobile(this.temporaryAccount))) ||
|
!(test.email(this.temporaryAccount) || test.mobile(this.temporaryAccount))) ||
|
||||||
(type === 'permanent' &&
|
(type === 'permanent' &&
|
||||||
!(test.email(this.permanentAccount) || test.mobile(this.permanentAccount)))
|
!(test.email(this.permanentAccount) || test.mobile(this.permanentAccount))) ||
|
||||||
|
(type === 'single' &&
|
||||||
|
!(test.email(this.singleAccount) || test.mobile(this.singleAccount))) ||
|
||||||
|
(type === 'cycle' && !(test.email(this.cycleAccount) || test.mobile(this.cycleAccount)))
|
||||||
) {
|
) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '请输入格式正确的手机号或邮箱',
|
title: '请输入格式正确的手机号或邮箱',
|
||||||
@ -150,7 +198,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'temporary' && this.temporaryValidTime >= this.temporaryInvalidTime) {
|
if (type === 'temporary' && this.startDate >= this.endDate) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '失效时间必须大于生效时间',
|
title: '失效时间必须大于生效时间',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
@ -158,6 +206,14 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type === 'cycle' && this.weekDays.length === 0) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请选择有效期',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const netWork = await this.getNetworkType()
|
const netWork = await this.getNetworkType()
|
||||||
if (!netWork) {
|
if (!netWork) {
|
||||||
return
|
return
|
||||||
@ -183,16 +239,31 @@
|
|||||||
}
|
}
|
||||||
if (type === 'temporary') {
|
if (type === 'temporary') {
|
||||||
params.keyNameForAdmin = this.temporaryName
|
params.keyNameForAdmin = this.temporaryName
|
||||||
params.endDate = this.temporaryInvalidTime.toString()
|
params.endDate = this.endDate.toString()
|
||||||
params.keyType = '2'
|
params.keyType = '2'
|
||||||
params.receiverUsername = this.temporaryAccount
|
params.receiverUsername = this.temporaryAccount
|
||||||
params.startDate = this.temporaryValidTime.toString()
|
params.startDate = this.startDate.toString()
|
||||||
} else {
|
} else if (type === 'permanent') {
|
||||||
params.keyNameForAdmin = this.permanentName
|
params.keyNameForAdmin = this.permanentName
|
||||||
params.startDate = new Date().getTime().toString()
|
params.startDate = new Date().getTime().toString()
|
||||||
params.endDate = '0'
|
params.endDate = '0'
|
||||||
params.keyType = '1'
|
params.keyType = '1'
|
||||||
params.receiverUsername = this.permanentAccount
|
params.receiverUsername = this.permanentAccount
|
||||||
|
} else if (type === 'single') {
|
||||||
|
params.keyNameForAdmin = this.singleName
|
||||||
|
params.startDate = new Date().getTime().toString()
|
||||||
|
params.endDate = '0'
|
||||||
|
params.keyType = '3'
|
||||||
|
params.receiverUsername = this.singleAccount
|
||||||
|
} else if (type === 'cycle') {
|
||||||
|
params.keyNameForAdmin = this.cycleName
|
||||||
|
params.startDate = this.cycleStartTime
|
||||||
|
params.endDate = this.cycleEndTime
|
||||||
|
params.keyType = '4'
|
||||||
|
params.receiverUsername = this.cycleAccount
|
||||||
|
params.weekDays = this.weekDays
|
||||||
|
params.startTime = this.cycleStartTime
|
||||||
|
params.endTime = this.cycleEndTime
|
||||||
}
|
}
|
||||||
const { code, message } = await createKeyRequest(params)
|
const { code, message } = await createKeyRequest(params)
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
@ -222,29 +293,39 @@
|
|||||||
}
|
}
|
||||||
this.pending = false
|
this.pending = false
|
||||||
},
|
},
|
||||||
changePermanentAccountInput(e) {
|
changeAccount(type, e) {
|
||||||
this.permanentAccount = e
|
if (type === 'permanent') {
|
||||||
|
this.permanentAccount = e
|
||||||
|
} else if (type === 'temporary') {
|
||||||
|
this.temporaryAccount = e
|
||||||
|
} else if (type === 'single') {
|
||||||
|
this.singleAccount = e
|
||||||
|
} else if (type === 'cycle') {
|
||||||
|
this.cycleAccount = e
|
||||||
|
}
|
||||||
},
|
},
|
||||||
changePermanentNameInput(e) {
|
changeName(type, e) {
|
||||||
this.permanentName = e
|
if (type === 'permanent') {
|
||||||
},
|
this.permanentName = e
|
||||||
changeTemporaryNameInput(e) {
|
} else if (type === 'temporary') {
|
||||||
this.temporaryName = e
|
this.temporaryName = e
|
||||||
},
|
} else if (type === 'single') {
|
||||||
changeTemporaryAccountInput(e) {
|
this.singleName = e
|
||||||
this.temporaryAccount = e
|
} else if (type === 'cycle') {
|
||||||
|
this.cycleName = e
|
||||||
|
}
|
||||||
},
|
},
|
||||||
changeTemporaryValidTime(e) {
|
changeTemporaryValidTime(e) {
|
||||||
this.temporaryValidTime = e
|
this.startDate = e
|
||||||
},
|
},
|
||||||
changeTemporaryInvalidTime(e) {
|
changeTemporaryInvalidTime(e) {
|
||||||
this.temporaryInvalidTime = e
|
this.endDate = e
|
||||||
},
|
},
|
||||||
clickTab(data) {
|
clickTab(data) {
|
||||||
this.currnetIndex = data.index
|
this.current = data.index
|
||||||
},
|
},
|
||||||
changeSwiper(e) {
|
changeSwiper(e) {
|
||||||
this.currnetIndex = e.detail.current
|
this.current = e.detail.current
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user