考勤机绑定接口调试

This commit is contained in:
BianLzhaoMin 2025-10-21 11:18:27 +08:00
parent b75fbc37cd
commit 06c20c63e6
3 changed files with 124 additions and 35 deletions

View File

@ -77,7 +77,12 @@
<script setup name="bindSetting"> <script setup name="bindSetting">
import { ref, onMounted } from 'vue' import { ref, onMounted } from 'vue'
import { getSubcontractorListAPI, getSubTeamContractListAPI } from '@/services/machine-setting' import {
getSubcontractorListAPI,
getSubTeamContractListAPI,
unBindPmAttDeviceAPI,
confirmBindPmAttDeviceAPI,
} from '@/services/machine-setting'
const subPickerShow = ref(false) const subPickerShow = ref(false)
const teamPickerShow = ref(false) const teamPickerShow = ref(false)
const subPickerColumns = ref([[]]) const subPickerColumns = ref([[]])
@ -93,6 +98,7 @@ const machineInfo = ref({
subName: '', subName: '',
teamId: '', teamId: '',
teamName: '', teamName: '',
serialNumber: '',
}) })
// //
@ -137,43 +143,87 @@ const onUnbind = () => {
uni.showModal({ uni.showModal({
title: '提示', title: '提示',
content: '确定要解除绑定吗?', content: '确定要解除绑定吗?',
success: (res) => { success: async (res) => {
if (res.confirm) { if (res.confirm) {
// TODO: // TODO:
console.log('解除绑定') console.log('解除绑定')
uni.showToast({ const res = await unBindPmAttDeviceAPI({
title: '解除绑定成功', deviceCode: machineInfo.value.deviceCode,
icon: 'success',
}) })
if (res.code === 200) {
uni.showToast({
title: '解绑成功',
icon: 'success',
})
setTimeout(() => {
uni.navigateBack()
//
uni.$emit('refreshMachineList', {})
}, 1000)
} else {
uni.showToast({
title: res?.msg || '解绑失败',
icon: 'none',
})
}
} }
}, },
}) })
} }
// //
const onConfirmBind = () => { const onConfirmBind = async () => {
if (!machineInfo.value.subcontractorName) { // if (!machineInfo.value.subcontractorName) {
uni.showToast({ // uni.showToast({
title: '请选择分包商', // title: '',
icon: 'none', // icon: 'none',
}) // })
return // return
} // }
if (!machineInfo.value.teamName) { // if (!machineInfo.value.teamName) {
uni.showToast({ // uni.showToast({
title: '请选择班组', // title: '',
icon: 'none', // icon: 'none',
}) // })
return // return
} // }
// TODO: // TODO:
console.log('确认绑定', machineInfo.value) console.log('确认绑定', machineInfo.value)
uni.showToast({
title: '绑定成功', const { proId, deviceCode, deviceName, serialNumber, subId, teamId } = machineInfo.value
icon: 'success',
}) const params = {
proId,
deviceCode,
deviceName,
serialNumber,
subId,
teamId,
}
const res = await confirmBindPmAttDeviceAPI(params)
if (res.code === 200) {
uni.showToast({
title: '绑定成功',
icon: 'success',
})
setTimeout(() => {
uni.navigateBack()
//
uni.$emit('refreshMachineList', {})
}, 1000)
} else {
uni.showToast({
title: res?.msg || '绑定失败',
icon: 'none',
})
}
} }
const onCancelSub = () => { const onCancelSub = () => {
@ -209,9 +259,12 @@ onMounted(() => {
if (options.params) { if (options.params) {
// TODO: ID // TODO: ID
console.log('考勤机ID:', JSON.parse(options.params))
machineInfo.value = JSON.parse(options.params) machineInfo.value = JSON.parse(options.params)
getSubcontractorListFun() getSubcontractorListFun()
if (machineInfo.value.proId && machineInfo.value.subId) {
getSubTeamContractListFun()
}
} }
}) })
</script> </script>

View File

@ -74,7 +74,7 @@
<script setup name="machineSetting"> <script setup name="machineSetting">
import { debounce } from 'lodash-es' import { debounce } from 'lodash-es'
import { ref, computed, onMounted, nextTick } from 'vue' import { ref, computed, onMounted, onUnmounted, nextTick } from 'vue'
import { getMachineListAPI } from '@/services/machine-setting.js' import { getMachineListAPI } from '@/services/machine-setting.js'
import { useCommonStore } from '@/stores' import { useCommonStore } from '@/stores'
@ -89,6 +89,7 @@ const queryParams = ref({
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
deviceName: '', deviceName: '',
proName: '',
}) })
// //
@ -100,10 +101,17 @@ const onSearchName = () => {
} }
// //
const getMachineListFun = async () => { const getMachineListFun = async (isRefresh = false) => {
const res = await getMachineListAPI(queryParams.value) const res = await getMachineListAPI(queryParams.value)
total.value = res?.total total.value = res?.total
machineList.value = [...machineList.value, ...res?.rows]
if (isRefresh) {
//
machineList.value = res?.rows || []
} else {
//
machineList.value = [...machineList.value, ...res?.rows]
}
} }
// //
@ -121,7 +129,17 @@ const hasMore = computed(() => {
// //
const onMachineSettingItem = (item) => { const onMachineSettingItem = (item) => {
const { deviceCode, deviceName, proId, proName, subId, subName, teamId, teamName } = item const {
deviceCode,
deviceName,
proId,
proName,
subId,
subName,
teamId,
teamName,
serialNumber,
} = item
const params = { const params = {
deviceCode, deviceCode,
deviceName, deviceName,
@ -131,15 +149,33 @@ const onMachineSettingItem = (item) => {
subName, subName,
teamId, teamId,
teamName, teamName,
serialNumber,
} }
uni.navigateTo({ uni.navigateTo({
url: `/pages/machine-setting/components/bindSetting?params=${JSON.stringify(params)}`, url: `/pages/machine-setting/components/bindSetting?params=${JSON.stringify(params)}`,
}) })
} }
//
const handleRefreshMachineList = (eventData) => {
console.log('收到刷新机器列表事件:', eventData)
//
queryParams.value.pageNum = 1
//
getMachineListFun(true)
}
onMounted(() => { onMounted(() => {
queryParams.value.proName = commonStore?.activeProjectName queryParams.value.proName = commonStore?.activeProjectName
getMachineListFun() getMachineListFun()
//
uni.$on('refreshMachineList', handleRefreshMachineList)
})
//
onUnmounted(() => {
uni.$off('refreshMachineList', handleRefreshMachineList)
}) })
</script> </script>

View File

@ -9,18 +9,18 @@ export const getMachineListAPI = (data) => {
}) })
} }
// 考勤机解除绑定 // 考勤机解除绑定
export const getMachineUnbindAPI = (data) => { export const unBindPmAttDeviceAPI = (data) => {
return http({ return http({
method: 'GET', method: 'POST',
url: `/bmw/worker/**`, url: `/bmw/pmAttDevice/updatePmAttDevice`,
data, data,
}) })
} }
// 考勤机确认绑定 // 考勤机确认绑定
export const getMachineConfirmBindAPI = (data) => { export const confirmBindPmAttDeviceAPI = (data) => {
return http({ return http({
method: 'GET', method: 'POST',
url: `/bmw/worker/**`, url: `/bmw/pmAttDevice/updatePmAttDevice`,
data, data,
}) })
} }