freight-web/src/pagesShipment/form/shipmentForm.vue

533 lines
13 KiB
Vue
Raw Normal View History

2024-03-09 12:37:17 +00:00
<template>
<view class="c-card">
<u-form
labelPosition="left"
:model="model1"
:rules="rules"
ref="form"
:labelWidth="80"
:labelStyle="{ padding: '0rpx 10rpx' }"
2024-03-25 06:19:03 +00:00
:errorType="'border-bottom'"
2024-03-09 12:37:17 +00:00
>
<u-form-item
2024-03-25 06:19:03 +00:00
:prop="`order.${item.key}`"
2024-03-09 12:37:17 +00:00
:label="item.name"
:required="item.required"
v-for="(item, index) in formAttrList"
:key="index"
@click="item.fn"
2024-03-25 06:19:03 +00:00
:borderBottom="false"
2024-03-09 12:37:17 +00:00
>
<u-textarea
v-if="item.type === 'textarea'"
v-model="(model1.order as any)[(item.key as any)]"
:placeholder="`请输入${item.name}`"
></u-textarea>
<u-input
v-if="item.type === 'select' || item.type === 'input'"
v-model="(model1.order as any)[(item.key as any)]"
:placeholder="`${item.type === 'select' ? '选择' : '输入'}${
item.name
}`"
:clearable="true"
:customStyle="{}"
border="none"
2024-04-16 07:53:59 +00:00
:disabled="item.disabled"
@change="(e:any) => {handleInput(e, item)}"
2024-03-09 12:37:17 +00:00
>
<template #suffix>
{{ item.unit }}
</template>
</u-input>
2024-04-16 07:53:59 +00:00
<!-- 自定义selectui -->
<u-input
v-if="item.type === 'selectCustom'"
v-model="(model1.order as any)[item.key]"
:placeholder="`请选择${item.name}`"
:clearable="true"
:customStyle="{}"
border="none"
disabled
disabledColor="#ffffff"
>
</u-input>
2024-03-09 12:37:17 +00:00
<!-- @afterRead="afterRead"
@delete="deletePic" -->
<!-- <u-upload
v-if="item.type === 'upload'"
:fileList="[]"
name="1"
multiple
:maxCount="10"
></u-upload> -->
2024-03-25 06:19:03 +00:00
2024-03-09 12:37:17 +00:00
<uni-file-picker
v-if="item.type === 'upload'"
2024-03-25 06:19:03 +00:00
v-model="model1.order.fileLists"
:limit="9"
title="最多可上传9张图片"
2024-03-09 12:37:17 +00:00
:auto-upload="false"
fileMediatype="image"
mode="grid"
2024-03-25 06:19:03 +00:00
ref="filesRef"
@delete="handleDelete"
2024-03-09 12:37:17 +00:00
></uni-file-picker>
<u-radio-group
v-if="item.type === 'radio'"
v-model="(model1.order as any)[(item.key as any)]"
placement="row"
>
<u-radio activeColor="#00DCEE" label="送货" :name="0"></u-radio>
&nbsp;&nbsp;&nbsp;
<u-radio activeColor="#00DCEE" label="自提" :name="1"></u-radio>
</u-radio-group>
2024-04-16 07:53:59 +00:00
<template #right v-if="item.type === 'select' || item.type === 'selectCustom'">
2024-03-09 12:37:17 +00:00
<u-icon name="arrow-right"></u-icon>
</template>
</u-form-item>
</u-form>
2024-03-25 06:19:03 +00:00
<block v-for="(item, index) in formAttrList" :key="index">
<u-action-sheet
v-if="item.type === 'select'"
: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"
:safeAreaInsetBottom="true"
></u-action-sheet>
</block>
2024-03-09 12:37:17 +00:00
</view>
<view class="btn-box">
<u-button type="primary" text="保存" @click="save()"></u-button>
</view>
2024-04-16 07:53:59 +00:00
<!-- 出货产品弹框 -->
<ProductDialog
:show="showDialog.showProduct"
@handleDialog="(v:boolean) => {handleDialog('showProduct', v)}"
@changeProduct="changeProduct"
ref="productRef"
:isShipment="true"
></ProductDialog>
2024-03-09 12:37:17 +00:00
</template>
<script setup lang="ts">
2024-03-25 06:19:03 +00:00
import { CustomerApi, GoodsApi, PictureApi, ShipmentApi } from "@/services";
import type { ComType } from "@/types/global";
2024-03-09 12:37:17 +00:00
import { ImagesType, OrderType, ScaleStatus } from "@/utils/enum";
import { onLoad } from "@dcloudio/uni-app";
2024-03-25 06:19:03 +00:00
import _ from "underscore";
2024-04-16 07:53:59 +00:00
import ProductDialog from "../components/ProductDialog.vue";
import valid from "@/utils/validate";
// 供应商选择
const showDialog = <
{
[key: string]: boolean;
}
>reactive({
showProduct: false,
});
const handleDialog = (key: string, v: boolean) => {
showDialog[key] = v;
};
// 收货产品选择
const changeProduct = (obj: any) => {
2024-04-17 01:51:39 +00:00
model1.order.productName = obj.shmProductsName; // 收货产品名称
2024-04-16 07:53:59 +00:00
model1.order.productId = obj.id; // 收货产品Id,
};
// 数量
const handleInput = (e: any, item: any) => {
if (item.key === "number" || item.key === "phone") {
const tempPrice = e?.replace(valid.valid_number, "");
setTimeout(() => {
model1.order[item.key] = tempPrice;
}, 100);
}
};
2024-03-12 05:34:36 +00:00
const model1 = reactive<any>({
2024-03-09 12:37:17 +00:00
order: {
id: 0,
splTime: "",
takeType: 1,
2024-03-25 06:19:03 +00:00
fileLists: [],
2024-03-09 12:37:17 +00:00
},
});
2024-03-25 06:19:03 +00:00
const rules = reactive({
"order.userName": {
2024-03-09 12:37:17 +00:00
type: "string",
required: true,
2024-03-25 06:19:03 +00:00
message: "请选择客户",
2024-03-09 12:37:17 +00:00
trigger: ["blur", "change"],
},
2024-03-25 06:19:03 +00:00
"order.productName": {
2024-03-09 12:37:17 +00:00
type: "string",
required: true,
2024-03-25 06:19:03 +00:00
message: "请选择出货产品名称",
trigger: ["blur", "change"],
},
"order.tare": {
type: "number",
required: true,
message: "请输入皮重",
trigger: ["blur", "change"],
},
"order.number": {
type: "number",
required: true,
2024-04-16 07:53:59 +00:00
message: "数量为空或数量输入错误",
2024-03-25 06:19:03 +00:00
trigger: ["blur", "change"],
},
"order.weighingMethod": {
type: "number",
required: true,
message: "请选择称重方式",
trigger: ["blur", "change"],
},
"order.deliveryMethod": {
type: "number",
required: true,
message: "请选择提货方式",
2024-03-09 12:37:17 +00:00
trigger: ["blur", "change"],
},
});
2024-03-25 06:19:03 +00:00
const contrlModalParams = reactive<ComType>({
userSelect: {
2024-03-09 12:37:17 +00:00
isShow: false,
title: "标题",
2024-03-25 06:19:03 +00:00
list: [],
},
productSelect: {
isShow: false,
title: "标题",
list: [],
2024-03-09 12:37:17 +00:00
},
});
2024-03-25 06:19:03 +00:00
const formAttrList = reactive<ComType>([
2024-03-09 12:37:17 +00:00
{
name: "客户",
2024-03-25 06:19:03 +00:00
key: "userName",
2024-04-16 07:53:59 +00:00
type: "selectCustom",
2024-03-09 12:37:17 +00:00
required: true,
2024-03-25 06:19:03 +00:00
childKey: "userSelect",
2024-03-09 12:37:17 +00:00
unit: "",
fn: () => {
2024-04-16 07:53:59 +00:00
// contrlModalParams.userSelect.isShow = true;
// contrlModalParams.userSelect.title = "客户";
uni.hideKeyboard();
2024-03-09 12:37:17 +00:00
},
},
{
name: "出货产品",
2024-03-25 06:19:03 +00:00
key: "productName",
2024-04-16 07:53:59 +00:00
type: "selectCustom",
2024-03-09 12:37:17 +00:00
required: true,
2024-03-25 06:19:03 +00:00
childKey: "productSelect",
2024-03-09 12:37:17 +00:00
unit: "",
fn: () => {
2024-04-16 07:53:59 +00:00
// contrlModalParams.productSelect.isShow = true;
// contrlModalParams.productSelect.title = "出货产品";
handleDialog("showProduct", true);
uni.hideKeyboard();
2024-03-09 12:37:17 +00:00
},
},
{
name: "数量",
key: "number",
type: "input",
required: true,
unit: "件",
},
{
2024-03-25 06:19:03 +00:00
name: "皮重",
key: "tare",
2024-03-09 12:37:17 +00:00
type: "input",
required: true,
unit: "KG",
2024-04-16 07:53:59 +00:00
disabled: true
2024-03-09 12:37:17 +00:00
},
{
name: "提货方式",
key: "deliveryMethod",
required: true,
type: "radio",
},
{
name: "车辆信息",
type: "text",
},
{
name: "车牌号",
key: "carNumber",
type: "input",
unit: "",
},
{
name: "司机电话",
key: "phone",
type: "input",
unit: "",
},
{
name: "集装箱",
type: "text",
},
{
name: "箱号",
key: "box",
type: "input",
unit: "",
},
{
name: "封号",
key: "title",
type: "input",
unit: "",
},
{
name: "备注",
2024-03-11 05:30:11 +00:00
key: "notes",
2024-03-09 12:37:17 +00:00
type: "textarea",
},
{
name: "上传照片",
key: "photo",
type: "upload",
},
]);
2024-03-25 06:19:03 +00:00
CustomerApi.getCustomUserList({}).then((res) => {
if (res.code === 200) {
contrlModalParams.userSelect.list = res.data;
}
});
GoodsApi.getShipmentProductList().then((res) => {
if (res.code === 200) {
contrlModalParams.productSelect.list = _.map(
res.data as any,
function (item: any) {
return { name: item.shmProductsName, ...item };
}
);
}
});
const handleSelect = (key: string, v: any) => {
contrlModalParams[key].isShow = false;
if (key === "userSelect") {
model1.order.userName = v.name;
model1.order.userId = v.id;
} else if (key === "productSelect") {
model1.order.productName = v.name;
model1.order.productId = v.id;
}
};
const filesRef = ref();
2024-03-09 12:37:17 +00:00
const handleUpload = () => {
// console.log(event.tempFilePaths)
2024-03-25 06:19:03 +00:00
return filesRef.value[0].filesList.map((item: any, index: number) => {
if (item.fileID) {
return;
}
2024-03-09 12:37:17 +00:00
return new Promise((resolve) => {
PictureApi.upload({
files: item,
path: item.path,
2024-03-25 06:19:03 +00:00
})
.then((res) => {
if (res.code === 200) {
resolve({
...(res.data as any),
businessId: model1.order.id,
imagesType: ImagesType.NORMARL, // 普通资源
orderType: OrderType.Shipment, // 入库单
});
}
})
.catch((e) => {
return;
});
2024-03-09 12:37:17 +00:00
});
});
};
2024-03-25 06:19:03 +00:00
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-09 12:37:17 +00:00
/**
* 点击保存 先执行upload接口
* 上传成功后 保存图片资源 和更新订单数据
*/
2024-03-25 06:19:03 +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-09 12:37:17 +00:00
const save = () => {
2024-04-16 07:53:59 +00:00
if (model1.order.carNumber) {
if (!valid.carNo.pattern.test(model1.order.carNumber)) {
uni.showToast({ icon: "none", title: "请输入正确的车牌号" });
return;
}
}
if (model1.order.phone) {
if (!valid.mobile.pattern.test(model1.order.phone)) {
uni.showToast({ icon: "none", title: "请输入正确的手机号" });
return;
}
}
2024-03-25 06:19:03 +00:00
check().then((res) => {
if (res) {
startSave();
}
});
};
const startSave = () => {
2024-03-09 12:37:17 +00:00
Promise.all(handleUpload()).then((res) => {
// 上传多个资源
if (res.length > 0) {
PictureApi.addListAnnex({ annexPos: res }).then((res1) => {
if (res1.code === 200) {
2024-03-25 06:19:03 +00:00
console.log("*** 资源文件更新成功");
2024-03-09 12:37:17 +00:00
}
});
}
});
2024-03-25 06:19:03 +00:00
updateOrder();
};
2024-03-09 12:37:17 +00:00
2024-03-25 06:19:03 +00:00
const updateOrder = () => {
// 编辑更新状态值
2024-04-16 07:53:59 +00:00
// else if (state.scaleStatus === ScaleStatus.ToBeGrossWeight) {
// status = ScaleStatus.ToBeShipmentReview;
// }
2024-03-25 06:19:03 +00:00
let status = 0;
if (state.scaleStatus === ScaleStatus.ToBeShipment) {
status = ScaleStatus.ToBeGrossWeight;
} else {
status = model1.order.status;
2024-03-12 05:34:36 +00:00
}
2024-03-09 12:37:17 +00:00
// 更新出货单
ShipmentApi.updateOrderIn({
2024-03-25 06:19:03 +00:00
orderOutPos: [{ ...model1.order, scaleStatus: status }],
2024-03-09 12:37:17 +00:00
}).then((res) => {
if (res.code === 200) {
uni.showToast({
title: "编辑成功",
icon: "success",
});
2024-04-16 07:53:59 +00:00
if (state.scaleStatus === ScaleStatus.ToBeShipment || state.scaleStatus === ScaleStatus.ToBeGrossWeight) {
2024-03-25 06:19:03 +00:00
uni.redirectTo({
2024-04-16 07:53:59 +00:00
url: "/pagesShipment/shipmenting?scaleStatus=" + state.scaleStatus, // 要跳转到的页面路径
2024-03-25 06:19:03 +00:00
});
} else {
uni.redirectTo({
url:
"/pagesShipment/review/index?id=" +
model1.order.id +
`&scaleStatusBtnType=1`, // 要跳转到的页面路径
2024-03-12 05:34:36 +00:00
});
}
2024-03-09 12:37:17 +00:00
}
});
};
2024-03-25 06:19:03 +00:00
const state = reactive({
scaleStatus: 0,
});
2024-03-09 12:37:17 +00:00
onLoad((option) => {
model1.order.id = (option as any).id;
2024-03-25 06:19:03 +00:00
state.scaleStatus = parseInt((option as any).scaleStatus);
if (state.scaleStatus === ScaleStatus.ToBeShipment) {
uni.setNavigationBarTitle({
title: "待出货编辑",
});
} else if (state.scaleStatus === ScaleStatus.ToBeGrossWeight) {
uni.setNavigationBarTitle({
title: "待过毛重编辑",
});
} else {
uni.setNavigationBarTitle({
title: "审核结算编辑",
});
}
2024-03-09 12:37:17 +00:00
if (model1.order.id) {
ShipmentApi.getDetailById({ id: model1.order.id }).then((res) => {
if (res.code === 200) {
2024-03-25 06:19:03 +00:00
model1.order = {
...res.data,
deliveryMethod:
res.data.deliveryMethod !== null ? res.data.deliveryMethod : 0,
fileLists: model1.order.fileLists.map((item: any) => {
return { ...item, fileID: item.id };
}),
};
console.log(model1.order);
2024-03-09 12:37:17 +00:00
}
});
PictureApi.getAnnex({
businessId: model1.order.id,
2024-03-25 06:19:03 +00:00
orderType: OrderType.Shipment,
2024-03-09 12:37:17 +00:00
imagesType: ImagesType.NORMARL,
}).then((res) => {
if (res.code === 200) {
2024-03-25 06:19:03 +00:00
model1.order.fileLists = res.data;
2024-03-09 12:37:17 +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-09 12:37:17 +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>