freight-web/src/pagesApp/receiveSpl.vue

639 lines
16 KiB
Vue
Raw Normal View History

2024-03-04 07:10:11 +00:00
<template>
<view class="c-card">
<u-form
labelPosition="left"
:model="model1"
:rules="rules"
ref="form"
:labelWidth="80"
:labelStyle="{ padding: '0rpx 10rpx' }"
:errorType="'border-bottom'"
2024-03-04 07:10:11 +00:00
>
<u-form-item
:prop="`order.${item.key}`"
2024-03-04 07:10:11 +00:00
:label="item.name"
2024-03-12 06:42:34 +00:00
:required="item.required"
2024-03-04 07:10:11 +00:00
v-for="(item, index) in formAttrList"
:key="index"
@click="item.fn"
>
<u-textarea
v-if="item.type === 'textarea'"
v-model="(model1.order as any)[item.key]"
:placeholder="`请输入${item.name}`"
></u-textarea>
<u-input
2024-03-04 07:10:11 +00:00
v-if="item.type === 'select' || item.type === 'input'"
v-model="(model1.order as any)[item.key]"
:placeholder="`${item.type === 'select' ? '选择' : '输入'}${
item.name
}`"
2024-04-26 06:13:57 +00:00
clearable
2024-03-04 07:10:11 +00:00
:customStyle="{}"
border="none"
:disabled="item.disabled || item.type === 'select'"
:disabledColor="['补单时间','站点磅秤','供应商','收货产品'].indexOf(item.name) > -1?'#ffffff':'#f5f7fa'"
@change="(e:any) => {handleInput(e, item)}"
2024-04-26 06:13:57 +00:00
@clear="handleClear(item)"
2024-03-04 07:10:11 +00:00
>
<template #suffix>
<text v-if="item.key === 'subtractNum'">
{{ model1.order.buttonType === 0 ? item.unit : "%" }}
2024-03-04 07:10:11 +00:00
</text>
<text v-else>
{{ item.unit }}
</text>
</template>
</u-input>
2024-03-04 07:10:11 +00:00
<!-- @afterRead="afterRead"
@delete="deletePic" -->
2024-03-12 06:42:34 +00:00
<uni-file-picker
2024-03-04 07:10:11 +00:00
v-if="item.type === 'upload'"
v-model="model1.order.fileLists"
limit="9"
title="最多可上传9张图片"
2024-03-12 06:42:34 +00:00
:auto-upload="false"
fileMediatype="image"
mode="grid"
ref="filesRef"
@delete="handleDelete"
2024-03-12 06:42:34 +00:00
></uni-file-picker>
2024-03-04 07:10:11 +00:00
<u-radio-group
v-if="item.type === 'radio'"
v-model="(model1.order as any)[item.key]"
placement="row"
>
<u-radio activeColor="#00DCEE" label="按固定重量" :name="0"></u-radio>
2024-03-04 07:10:11 +00:00
&nbsp;&nbsp;&nbsp;
<u-radio activeColor="#00DCEE" label="按百分比" :name="1"></u-radio>
2024-03-04 07:10:11 +00:00
</u-radio-group>
<template #right v-if="item.type === 'select'">
<u-icon name="arrow-right"></u-icon>
</template>
</u-form-item>
</u-form>
<u-datetime-picker
:show="contrlModalParams.isShowSplTime"
v-model="contrlModalParams.spltime"
mode="datetime"
2024-03-12 06:42:34 +00:00
@confirm="(v: any) => {handleTime(v)}"
2024-03-04 07:10:11 +00:00
@cancel="contrlModalParams.isShowSplTime = false"
2024-04-25 08:30:50 +00:00
:closeOnClickOverlay="true"
@close="contrlModalParams.isShowSplTime = false"
2024-03-04 07:10:11 +00:00
></u-datetime-picker>
2024-03-12 06:42:34 +00:00
<block v-for="(item, index) in formAttrList" :key="index">
<u-action-sheet
v-if="item.type === 'select' && item.key !== 'repairTime'"
2024-03-12 06:42:34 +00:00
:actions="contrlModalParams[item.childKey].list"
:title="contrlModalParams[item.childKey].title"
:show="contrlModalParams[item.childKey].isShow"
@select="(v: any) => handleSelect(item.childKey, v)"
@close="contrlModalParams[item.childKey].isShow = false"
:closeOnClickAction="true"
></u-action-sheet>
2024-03-12 06:42:34 +00:00
</block>
2024-03-04 07:10:11 +00:00
</view>
<view class="btn-box">
2024-03-12 06:42:34 +00:00
<u-button type="primary" text="保存" @click="save()"></u-button>
2024-03-04 07:10:11 +00:00
</view>
<!-- 供应商选择弹框 -->
<SupplierDialog
ref="supplierDialog"
:show="showDialog.showSupplier"
@handleDialog="(v:boolean) => {handleDialog('showSupplier', v)}"
@changeUser="changeUser"
:isShipment="false"
></SupplierDialog>
<!-- 收货产品弹框 -->
<ProductDialog
:show="showDialog.showProduct"
@handleDialog="(v:boolean) => {handleDialog('showProduct', v)}"
@changeProduct="changeProduct"
ref="productRef"
:isShipment="false"
></ProductDialog>
2024-03-04 07:10:11 +00:00
</template>
<script setup lang="ts">
2024-03-13 02:41:39 +00:00
import {
DeviceApi,
PictureApi,
ProfileApi,
ReceiveApi,
ReceiveProductApi,
SupplierApi,
2024-03-13 02:41:39 +00:00
} from "@/services";
import { countDots, formatDate } from "@/utils";
import { DeviceType, ImagesType, OrderType } from "@/utils/enum";
import _ from "underscore";
import SupplierDialog from "./components/SupplierDialog.vue";
import ProductDialog from "./components/ProductDialog.vue";
import valid from "@/utils/validate";
2024-04-26 06:13:57 +00:00
const handleClear = (item:any) => {
(model1.order as any)[item.key] = '';
}
// 供应商选择
const showDialog = <
{
[key: string]: boolean;
}
>reactive({
showSupplier: false,
showProduct: false,
});
const handleDialog = (key: string, v: boolean) => {
showDialog[key] = v;
};
const changeUser = (obj: any) => {
model1.order.userName = obj.name; // 供应商名称
model1.order.userId = obj.id; // 供应商Id,
};
// 收货产品选择
const changeProduct = (obj: any) => {
model1.order.productName = obj.reProductsName; // 收货产品名称
model1.order.productId = obj.id; // 收货产品Id,
model1.order.price = obj.commonPrice; // 设置常用价格
model1.order.minPrice = obj.minPrice; // 保存最大最小值
model1.order.maxPrice = obj.maxPrice;
};
// 毛重 皮重 杂质扣除校验 净重 单价 预估总价 货款金额
const handleInput = (e: any, item: any) => {
if (
["grossWeight", "tare", "price", "balanceTotalPrice"].indexOf(item.key) > -1
) {
const temp = e?.replace(valid.valid_decimal.pattern, "");
if (countDots(temp).length > 1) {
uni.showToast({
title: "请输入正确的" + item.name,
icon: "none",
});
}
if (item.key === "price") {
if (model1.order.minPrice && model1.order.maxPrice) {
if (temp < model1.order.minPrice || temp > model1.order.maxPrice) {
uni.showToast({
title: `${item.name}应在${model1.order.minPrice}-${model1.order.maxPrice}之间`,
icon: "none",
});
return;
}
}
}
if (item.key === "tare") {
if (
parseFloat(model1.order.tare) > parseFloat(model1.order.grossWeight)
) {
uni.showToast({
title: `毛重需大于皮重`,
icon: "none",
});
return;
}
}
setTimeout(() => {
model1.order[item.key] = temp;
2024-04-26 06:13:57 +00:00
}, 10);
}
if (item.key === "subtractNum") {
const temp = e?.replace(valid.valid_decimal.pattern, "");
if (
model1.order.buttonType === 1 &&
(parseInt(temp) > 100 || parseInt(temp) < 0)
) {
uni.showToast({
title: `${item.name}正确范围是0-100`,
icon: "none",
});
}
setTimeout(() => {
model1.order[item.key] = temp;
2024-04-26 06:13:57 +00:00
}, 10);
}
};
2024-03-12 06:42:34 +00:00
const model1 = reactive<any>({
2024-03-04 07:10:11 +00:00
order: {
buttonType: 0,
fileLists: [],
splTime: "",
2024-03-04 07:10:11 +00:00
subtractType: 1,
netWeight: 0,
totalPrice: 0
2024-03-04 07:10:11 +00:00
},
});
const rules = reactive({
"order.repairTime": {
2024-03-04 07:10:11 +00:00
type: "string",
required: true,
message: "请选择补单时间",
2024-03-04 07:10:11 +00:00
trigger: ["blur", "change"],
},
"order.deviceName": {
2024-03-04 07:10:11 +00:00
type: "string",
required: true,
message: "请选择站点磅秤",
trigger: ["blur", "change"],
},
"order.userName": {
type: "string",
required: true,
message: "请选择供应商",
trigger: ["blur", "change"],
},
"order.productName": {
type: "string",
required: true,
message: "请选择收货产品",
trigger: ["blur", "change"],
},
"order.grossWeight": {
type: "number",
required: true,
message: "毛重为空或输入错误",
trigger: ["blur", "change"],
},
"order.tare": {
type: "number",
required: true,
message: "皮重为空或输入错误",
trigger: ["blur", "change"],
},
"order.price": {
type: "number",
required: true,
message: "单价为空或输入错误",
trigger: ["blur", "change"],
},
"order.balanceTotalPrice": {
type: "number",
required: true,
message: "货款金额为空或输入错误",
2024-03-04 07:10:11 +00:00
trigger: ["blur", "change"],
},
});
2024-03-12 06:42:34 +00:00
const contrlModalParams = reactive<any>({
2024-03-04 07:10:11 +00:00
isShowSplTime: false,
spltime: Number(new Date()),
2024-03-12 06:42:34 +00:00
device: {
2024-03-04 07:10:11 +00:00
isShow: false,
title: "标题",
list: [],
2024-03-04 07:10:11 +00:00
},
2024-03-12 06:42:34 +00:00
user: {
isShow: false,
title: "标题",
list: [],
},
product: {
isShow: false,
title: "标题",
list: [],
},
2024-03-04 07:10:11 +00:00
});
const formAttrList = reactive<any>([
2024-03-04 07:10:11 +00:00
{
name: "补单时间",
2024-03-12 06:42:34 +00:00
key: "repairTime",
2024-03-04 07:10:11 +00:00
type: "select",
unit: "",
2024-03-12 06:42:34 +00:00
required: true,
2024-03-04 07:10:11 +00:00
fn: () => {
contrlModalParams.isShowSplTime = true;
},
},
{
name: "站点磅秤",
2024-03-12 06:42:34 +00:00
key: "deviceName",
2024-03-04 07:10:11 +00:00
type: "select",
2024-03-13 02:41:39 +00:00
childKey: "device",
2024-03-12 06:42:34 +00:00
required: true,
2024-03-04 07:10:11 +00:00
unit: "",
fn: () => {
contrlModalParams.device.isShow = true;
contrlModalParams.device.title = "站点磅秤";
2024-03-04 07:10:11 +00:00
},
},
{
name: "供应商",
2024-03-12 06:42:34 +00:00
key: "userName",
2024-03-04 07:10:11 +00:00
type: "select",
2024-03-13 02:41:39 +00:00
childKey: "user",
2024-03-12 06:42:34 +00:00
required: true,
2024-03-04 07:10:11 +00:00
unit: "",
fn: () => {
// contrlModalParams.user.isShow = true;
// contrlModalParams.user.title = "供应商";
handleDialog("showSupplier", true);
uni.hideKeyboard();
2024-03-04 07:10:11 +00:00
},
},
{
name: "车牌号",
2024-03-12 06:42:34 +00:00
key: "carNumber",
2024-03-04 07:10:11 +00:00
type: "input",
unit: "",
},
{
name: "收货产品",
2024-03-12 06:42:34 +00:00
key: "productName",
2024-03-04 07:10:11 +00:00
type: "select",
2024-03-13 02:41:39 +00:00
childKey: "product",
2024-03-12 06:42:34 +00:00
required: true,
2024-03-04 07:10:11 +00:00
unit: "",
fn: () => {
// contrlModalParams.product.isShow = true;
// contrlModalParams.product.title = "收货产品";
handleDialog("showProduct", true);
uni.hideKeyboard();
2024-03-04 07:10:11 +00:00
},
},
{
name: "毛重",
key: "grossWeight",
type: "input",
2024-03-12 06:42:34 +00:00
required: true,
2024-03-04 07:10:11 +00:00
unit: "KG",
},
{
name: "皮重",
key: "tare",
type: "input",
2024-03-12 06:42:34 +00:00
required: true,
2024-03-04 07:10:11 +00:00
unit: "KG",
},
{
name: "扣杂",
2024-03-12 06:42:34 +00:00
key: "buttonType",
2024-03-04 07:10:11 +00:00
type: "radio",
},
{
name: "杂质扣除",
key: "subtractNum",
type: "input",
unit: "KG",
},
{
name: "净重",
key: "netWeight",
type: "input",
unit: "KG",
disabled: true,
2024-03-04 07:10:11 +00:00
},
{
name: "单价",
2024-03-12 06:42:34 +00:00
key: "price",
2024-03-04 07:10:11 +00:00
type: "input",
2024-03-12 06:42:34 +00:00
required: true,
2024-03-04 07:10:11 +00:00
unit: "元/KG",
},
{
name: "预估总价",
2024-03-12 06:42:34 +00:00
key: "totalPrice",
2024-03-04 07:10:11 +00:00
type: "input",
unit: "元",
disabled: true,
2024-03-04 07:10:11 +00:00
},
{
name: "货款金额",
2024-03-12 06:42:34 +00:00
key: "balanceTotalPrice",
2024-03-04 07:10:11 +00:00
type: "input",
2024-03-12 06:42:34 +00:00
required: true,
2024-03-04 07:10:11 +00:00
unit: "元",
},
{
name: "备注",
2024-03-12 06:42:34 +00:00
key: "notes",
2024-03-04 07:10:11 +00:00
type: "textarea",
},
{
name: "货品照片",
key: "photo",
type: "upload",
},
]);
// 监听毛重 皮重
watch(
[
() => model1.order.grossWeight,
() => model1.order.tare,
() => model1.order.price,
() => model1.order.subtractNum,
() => model1.order.buttonType,
],
([grossWeightNew, tareNew]) => {
/**
* 过磅净重 毛重-皮重
结算重量 过磅净重-扣杂
预估总价 结算单价*结算重量
实际收入实际结算金额-运费-杂费
*/
model1.order.netWeight = ((parseFloat(grossWeightNew) || 0) - (parseFloat(tareNew) || 0)).toFixed(2);
if (model1.order.buttonType === 0) {
if (model1.order.subtractNum) {
model1.order.netWeight =
model1.order.netWeight - model1.order.subtractNum;
}
} else if (model1.order.buttonType === 1) {
if (model1.order.subtractNum) {
model1.order.netWeight =
model1.order.netWeight * ((100 - model1.order.subtractNum) / 100);
}
}
model1.order.totalPrice =
(model1.order.price || 0) * (model1.order.netWeight || 0);
// 货款金额默认=预估总价,当系统自动算出预估总价时,值需同步
model1.order.balanceTotalPrice = model1.order.totalPrice;
}
);
const handleDelete = (e: any) => {
console.log(model1.order.fileLists);
if (e.tempFile.fileID) {
PictureApi.deleteById({ id: e.tempFile.fileID }).then((res) => {
if (res.code === 200) {
uni.showToast({ title: "已删除" });
}
});
}
};
2024-03-12 06:42:34 +00:00
const filesRef = ref();
const handleUpload = () => {
// console.log(event.tempFilePaths)
return filesRef.value[0].filesList.map((item: any, index: number) => {
if (item.fileID) {
return;
}
2024-03-12 06:42:34 +00:00
return new Promise((resolve) => {
PictureApi.upload({
files: item,
path: item.path,
})
.then((res) => {
if (res.code === 200) {
resolve({
...(res.data as any),
businessId: model1.order.id,
imagesType: ImagesType.NORMARL, // 普通资源
orderType: OrderType.Receive, // 入库单
});
}
})
.catch((e) => {
return;
});
2024-03-12 06:42:34 +00:00
});
});
};
const handleSelect = (key: string, v: any) => {
contrlModalParams[key].isShow = false;
if (key === "user") {
model1.order.userName = v.name;
model1.order.userId = v.id;
} else if (key === "product") {
model1.order.productName = v.name;
model1.order.productId = v.id;
} else if (key === "device") {
model1.order.deviceName = v.name;
model1.order.deviceId = v.id;
}
};
// 供应商信息
SupplierApi.getSupplierUserList({}).then((res) => {
if (res.code === 200) {
contrlModalParams.user.list = res.data;
}
});
// 产品信息
ReceiveProductApi.getAllReProducts().then((res) => {
if (res.code === 200) {
contrlModalParams.product.list = _.map(
res.data as any,
function (item: any) {
return { name: item.reProductsName, ...item };
}
);
}
});
// 设备信息
2024-03-13 02:41:39 +00:00
DeviceApi.getDeviceList({ deviceType: DeviceType.Weighbridge }).then((res) => {
if (res.code === 200) {
contrlModalParams.device.list = _.map(
res.data as any,
function (item: any) {
return { name: item.deviceName, ...item };
}
);
}
2024-03-13 02:41:39 +00:00
});
const upload = () => {
Promise.all(handleUpload()).then((res) => {
// 上传多个资源
if (res.length > 0) {
PictureApi.addListAnnex({ annexPos: res }).then((res1) => {
if (res1.code === 200) {
console.log("*** 资源文件更新成功");
2024-03-13 02:41:39 +00:00
}
});
}
});
};
/**
* 校验
*/
const form = ref();
const check = () => {
return new Promise((resolve) => {
form.value
.validate()
.then((res: boolean) => {
resolve(res);
})
.catch((errors: any) => {
resolve(false);
uni.showToast({
icon: "none",
title: errors[0].message || "校验失败",
});
});
});
};
2024-03-12 06:42:34 +00:00
const save = () => {
if (model1.order.carNumber) {
if (!valid.carNo.pattern.test(model1.order.carNumber)) {
uni.showToast({ icon: "none", title: "请输入正确的车牌号" });
return;
}
}
if (parseFloat(model1.order.tare) > parseFloat(model1.order.grossWeight)) {
uni.showToast({
title: `毛重需大于皮重`,
icon: "none",
});
return;
}
check().then((res) => {
if (res) {
startSave();
}
});
};
const startSave = () => {
2024-03-12 06:42:34 +00:00
if (model1.order.buttonType === 0) {
model1.order.buckleMiscellaneous = model1.order.subtractNum;
} else if (model1.order.buttonType === 1) {
model1.order.points = model1.order.subtractNum;
}
ReceiveApi.addOrderIn(model1.order).then((res) => {
if (res.code === 200) {
2024-03-13 02:41:39 +00:00
model1.order.id = res.data;
upload();
uni.navigateBack()
2024-03-12 06:42:34 +00:00
}
});
};
const handleTime = (v: any) => {
model1.order.repairTime = formatDate(v.value, "{y}-{m}-{d} {h}:{i}:{s}");
contrlModalParams.isShowSplTime = false;
};
2024-03-04 07:10:11 +00:00
</script>
<style lang="scss" scoped>
.c-card {
background: #ffffff;
// box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(5, 68, 37, 0.12);
border-radius: 13rpx;
margin: 30rpx 25rpx;
2024-03-21 05:52:15 +00:00
padding: 0rpx 20rpx;
2024-03-04 07:10:11 +00:00
::v-deep .u-form-item {
height: auto;
}
::v-deep .u-form-item + .u-form-item {
border-top: 1rpx solid rgba(233, 233, 233, 0.76);
}
}
.btn-box {
margin-top: 60rpx;
display: flex;
background: #ffffff;
box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0, 56, 93, 0.12);
border-radius: 13rpx 13rpx 0rpx 0rpx;
padding: 25rpx 50rpx;
position: sticky;
bottom: 0rpx;
z-index: 999;
::v-deep button {
border-radius: 43rpx;
}
}
</style>