You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

528 lines
13 KiB

<template>
<!-- 添加维修工单 -->
<view class="add-form-container">
<!-- <u-form :model="form" ref="form1" label-width="160rpx">
<u-form-item label="申请主题" prop="name" required>
<u-input v-model="form.name" placeholder="请输入申请主题" />
</u-form-item>
</u-form> -->
<view class="list">
<view class="title">
<span>*</span>备件维修
</view>
<view class="item " v-for="(item,index) in form" :key="index">
<view class="item-box">
<view class="spare-title">
<view class="title-txt">
{{item.name}}
</view>
</view>
<u-row gutter="16">
<u-col :span="24">
<view class="dec">
库区:{{item.areaName}}
</view>
</u-col>
<u-col :span="24">
<view class="dec">
库位:{{item.locationName}}
</view>
</u-col>
<u-col :span="24">
<view class="dec">
数量:{{item.qty}}
</view>
</u-col>
<u-col :span="24">
<view class="dec">
维修原因:{{item.repairCause}}
</view>
</u-col>
</u-row>
</view>
<u-icon name="minus-circle" color="#aaaaaa" size="60" @click="delSpareParts(index)"></u-icon>
</view>
<view class="add-btn">
<u-button type="primary" @click="open"><u-icon name="plus-circle" color="#ffffff"
size="36"></u-icon>添加备件</u-button>
</view>
</view>
<view class="footer">
<view class="btns">
<button class="reset" @click="reset">重置</button>
<button class="sure" @click="submit" :loading='loading' :disabled='loading'>确定</button>
</view>
<view style="height: constant(safe-area-inset-bottom); height: env(safe-area-inset-bottom);"></view>
</view>
<!-- 添加备件 -->
<u-popup v-model="isPopupShow" mode="center" border-radius="14">
<view class="popup-title">添加备件</view>
<view class="popup">
<u-form :model="form1" ref="formRef" label-width="200rpx">
<u-form-item :label="`备件`" prop="sparePartsCode" required>
<view class="select" @click="openSingleColumn('sparePartsCode',form1.sparePartsCode,sparePartsList)">
<view class="input" v-if='form1.sparePartsCode'>
{{form1.name}}
</view>
<view class="placeholder" v-else>
请选择备件
</view>
<u-icon name="arrow-right" color="#aaaaaa" size="28"></u-icon>
</view>
</u-form-item>
<u-form-item label="库区" prop="areaCode" required>
<u-input v-model="form1.areaName" placeholder="请选择备件" disabled="true" @blur="blur()" @confirm='blur()'/>
<view class="right-button" @click="chickRightButton" v-if="isShow">
扫描
</view>
</u-form-item>
<u-form-item label="库位" prop="locationCode" required>
<u-input v-model="form1.locationName" placeholder="请选择备件" disabled="true" @blur="blur()" @confirm='blur()'/>
<view class="right-button" @click="chickRightButton" v-if="isShow">
扫描
</view>
</u-form-item>
<u-form-item label="数量" prop="qty" required >
<u-input v-model="form1.qty" type="number" disabled="true" placeholder="请输入数量" />
</u-form-item>
<u-form-item label="维修原因" prop="repairCause" required>
<u-input v-model="form1.repairCause" placeholder="请输入维修原因" />
</u-form-item>
</u-form>
</view>
<view class="popup-footer">
<view @click="isPopupShow = false">取消</view>
<view class="sure" @click="addSpare">确认</view>
</view>
</u-popup>
<u-select v-model="singleColumnShow" mode="single-column" :default-value='singleColumnDefaultValue'
:list="singleColumnList" @confirm="chooseSingleColumn" @cancle='singleColumnShow = false'></u-select>
</view>
</template>
<script setup lang="ts">
import {
onLoad,
} from '@dcloudio/uni-app'
import {
ref,
getCurrentInstance
} from 'vue'
import * as sparePartsApi from "@/api/eam/spareParts.js"
import * as sparePartsServiceWorkOrderListApi from "@/api/eam/sparePartsServiceWorkOrderList.js"
import * as dictApi from "@/api/eam/dict.js"
import * as locationApi from "@/api/location.js"
import * as workShopApi from "@/api/wms/workShop.js"
const { proxy } = getCurrentInstance()
const loading = ref(false)
const type = ref('')
// 备件弹窗
const isPopupShow = ref(false)
const sparePartsList = ref([])
const singleColumnShow = ref(false)
const singleColumnDefaultValue = ref([])
const singleColumnList = ref([])
const field = ref('')
const form = ref([])
const form1 = ref({
sparePartsCode: "",
qty: '',
result: 'YES',
repairCause: '',
locationCode: '',
areaCode: '',
locationName: '',
areaName: '',
})
const result = ref([])
const isShow = ref(false)
const choosesingleColumnItem = ref()
const sparePartsCode = ref()
const msg = ref('')
const areaBasicInfo = ref([])
const locationBasicInfo = ref([])
// 触发提交表单
function submit() {
// 校验
if (form1.value == 0) {
proxy.$modal.showToast('请选择备件')
return;
}
proxy.$modal.confirm('是否添加备件维修工单').then(() => {
proxy.$modal.loading('加载中')
loading.value = true
sparePartsServiceWorkOrderListApi.sparePartsServiceWorkOrderListCreate(form1.value).then((
res) => {
proxy.$modal.closeLoading()
if (res.data) {
proxy.$modal.showToast('添加成功')
setTimeout(() => {
proxy.$tab.navigateBack()
loading.value = false
}, 1500)
} else {
if(res.msg){
proxy.$modal.showToast(res.msg)
}else{
proxy.$modal.showToast('添加失败')
}
loading.value = false
}
}).catch(() => {
proxy.$modal.closeLoading()
loading.value = false
})
})
}
// 重置
function reset() {
form1.value = {
sparePartsCode: "",
qty: '',
result: 'YES',
repairCause: '',
locationCode: '',
areaCode: '',
locationName: '',
areaName: ''
}
}
// 单列模式
function openSingleColumn(fieldName, val, list) {
if (fieldName == 'deviceNumber' && form.value.id) return;
singleColumnList.value = list
field.value = fieldName
if (val) {
singleColumnDefaultValue.value = [list.findIndex(item => item.value == val)]
} else {
singleColumnDefaultValue.value = []
}
workShopApi.getAreaBasicInfoNoPage({}).then(res=>{
areaBasicInfo.value = res.data
})
workShopApi.getLocationBasicInfoNoPage({}).then(res=>{
locationBasicInfo.value = res.data
})
singleColumnShow.value = true
}
// 单列模式点击确定之后
function chooseSingleColumn(e) {
form1.value[field.value] = e[0].value
if (field.value == 'sparePartsCode') {
choosesingleColumnItem.value = singleColumnList.value.filter(item => item.code == e[0].value)
form1.value.name = e[0].label
form1.value.qty = 1
form1.value.locationCode = choosesingleColumnItem.value[0].locationCode
form1.value.areaCode = choosesingleColumnItem.value[0].areaCode
form1.value.areaName = areaBasicInfo.value?.find(item=>{
return item.code == form1.value.areaCode
})?.name
form1.value.locationName = locationBasicInfo.value?.find(item=>{
return item.code == form1.value.locationCode
})?.name
if (!choosesingleColumnItem.value[0].locationCode) {
isShow.value = true
} else {
isShow.value = false
sparePartsCode.value = ''
}
}
singleColumnShow.value = false
}
// 获取备件列表
async function getServiceSparePartsList() {
await sparePartsApi.getServiceSparePartsList().then(res => {
sparePartsApi.getItemAccountsNoPage().then(resp => {
const filteredData = res.data.filter(item => {
// 在resp中查找与item.code匹配的项
const matchedRespItem = resp.data.find(respItem => respItem.itemNumber === item.code);
if (matchedRespItem) {
// 将匹配的项的字段赋值给item
item.areaCode = matchedRespItem.areaNumber;
item.locationCode = matchedRespItem.locationNumber;
item.singlePrice = matchedRespItem.singlePrice;
item.qty = matchedRespItem.qty;
item.value = item.code;
item.label = item.name;
return true; // 保留该项
}
return false; // 过滤掉该项
});
sparePartsList.value = filteredData;
});
}).catch(() => { });
}
// 扫描设备条码
function chickRightButton(field) {
uni.scanCode({
success: function (res) {
form1.value.locationCode = res.result
getLocation()
}
});
}
function getLocation() {
workShopApi.getAreaBasicInfoNoPage({code:form1.value.locationCode}).then(res => {
if (!res.data[0]) {
msg.value = res.msg ? res.msg : '找不到该库位'
proxy.$modal.showToast(msg.value)
form1.value.areaCode =''
sparePartsCode.value = ''
return;
}
msg.value = ''
form1.value.areaCode = res.data[0].areaCode;
sparePartsCode.value = res.data[0].sparePartsCode
}).catch(() => { })
}
function blur() {
if (form1.value.locationCode) {
getLocation()
}
}
// 打开弹窗
function open() {
form1.value = {
sparePartsCode: "",
qty: '',
result: 'YES',
repairCause: '',
locationCode: '',
areaCode: '',
locationName: '',
areaName: ''
}
isPopupShow.value = true
}
// 添加配件
function addSpare() {
// 校验
if (!form1.value.sparePartsCode) {
proxy.$modal.showToast('请选择备件')
return;
}
if (!form1.value.areaCode) {
proxy.$modal.showToast('请扫描库区')
return;
}
if (!form1.value.locationCode) {
proxy.$modal.showToast('请扫描库位')
return;
}
if(msg.value){
proxy.$modal.showToast(msg.value)
return;
}
if (sparePartsCode.value) {
proxy.$modal.showToast('该库位已绑定过备件')
return;
}
// if (!form1.value.qty) {
// proxy.$modal.showToast(`请输入数量`)
// return;
// }
// if (!form1.value.result) {
// proxy.$modal.showToast('请选择维修结果')
// return;
// }
if (!form1.value.repairCause) {
proxy.$modal.showToast('请输入维修原因')
return;
}
if (form.value && form.value.length > 0) {
let arr = form.value.filter(item => item.sparePartsCode == form1.value.sparePartsCode)
if (arr && arr.length > 0) {
proxy.$modal.showToast('该备件已添加')
return;
}
}
if (form.value && form.value.length > 0) {
let arr1 = form.value.filter(item => item.locationCode == form1.value.locationCode)
if (arr1 && arr1.length > 0) {
proxy.$modal.showToast('该库位已经绑定备件')
return;
}
}
form.value.push(form1.value)
isPopupShow.value = false
}
// 删除备件
function delSpareParts(index) {
form.value.splice(index, 1)
}
onLoad(async (option) => {
if (option.type) type.value = option.type;
result.value = await dictApi.getDict('result')
await getServiceSparePartsList()
})
</script>
<style lang="scss" scoped>
.add-form-container {
min-height: calc(100vh - 140rpx);
background: white;
padding: 0px 0rpx 140rpx;
}
.u-form-item {
padding: 20rpx 30rpx;
}
.disabled {
background: #f5f5f5;
}
.footer {
position: fixed;
bottom: 0px;
left: 0px;
width: 100%;
z-index: 22;
}
.btns {
display: flex;
button {
flex: 1;
}
.sure {
background: #409eff;
color: white;
border-radius: 0px;
&::after {
border: 1px solid #409eff;
border-radius: 0px;
}
}
.reset {
background: #F5F5F5;
border-radius: 0px;
&::after {
border-radius: 0px;
}
}
}
.right-button {
background: #409eff;
color: white;
padding: 0rpx 30rpx;
border-radius: 16rpx;
text-align: center;
font-size: 28rpx;
}
.select {
display: flex;
align-items: center;
height: 72rpx;
width: 100%;
.input {
flex: 1;
font-size: 28rpx;
color: #000000;
}
.placeholder {
flex: 1;
font-size: 28rpx;
color: rgb(192, 196, 204);
}
}
.title {
padding: 32rpx 0rpx;
position: relative;
span {
position: absolute;
left: -16rpx;
color: #fa3534;
top: 19px;
}
}
.list {
padding: 0rpx 30rpx;
.item {
display: flex;
margin-bottom: 20rpx;
.item-box {
background: #F5F5F5;
border-radius: 12rpx;
flex: 1;
width: 0rpx;
}
.spare-title {
padding: 20rpx 30rpx;
border-bottom: 1px solid #e4e4e4;
.title-txt {
color: #409eff;
font-size: 30rpx;
font-weight: bold;
}
}
.dec {
color: #9c9c9c;
padding: 20rpx 30rpx 20rpx;
}
}
}
.add-btn {
display: flex;
justify-content: flex-start;
align-items: center;
}
.popup-title {
text-align: center;
font-size: 32rpx;
font-weight: bold;
color: #409eff;
padding: 30rpx 30rpx 0px
}
.popup {
width: 600rpx;
padding: 30rpx 0rpx 30rpx;
}
.popup-footer {
display: flex;
border-top: 1px solid #e4e4e4;
view {
line-height: 100rpx;
flex: 1;
text-align: center;
&.sure {
color: #409eff;
}
}
}
::v-deep .u-checkbox-group {
display: grid !important;
}
</style>