598 lines
16 KiB
Vue
Raw Normal View History

2025-04-14 10:57:27 +08:00
<template>
2025-05-20 10:19:17 +08:00
<div class="container">
<div class="form-panel">
<uni-forms ref="baseForm" :modelValue="baseFormData" labelWidth="100px">
<uni-forms-item label="所属区域" required name="owningRegion"
:rules="[{ required: true, errorMessage: '请选择所属区域' }]">
<selectOperation v-model="baseFormData.owningRegion" placeholder="请选择所属区域" :disabled="readOnly">
</selectOperation>
</uni-forms-item>
<uni-forms-item label="选择部件" required name="componentType"
:rules="[{ required: true, errorMessage: '请选择部件' }]">
<selectComponentType v-model="baseFormData.componentType" placeholder="请选择部件" :disabled="readOnly"
@change="changeType"></selectComponentType>
</uni-forms-item>
<uni-section v-if="baseFormData.componentType == '262711452730000'" title="电池列表" type="line">
<template v-slot:right>
<uni-icons type="scan" size="20" @click="onBatteryScanClick" v-if="!readOnly"></uni-icons>
</template>
<uni-swipe-action>
<uni-swipe-action-item v-for="(item,index) in listBatteryData" :key="index"
:right-options="listBatteryOptions" :disabled="readOnly">
<div class="content-box">
<label>{{item.batteryCode}}</label>
<div v-show="readOnly" @click="delData(index)">
<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
color="rgb(121 116 116)" size="20" />
</div>
</div>
</uni-swipe-action-item>
</uni-swipe-action>
</uni-section>
<uni-section v-if="baseFormData.componentType == '262711452730001'" title="头盔列表" type="line">
<template v-slot:right>
<uni-icons type="scan" size="20" @click="onHelmetScanClick" v-if="!readOnly"></uni-icons>
</template>
<uni-swipe-action>
<uni-swipe-action-item v-for="(item,index) in listHelmetData" :key="index"
:right-options="listHelmetOptions" @click="onHelmetListClick($event, index, item)"
:disabled="readOnly">
<div class="content-box">
<label>{{item.helmetCode}}</label>
<div v-show="readOnly" @click="delData(index)">
<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
color="rgb(121 116 116)" size="20" />
</div>
</div>
</uni-swipe-action-item>
</uni-swipe-action>
</uni-section>
<uni-section v-if="baseFormData.componentType == '262711452730008'" title="中控列表" type="line">
<template v-slot:right>
<uni-icons type="scan" size="20" @click="onScanClick" v-if="!readOnly"></uni-icons>
</template>
<uni-swipe-action>
<uni-swipe-action-item v-for="(item,index) in listEcuData" :key="index"
:right-options="listHelmetOptions"
:disabled="readOnly">
<div class="content-box">
<label>sn{{item.sn}}</label>
<div v-show="readOnly" @click="delData(index)">
<uni-icons custom-prefix="iconfont" type="icon-ebikeshanchu"
color="rgb(121 116 116)" size="20" />
</div>
</div>
</uni-swipe-action-item>
</uni-swipe-action>
</uni-section>
<uni-forms-item label="入库数量" required name="enterQuantity"
:rules="[{ required: true, errorMessage: '请输入入库数量' }]">
<uni-number-box :background="(readOnly||disabledNum)?'#d8d9d0':'#ffffff'"
v-model="baseFormData.enterQuantity" placeholder="请输入入库数量" :disabled="readOnly||disabledNum" />
</uni-forms-item>
<uni-forms-item label="部件单价(元)">
<uni-easyinput v-model="baseFormData.componentPrice" placeholder="请输入部件单价,单位:元"
:disabled="readOnly" />
</uni-forms-item>
</uni-forms>
</div>
</div>
<div class="nav-panel" v-if="baseFormData.state == '0'">
<c-uni-goods-nav :fill="true" :options="navOptions" @click="navOptionsClick" :buttonGroup="navButtonGroup"
@buttonClick="navButtonClick" />
</div>
2025-04-14 10:57:27 +08:00
</template>
<script setup>
import {
onMounted,
ref,
reactive,
computed
} from 'vue';
import * as api from '@/utils/api.js';
import {
showModelMessage,
isNullOrEmpty,
dataFormat
} from '@/utils/tools.js';
2025-05-20 10:19:17 +08:00
import {
onLoad,
onShow
} from '@dcloudio/uni-app';
2025-04-14 10:57:27 +08:00
import {
useScanCodeStore
} from '@/stores/scancode.js';
const scancode = useScanCodeStore();
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
const baseForm = ref(null);
const readOnly = ref(false);
const userInfo = ref(null);
const componentEnterRecordId = ref("");
// 基础表单数据
const baseFormData = ref({
"componentEnterRecordId": "",
"owningRegion": "",
"componentType": "",
"enterQuantity": 0,
"componentPrice": "",
"createdUser": "",
"createdAt": "",
"state": "0",
"updateUser": "",
"updateAt": ""
});
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
const navOptions = reactive([{
icon: 'download',
text: '暂存',
disable: false
}, {
icon: 'closeempty',
text: '取消',
disable: false
}]);
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
const navButtonGroup = reactive([{
text: '入库',
backgroundColor: '#0078D4',
color: '#fff',
disable: false
}]);
2025-05-20 10:19:17 +08:00
const disabledNum = ref(false);
2025-04-14 10:57:27 +08:00
// 在组件挂载完成后加载数据
onMounted(() => {
2025-05-20 10:19:17 +08:00
if (!isNullOrEmpty(componentEnterRecordId.value)) {
2025-04-14 10:57:27 +08:00
loadData();
}
});
2025-05-20 10:19:17 +08:00
onLoad((options) => {
if (options.componentEnterRecordId) {
componentEnterRecordId.value = options.componentEnterRecordId;
2025-04-14 10:57:27 +08:00
}
userInfo.value = uni.getStorageSync('userInfo');
})
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
onShow(() => {
2025-05-20 10:19:17 +08:00
if (!isNullOrEmpty(scancode.code)) {
2025-04-14 10:57:27 +08:00
const arr = scancode.code;
for (let i = 0; i < arr.length; i++) {
2025-05-20 10:19:17 +08:00
if (scancode.type == 'inBattery') {
2025-04-14 10:57:27 +08:00
const oneBattery = {
2025-05-20 10:19:17 +08:00
"batteryEnterRecordId": "",
"componentEnterRecordId": componentEnterRecordId.value,
"batteryCode": arr[i]
2025-04-14 10:57:27 +08:00
}
listBatteryData.value.push(oneBattery)
baseFormData.value.enterQuantity = listBatteryData.value.length
2025-05-20 10:19:17 +08:00
} else if (scancode.type == 'inHelmet') {
2025-04-14 10:57:27 +08:00
const oneHelmet = {
2025-05-20 10:19:17 +08:00
"helmetEnterRecordId": "",
"componentEnterRecordId": componentEnterRecordId.value,
"helmetCode": arr[i]
2025-04-14 10:57:27 +08:00
}
listHelmetData.value.push(oneHelmet)
baseFormData.value.enterQuantity = listHelmetData.value.length
2025-05-20 10:19:17 +08:00
}
else if (scancode.type == 'inEcu') {
const arrCode=arr[i].split(" ");
const imei = arrCode[0].replace("IMEI:", "");
const sn = arrCode[1].replace("SN:", "");
const oneHelmet = {
id: "",
imei: imei,
sn: sn
}
listEcuData.value.push(oneHelmet);
baseFormData.value.enterQuantity = listEcuData.value.length;
}
else break;
2025-04-14 10:57:27 +08:00
}
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
scancode.clearCode();
2025-05-20 10:19:17 +08:00
}
2025-04-14 10:57:27 +08:00
});
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
// 假设这是从接口加载的数据
const loadData = () => {
2025-05-20 10:19:17 +08:00
api.callOperateApi("ebikeComponentEnterRecords/getInfo?id=" + componentEnterRecordId.value, {}, "get").then((
res) => {
2025-04-14 10:57:27 +08:00
if (res.code === 200) {
baseFormData.value = res.data;
2025-05-20 10:19:17 +08:00
if (baseFormData.value.componentType == '262711452730000') {
2025-04-14 10:57:27 +08:00
getBatteryList(baseFormData.value.componentEnterRecordId);
2025-05-20 10:19:17 +08:00
} else if (baseFormData.value.componentType == '262711452730001') {
2025-04-14 10:57:27 +08:00
getHelmetList(baseFormData.value.componentEnterRecordId);
}
2025-05-20 10:19:17 +08:00
if (baseFormData.value.state != "0") {
2025-04-14 10:57:27 +08:00
readOnly.value = true;
navOptions[0].disable = true;
navOptions[1].disable = true;
navButtonGroup[0].disable = true;
}
}
})
};
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
const listBatteryData = ref([]);
const listHelmetData = ref([]);
2025-05-20 10:19:17 +08:00
const listEcuData = ref([]);
function getBatteryList(componentEnterRecordId, pageNo = 1, pageSize = 100) {
2025-04-14 10:57:27 +08:00
// 组装参数
const params = {
"componentEnterRecordId": componentEnterRecordId,
"pageParam": {
"pageNum": pageNo,
"pageSize": pageSize
}
}
api.callOperateApi("ebikeBatteryEnterRecords/list", params).then((res) => {
if (res.code === 200) {
listBatteryData.value.push(...res.data.records);
baseFormData.value.enterQuantity = listBatteryData.value.length;
2025-05-20 10:19:17 +08:00
if (res.data.totalRow > pageNo * pageSize) {
2025-04-14 10:57:27 +08:00
pageNo += 1;
getBatteryList(componentEnterRecordId, pageNo, pageSize);
}
}
});
}
2025-05-20 10:19:17 +08:00
const getHelmetList = (componentEnterRecordId, pageNo = 1, pageSize = 100) => {
2025-04-14 10:57:27 +08:00
// 组装参数
const params = {
"componentEnterRecordId": componentEnterRecordId,
"pageParam": {
"pageNum": pageNo,
"pageSize": pageSize
}
}
api.callOperateApi("ebikeHelmetEnterRecords/list", params).then((res) => {
if (res.code === 200) {
listHelmetData.value.push(...res.data.records);
baseFormData.value.enterQuantity = listHelmetData.value.length;
2025-05-20 10:19:17 +08:00
if (res.data.totalRow > pageNo * pageSize) {
2025-04-14 10:57:27 +08:00
pageNo += 1;
getHelmetList(componentEnterRecordId, pageNo, pageSize);
}
}
});
}
2025-05-20 10:19:17 +08:00
const navOptionsClick = (e) => {
2025-04-14 10:57:27 +08:00
const index = e.index;
2025-05-20 10:19:17 +08:00
if (index == 0) {
2025-04-14 10:57:27 +08:00
handleSubmit('0');
2025-05-20 10:19:17 +08:00
} else if (index == 1) {
2025-04-14 10:57:27 +08:00
handleSubmit('-1');
}
}
2025-05-20 10:19:17 +08:00
const navButtonClick = (e) => {
2025-04-14 10:57:27 +08:00
const index = e.index;
//navButtonGroup[index].disable = true;
2025-05-20 10:19:17 +08:00
if (index == 0) {
2025-04-14 10:57:27 +08:00
if (baseForm.value) { // 确保表单元素已挂载
baseForm.value.validate().then((res) => {
2025-05-20 10:19:17 +08:00
if (baseFormData.value.componentType == '262711452730000') {
if (listBatteryData.value.length == 0) {
2025-04-14 10:57:27 +08:00
showModelMessage("电池列表不能为空!");
return false;
}
}
2025-05-20 10:19:17 +08:00
if (baseFormData.value.componentType == '262711452730001') {
if (listHelmetData.value.length == 0) {
2025-04-14 10:57:27 +08:00
showModelMessage("头盔列表不能为空!");
return false;
}
}
handleSubmit('1');
}).catch((err) => {
//console.log('err', err);
});
} else {
//console.error('Form element is not available'); // 调试信息,以防万一
}
}
}
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
const handleSubmit = (state) => {
let sucessMsg = "保存成功";
let errorMsg = "保存失败";
2025-05-20 10:19:17 +08:00
if (state == '-1') {
2025-04-14 10:57:27 +08:00
sucessMsg = "取消成功";
errorMsg = "取消失败";
baseFormData.value.state = '-1';
2025-05-20 10:19:17 +08:00
} else if (state == '1') {
2025-04-14 10:57:27 +08:00
sucessMsg = "入库成功";
errorMsg = "入库失败";
baseFormData.value.state = '1';
}
const params = baseFormData.value;
2025-05-20 10:19:17 +08:00
saveBaseInfo((bresult) => {
if (!bresult) {
2025-04-14 10:57:27 +08:00
uni.showToast({
title: errorMsg,
icon: 'error',
duration: 5000
});
2025-05-20 10:19:17 +08:00
} else {
if (params.componentType == '262711452730000') {
saveBatteryData((bresult1) => {
if (!bresult1) {
2025-04-14 10:57:27 +08:00
uni.showToast({
title: errorMsg,
icon: 'error',
duration: 5000
});
2025-05-20 10:19:17 +08:00
} else {
2025-04-14 10:57:27 +08:00
uni.showToast({
title: sucessMsg,
icon: 'success',
duration: 1000,
success: (res) => {
2025-05-20 10:19:17 +08:00
if (params.state != '0') {
setTimeout(function() {
uni.navigateBack();
2025-04-14 10:57:27 +08:00
}, 1000);
}
}
});
}
})
2025-05-20 10:19:17 +08:00
} else if (params.componentType == '262711452730001') {
saveHelmetData((bresult1) => {
if (!bresult1) {
uni.showToast({
title: errorMsg,
icon: 'error',
duration: 5000
});
} else {
uni.showToast({
title: sucessMsg,
icon: 'success',
duration: 1000,
success: (res) => {
if (params.state != '0') {
setTimeout(function() {
uni.navigateBack();
}, 1000);
2025-04-14 10:57:27 +08:00
}
2025-05-20 10:19:17 +08:00
}
});
}
2025-04-14 10:57:27 +08:00
})
2025-05-20 10:19:17 +08:00
} else {
2025-04-14 10:57:27 +08:00
uni.showToast({
title: sucessMsg,
icon: 'success',
duration: 1000,
success: (res) => {
2025-05-20 10:19:17 +08:00
if (params.state != '0') {
setTimeout(function() {
uni.navigateBack();
2025-04-14 10:57:27 +08:00
}, 1000);
}
}
});
}
}
});
};
2025-05-20 10:19:17 +08:00
const saveBaseInfo = (callback) => {
2025-04-14 10:57:27 +08:00
const params = baseFormData.value;
2025-05-20 10:19:17 +08:00
if (isNullOrEmpty(baseFormData.value.createdUser)) baseFormData.value.createdUser = userInfo.value.username;
if (isNullOrEmpty(baseFormData.value.createdAt)) baseFormData.value.createdAt = dataFormat(new Date(),
'yyyy-MM-dd HH:mm:ss');
if (!isNullOrEmpty(componentEnterRecordId.value)) {
2025-04-14 10:57:27 +08:00
baseFormData.value.updateUser = userInfo.value.username;
2025-05-20 10:19:17 +08:00
baseFormData.value.updateAt = dataFormat(new Date(), 'yyyy-MM-dd HH:mm:ss');
api.callOperateApi("ebikeComponentEnterRecords/update", params).then((res) => {
if (res.code == '200') callback(true);
2025-04-14 10:57:27 +08:00
else callback(false);
});
2025-05-20 10:19:17 +08:00
} else {
api.callOperateApi("ebikeComponentEnterRecords/save", params).then((res) => {
if (res.code == '200') {
2025-04-14 10:57:27 +08:00
componentEnterRecordId.value = res.data;
callback(true);
2025-05-20 10:19:17 +08:00
} else callback(false);
2025-04-14 10:57:27 +08:00
});
}
}
2025-05-20 10:19:17 +08:00
const saveBatteryData = (callback) => {
2025-04-14 10:57:27 +08:00
const listdatas = [];
listBatteryData.value.forEach((item, index) => {
listdatas.push(item.batteryCode);
});
const params = {
componentEnterRecordId: componentEnterRecordId.value,
batteryCodes: listdatas
}
2025-05-20 10:19:17 +08:00
api.callOperateApi("ebikeBatteryEnterRecords/batchSaveByComponentEnterRecordId", params).then((res) => {
if (res.code == '200') {
if (baseFormData.value.state == '1') {
api.callEbikeInfo("saveBatteryInfo", listdatas).then((res) => {
if (res.code == '200') {
2025-04-14 10:57:27 +08:00
callback(true);
2025-05-20 10:19:17 +08:00
} else {
2025-04-14 10:57:27 +08:00
callback(false);
}
});
2025-05-20 10:19:17 +08:00
} else {
2025-04-14 10:57:27 +08:00
callback(true);
}
2025-05-20 10:19:17 +08:00
} else {
2025-04-14 10:57:27 +08:00
callback(false);
}
});
}
2025-05-20 10:19:17 +08:00
const saveHelmetData = (callback) => {
2025-04-14 10:57:27 +08:00
const listdatas = [];
listHelmetData.value.forEach((item, index) => {
listdatas.push(item.helmetCode);
});
const params = {
componentEnterRecordId: componentEnterRecordId.value,
helmetCodes: listdatas
}
2025-05-20 10:19:17 +08:00
api.callOperateApi("ebikeHelmetEnterRecords/batchSaveByComponentEnterRecordId", params).then((res) => {
if (res.code == '200') {
if (baseFormData.value.state == '1') {
api.callEbikeInfo("saveHelmetInfo", listdatas).then((res) => {
if (res.code == '200') {
2025-04-14 10:57:27 +08:00
callback(true);
2025-05-20 10:19:17 +08:00
} else {
2025-04-14 10:57:27 +08:00
callback(false);
}
});
2025-05-20 10:19:17 +08:00
} else {
2025-04-14 10:57:27 +08:00
callback(true);
}
2025-05-20 10:19:17 +08:00
} else {
2025-04-14 10:57:27 +08:00
callback(false);
}
});
}
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
const listBatteryOptions = reactive([{
text: '删除',
style: {
backgroundColor: '#007aff'
}
}]);
2025-05-20 10:19:17 +08:00
2025-04-14 10:57:27 +08:00
const listHelmetOptions = reactive([{
text: '删除',
style: {
backgroundColor: '#007aff'
}
}]);
2025-05-20 10:19:17 +08:00
const onBatteryListClick = (e, index, item) => {
if (e.position == 'right') {
if (e.index == 0) {
2025-04-14 10:57:27 +08:00
if (index != -1) {
2025-05-20 10:19:17 +08:00
listBatteryData.value.splice(index, 1); // 删除索引位置的元素
2025-04-14 10:57:27 +08:00
baseFormData.value.enterQuantity = listBatteryData.value.length;
}
}
2025-05-20 10:19:17 +08:00
}
2025-04-14 10:57:27 +08:00
}
2025-05-20 10:19:17 +08:00
const onHelmetListClick = (e, index, item) => {
if (e.position == 'right') {
if (e.index == 0) {
2025-04-14 10:57:27 +08:00
if (index != -1) {
2025-05-20 10:19:17 +08:00
listHelmetData.value.splice(index, 1); // 删除索引位置的元素
2025-04-14 10:57:27 +08:00
baseFormData.value.enterQuantity = listHelmetData.value.length;
}
}
}
}
2025-05-20 10:19:17 +08:00
const onBatteryScanClick = (e) => {
2025-04-14 10:57:27 +08:00
uni.navigateTo({
url: `/pages/common/batchscancode?type=inBattery`, //
});
// uni.scanCode({
// onlyFromCamera: true, //只能扫码
// scanType: ["qrCode"],
// success: function(res) {
// const {
// result
// } = res;
// console.log(result);
// const oneBattery = {
// "batteryEnterRecordId": "",
// "componentEnterRecordId": componentEnterRecordId.value,
// "batteryCode": result
// }
// listBatteryData.value.push(oneBattery)
// baseFormData.value.enterQuantity = listBatteryData.value.length
// }
// })
}
2025-05-20 10:19:17 +08:00
const onHelmetScanClick = (e) => {
2025-04-14 10:57:27 +08:00
uni.navigateTo({
url: `/pages/common/batchscancode?type=inHelmet`, //
});
2025-05-20 10:19:17 +08:00
}
function onScanClick (e) {
uni.navigateTo({
url: `/pages/common/batchscancode?k=${Date.now()}`, //
});
}
function changeType(value) {
if (",262711452730000,262711452730001,262711452730008,".indexOf("," + value + ",") > -1) {
disabledNum.value = true;
} else {
disabledNum.value = false;
}
baseFormData.value.enterQuantity = 0;
}
function delData(index) {
switch (baseFormData.value.componentType) {
case "262711452730000":
listBatteryData.value.splice(index, 1);
break;
case "262711452730001":
listHelmetData.value.splice(index, 1);
break;
case "262711452730008":
listEcuData.value.splice(index, 1);
break;
}
baseFormData.enterQuantity.value = baseFormData.enterQuantity.value - 1;
2025-04-14 10:57:27 +08:00
}
</script>
<style lang="scss">
.container {
padding: 15px;
background-color: #fff;
}
2025-05-20 10:19:17 +08:00
.form-panel {
2025-04-14 10:57:27 +08:00
padding-bottom: 55px;
}
2025-05-20 10:19:17 +08:00
.nav-panel {
2025-04-14 10:57:27 +08:00
position: fixed;
bottom: 0rpx;
width: 100%;
padding-bottom: 10px;
z-index: 999;
2025-05-20 10:19:17 +08:00
background-color: #fff;
2025-04-14 10:57:27 +08:00
}
2025-05-20 10:19:17 +08:00
.content-box {
display: flex;
2025-04-14 10:57:27 +08:00
line-height: 50px;
border-bottom: 1px solid #f4f4f4;
}
2025-05-20 10:19:17 +08:00
.content-box label {
flex: 1
}
.uni-section {
2025-04-14 10:57:27 +08:00
margin: 20px 0px;
}
2025-05-20 10:19:17 +08:00
.uni-section-header {
2025-04-14 10:57:27 +08:00
border-top: 1px solid #f4f4f4;
border-bottom: 1px solid #f4f4f4;
}
</style>