This commit is contained in:
Vinjor 2024-11-20 15:52:54 +08:00
commit 0b9b3a5811
2 changed files with 324 additions and 74 deletions

View File

@ -17,7 +17,10 @@
<view class="listBox"> <view class="listBox">
<view class="list"> <view class="list">
<view v-for="(item, index) in wares" :key="index" class="listItem"> <view v-for="(item, index) in wares" :key="index" class="listItem">
<view class="repairName">{{ item.waresName }}</view> <view class="repairName">
<radio @click="chooseItem(item)" :checked="item.isSelected"/>
{{ item.waresName }}
</view>
<view class="repairBottom"> <view class="repairBottom">
<text class="repairDesc">单位 <text class="repairDesc">单位
<text class="repairUnit">{{ item.wares.unit }}</text> <text class="repairUnit">{{ item.wares.unit }}</text>
@ -74,7 +77,8 @@ export default {
formData: {}, formData: {},
active: '', active: '',
isToBeReviewed: true, isToBeReviewed: true,
query: null query: null,
selectRows: []
}; };
}, },
onLoad(data) { onLoad(data) {
@ -91,7 +95,21 @@ export default {
computed: {}, computed: {},
methods: { methods: {
handleSearch(){ chooseItem(item) {
const index = this.selectRows.findIndex(i => i.id === item.id)
const parentIndex = this.wares.findIndex(i => i.id === item.id)
if (index === -1) {
this.$set(item, 'isSelected', true)
this.selectRows.push(item)
} else {
this.$set(item, 'isSelected', false)
this.selectRows.splice(index, 1)
}
if (parentIndex !== -1) {
this.$set(this.wares, parentIndex, item)
}
},
handleSearch() {
this.init() this.init()
}, },
/** /**
@ -108,12 +126,12 @@ export default {
params: params params: params
}).then((res) => { }).then((res) => {
this.wares = res.data this.wares = res.data
if (this.isToBeReviewed){ if (this.isToBeReviewed) {
this.wares = this.wares.filter(item => item.waresStatus === '1') this.wares = this.wares.filter(item => item.waresStatus === '1')
this.wares = this.wares.filter(item => this.isReceive ? (item.waresCount > item.waresAlreadyCount) : (item.waresAlreadyCount > 0)) this.wares = this.wares.filter(item => this.isReceive ? (item.waresCount > item.waresAlreadyCount) : (item.waresAlreadyCount > 0))
} }
this.wares.forEach(item => { this.wares.forEach(item => {
if (!item.wares.stock){ if (!item.wares.stock) {
item.wares.stock = 0 item.wares.stock = 0
} }
if (this.isReceive) { if (this.isReceive) {
@ -128,6 +146,11 @@ export default {
item.maxNum = item.waresAlreadyCount item.maxNum = item.waresAlreadyCount
item.thisNum = 0 item.thisNum = 0
} }
if (!this.selectRows || this.selectRows.length === 0){
item.isSelected = false
}else {
item.isSelected = this.selectRows.findIndex(i => i.id === item.id) !== -1
}
}) })
// res.data.map((item)=>{ // res.data.map((item)=>{
// if(!item.waresAlreadyCount){ // if(!item.waresAlreadyCount){
@ -208,7 +231,7 @@ export default {
} }
// thisNum0 // thisNum0
const flag = this.wares.filter(item => item.thisNum > 0) const flag = this.wares.filter(item => item.thisNum > 0)
if (!flag || flag.length === 0){ if (!flag || flag.length === 0) {
uni.showToast({ uni.showToast({
title: '请设置配件数量!', title: '请设置配件数量!',
icon: 'none' icon: 'none'
@ -252,7 +275,11 @@ export default {
*/ */
toPart() { toPart() {
const formData = this.formData; const formData = this.formData;
if (this.selectRows && this.selectRows.length > 0) {
formData.items = this.selectRows
} else {
formData.items = this.wares; formData.items = this.wares;
}
setJSONData("applyWaresForm", formData) setJSONData("applyWaresForm", formData)
uni.navigateTo({ uni.navigateTo({
url: '/pages-warehouse/inOutWarehouse/part' url: '/pages-warehouse/inOutWarehouse/part'

View File

@ -8,6 +8,11 @@
<input type="text" style="text-align: right" v-model="serviceName" placeholder="请输入供应商名称"/> <input type="text" style="text-align: right" v-model="serviceName" placeholder="请输入供应商名称"/>
<view @click="searchService">查询</view> <view @click="searchService">查询</view>
</view> </view>
<view class="formItem" v-if="isInput">
<text class="formLabel">关键字</text>
<input type="text" style="text-align: right" v-model="query" placeholder="名称、规格、编码"/>
<view @click="searchQuery">查询</view>
</view>
<view class="formItem" v-if="!isInput"> <view class="formItem" v-if="!isInput">
<text class="formLabel">备注</text> <text class="formLabel">备注</text>
<text class="formValue"></text> <text class="formValue"></text>
@ -15,16 +20,76 @@
<view style="padding-bottom: 60rpx;border-bottom: 1px solid #ddd;" class="formItem" v-if="!isInput"> <view style="padding-bottom: 60rpx;border-bottom: 1px solid #ddd;" class="formItem" v-if="!isInput">
<textarea style="height: 50px" auto-height placeholder="请输入备注" v-model="remark"/> <textarea style="height: 50px" auto-height placeholder="请输入备注" v-model="remark"/>
</view> </view>
<uni-card v-for="(item, index) in partList" :key="index" :title="item.name" :extra="'上次价格:'+item.purPrice"> <uni-card title="车辆信息" v-if="!isInput">
<view class="formItem"> <view class="formItem">
<view class="formLabel">单价</view> <view>车牌号</view>
<input type="number" style="text-align: right" v-model="item.newPrice" placeholder="请输入单价"/> <view>{{ carInfo.licenseNumber }}</view>
</view> </view>
<view class="formItem"> <view class="formItem">
<view class="formLabel">数量</view> <view>品牌</view>
<input type="number" style="text-align: right" v-model="item.count" placeholder="请输入数量"/> <view>{{ carInfo.carBrand }}</view>
</view>
<view class="formItem">
<view>型号</view>
<view>{{ carInfo.carModel }}</view>
</view> </view>
</uni-card> </uni-card>
<uni-collapse ref="collapse">
<uni-collapse-item v-for="[key, value] in partList" :title="key + `(${value.length})`">
<uni-card v-for="(item, index) in value" :key="index">
<template>
<view class="card-header">
<radio :checked="item.isSelected" @click="chooseItem(item)"/>
<text class="card-title">{{ item.wares.name }}</text>
</view>
</template>
<view class="formItem">
<view class="formLabel">进价</view>
<input type="number" style="text-align: right" v-model="item.wares.purPrice" placeholder="请输入单价"/>
</view>
<view class="formItem">
<view class="formLabel">售价</view>
<input type="number" style="text-align: right" v-model="item.wares.price" placeholder="请输入单价"/>
</view>
<view class="formItem">
<view class="formLabel">分类</view>
<view>
<picker @change="bindPickerChange($event, item)" :range="options" range-key="label">
<view class="picker">
{{ getServerName(item.wares.type) }}
</view>
</picker>
</view>
</view>
<view class="formItem">
<view class="formLabel">计量单价</view>
<picker @change="bindUnitChange($event, item)" :range="unitList" range-key="label">
<view class="picker">
{{ getUnitName(item.wares.unit) }}
</view>
</picker>
</view>
<view class="formItem" v-if="!isInput">
<view class="formLabel">数量</view>
<input type="number" style="text-align: right" v-model="item.waresCount" placeholder="请输入数量"/>
</view>
<view class="formItem" v-if="isInput">
<view class="formLabel">数量</view>
<input type="number" style="text-align: right" v-model="item.inCount" placeholder="请输入数量"/>
</view>
</uni-card>
</uni-collapse-item>
</uni-collapse>
<!-- <uni-card v-for="(item, index) in partList" :key="index" :title="item.name" :extra="'上次价格:'+item.purPrice">-->
<!-- <view class="formItem">-->
<!-- <view class="formLabel">单价</view>-->
<!-- <input type="number" style="text-align: right" v-model="item.newPrice" placeholder="请输入单价"/>-->
<!-- </view>-->
<!-- <view class="formItem">-->
<!-- <view class="formLabel">数量</view>-->
<!-- <input type="number" style="text-align: right" v-model="item.count" placeholder="请输入数量"/>-->
<!-- </view>-->
<!-- </uni-card>-->
</view> </view>
</view> </view>
<view class="footer"> <view class="footer">
@ -41,9 +106,11 @@ import VNavigationBar from "@/components/VNavigationBar.vue";
import request from '@/utils/request'; import request from '@/utils/request';
import {getDictTextByCodeAndValue, createUniqueCodeByHead} from "@/utils/utils"; import {getDictTextByCodeAndValue, createUniqueCodeByHead} from "@/utils/utils";
import {getUserInfo, getJSONData} from '@/utils/auth.js' import {getUserInfo, getJSONData} from '@/utils/auth.js'
import UniCollapse from "../../uni_modules/uni-collapse/components/uni-collapse/uni-collapse.vue";
import {getStorageWithExpiry} from "../../utils/auth";
export default { export default {
components: {VNavigationBar}, components: {UniCollapse, VNavigationBar},
data() { data() {
return { return {
//id //id
@ -69,27 +136,105 @@ export default {
//id //id
serviceId: "", serviceId: "",
soId: "", soId: "",
soiIds: [] soiIds: [],
carInfo: {},
options: [],
selectedIndex: -1,
unitList: [],
query: null,
selectRows: [],
}; };
}, },
onLoad(data) { onLoad(data) {
this.listServer()
this.listUnit()
if (data.soId) { if (data.soId) {
this.soId = data.soId this.soId = data.soId
this.isInput = true this.isInput = true
this.title = '配件入库' this.title = '配件入库'
this.getSoiId() this.getSoiId()
}else { } else {
if (getJSONData("applyWaresForm")) { if (getJSONData("applyWaresForm")) {
this.formData = getJSONData("applyWaresForm") this.formData = getJSONData("applyWaresForm")
this.wares = this.formData.items this.wares = this.formData.items
this.init() this.init()
} }
} }
}, },
computed: {}, computed: {},
methods: { methods: {
chooseItem(item) {
const parentIndex = this.partList.map(([key, value]) => value).reduce((acc, value) => acc.concat(value)).findIndex(i => i.id === item.id)
const index = this.selectRows.findIndex(i => i.id === item.id)
if (index === -1){
this.$set(item, 'isSelected', true)
this.selectRows.push(item)
}else {
this.$set(item, 'isSelected', false)
this.selectRows.splice(index, 1)
}
if (parentIndex !== -1){
const partListFlat = this.partList
.map(([key, value]) => value)
.reduce((acc, value) => acc.concat(value), []);
this.$set(partListFlat, parentIndex, { ...partListFlat[parentIndex], isSelected: item.isSelected });
const updatedPartList = this.partList.map(([key, value]) => {
const newValue = value.map(v => {
const foundItem = partListFlat.find(f => f.id === v.id);
return foundItem ? { ...v, ...foundItem } : v;
});
return [key, newValue];
});
this.$set(this, 'partList', updatedPartList);
}
},
searchQuery() {
this.getSoiId()
},
getUnitName(id) {
const index = this.unitList.findIndex(item => item.value === id)
if (index !== -1) {
return this.unitList[index].label
}
return "请选择"
},
bindUnitChange(e, row) {
const index = e.detail.value
const choose = this.unitList[index]
row.wares.unit = choose.value
},
listUnit() {
if (!getStorageWithExpiry("repair_unit")) {
getDictTextByCodeAndValue("repair_unit", null)
}
this.unitList = getStorageWithExpiry("repair_unit")
},
getServerName(id) {
const index = this.options.findIndex(item => item.value === id)
if (index !== -1) {
return this.options[index].label
}
return "请选择"
},
listServer() {
request({
url: '/admin-api/conf/baseType/list',
method: 'get',
params: {type: '02'}
}).then(res => {
this.options = res.data.map(item => {
return {
label: item.name,
value: item.id
}
})
})
},
bindPickerChange(node, row) {
const index = node.detail.value
const choose = this.options[index]
row.wares.type = choose.value
},
/** /**
* 查询供应商 * 查询供应商
*/ */
@ -129,14 +274,35 @@ export default {
* 初始化配件数据 * 初始化配件数据
*/ */
init() { init() {
this.partList = [...this.wares.map(item => { request({
return { url: '/admin-api/repair/tickets/getCusAndCarById?id=' + this.formData.ticketId,
...item.wares, method: 'get'
count: item.waresCount, }).then(res => {
newPrice: item.wares.purPrice, this.carInfo = res.data.carInfo
totalPrice: item.waresCount * item.wares.purPrice, if (this.carInfo.carBrand) {
request({
url: '/admin-api/base/carBrand/get?id=' + this.carInfo.carBrand,
method: 'get'
}).then(res => {
this.carInfo.carBrand = res.data.brandName
})
} }
})] })
const ids = this.wares.map(item => item.id)
request({
url: "/admin-api/repair/tw/getByIds?ids=" + ids,
method: 'get'
}).then(res => {
this.partList = Object.entries(res.data)
const value = this.partList.map(([key, value]) => value)
value.forEach(item => {
item.forEach(i => {
// i.count = i.waresCount
// i.newPrice = i.wares.purPrice
i.totalPrice = i.waresCount * i.wares.purPrice
})
})
})
}, },
/** /**
* *
@ -171,33 +337,34 @@ export default {
*/ */
submit() { submit() {
const userInfo = getUserInfo() const userInfo = getUserInfo()
const values = this.partList.map(([key, value]) => value).reduce((acc, value) => acc.concat(value))
const data = { const data = {
soType: '01', soType: '01',
purchaseType: '01', purchaseType: '01',
soNo: createUniqueCodeByHead("CG"), soNo: createUniqueCodeByHead("CG"),
userId: userInfo.id, userId: userInfo.id,
userName: userInfo.nickname, userName: userInfo.nickname,
itemCount: this.partList.length, itemCount: values.length,
totalPrice: this.partList.reduce((x, y) => { totalPrice: values.reduce((x, y) => {
return x + y.totalPrice return x + y.totalPrice
}, 0), }, 0),
soStatus: '03', soStatus: "03",
remark: this.remark, remark: this.remark,
supplierId: this.serviceId, supplierId: this.serviceId,
supplierName: this.serviceName supplierName: this.serviceName
} }
data.goodsList = [...this.partList.map(item => { data.goodsList = [...values.map(item => {
return { return {
soiType: '01', soiType: '01',
goodsId: item.id, goodsId: item.wares.id,
goodsType: '0', goodsType: '0',
wareId: item?.wareId, wareId: item.wares?.warehouse,
goodsCount: item.count, goodsCount: item.waresCount,
goodsPrice: item.newPrice, goodsPrice: item.wares.price,
remark: item.remark remark: item.remark
} }
})] })]
console.log(data) data.waresList = [...values.map(item => item.wares)]
request({ request({
url: '/admin-api/repair/so/create', url: '/admin-api/repair/so/create',
method: 'post', method: 'post',
@ -216,59 +383,85 @@ export default {
}, },
getSoiId() { getSoiId() {
request({ request({
url: '/admin-api/repair/so/get', url: '/admin-api/repair/soi/getMapBySoIdAndQuery?id=' + this.soId + "&query=" + this.query,
method: 'get', method: 'get'
params: { }).then(res => {
id: this.soId this.partList = Object.entries(res.data)
this.partList = this.partList.filter(([key, value]) => {
const newValue = value.filter(item => item.inCount !== item.goodsCount)
return newValue && newValue.length > 0
})
this.partList.forEach(([key, value]) => {
value.forEach(item => {
item.goodsCount = item.goodsCount - item?.inCount | 0
item.inCount = item.goodsCount - item?.inCount | 0
})
})
const values = this.partList.map(([key, value]) => value)
if (!this.selectRows || this.selectRows.length === 0){
values.forEach(item => {
item.forEach(i => {
i.isSelected = false
})
})
}else {
values.forEach(item => {
item.forEach(i => {
i.isSelected = this.selectRows.findIndex(j => j.id === i.id) !== -1
})
})
} }
}).then((res) => { // `.then`
console.log(res)
res.data.goodsList.forEach(item => {
this.soiIds.push(item.id)
})
console.log('返回',res.data)
request({
url: '/admin-api/repair/soi/get',
method: 'get',
params: {
ids: this.soiIds.join(',')
}
}).then((res) => { //
console.log('配件信息', res.data)
res.data.map(item => {
item.wares = item.repairWares
item.waresCount = 0
})
this.wares = res.data
this.init()
})
}) })
// request({
// url: '/admin-api/repair/so/get',
// method: 'get',
// params: {
// id: this.soId
// }
// }).then((res) => { // `.then`
// // console.log(res)
// res.data.goodsList.forEach(item => {
// this.soiIds.push(item.id)
// })
// console.log('', res.data)
//
// request({
// url: '/admin-api/repair/soi/get',
// method: 'get',
// params: {
// ids: this.soiIds.join(',')
// }
// }).then((res) => { //
// console.log('', res.data)
// res.data.map(item => {
// item.wares = item.repairWares
// item.waresCount = 0
// })
// this.wares = res.data
// this.init()
// })
// })
}, },
/** /**
* 入库 * 入库
*/ */
inWare(){ inWare() {
console.log('partList',this.partList) const data = {
// this.partList.forEach(item => { id: this.soId,
// item.inCount = item.count soNo: createUniqueCodeByHead("RK")
// item.goodsId = item.id }
// // item.id = this.soiIds[0] if (this.selectRows && this.selectRows.length > 0){
// }) data.soiList = [...this.selectRows]
const copiedPartList = JSON.parse(JSON.stringify(this.partList)); data.waresList = [...this.selectRows.map(item => item.wares)]
for (let i = 0; i < this.partList.length; i++) { }else {
this.partList[i].inCount = this.partList[i].count const values = this.partList.map(([key, value]) => value).reduce((acc, item) => acc.concat(item))
this.partList[i].goodsId = copiedPartList[i].id data.soiList = [...values]
this.partList[i].id = this.soiIds[i] data.waresList = [...values.map(item => item.wares)]
} }
console.log('partList',this.partList)
request({ request({
url: '/admin-api/repair/so/inWare', url: '/admin-api/repair/so/inWare',
method: 'post', method: 'post',
data: { data: data
id: this.soId,
soiList: this.partList
}
}).then((res) => { }).then((res) => {
if (res.code == 200) { if (res.code == 200) {
uni.showToast({ uni.showToast({
@ -280,6 +473,36 @@ export default {
}, 700) }, 700)
} }
}) })
// this.partList.forEach(item => {
// item.inCount = item.count
// item.goodsId = item.id
// // item.id = this.soiIds[0]
// })
// const copiedPartList = JSON.parse(JSON.stringify(this.partList));
// for (let i = 0; i < this.partList.length; i++) {
// this.partList[i].inCount = this.partList[i].count
// this.partList[i].goodsId = copiedPartList[i].id
// this.partList[i].id = this.soiIds[i]
// }
// console.log('partList', this.partList)
// request({
// url: '/admin-api/repair/so/inWare',
// method: 'post',
// data: {
// id: this.soId,
// soiList: this.partList
// }
// }).then((res) => {
// if (res.code == 200) {
// uni.showToast({
// title: '',
// icon: 'none'
// })
// setTimeout(() => {
// uni.navigateBack()
// }, 700)
// }
// })
} }