代码优化

This commit is contained in:
BianLzhaoMin 2024-09-12 15:02:11 +08:00
parent 4783bdf3e0
commit 01e63e51d9
4 changed files with 340 additions and 331 deletions

View File

@ -25,7 +25,7 @@ class HttpConfig {
// systemPath = `${this.baseUrl}/dev-api/system` // systemPath = `${this.baseUrl}/dev-api/system`
// basePath = `${this.baseUrl}/dev-api/base` // basePath = `${this.baseUrl}/dev-api/base`
// materialPath = `${this.baseUrl}/dev-api/material` // materialPath = `${this.baseUrl}/dev-api/material`
baseUrl = ENV === "production" ? "http://192.168.0.56:21627" : this.target; baseUrl = ENV === "production" ? "http://112.29.103.165:21626" : this.target;
authPath = authPath =
ENV === "production" ENV === "production"
? `${this.baseUrl}/dev-api/auth` ? `${this.baseUrl}/dev-api/auth`

View File

@ -1,31 +1,37 @@
<template> <template>
<view> <view>
<view class="search-bar"> <view class="search-bar">
<uni-easyinput prefixIcon="search" v-model="inputs" placeholder="请输入名称"></uni-easyinput> <uni-easyinput
</view> prefixIcon="search"
<view class="dataInfo"> v-model="inputs"
<view class="dataList" v-for="(item,index) in searchData" :key="index"> placeholder="请输入名称"></uni-easyinput>
<!-- <checkbox-group @change="checkClick(item)"> </view>
<view class="dataInfo">
<view
class="dataList"
v-for="(item, index) in searchData"
:key="index">
<!-- <checkbox-group @change="checkClick(item)">
<checkbox :checked="item.checked" /> <checkbox :checked="item.checked" />
</checkbox-group> --> </checkbox-group> -->
<view class="details"> <view class="details">
<!-- <view class="img"> <!-- <view class="img">
<image :src="item.url"></image> <image :src="item.url"></image>
</view> --> </view> -->
<view class="text"> <view class="text">
<text>类型名称{{item.typeName}}</text> <text>类型名称{{ item.typeName }}</text>
<text>规格编号{{item.typeCode}}</text> <text>规格编号{{ item.typeCode }}</text>
<text>退料数量{{item.num}}</text> <text>退料数量{{ item.num }}</text>
</view> </view>
</view> </view>
<!-- <view class="action"> <!-- <view class="action">
<text @click="reduce(item)">-</text> <text @click="reduce(item)">-</text>
<text>{{item.offNum}}</text> <text>{{item.offNum}}</text>
<text @click="add(item)">+</text> <text @click="add(item)">+</text>
</view> --> </view> -->
</view> </view>
</view> </view>
<!-- <view class="buy"> <!-- <view class="buy">
<view class="checked"> <view class="checked">
<checkbox-group @tap="checkAll"> <checkbox-group @tap="checkAll">
<checkbox :checked="allChecked" /> <checkbox :checked="allChecked" />
@ -38,313 +44,316 @@
</view> </view>
</view> </view>
</view> --> </view> -->
</view> </view>
</template> </template>
<script> <script>
import { basePath } from '../../public'; import { basePath } from "../../public";
export default { export default {
data() { data() {
return { return {
iptVal: '', iptVal: "",
allChecked: false, allChecked: false,
inputs: "", inputs: "",
list: [ list: [],
], totalFine: "",
totalFine: '', cartList: [],
cartList: [], typeId: "",
typeId: '' };
} },
}, computed: {
computed: { totalNum() {
totalNum() { //
// var str = 0;
var str = 0; for (var i = 0; i < this.searchData.length; i++) {
for (var i = 0; i < this.searchData.length; i++) { if (this.searchData[i].checked) {
if (this.searchData[i].checked) { str += this.searchData[i].num;
str += this.searchData[i].num; }
} }
} this.totalFine = str;
this.totalFine = str return str;
return str; },
}, searchData: function () {
searchData: function() { //
// if (!this.inputs) {
if (!this.inputs) { return this.list;
return this.list; }
} return this.list.filter((item) => {
return this.list.filter((item) => { return item.typeName.includes(this.inputs);
return item.typeName.includes(this.inputs); });
}); },
}, },
}, methods: {
methods: { iconClick() {
iconClick () { console.log(this.iptVal);
console.log(this.iptVal); },
}, add(item) {
add(item) { // //
let num = item.offNum let num = item.offNum;
if (num >= item.num) { if (num >= item.num) {
uni.showToast({ uni.showToast({
icon: 'none', icon: "none",
title: '退料数量不可大于当前在用量!' title: "退料数量不可大于当前在用量!",
}) });
} else { } else {
item.offNum = num + 1 item.offNum = num + 1;
} }
}, },
reduce(item) { // reduce(item) {
let num = item.offNum //
if (num > 1) { let num = item.offNum;
num -= 1 if (num > 1) {
} else if (num = 1) { num -= 1;
uni.showToast({ } else if ((num = 1)) {
icon: 'none', uni.showToast({
title: "该器具无法再减少" icon: "none",
}) title: "该器具无法再减少",
} });
item.offNum = num }
}, item.offNum = num;
// },
checkClick(item) { //
item.checked = !item.checked checkClick(item) {
if (!item.checked) { item.checked = !item.checked;
this.allChecked = false if (!item.checked) {
} else { this.allChecked = false;
// } else {
const goods = this.list.every(item => { //
return item.checked === true const goods = this.list.every((item) => {
}) return item.checked === true;
if (goods) { });
this.allChecked = true if (goods) {
} else { this.allChecked = true;
this.allChecked = false } else {
} this.allChecked = false;
} }
}, }
checkAll() { },
this.allChecked = !this.allChecked checkAll() {
if (this.allChecked) { this.allChecked = !this.allChecked;
this.list.map(item => { if (this.allChecked) {
item.checked = true this.list.map((item) => {
}) item.checked = true;
} else { });
this.list.map(item => { } else {
item.checked = false this.list.map((item) => {
}) item.checked = false;
} });
}, }
finishCart () { },
let that = this finishCart() {
that.cartList = that.list.filter((item) => { let that = this;
return item.checked == true that.cartList = that.list.filter((item) => {
}) return item.checked == true;
if (that.cartList.length == 0) { });
uni.showToast({ if (that.cartList.length == 0) {
icon: 'none', uni.showToast({
title: '请选择退料项!' icon: "none",
}) title: "请选择退料项!",
} else { });
let subList = [] } else {
for (let i = 0; i < that.cartList.length; i++) { let subList = [];
subList.push(that.cartList[i].offNum) for (let i = 0; i < that.cartList.length; i++) {
} subList.push(that.cartList[i].offNum);
subList = subList.join(',') }
console.log(subList, that.typeId); subList = subList.join(",");
// 退 console.log(subList, that.typeId);
that.$api.exitMaterial.subExitMaterial({ // 退
typeId: that.typeId, that.$api.exitMaterial
num: subList .subExitMaterial({
}).then(res => { typeId: that.typeId,
console.log(res); num: subList,
}).catch(err => { })
console.log(err); .then((res) => {
}) console.log(res);
} })
} .catch((err) => {
}, console.log(err);
onLoad(params) { });
let that = this }
console.log(params.id); },
that.typeId = params.typeId },
// 退 onLoad(params) {
that.$api.exitMaterial.exitMaterialDetail({ let that = this;
id: params.id console.log(params.id);
}).then(res => { that.typeId = params.typeId;
if (res.data.code == 200) { // 退
for (let i = 0; i < res.data.data.length; i++) { that.$api.exitMaterial
res.data.data[i].num = Number(res.data.data[i].num.split('.')[0]) .exitMaterialDetail({
res.data.data[i].offNum = 1 id: params.id,
} })
console.log(res); .then((res) => {
that.list = res.data.data if (res.data.code == 200) {
} for (let i = 0; i < res.data.data.length; i++) {
}).catch(err => { // res.data.data[i].num = Number(res.data.data[i].num.split('.')[0])
console.log(err); res.data.data[i].offNum = 1;
}) }
} console.log(res);
} that.list = res.data.data;
}
})
.catch((err) => {
console.log(err);
});
},
};
</script> </script>
<style> <style>
.search-bar{ .search-bar {
width: 95%; width: 95%;
margin: 20rpx auto; margin: 20rpx auto;
} }
/deep/uni-checkbox .uni-checkbox-input { /deep/uni-checkbox .uni-checkbox-input {
border-radius: 50%; border-radius: 50%;
} }
/deep/uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked { /deep/uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
border-color: #ddd; border-color: #ddd;
color: #fff !important; color: #fff !important;
background-color: #2DCF8C !important; background-color: #2dcf8c !important;
} }
/deep/uni-checkbox .uni-checkbox-input { /deep/uni-checkbox .uni-checkbox-input {
border-color: #ddd; border-color: #ddd;
} }
/deep/uni-checkbox .uni-checkbox-input:hover { /deep/uni-checkbox .uni-checkbox-input:hover {
border-color: #ddd; border-color: #ddd;
} }
.search { .search {
padding-top: 20rpx; padding-top: 20rpx;
} }
.search .searchIput { .search .searchIput {
background-color: #e6e6e6; background-color: #e6e6e6;
width: 95%; width: 95%;
margin: 0 auto; margin: 0 auto;
height: 72rpx; height: 72rpx;
line-height: 72rpx; line-height: 72rpx;
border-radius: 50rpx; border-radius: 50rpx;
padding: 0 32rpx; padding: 0 32rpx;
box-sizing: border-box; box-sizing: border-box;
display: flex; display: flex;
align-items: center; align-items: center;
} }
.search .searchIput input { .search .searchIput input {
font-size: 26rpx; font-size: 26rpx;
width: 100%; width: 100%;
color: grey; color: grey;
} }
.search .searchIput image { .search .searchIput image {
width: 34rpx; width: 34rpx;
height: 34rpx; height: 34rpx;
} }
.dataInfo {
width: 95%;
margin: 0 auto;
}
.dataInfo .dataList {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 2px solid #f1f1f1;
padding: 25rpx 0;
}
.dataInfo { .dataInfo .dataList .details {
width: 95%; display: flex;
margin: 0 auto; align-items: center;
} flex: 1;
font-size: 0;
}
.dataInfo .dataList { .dataInfo .dataList .details .img image {
display: flex; width: 200rpx;
align-items: center; height: 140rpx;
justify-content: space-between; padding: 0 20rpx;
border-bottom: 2px solid #F1F1F1; }
padding: 25rpx 0;
}
.dataInfo .dataList .details { .dataInfo .dataList .details .text text {
display: flex; color: #000;
align-items: center; font-size: 23rpx;
flex: 1; display: block;
font-size: 0; padding: 10rpx 0;
} }
.dataInfo .dataList .details .img image { .dataInfo .dataList .details .text {
width: 200rpx; color: red;
height: 140rpx; font-size: 25rpx;
padding: 0 20rpx; }
}
.dataInfo .dataList .details .text text { .dataInfo .dataList .action text {
color: #000; font-size: 25rpx;
font-size: 23rpx; color: #000;
display: block; border: 1px solid #c8c7cc;
padding: 10rpx 0; display: inline-block;
} line-height: 50rpx;
width: 60rpx;
text-align: center;
box-sizing: border-box;
}
.dataInfo .dataList .details .text { .dataInfo .dataList .action text:nth-child(2) {
color: red; border-left: none;
font-size: 25rpx; border-right: none;
} }
.dataInfo .dataList .action text { .buy {
font-size: 25rpx; display: flex;
color: #000; align-items: center;
border: 1px solid #C8C7CC; justify-content: space-between;
display: inline-block; position: fixed;
line-height: 50rpx; left: 50%;
width: 60rpx; bottom: 0;
text-align: center; width: 95%;
box-sizing: border-box; transform: translate(-50%, 0);
} }
.dataInfo .dataList .action text:nth-child(2) { .buy .checked {
border-left: none; display: flex;
border-right: none; align-items: center;
} }
.buy { .buy .checked text {
display: flex; font-size: 25rpx;
align-items: center; color: #000;
justify-content: space-between; padding: 0 12rpx;
position: fixed; }
left: 50%;
bottom: 0;
width: 95%;
transform: translate(-50%, 0);
}
.buy .checked { .buy .total {
display: flex; display: flex;
align-items: center; align-items: center;
} justify-content: space-between;
}
.buy .checked text { .buy .total .price {
font-size: 25rpx; padding-right: 20rpx;
color: #000; }
padding: 0 12rpx;
}
.buy .total { .buy .total .price text {
display: flex; font-size: 27rpx;
align-items: center; color: #c8c7cc;
justify-content: space-between; display: inline-block;
} }
.buy .total .price { .buy .total .price text:last-child {
padding-right: 20rpx; color: red;
font-weight: bold;
}
} .buy .total .bill text {
font-size: 25rpx;
.buy .total .price text { color: #fff;
font-size: 27rpx; display: inline-block;
color: #C8C7CC; background-color: red;
display: inline-block; line-height: 70rpx;
} width: 150rpx;
text-align: center;
.buy .total .price text:last-child { }
color: red;
font-weight: bold;
}
.buy .total .bill text {
font-size: 25rpx;
color: #fff;
display: inline-block;
background-color: red;
line-height: 70rpx;
width: 150rpx;
text-align: center;
}
</style> </style>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long