freight-web/src/pagesApp/components/addCustomer.vue

249 lines
6.1 KiB
Vue
Raw Normal View History

2024-03-16 13:26:04 +00:00
<template>
<view class="c-card">
<u-form
labelPosition="left"
:model="model1"
:rules="rules"
ref="form"
:labelWidth="100"
:labelStyle="{ padding: '0rpx 10rpx' }"
2024-03-28 08:55:03 +00:00
:errorType="'border-bottom'"
2024-03-16 13:26:04 +00:00
>
<u-form-item
2024-03-28 08:55:03 +00:00
:prop="`formData.${item.key}`"
2024-03-16 13:26:04 +00:00
:label="item.name"
:required="item.required"
v-for="(item, index) in formAttrList"
:key="index"
@click="item.fn"
>
<u-textarea
v-if="item.type === 'textarea'"
v-model="(model1.formData as any)[item.key]"
:placeholder="`请输入${item.name}`"
></u-textarea>
<u-input
v-if="item.type === 'select' || item.type === 'input'"
v-model="(model1.formData as any)[item.key]"
:placeholder="`${item.type === 'select' ? '选择' : '输入'}${
item.name
}`"
:clearable="true"
:customStyle="{}"
border="none"
:disabled="item.type === 'select'"
:disabledColor="['卡号'].indexOf(item.name) > -1?'#ffffff':'#f5f7fa'"
2024-03-16 13:26:04 +00:00
>
<template #suffix>
<text>
{{ item.unit }}
</text>
</template>
</u-input>
<template #right v-if="item.type === 'select'">
<u-icon name="arrow-right"></u-icon>
</template>
</u-form-item>
</u-form>
<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"
></u-action-sheet>
</block>
</view>
<view class="btn-box">
<u-button type="primary" text="保存" @click="save()"></u-button>
</view>
</template>
<script setup lang="ts">
import { CustomerApi, StockCardApi } from "@/services";
import { formatDate } from "@/utils";
2024-03-28 08:55:03 +00:00
import { DeviceType, ImagesType, OrderType, StockCardType } from "@/utils/enum";
2024-03-16 13:26:04 +00:00
import { onLoad } from "@dcloudio/uni-app";
import _ from "underscore";
const model1 = reactive<any>({
formData: {},
});
const rules = ref({
2024-03-28 08:55:03 +00:00
"formData.stockCardName": {
2024-03-16 13:26:04 +00:00
type: "string",
required: true,
2024-03-28 08:55:03 +00:00
message: "请选择出库卡",
2024-03-16 13:26:04 +00:00
trigger: ["blur", "change"],
},
2024-03-28 08:55:03 +00:00
"formData.name": {
2024-03-16 13:26:04 +00:00
type: "string",
required: true,
2024-03-28 08:55:03 +00:00
message: "请输入客户名称",
trigger: ["blur", "change"],
},
"formData.contacts": {
type: "string",
required: true,
message: "请输入联系人",
2024-03-16 13:26:04 +00:00
trigger: ["blur", "change"],
},
});
const contrlModalParams = reactive<any>({
supplierType: {
isShow: false,
title: "标题",
list: [],
},
stockCard: {
isShow: false,
title: "标题",
list: [],
},
});
const formAttrList = reactive<any>([
{
name: "卡号",
key: "stockCardName",
type: "select",
childKey: "stockCard",
required: true,
fn: () => {
if (contrlModalParams.stockCard.list.length === 0) {
uni.showToast({icon: 'none', title: '当前无可用卡号,请添加出库卡'})
return
}
2024-03-16 13:26:04 +00:00
contrlModalParams.stockCard.isShow = true;
contrlModalParams.stockCard.title = "卡号";
},
},
{
name: "客户名称",
key: "name",
type: "input",
required: true,
unit: "",
},
{
name: "联系人",
key: "contacts",
type: "input",
required: true,
unit: "",
},
]);
const handleSelect = (key: string, v: any) => {
contrlModalParams[key].isShow = false;
if (key === "stockCard") {
model1.formData.stockCardName = v.name;
model1.formData.stockCardId = v.id;
}
};
2024-03-28 08:55: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-16 13:26:04 +00:00
const save = () => {
2024-03-28 08:55:03 +00:00
check().then((res) => {
if (res) {
startSave();
}
});
};
const startSave = () => {
2024-03-16 13:26:04 +00:00
if (model1.formData.id) {
CustomerApi.updateCustomUser(model1.formData).then((res) => {
if (res.code === 200) {
uni.redirectTo({
url: "/pagesApp/customerMgt", // 要跳转到的页面路径
});
}
});
} else {
CustomerApi.addCustomUser(model1.formData).then((res) => {
if (res.code === 200) {
uni.redirectTo({
url: "/pagesApp/customerMgt", // 要跳转到的页面路径
});
}
});
}
};
const getStockCardList = () => {
StockCardApi.getStockCardListInfo({ vincolante: StockCardType.Shipment }).then((res) => {
2024-03-16 13:26:04 +00:00
if (res.code === 200) {
contrlModalParams.stockCard.list = (res.data as any).map(
2024-03-16 13:26:04 +00:00
(item: any) => {
return { ...item, name: item.cardCode };
}
);
}
});
};
onMounted(() => {
getStockCardList();
});
onLoad((option) => {
// 接收传递的标题参数
const title = (option as any).title;
model1.formData = JSON.parse((option as any).item);
if (model1.formData.cardCode) {
model1.formData.stockCardName = model1.formData.cardCode;
}
// 设置页面标题
uni.setNavigationBarTitle({
title: title,
});
});
</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-16 13:26:04 +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>