453 lines
18 KiB
Vue
Raw Normal View History

2023-11-27 19:05:43 +08:00
<template>
<div class="edit-popup">
2024-03-07 15:43:35 +08:00
<popup ref="popupRef" :title="popupTitle" :async="true" width="80%" @confirm="handleSubmit"
@close="handleClose">
<el-form ref="formRef" :model="formData" label-width="auto" :rules="formRules" inline>
2023-12-12 11:29:58 +08:00
<el-row>
<el-col :span="8">
2024-03-20 10:22:32 +08:00
<el-form-item label="客户名称" prop="custom_id"
2024-01-13 18:46:39 +08:00
:rules="[{ required: true, message: '不可为空', trigger: 'change' }]">
2024-01-15 18:20:06 +08:00
<el-input v-model="customer_name" clearable placeholder="点击选择客户" readonly
2024-01-13 18:46:39 +08:00
@click="showDialog = true" />
2023-12-12 11:29:58 +08:00
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="联系人" prop="custom_master_name">
2024-01-22 19:24:31 +08:00
<el-input v-model="formData.custom_master_name" disabled clearable placeholder="请输入联系人" />
2024-02-19 18:01:49 +08:00
</el-form-item>
</el-col>
2023-12-12 11:29:58 +08:00
<el-col :span="8">
2024-01-13 18:46:39 +08:00
<el-form-item label="联系电话" prop="custom_master_phone"
:rules="[{ validator: isMobileNumber, trigger: 'blur' }]">
2024-01-22 19:24:31 +08:00
<el-input v-model="formData.custom_master_phone" disabled clearable placeholder="请输入联系电话"
2024-01-13 18:46:39 +08:00
:regex="/^ 1[3 - 9]\d{ 9}$ /" />
2023-12-12 11:29:58 +08:00
</el-form-item>
</el-col>
2024-01-22 19:24:31 +08:00
<el-col :span="8">
<el-form-item label="报价日期" prop="quotation_date">
2024-01-26 00:20:03 +08:00
<el-date-picker v-model="formData.quotation_date" clearable type="date"
2024-01-22 19:24:31 +08:00
value-format="YYYY-MM-DD" placeholder="选择报价日期">
</el-date-picker>
</el-form-item>
</el-col>
2023-12-12 11:29:58 +08:00
<el-col :span="8">
<el-form-item label="制单人" prop="create_user">
<el-input v-model="formData.create_user" clearable placeholder="请输入制单人" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="发票类型" prop="invoice_type">
<el-radio-group v-model="formData.invoice_type" placeholder="请选择发票类型">
2024-01-13 18:46:39 +08:00
<el-radio v-for="( item, index ) in dictData.invoice_type " :key="index"
:label="parseInt(item.value)">
2023-12-12 11:29:58 +08:00
{{ item.name }}
</el-radio>
</el-radio-group>
</el-form-item>
2024-02-19 18:01:49 +08:00
</el-col>
<el-col :span="8">
2024-01-13 18:46:39 +08:00
<el-form-item label="含税金额" prop="amount_including_tax"
:rules="[{ required: true, message: '不可为空', trigger: 'change' }]">
2024-01-15 18:20:06 +08:00
<el-input v-model="formData.amount_including_tax" disabled clearable placeholder="请输入含税金额"
2024-01-13 18:46:39 +08:00
@input="amountinput" />
2024-02-19 18:01:49 +08:00
</el-form-item>
</el-col>
<el-col :span="8">
2024-01-13 18:46:39 +08:00
<el-form-item label="含税金额大写" prop="amount_including_tax"
:rules="[{ required: true, message: '不可为空', trigger: 'change' }]">
<el-input v-model="amount_including_daxie" disabled clearable placeholder="请输入含税金额大写" />
</el-form-item></el-col>
<el-col :span="8">
2024-01-13 18:46:39 +08:00
<el-form-item label="运费" prop="freight"
:rules="[{ required: true, message: '不可为空', trigger: 'blur' }]">
2024-01-15 18:20:06 +08:00
<el-input v-model="formData.freight" clearable placeholder="请输入运费" type="number" />
2023-12-12 11:29:58 +08:00
</el-form-item></el-col><el-col :span="8">
2024-01-13 18:46:39 +08:00
<el-form-item label="其他费用" prop="other_fee"
:rules="[{ required: true, message: '不可为空', trigger: 'blur' }]">
2024-01-15 18:20:06 +08:00
<el-input v-model="formData.other_fee" clearable type="number" placeholder="请输入其他费用" />
</el-form-item></el-col>
<el-col :span="8">
2023-12-12 11:29:58 +08:00
<el-form-item label="合计金额" prop="total_amount">
2024-01-15 18:20:06 +08:00
<el-input v-model="formData.total_amount" disabled clearable placeholder="请输入合计金额"
2024-01-13 18:46:39 +08:00
@input="amountinput1" />
2024-01-15 18:20:06 +08:00
<div v-show="false">{{ totalPrice }}</div>
</el-form-item></el-col>
<el-col :span="8">
<el-form-item label="合计金额大写" prop="total_amount">
<el-input v-model="total_amount_daxie" clearable disabled placeholder="请输入合计金额大写" />
</el-form-item></el-col>
<el-col :span="8">
2024-01-13 18:46:39 +08:00
<el-form-item label="客户需求" prop="customer_require"
:rules="[{ required: true, message: '不可为空', trigger: 'blur' }]">
2023-12-12 11:29:58 +08:00
<el-input v-model="formData.customer_require" clearable placeholder="请输入客户需求" />
2024-02-19 18:01:49 +08:00
</el-form-item></el-col>
<el-col :span="8">
2023-12-12 11:29:58 +08:00
<el-form-item label="备注" prop="remark">
<el-input v-model="formData.remark" clearable placeholder="请输入备注" />
2024-02-19 18:01:49 +08:00
</el-form-item>
</el-col>
<el-col :span="8">
2024-03-13 14:47:51 +08:00
<el-form-item label="附件">
2024-01-13 18:46:39 +08:00
<el-upload
accept="doc, docx, xls, xlsx, ppt, pptx, pdf, txt, zip, rar, tar, jpg, png, gif, jpeg, webp, wmv, avi, mpg, mpeg, 3gp, mov, mp4, flv, f4v, rmvb, mkv"
class="upload-demo" :show-file-list="false" aria-hidden="true"
:headers="{ Token: userStore.token }" :action="base_url + '/upload/file'"
:on-success="handleAvatarSuccess_four" ref="upload">
2023-12-12 11:29:58 +08:00
<el-button type="primary">
上传
</el-button>
</el-upload>
<div>
2023-12-14 17:49:48 +08:00
<div v-for="(item, index) in formDataannex" style="margin-left: 5px;display: block;">
2024-03-07 15:43:35 +08:00
<a style="margin-left: 10px; color: #4a5dff; align-self: flex-start"
:href="item.uri" target="_blank">{{ item.name }}</a>
2023-12-12 11:29:58 +08:00
<span style="cursor: pointer;margin-left: 5px;" @click="delFileFn(index)">x</span>
</div>
</div>
</el-form-item>
</el-col>
</el-row>
2024-01-13 18:46:39 +08:00
<div style=" display: flex;justify-content: flex-end;margin-bottom: 30px;"> <el-button
@click="showDialog1 = true">选择产品</el-button></div>
2023-12-12 11:29:58 +08:00
<div style="margin-bottom: 30px;">
2023-12-28 17:32:05 +08:00
<el-table :data="tableData">
2023-12-12 11:29:58 +08:00
<el-table-column label="序号">
<template #default="{ row }">
2024-01-05 16:55:41 +08:00
<el-button @click="handleDelete(row)" size="small">-</el-button>
2023-12-12 11:29:58 +08:00
</template>
</el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="产品名称" prop="name">
2024-03-07 15:43:35 +08:00
2023-12-12 11:29:58 +08:00
<template #default="{ row }">
2024-01-04 18:07:12 +08:00
<el-input v-model="row.name" disabled placeholder="系统自动填写" />
2023-12-12 11:29:58 +08:00
</template>
</el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="产品编码" prop="code">
2024-03-07 15:43:35 +08:00
2024-01-13 18:46:39 +08:00
<template #default="{ row }"> <el-input v-model="row.code" disabled placeholder="系统自动填写" />
</template></el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="规格型号" prop="specs">
2024-03-07 15:43:35 +08:00
2024-01-13 18:46:39 +08:00
<template #default="{ row }"> <el-input v-model="row.specs" disabled placeholder="系统自动填写" />
</template></el-table-column>
2023-12-12 11:29:58 +08:00
2024-01-04 18:07:12 +08:00
<el-table-column label="品牌" prop="brand">
2024-03-07 15:43:35 +08:00
2023-12-12 11:29:58 +08:00
<template #default="{ row }">
2024-01-04 18:07:12 +08:00
<el-input v-model="row.brand" disabled placeholder="系统自动填写" />
2023-12-12 11:29:58 +08:00
</template>
</el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="参数说明" prop="parameter_description">
2024-03-07 15:43:35 +08:00
2024-01-13 18:46:39 +08:00
<template #default="{ row }"> <el-input v-model="row.parameter_description" disabled />
</template></el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="单位" prop="unit">
2024-03-07 15:43:35 +08:00
2024-01-13 18:46:39 +08:00
<template #default="{ row }"> <el-input v-model="row.unit" disabled />
</template></el-table-column>
2023-12-12 11:29:58 +08:00
<el-table-column label="数量" prop="product_num">
2024-03-07 15:43:35 +08:00
2023-12-12 11:29:58 +08:00
<template #default="{ row }">
<el-input v-model="row.product_num" />
</template>
</el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="税率(%)" prop="tax_rate">
2024-03-07 15:43:35 +08:00
2023-12-12 11:29:58 +08:00
<template #default="{ row }">
2024-01-04 18:07:12 +08:00
2024-01-22 19:24:31 +08:00
<el-select class="flex-1" v-model="row.tax_rate" clearable placeholder="请选择税率">
2024-03-07 15:43:35 +08:00
<el-option v-for="(item, index) in dictData.tax_rate" :key="index"
:label="item.name" :value="item.value" />
2024-01-04 18:07:12 +08:00
</el-select>
2023-12-12 11:29:58 +08:00
</template>
</el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="含税单价" prop="price">
2024-03-07 15:43:35 +08:00
2023-12-12 11:29:58 +08:00
<template #default="{ row }">
2024-01-04 18:07:12 +08:00
<el-input v-model="row.price" />
2023-12-12 11:29:58 +08:00
</template>
</el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="含税金额" prop="amount">
2024-03-07 15:43:35 +08:00
2023-12-12 11:29:58 +08:00
<template #default="{ row }">
2024-01-04 18:07:12 +08:00
<el-input v-model="row.amount" disabled />
2023-12-12 11:29:58 +08:00
</template>
</el-table-column>
2024-01-04 18:07:12 +08:00
<el-table-column label="不含税金额" prop="amount_including">
2024-03-07 15:43:35 +08:00
2023-12-12 11:29:58 +08:00
<template #default="{ row }">
2024-01-04 18:07:12 +08:00
<el-input v-model="row.amount_including" disabled />
2023-12-12 11:29:58 +08:00
</template>
</el-table-column>
<el-table-column label="备注" prop="remark">
2024-03-07 15:43:35 +08:00
2023-12-12 11:29:58 +08:00
<template #default="{ row }">
<el-input v-model="row.remark" />
</template>
</el-table-column>
</el-table>
</div>
2023-11-27 19:05:43 +08:00
</el-form>
</popup>
2023-12-12 11:29:58 +08:00
<el-dialog v-model="showDialog" title="选择客户" width="70%">
<customDialog @customEvent="customEvent"></customDialog>
</el-dialog>
<el-dialog v-model="showDialog1" title="选择产品" width="70%">
<customDialog1 @customEvent="customEvent1"></customDialog1>
</el-dialog>
2023-11-27 19:05:43 +08:00
</div>
</template>
<script lang="ts" setup name="quotationEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiQuotationAdd, apiQuotationEdit, apiQuotationDetail } from '@/api/quotation'
2024-03-20 10:30:05 +08:00
import { convertToChinese } from '@/utils/util'
import { toChinesNum } from "@/utils/util";
2023-12-12 11:29:58 +08:00
import customDialog1 from '@/components/product/index.vue'
2023-11-27 19:05:43 +08:00
import type { PropType } from 'vue'
2024-01-15 18:20:06 +08:00
import { computed, watch } from "vue"
const props = defineProps({
2023-11-27 19:05:43 +08:00
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
2024-02-19 18:01:49 +08:00
2023-11-27 19:05:43 +08:00
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
2023-12-12 11:29:58 +08:00
const showDialog = ref(false)
const showDialog1 = ref(false)
const customer_name = ref('')
const amount_including_daxie = ref('')
const total_amount_daxie = ref('')
2024-01-04 18:07:12 +08:00
const tableData = ref([])
2023-12-14 17:49:48 +08:00
const formDataannex = reactive([])
import feedback from '@/utils/feedback'
import configs from "@/config"
const base_url = configs.baseUrl + configs.urlPrefix
import useUserStore from "@/stores/modules/user";
const userStore = useUserStore();
2023-12-12 11:29:58 +08:00
// 上传文件
const handleAvatarSuccess_four = (
response,
uploadFile
) => {
if (response.code == 0) {
2023-12-14 17:49:48 +08:00
feedback.msgError(response.msg);
2023-12-12 11:29:58 +08:00
return;
}
2023-12-14 17:49:48 +08:00
formDataannex.push(
2023-12-12 11:29:58 +08:00
{ uri: response.data.uri, name: response.data.name }
2023-11-27 19:05:43 +08:00
2023-12-12 11:29:58 +08:00
);
};
// 删除上传的文件
const delFileFn = (index: number) => {
2023-12-14 17:49:48 +08:00
formDataannex.splice(index, 1)
2023-12-12 11:29:58 +08:00
}
2023-11-27 19:05:43 +08:00
// 弹窗标题
const popupTitle = computed(() => {
return mode.value == 'edit' ? '编辑报价单' : '新增报价单'
})
2024-03-20 10:30:05 +08:00
//监听金额大写输入
const amountinput = (e) => {
if (e && e > 0) {
amount_including_daxie.value = toChinesNum(e)
}
}
const amountinput1 = (e) => {
if (e && e > 0) {
total_amount_daxie.value = toChinesNum(e)
}
}
2023-11-27 19:05:43 +08:00
// 表单数据
const formData = reactive({
id: '',
2024-01-04 18:07:12 +08:00
approve_id: 1,
custom_id: '',
2023-11-27 19:05:43 +08:00
quotation_date: '',
custom_master_name: '',
custom_master_phone: '',
2023-11-27 19:05:43 +08:00
create_user: '',
invoice_type: '',
amount_including_tax: '',
freight: '',
other_fee: '',
total_amount: '',
customer_require: '',
remark: '',
2024-01-14 19:36:58 +08:00
annex: [],
2024-01-13 18:46:39 +08:00
quotation_detail: [],
2023-11-27 19:05:43 +08:00
2023-12-12 11:29:58 +08:00
})
2023-11-27 19:05:43 +08:00
2023-12-12 11:29:58 +08:00
const customEvent = (e: any) => {
formData.custom_id = e.id;
2023-12-12 11:29:58 +08:00
customer_name.value = e.name;
2024-01-22 19:24:31 +08:00
formData.custom_master_name = e.master_name
formData.custom_master_phone = e.master_phone
2023-12-12 11:29:58 +08:00
showDialog.value = false;
2024-01-22 19:24:31 +08:00
2023-12-12 11:29:58 +08:00
};
const customEvent1 = (e: any) => {
2024-01-04 18:07:12 +08:00
tableData.value.push({
2024-01-05 17:50:44 +08:00
product_id: e.id,
2024-01-04 18:07:12 +08:00
name: e.name,
code: e.code,
unit: e.unit,
specs: e.specs,
brand: e.brand,
parameter_description: e.parameter_description,
2024-01-15 18:20:06 +08:00
product_num: 1,
2024-01-04 18:07:12 +08:00
tax_rate: '',
2024-01-15 18:20:06 +08:00
price: e.sales_price,
2024-01-04 18:07:12 +08:00
remark: '',
2024-01-15 18:20:06 +08:00
amount: e.sales_price,
amount_including: e.sales_price
2024-01-04 18:07:12 +08:00
})
2023-12-12 11:29:58 +08:00
showDialog1.value = false;
2024-01-04 18:07:12 +08:00
2023-12-12 11:29:58 +08:00
};
2023-11-27 19:05:43 +08:00
// 表单验证
const formRules = reactive<any>({
})
2023-12-12 11:29:58 +08:00
const handleAdd = (row: any) => {
// 在 row 后面插入一行数据
2024-01-04 18:07:12 +08:00
const index = tableData.value.indexOf(row);
tableData.value.splice(index + 1, 0, {});
2023-12-12 11:29:58 +08:00
};
2023-11-27 19:05:43 +08:00
2023-12-12 11:29:58 +08:00
const handleDelete = (row: any) => {
// 删除 row
2024-01-04 18:07:12 +08:00
const index = tableData.value.indexOf(row);
tableData.value.splice(index, 1);
2023-12-12 11:29:58 +08:00
};
2024-02-19 18:01:49 +08:00
2023-11-27 19:05:43 +08:00
// 获取详情
const setFormData = async (data: Record<any, any>) => {
if (data.annex && data.annex.length > 0) {
2023-12-22 18:25:00 +08:00
const arry1 = data.annex.map((item: any, index: any) => {
return {
name: `文件${index + 1}`,
uri: item
};
});
Object.assign(formDataannex, arry1)
2023-12-14 17:49:48 +08:00
}
if (data.total_amount && data.total_amount > 0) {
amountinput1(data.total_amount)
}
if (data.amount_including_tax && data.amount_including_tax > 0) {
amountinput(data.amount_including_tax)
}
customer_name.value = data.custom_name
2023-11-27 19:05:43 +08:00
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key]
}
}
}
const getDetail = async (row: Record<string, any>) => {
2023-12-12 11:29:58 +08:00
2023-11-27 19:05:43 +08:00
const data = await apiQuotationDetail({
id: row.id
})
setFormData(data)
}
2023-12-12 11:29:58 +08:00
const isMobileNumber = (rule: any, value: string | number | any[], callback: (arg0: Error | undefined) => void) => {
if (value && !/^1[3|4|5|7|8][0-9]{9}$/.test(value)) {
callback(new Error('请输入正确的手机号码'));
} else {
callback()
2023-12-12 11:29:58 +08:00
}
};
2023-11-27 19:05:43 +08:00
// 提交按钮
const handleSubmit = async () => {
2023-12-14 17:49:48 +08:00
if (formDataannex.length > 0) {
2024-01-14 19:36:58 +08:00
formData.annex = formDataannex.map((item) => item.uri)
2023-12-14 17:49:48 +08:00
}
2024-01-04 18:07:12 +08:00
if (tableData.value.length > 0) {
2024-01-13 18:46:39 +08:00
formData.quotation_detail = tableData.value.map(item => ({
tax_inclusive_price: item.price,
2024-01-04 18:07:12 +08:00
product_id: item.product_id,
2024-01-13 18:46:39 +08:00
num: item.product_num,
2024-01-04 18:07:12 +08:00
tax_rate: item.tax_rate,
remark: item.remark
}));
2024-01-13 18:46:39 +08:00
2024-01-04 18:07:12 +08:00
}
2023-11-27 19:05:43 +08:00
await formRef.value?.validate()
const data = { ...formData, }
mode.value == 'edit'
? await apiQuotationEdit(data)
: await apiQuotationAdd(data)
popupRef.value?.close()
emit('success')
}
//打开弹窗
const open = (type = 'add') => {
mode.value = type
popupRef.value?.open()
}
// 关闭回调
const handleClose = () => {
emit('close')
}
2024-01-15 18:20:06 +08:00
// 计算价格
const totalPrice = computed(() => {
formData.total_amount = Number(formData.amount_including_tax) + Number(formData.freight || 0) + Number(formData.other_fee || 0)
total_amount_daxie.value = convertToChinese(formData.total_amount)
return Number(formData.amount_including_tax) + Number(formData.freight || 0) + Number(formData.other_fee || 0)
})
2023-11-27 19:05:43 +08:00
2024-01-15 18:20:06 +08:00
watch(tableData.value, (newVal, oldVal) => {
let num = 0;
tableData.value.forEach(item => {
2024-01-22 19:24:31 +08:00
item.amount = item.price * item.product_num
let name;
props.dictData.tax_rate.forEach(items => {
if (items.value == item.tax_rate) {
name = items.name
}
})
item.amount_including = item.amount * (1 - (Number(name) / 100)) || 0
num += item.amount
2024-01-15 18:20:06 +08:00
})
formData.amount_including_tax = num
amount_including_daxie.value = convertToChinese(num)
})
2023-11-27 19:05:43 +08:00
defineExpose({
open,
setFormData,
getDetail
})
</script>