现场维修二维码

This commit is contained in:
jiang 2025-07-30 16:16:45 +08:00
parent 6ce7237725
commit dd7c0ffc0c
4 changed files with 400 additions and 310 deletions

View File

@ -108,7 +108,6 @@ const onQrCode = () => {
const handleSearch = () => {
console.log('🚀 ~ handleSearch ~ 查询:', keyWord.value)
// typeList.value =[];
reset()
getWsMaInfoList({ maCode: keyWord.value }).then(res => {
if (res.code === 200 && res.data && res.data.length > 0) {
@ -116,9 +115,7 @@ const handleSearch = () => {
return {
id: option.id,
label: option.maName + '-' + option.maModel + '-' + option.maCode,
/* isChecked: 1,*/
item: option,
}
})
if (res.data.length === 1) {
@ -164,7 +161,7 @@ const handleCheck = (item) => {
//
const handleScanSuccess = (result) => {
keyWord.value = result?.data?.split('?qrcode=')[1] || result?.data
keyWord.value = result?.data?.split('?qrcode=')[1]
if (keyWord.value === '') {
uni.showToast({ title: '扫码识别失败', icon: 'none' })
} else {
@ -293,13 +290,17 @@ const handleSubmit = () => {
//
.btn {
margin-top: auto;
padding: 32rpx;
// background: #fff;
// box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
position: fixed;
bottom: 0;
left: 0;
width: calc(100% - 20px);
background-color: #fff; /* 可根据需要设定背景色 */
padding: 10px;
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1); /* 可选:添加顶部阴影 */
display: flex;
justify-content: space-between;
gap: 24rpx;
justify-content: center; /* 水平居中 */
gap: 10px; /* 按钮间距 */
z-index: 999; /* 保证显示在最上层 */
.btn-cont {
flex: 1;

View File

@ -1,346 +1,424 @@
<template>
<uni-nav-bar
fixed
:border="false"
background-color="#dcf4ff"
color="black"
status-bar
title="铭牌信息更新"
><template v-slot:left>
<view style="display: flex; align-items: center" @click="back">
<!-- 图标 -->
<uni-icons type="left" size="20" color="black"></uni-icons>
</view>
</template>
<template v-slot:right>
<view style="display: flex; align-items: center" @click="onQrCode">
<!-- 文本 -->
<text>二维码</text>
</view>
</template>
</uni-nav-bar>
<div class="content">
<div class="search">
<uni-easyinput v-model="keyWord" placeholder="请输入设备编码"></uni-easyinput>
<button
type="primary"
size="mini"
@click="handleSearch"
style="margin-left: 10px; background-color: #18bc37"
>
查询
</button>
</div>
<div
v-if="typeList.length > 1"
class="popup"
style="margin-bottom: 30px"
@click="handlePopup(1)"
<uni-nav-bar
fixed
:border="false"
background-color="#dcf4ff"
color="black"
status-bar
title="铭牌信息更新"
>
{{ typeName || '请选择对应机具' }}
</div>
<template v-slot:left>
<view class="nav-back" @click="handleBack">
<uni-icons type="left" size="20" color="black" />
</view>
</template>
</uni-nav-bar>
<div class="search-item">
<div>设备类型{{ formData.materialName }}</div>
<div>
<span><span style="color: red">*</span>规格型号</span
><uni-easyinput v-model="formData.materialModel" placeholder="请输入"></uni-easyinput>
</div>
<div>二维码{{ formData.qrCode }}</div>
<div>设备编码{{ formData.maCode }}</div>
<div>设备状态{{ formData.maStatus }}</div>
<div>
<span>本次检修人员</span
><uni-easyinput v-model="formData.checkMan" placeholder="请输入"></uni-easyinput>
</div>
<div>
<span>本次检修时间</span>
<uni-datetime-picker type="date" v-model="formData.thisCheckTime" @change="changeTime" />
</div>
<div>
<span>下次检修时间</span>
<uni-datetime-picker
type="date"
v-model="formData.nextCheckTime"
@change="changeNextTime"
/>
</div>
<div>
<span><span style="color: red">*</span>出厂时间</span>
<uni-datetime-picker type="date" v-model="formData.outFacTime" @change="changeFacTime" />
</div>
<div style="display: flex; align-items: center; justify-content: space-between">
<div><span style="color: red">*</span>机具厂家</div>
<div class="popup" style="width: 70%" @click="handlePopup(2)">
{{ formData.maVender || '请选择' }}
</div>
</div>
</div>
<button
type="primary"
size="mini"
@click="handleSubmit"
style="margin-top: 30px; background-color: #18bc37; width: 100%"
>
确认修改
</button>
</div>
<view class="container">
<!-- 搜索区域 -->
<view class="search-card card">
<view class="search-container">
<uni-easyinput
v-model="searchParams.keyWord"
placeholder="请输入设备编码"
clearable
/>
<button
type="primary"
size="mini"
@click="handleSearch"
class="search-btn"
>
查询
</button>
<button
type="primary"
size="mini"
@click="handleScanQrCode"
class="search-btn"
>
二维码
</button>
</view>
</view>
<uni-popup ref="popup" border-radius="5px 5px 5px 5px" background-color="#fff">
<div
v-for="(item, index) in list"
:key="index"
class="popup-item"
@click.stop="handleCheck(item)"
>
<div>{{ item.name }}</div>
<uni-data-checkbox
v-model="item.isChecked"
:localdata="range"
@change="handleCheck(item, $event)"
></uni-data-checkbox>
</div>
</uni-popup>
<ScanQrCode ref="scanQrCodeRef" @scanSuccess="handleScanSuccess" @scanError="handleScanError" />
<!-- 设备类型选择 -->
<view class="card" v-if="deviceTypes.length > 1">
<select-one
v-model="selectedDeviceTypeId"
:options="deviceTypes"
placeholder="请选择对应机具"
@change="handleDeviceTypeChange"
/>
</view>
<!-- 表单区域 -->
<view class="card">
<uni-forms :model="formData" label-width="200rpx" :border="true">
<uni-forms-item label="设备类型" name="materialName" required>
<uni-easyinput disabled v-model="formData.materialName" />
</uni-forms-item>
<uni-forms-item label="规格型号" name="materialModel" required>
<uni-easyinput v-model="formData.materialModel" />
</uni-forms-item>
<uni-forms-item label="二维码" name="qrCode" required>
<uni-easyinput disabled v-model="formData.qrCode" />
</uni-forms-item>
<uni-forms-item label="设备编码" name="maCode" required>
<uni-easyinput disabled v-model="formData.maCode" />
</uni-forms-item>
<uni-forms-item label="设备状态" name="maStatus" required>
<uni-easyinput disabled v-model="formData.maStatus" />
</uni-forms-item>
<uni-forms-item label="本次检修人员" name="checkMan" required>
<uni-easyinput v-model="formData.checkMan" />
</uni-forms-item>
<uni-forms-item label="本次检修时间" name="thisCheckTime" required>
<uni-datetime-picker
type="date"
v-model="formData.thisCheckTime"
@change="handleThisCheckTimeChange"
/>
</uni-forms-item>
<uni-forms-item label="下次检修时间" name="nextCheckTime" required>
<uni-datetime-picker
type="date"
v-model="formData.nextCheckTime"
@change="handleNextCheckTimeChange"
/>
</uni-forms-item>
<uni-forms-item label="出厂时间" name="outFacTime" required>
<uni-datetime-picker
type="date"
v-model="formData.outFacTime"
@change="handleOutFacTimeChange"
/>
</uni-forms-item>
<uni-forms-item label="机具厂家" name="supplierId" required>
<select-one
ref="supplierSelect"
v-model="formData.supplierId"
:options="suppliers"
placeholder="请选择机具厂家"
@change="handleSupplierChange"
/>
</uni-forms-item>
</uni-forms>
</view>
<!-- 提交按钮 -->
<view class="submit-btn-container">
<button class="submit-btn" @click="handleSubmit">
确认
</button>
</view>
</view>
<ScanQrCode
ref="scanQrCodeRef"
@scanSuccess="handleScanSuccess"
@scanError="handleScanError"
/>
</template>
<script setup>
import { getInfoByCode, updateInfo } from '@/services/information'
import { getSupplierList } from '@/services/repair/repair.js'
import { onLoad } from '@dcloudio/uni-app'
import { reactive, ref } from 'vue'
import { ref, onMounted } from 'vue'
import {
getInfoByCode,
updateInfo,
getSupplierList,
} from '@/services/information'
import ScanQrCode from '@/pages/devicesSearch/ScanQrCode'
import SelectOne from '../repair/tree-select/select-one.vue'
const keyWord = ref('')
const qrCode = ref('')
let formData = reactive({
id: '',
maVender: '',
supplierId: '',
})
const scanQrCodeRef = ref()
const popup = ref()
const typeName = ref('')
const list = ref([])
const typeList = ref([]) //
const range = ref([{ value: 0, text: '' }])
const supplierList = ref([]) //
// Refs
const scanQrCodeRef = ref(null)
const selectedDeviceTypeId = ref('')
const supplierSelect = ref('')
onLoad(() => {
console.log('onLoad')
getSupplier()
//
const searchParams = ref({
keyWord: '',
})
const back = () => {
uni.navigateBack({
delta: 1,
})
//
const formData = ref({
materialName: '',
materialModel: '',
qrCode: '',
maCode: '',
maStatus: '',
checkMan: '',
thisCheckTime: '',
nextCheckTime: '',
outFacTime: '',
supplierId: '',
})
//
const deviceTypes = ref([])
const suppliers = ref([])
//
onMounted(() => {
fetchSuppliers()
})
//
const handleBack = () => {
uni.navigateBack({ delta: 1 })
}
const onQrCode = () => {
console.log('🚀 ~ onQrCode ~ 二维码:')
if (scanQrCodeRef.value) scanQrCodeRef.value.scanQrCode()
}
const handleSearch = async () => {
if (!searchParams.value.keyWord) {
uni.showToast({ title: '请输入设备编码', icon: 'none' })
return
}
const handleSearch = () => {
console.log('🚀 ~ handleSearch ~ 查询:', keyWord.value)
if (!keyWord.value) {
uni.showToast({
title: '请输入设备编码',
icon: 'none',
})
return
}
qrCode.value = ''
typeList.value = []
getInfo()
}
const getInfo = () => {
const params = {
maCode: keyWord.value,
qrCode: qrCode.value,
}
resetFormData()
getInfoByCode(params)
.then((res) => {
if (res.code === 200 && res.data && res.data.length > 0) {
typeList.value = res.data.map((option) => {
return {
...option,
id: option.maId,
name: option.materialName + '-' + option.materialModel,
isChecked: 1,
}
})
if (res.data.length === 1) {
formData = res.data[0]
try {
const res = await getInfoByCode({ maCode: searchParams.value.keyWord })
if (res.code === 200 && res.data?.length) {
deviceTypes.value = res.data.map(item => ({
...item,
id: item.maId,
label: `${item.materialName}-${item.materialModel}`,
}))
if (res.data.length === 1) {
handleDeviceTypeChange(res.data[0])
}
}
}
})
.catch((error) => {
console.log(error)
})
} catch (error) {
console.error('获取设备信息失败:', error)
uni.showToast({ title: '查询失败', icon: 'none' })
}
}
//
const getSupplier = () => {
getSupplierList()
.then((res) => {
if (res.code === 200) {
supplierList.value = res.rows.map((item) => {
return {
...item,
id: item.supplierId,
name: item.supplier,
isChecked: 1,
isSupplier: true,
}
})
}
})
.catch((error) => {
console.log(error)
})
const fetchSuppliers = async () => {
try {
const res = await getSupplierList()
if (res.code === 200) {
suppliers.value = res.rows.map(item => ({
id: item.supplierId,
label: item.supplier,
}))
}
} catch (error) {
console.error('获取供应商列表失败:', error)
}
}
const changeTime = (e) => {
formData.thisCheckTime = e
const handleDeviceTypeChange = (item) => {
console.log(item)
selectedDeviceTypeId.value = item.maId
formData.value = {
materialName: item.materialName,
materialModel: item.materialModel,
qrCode: item.qrCode,
maCode: item.maCode,
maStatus: item.maStatus,
checkMan: item.checkMan || '',
thisCheckTime: item.thisCheckTime || '',
nextCheckTime: item.nextCheckTime || '',
outFacTime: item.outFacTime || '',
supplierId: item.supplierId || '',
}
supplierSelect.value.showLabel = item.maVender
}
const changeNextTime = (e) => {
formData.nextCheckTime = e
const handleSupplierChange = (item) => {
formData.value.supplierId = item.id
}
const changeFacTime = (e) => {
formData.outFacTime = e
const handleThisCheckTimeChange = (date) => {
formData.value.thisCheckTime = date
// 1
if (date) {
const nextDate = new Date(date)
nextDate.setFullYear(nextDate.getFullYear() + 1)
formData.value.nextCheckTime = formatDate(nextDate)
}
}
const handlePopup = (type) => {
console.log('🚀 ~ handlePopup ~ 弹窗:')
if (type === 1) {
list.value = typeList.value
} else {
list.value = supplierList.value
}
if (list.value.length === 0) {
uni.showToast({ title: '暂无数据', icon: 'none' })
return
}
popup.value.open()
const handleNextCheckTimeChange = (date) => {
formData.value.nextCheckTime = date
}
const handleCheck = (item) => {
console.log('🚀 ~ handleCheck ~ 单选:', item)
// typeList item.isChecked 0 1
list.value.forEach((i) => {
i.isChecked = i.id === item.id ? 0 : 1
})
if (item.isSupplier) {
formData.maVender = item.supplier
formData.supplierId = item.supplierId
} else {
formData = {}
formData = item
typeName.value = item.name
}
popup.value.close()
const handleOutFacTimeChange = (date) => {
formData.value.outFacTime = date
}
const handleScanQrCode = () => {
scanQrCodeRef.value?.scanQrCode()
}
//
const handleScanSuccess = (result) => {
qrCode.value = result?.data?.split('?qrcode=')[1] || result?.data
if (qrCode.value === '') {
uni.showToast({ title: '扫码识别失败', icon: 'none' })
} else {
keyWord.value = ''
getInfo()
}
const qrCode = result?.data?.split('?qrcode=')[1]
if (qrCode) {
searchParams.value.keyWord = ''
formData.value.qrCode = qrCode
handleSearch()
} else {
uni.showToast({ title: '扫码识别失败', icon: 'none' })
}
}
//
const handleScanError = (error) => {
console.error('扫描出错:', error.message)
uni.showToast({ title: error.message, icon: 'none' })
console.error('扫描出错:', error.message)
uni.showToast({ title: error.message, icon: 'none' })
}
//
const handleSubmit = () => {
//
console.log('🚀 ~ handleSubmit ~ formData:', formData)
if (!formData.materialModel || !formData.outFacTime || !formData.maVender) {
uni.showToast({ title: '请填写完整信息', icon: 'none' })
return
}
delete formData.maStatus
updateInfo(formData)
.then((res) => {
if (res.code === 200) {
uni.showToast({
title: res.msg,
icon: 'none',
})
getInfo()
}
})
.catch((error) => {
console.log(error)
})
const handleSubmit = async () => {
const requiredFields = ['materialModel', 'outFacTime', 'supplierId']
const missingField = requiredFields.find(field => !formData.value[field])
if (missingField) {
uni.showToast({ title: '请填写完整信息', icon: 'none' })
return
}
try {
const payload = {
maId: selectedDeviceTypeId.value,
materialModel: formData.value.materialModel,
checkMan: formData.value.checkMan,
thisCheckTime: formData.value.thisCheckTime,
nextCheckTime: formData.value.nextCheckTime,
outFacTime: formData.value.outFacTime,
maVender: formData.value.supplierId,
}
const res = await updateInfo(payload)
if (res.code === 200) {
resetForm()
uni.showToast({ title: res.msg, icon: 'none' })
}
} catch (error) {
console.error('提交失败:', error)
uni.showToast({ title: '提交失败', icon: 'none' })
}
}
const resetFormData = () => {
Object.keys(formData).forEach((key) => {
formData[key] = ''
})
typeName.value = ''
typeList.value = []
const resetForm = () => {
deviceTypes.value = []
formData.value = {
materialName: '',
materialModel: '',
qrCode: '',
maCode: '',
maStatus: '',
checkMan: '',
thisCheckTime: '',
nextCheckTime: '',
outFacTime: '',
supplierId: '',
}
supplierSelect.value.showLabel = ''
selectedDeviceTypeId.value = ''
}
const formatDate = (date) => {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`
}
</script>
<style scoped lang="scss">
.content {
padding: 10px;
<style lang="scss">
.container {
padding: 24rpx 24rpx 100rpx;
background-color: #f7f8fa;
}
.search {
.nav-back {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 30px;
}
}
.popup {
background: #fff;
/* margin: 20px 0 30px; */
padding: 5px 10px;
}
.card {
padding: 32rpx;
background-color: #fff;
border-radius: 20rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
margin-bottom: 24rpx;
}
.search-item {
line-height: 1.9;
div {
display: flex;
align-items: center;
margin-bottom: 5px;
.search-card {
.search-container {
display: flex;
align-items: center;
gap: 10px;
.search-btn {
margin-left: 10px;
background: linear-gradient(135deg, #4b8eff 0%, #3784fb 100%);
white-space: nowrap;
}
}
}
}
.popup-item {
padding: 10px;
border-bottom: 1px solid #c7c9ce;
display: flex;
align-items: center;
justify-content: space-between;
.submit-btn-container {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 20rpx;
background-color: #fff;
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
.submit-btn {
width: 100%;
height: 88rpx;
background: linear-gradient(135deg, #4b8eff 0%, #3784fb 100%);
color: #fff;
border-radius: 44rpx;
font-size: 32rpx;
font-weight: 600;
&:active {
opacity: 0.9;
transform: scale(0.98);
}
}
}
::v-deep .uni-popup__wrapper {
width: calc(100% - 20px);
max-height: 80vh;
overflow: auto;
/* 表单样式优化 */
.uni-forms-item {
padding: 24rpx 0;
border-bottom: 2rpx solid #f5f5f5;
&:last-child {
border-bottom: none;
}
.uni-forms-item__label {
color: #8c8c8c;
}
}
::v-deep .uni-data-checklist {
// flex: 1
flex: none;
/* 输入框和选择框统一样式 */
.uni-easyinput__content,
.uni-select {
border: 2rpx solid #e8e8e8;
border-radius: 12rpx;
height: 88rpx;
padding: 0 24rpx;
&:focus-within {
border-color: #3784fb;
box-shadow: 0 0 0 2rpx rgba(55, 132, 251, 0.1);
}
}
</style>

View File

@ -293,8 +293,7 @@ onLoad(() => {
<style lang="scss">
.accept {
padding: 24rpx;
height: 90vh;
padding: 24rpx 24rpx 100rpx;
word-break: break-all;
background-color: #f7f8fa;
display: flex;
@ -380,13 +379,17 @@ onLoad(() => {
//
.btn {
margin-top: auto;
padding: 32rpx;
// background: #fff;
// box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
position: fixed;
bottom: 0;
left: 0;
width: calc(100% - 20px);
background-color: #fff; /* 可根据需要设定背景色 */
padding: 10px;
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1); /* 可选:添加顶部阴影 */
display: flex;
justify-content: space-between;
gap: 24rpx;
justify-content: center; /* 水平居中 */
gap: 10px; /* 按钮间距 */
z-index: 999; /* 保证显示在最上层 */
.btn-cont {
flex: 1;

View File

@ -18,6 +18,14 @@ export const updateInfo = (data) => {
})
}
export const getSupplierList = (data) => {
return http({
method: 'GET',
url: '/material/ma_supplier_info/select',
data,
})
}
// 盘点绑定-获取设备信息
export const getInventoryInfo = (data) => {
return http({