bonus-material-app/src/pages/back/backNum.vue

550 lines
19 KiB
Vue
Raw Normal View History

2024-11-20 14:24:17 +08:00
<template>
2025-06-20 15:35:54 +08:00
<uni-nav-bar leftIcon="left" right-text="确定" title="退料数量" backgroundColor="#dcf4ff" :border="false" fixed @clickLeft="leftClick" @clickRight="submitNum"/>
2024-11-20 14:24:17 +08:00
<view class="accept page-common">
2025-06-20 15:35:54 +08:00
<div class="card top-content" :class="{'is-expanded': isExpanded}">
<div class="card-header" @click="isExpanded = !isExpanded">
<span class="title">任务信息</span>
2025-06-20 15:35:54 +08:00
<uni-icons class="icon" type="down" size="19" :class="{'is-expanded': isExpanded}"></uni-icons>
</div>
2024-12-10 14:41:47 +08:00
<uni-forms :model="taskInfo" label-width="170rpx" :border="true">
<uni-forms-item label="单位:" name="unitName">
2024-11-21 09:22:25 +08:00
<span style="height: 100%;display: flex;align-items: center;">{{ taskInfo.unitName }}</span>
2024-11-20 14:24:17 +08:00
</uni-forms-item>
<uni-forms-item label="工程:" name="proName">
2024-11-21 09:22:25 +08:00
<span style="height: 100%;display: flex;align-items: center;">{{ taskInfo.proName }}</span>
2024-11-20 14:24:17 +08:00
</uni-forms-item>
<uni-forms-item label="单号:" name="code">
2024-11-21 09:22:25 +08:00
<span style="height: 100%;display: flex;align-items: center;">{{ taskInfo.code }}</span>
2024-11-20 14:24:17 +08:00
</uni-forms-item>
<uni-forms-item label="人员:" name="backPerson">
2024-11-21 09:22:25 +08:00
<span style="height: 100%;display: flex;align-items: center;">{{ taskInfo.backPerson }}</span>
2024-11-20 14:24:17 +08:00
</uni-forms-item>
<uni-forms-item label="电话:" name="phone">
2024-11-21 09:22:25 +08:00
<span style="height: 100%;display: flex;align-items: center;">{{ taskInfo.phone }}</span>
2024-11-20 14:24:17 +08:00
</uni-forms-item>
</uni-forms>
</div>
<div class="card">
<div class="card-header">
<span class="title">退料物资</span>
<div class="header-right">
<span class="tip">已选 {{ typeList.length }} </span>
</div>
</div>
<div class="select-area">
2024-11-21 09:22:25 +08:00
<uni-row :gutter="24" style="display: flex; align-items: center">
2025-06-20 15:35:54 +08:00
<uni-col :span="12">
2024-11-21 09:22:25 +08:00
<view>
2025-06-20 15:35:54 +08:00
<!-- <uni-data-select v-model="typeId"
placeholder="请选择物资类型"
2025-02-20 23:37:13 +08:00
:localdata="maTypeSelectList" @change="getMaCode" filterable >
2025-06-20 15:35:54 +08:00
</uni-data-select> -->
<eselect
style="width: 100%; height: 90rpx"
v-model="typeId"
:options="maTypeSelectList"
@change="getMaCode"
@clear="clearTypeId"
></eselect>
2024-11-21 09:22:25 +08:00
</view>
</uni-col>
2025-06-20 15:35:54 +08:00
<uni-col :span="12">
2024-11-21 09:22:25 +08:00
<view>
2025-06-20 15:35:54 +08:00
<!-- <uni-data-select v-model="typeCode"
placeholder="请选择规格型号"
2024-11-22 09:40:01 +08:00
:localdata="maCodeSelectList" @change="selectMaCode">
2025-06-20 15:35:54 +08:00
</uni-data-select> -->
<eselect
style="width: 100%; height: 90rpx"
v-model="typeCode"
ref="treeSelect"
:options="maCodeSelectList"
@change="selectMaCode"
@clear=""
></eselect>
2024-11-21 09:22:25 +08:00
</view>
</uni-col>
</uni-row>
</div>
2024-11-20 14:24:17 +08:00
</div>
2025-06-20 16:22:02 +08:00
<uni-table border stripe emptyText="暂无更多数据">
<!-- 表头行 -->
<uni-tr>
<uni-th width="100px" style="font-size: 24rpx;" align="center">类型名称</uni-th>
<uni-th width="100px" style="font-size: 24rpx;" align="center">规格型号</uni-th>
<uni-th width="60px" style="font-size: 24rpx;" align="center">在用数</uni-th>
<uni-th width="90px" style="font-size: 24rpx;" align="center">退料数</uni-th>
<!-- <uni-th width="90px" style="font-size: 24rpx;" align="center">外观</uni-th> -->
<uni-th width="90px" style="font-size: 24rpx;" align="center">完好数量</uni-th>
<uni-th width="90px" style="font-size: 24rpx;" align="center">不合格数量</uni-th>
<uni-th width="70px" style="font-size: 24rpx;" align="center">操作</uni-th>
</uni-tr>
<!-- 表格数据行 -->
<uni-tr v-for="(item,index) in typeList" :key="item.id">
<uni-td style="font-size: 24rpx;text-align: center;">{{item.materialName}}</uni-td>
<uni-td style="font-size: 24rpx;text-align: center;">{{item.typeName}}</uni-td>
<uni-td style="font-size: 24rpx;text-align: center;">{{item.num}}</uni-td>
<uni-td style="font-size: 24rpx;text-align: center;">
<uni-easyinput
placeholder="退料数"
v-model="item.preNum"
type="number"
:clearable="false"
@input="onChangeNumber(item)"
:styles="{width: '100rpx'}"
/>
</uni-td>
<uni-td style="font-size: 24rpx;text-align: center;">
<uni-easyinput
placeholder="完好数量"
v-model="item.goodNum"
type="number"
:clearable="false"
@change="changeNum(item)"
:styles="{width: '100rpx'}"
:disabled="!item.preNum"
/>
</uni-td>
<uni-td style="font-size: 24rpx;text-align: center;">
<uni-easyinput
placeholder="不合格数量"
v-model="item.badNum"
type="number"
:clearable="false"
@change="changeNum(item)"
:styles="{width: '100rpx'}"
:disabled="!item.preNum"
/>
</uni-td>
<!-- <uni-td style="font-size: 24rpx;text-align: center;">
<uni-easyinput
placeholder="外观"
v-model="item.apDetection"
:styles="{width: '100rpx'}"
/>
</uni-td> -->
<uni-td style="font-size: 24rpx;text-align: center;">
<view class="uni-group">
<view class="action-btn" @click="uploadImg(item)">
<uni-icons type="camera" size="20" style="color: #3784fb;"/>
</view>
<view class="action-btn delete" @click="delRow(index)">
<uni-icons type="trash-filled" size="20" style="color: red;margin-left:10px;"/>
</view>
</view>
</uni-td>
</uni-tr>
</uni-table>
2025-06-20 15:35:54 +08:00
<!-- <div class="footer-btn">
2024-11-22 09:40:01 +08:00
<button class="btn-cont" @click="submitNum">确认</button>
2025-06-20 15:35:54 +08:00
</div> -->
2024-11-20 14:24:17 +08:00
</view>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
2024-11-22 09:40:01 +08:00
import { getUseType,insertApp } from '../../services/back.js';
2025-06-20 15:35:54 +08:00
import eselect from '@/components/tree-select/eselect.vue'
2024-11-21 09:22:25 +08:00
const taskInfo = ref({})
2024-11-22 09:40:01 +08:00
const maTypeSelectList = ref([])
2025-06-20 15:35:54 +08:00
const typeId = ref()//类型
2024-11-22 09:40:01 +08:00
const maCodeSelectList = ref([])
const typeCode = ref("")//规格型号
2024-11-21 09:22:25 +08:00
const typeList = ref([])
2025-06-20 15:35:54 +08:00
const isExpanded = ref(false)
const treeSelect = ref()
const leftClick = () => {
// 返回
uni.navigateBack({
delta: 1, // 返回到已存在的页面
})
}
//类下拉选
2024-11-22 09:40:01 +08:00
const getMaType = () => {
let obj = {
"agreementId":taskInfo.value.agreementId,
}
getUseType(obj).then(res => {
console.log(res)
maTypeSelectList.value = res.data.map(option => {
return {
2025-06-20 15:35:54 +08:00
// value:option.typeId,
// text:option.typeName,
id:option.typeId,
name:option.typeName,
parentId: 0
2024-11-22 09:40:01 +08:00
}
});
}).catch(error => {
console.log(error)
})
}
//规格
2025-06-20 15:35:54 +08:00
const getMaCode = (e) => {
console.log('🚀 ~ getMaCode ~ e:', e.id)
typeId.value = e.id
console.log('🚀 ~ getMaCode ~ typeId.value:', typeId.value)
2024-11-22 09:40:01 +08:00
let obj = {
"agreementId":taskInfo.value.agreementId,
"typeId":typeId.value
}
2025-06-20 15:35:54 +08:00
console.log('🚀 ~ getMaCode ~ obj:', obj)
2024-11-22 09:40:01 +08:00
getUseType(obj).then(res => {
console.log(res)
maCodeSelectList.value = res.data.map(option => {
let obj = {
...option,
bmFileInfos:[],
2025-06-20 15:35:54 +08:00
// value:option.typeId,
// text:option.typeName,
id:option.typeId,
name:option.typeName,
parentId: 0
2024-11-22 09:40:01 +08:00
}
return obj
});
}).catch(error => {
console.log(error)
})
}
2025-06-20 15:35:54 +08:00
const clearTypeId = () => {
typeId.value = ''
typeCode.value = ''
maCodeSelectList.value = []
treeSelect.value.showLabel = ''
console.log('🚀 ~ clearTypeId ~ treeSelect.value:', treeSelect.value)
}
2024-11-22 09:40:01 +08:00
//选择规格型号
const selectMaCode = (e) => {
2025-06-20 15:35:54 +08:00
console.log('🚀 ~ selectMaCode ~ e:', e)
// 不可重复添加
if(typeList.value.some(item => item.typeId == e.id)){
// 提示
uni.showToast({
title: '请勿重复添加',
icon: 'none'
});
return
}
2024-11-22 09:40:01 +08:00
maCodeSelectList.value.forEach(item=>{
console.log(item)
2025-06-20 15:35:54 +08:00
if(item.typeId==e.id){
typeList.value.unshift(item)
2024-11-22 09:40:01 +08:00
}
})
console.log(typeList.value)
}
//提交
const submitNum = () => {
console.log(taskInfo.value)
console.log(typeList.value)
2025-02-11 15:31:20 +08:00
// 校验 preNum 必须大于 0
if (typeList.value.length === 0) {
console.log('🚀 ~ submitNum ~ typeList.value:', typeList.value)
uni.showToast({
title: '请添加退料物资',
icon: 'none',
})
return
}
for (let i = 0; i < typeList.value.length; i++) {
if (typeList.value[i].preNum <= 0 || !typeList.value[i].preNum) {
uni.showToast({
title: '退料数不能为空或等于0',
icon: 'none',
})
return
}
}
2024-11-22 09:40:01 +08:00
let obj = {
"backApplyInfo":taskInfo.value,
"backApplyDetailsList":typeList.value
}
insertApp(obj).then(res => {
console.log(res)
if(res.code==200){
uni.showToast({ title: '编辑成功', icon: 'none' })
uni.navigateBack({
delta: 1 // 返回到已存在的页面
});
}else{
uni.showToast({ title: res.msg, icon: 'none' })
}
}).catch(error => {
console.log(error)
})
}
//上传
const uploadImg = (item) => {
uni.chooseImage({
count: 1, //图片可选择数量
sizeType: ['original', 'compressed'], //original 原图compressed 压缩图,默认二者都有
sourceType: ['album', 'camera',], //album 从相册选图camera 使用相机,默认二者都有。
success: res => {
console.log(res)
let imgFiles = res.tempFilePaths //图片的本地文件路径列表
// imgBeseUrl.value = imgFiles[0]
// console.log('本地地址', imgFiles)
// console.log('请求地址', baseURL+"/file/upload")
uni.uploadFile({
// url: baseURL+"/file/upload",//app
url: "/file/upload",//h5
filePath: imgFiles[0],
name: 'file',
success: (res) => {
res = JSON.parse(res.data)
console.log('上传成功', res.code);
console.log('上传成功', res.data);
if(res.code&&res.code==200){
let obj = {
"name":res.data.name,
"url":res.data.url
}
item.bmFileInfos.value = [obj]
uni.showToast({ title: '上传成功', icon: 'none' })
}else{
item.bmFileInfos.value = []
uni.showToast({ title: '上传失败', icon: 'none' })
}
},
fail: (err) => {
console.error('上传失败', err);
}
});
// this.$refs.vForm.clearValidate()
}
})
}
//删除
const delRow = (index) => {
console.log(index)
console.log(typeList.value)
typeList.value.splice(index,1)
2024-12-10 14:41:47 +08:00
}
// 数量框change事件
const onChangeNumber = (item) => {
console.log(item)
console.log(item.preNum)
console.log(item.preNum)
let maxNum = Number(item.num)
// outboundNum.value
setTimeout(()=>{
if(item.unitValue==1){
item.preNum = Number(String(item.preNum).replace(/[^\d.]/g,''))
}else{
item.preNum = Number(String(item.preNum).replace(/[^\d]/g,''))
}
if (Number(item.preNum)<= 0) {
item.preNum = 0;
}
if (Number(item.preNum) > maxNum) {
uni.showToast({
title: '已达到当前资最大在用数量!',
2024-12-10 14:41:47 +08:00
icon: 'none',
})
item.preNum = maxNum;
}
},500)
}
2025-02-11 15:31:20 +08:00
const changeNum = (row) => {
console.log('🚀 ~ changeNum ~ row:', row)
// 将badNum 和 goodNum 向上取整
// 只能输入正整数 过滤掉除正整数外的东西
if (row.badNum) {
row.badNum = Math.ceil(String(row.badNum).replace(/[^\d]/g, ''))
console.log('🚀 ~ changeNum ~ row.badNum:', row.badNum)
}
if (row.goodNum) {
console.log('🚀 ~ changeNum ~ row.goodNum:', row.goodNum)
row.goodNum = Math.ceil(String(row.goodNum).replace(/[^\d]/g, ''))
}
// 不能大于preNum
if (Number(row.badNum) + Number(row.goodNum) > row.preNum) {
console.log('🚀 ~ changeNum ~ row.badNum + row.goodNum > row.preNum:', row.badNum , row.goodNum)
2025-06-11 20:25:20 +08:00
// this.$message.error('完好数量和不合格数量之和不能大于退料数量')
2025-02-11 15:31:20 +08:00
uni.showToast({
2025-06-11 20:25:20 +08:00
title: '完好数量和不合格数量之和不能大于退料数量',
2025-02-11 15:31:20 +08:00
icon: 'none',
})
row.badNum = 0
row.goodNum = 0
}
}
2024-11-20 14:24:17 +08:00
onLoad((options)=>{
console.log(options)
2024-11-21 09:22:25 +08:00
taskInfo.value = JSON.parse(options.taskInfo)
console.log(taskInfo.value)
2024-11-22 09:40:01 +08:00
getMaType()
2024-11-20 14:24:17 +08:00
})
</script>
2025-06-20 15:35:54 +08:00
<style lang="scss" scoped>
::v-deep .tree-item .head {
justify-content: center !important;
}
2024-11-20 14:24:17 +08:00
.accept {
padding: 24rpx;
2024-11-21 09:22:25 +08:00
height: 95vh;
2024-11-20 14:24:17 +08:00
word-break: break-all;
background-color: #f7f8fa;
2024-11-20 14:24:17 +08:00
display: flex;
flex-direction: column;
// 卡片样式
.card {
padding: 32rpx;
background-color: #fff;
border-radius: 20rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
margin-bottom: 24rpx;
// 卡片头部
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24rpx;
.title {
font-size: 32rpx;
font-weight: 600;
color: #262626;
position: relative;
padding-left: 24rpx;
&::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 6rpx;
height: 28rpx;
background: #3784fb;
border-radius: 6rpx;
}
}
.header-right {
.tip {
font-size: 26rpx;
color: #8c8c8c;
}
}
2025-06-20 15:35:54 +08:00
.icon {
transition: transform 0.5s ease; /* 添加动画过渡 */
transform: rotate(0deg);
&.is-expanded {
transform: rotate(180deg);
}
}
}
2025-01-14 17:56:14 +08:00
// 操作按钮样式
.uni-group {
display: flex;
justify-content: center;
align-items: center;
.uni-icons {
padding: 8rpx;
border-radius: 8rpx;
transition: all 0.3s ease;
&:active {
transform: scale(0.9);
opacity: 0.8;
}
}
}
2024-11-20 14:24:17 +08:00
// 选择区域
.select-area {
padding: 24rpx 0;
border-bottom: 2rpx solid #f5f5f5;
}
2025-01-14 17:56:14 +08:00
// // 表格区域
// .table-area {
// margin-top: 24rpx;
// margin: 24rpx -32rpx 0;
// overflow-x: auto;
2025-01-14 17:56:14 +08:00
// :deep(.uni-table) {
// width: 1080rpx;
// padding: 0 10rpx;
// .uni-table-tr {
// .uni-table-th {
// min-width: 140rpx;
// &:last-child {
// min-width: 120rpx;
// }
// }
2025-01-14 17:56:14 +08:00
// .uni-table-td {
// .action-btn {
// display: inline-flex;
// padding: 12rpx;
// border-radius: 8rpx;
// transition: all 0.3s ease;
// margin: 0 8rpx;
2025-01-14 17:56:14 +08:00
// &:active {
// background-color: rgba(0, 0, 0, 0.05);
// }
2025-01-14 17:56:14 +08:00
// &.delete:active {
// background-color: rgba(255, 77, 79, 0.05);
// }
// }
// }
// }
// }
// }
}
// 底部按钮
.footer-btn {
margin-top: auto;
padding: 32rpx;
background: #fff;
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
.btn-cont {
width: 100%;
height: 88rpx;
line-height: 88rpx;
text-align: center;
background: linear-gradient(135deg, #4b8eff 0%, #3784fb 100%);
color: #fff;
border-radius: 44rpx;
font-size: 32rpx;
font-weight: 600;
box-shadow: 0 6rpx 20rpx rgba(55, 132, 251, 0.2);
transition: all 0.3s ease;
&:active {
transform: scale(0.98);
opacity: 0.9;
box-shadow: 0 2rpx 8rpx rgba(55, 132, 251, 0.2);
}
}
2024-11-20 14:24:17 +08:00
}
}
2025-06-20 15:35:54 +08:00
.top-content {
max-height: 30px;
overflow: hidden;
transition: max-height 0.5s ease-out;
&.is-expanded {
max-height: 800px;
}
}
2024-11-20 14:24:17 +08:00
</style>