| | |
| | | <template> |
| | | <div> |
| | | <el-dialog :title="operationType === 'add' ? '新增出库' : '编辑出库'" |
| | | <el-dialog :title="operationType === 'add' ? '新增销售出库' : '编辑销售出库'" |
| | | v-model="dialogVisitable" width="800px" @close="cancel"> |
| | | <el-form :model="form" :rules="rules" ref="userRef" label-width="100px"> |
| | | <el-form :model="form" :rules="rules" ref="formRef" label-width="120px"> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="销售日期" prop="userName"> |
| | | <el-form-item label="销售日期" prop="saleDate"> |
| | | <el-date-picker |
| | | v-model="form.userName" |
| | | v-model="form.saleDate" |
| | | type="date" |
| | | value-format="YYYY-MM-DD" |
| | | format="YYYY-MM-DD" |
| | |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="客户" prop="nickName"> |
| | | <el-select v-model="form.nickName" placeholder="请选择客户"> |
| | | <el-form-item label="客户" prop="customerId"> |
| | | <el-select v-model="form.customerId" placeholder="请选择客户"> |
| | | <el-option |
| | | v-for="item in customerOptions" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | :key="item.id" |
| | | :label="item.customerName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | |
| | | </el-row> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="煤种" prop="type"> |
| | | <el-select v-model="form.nickName" placeholder="请选择煤种"> |
| | | <el-form-item label="煤种" prop="coalId"> |
| | | <el-select v-model="form.coalId" placeholder="请选择煤种" @change="setInfo"> |
| | | <el-option |
| | | v-for="item in typeOptions" |
| | | :key="item.value" |
| | | :label="item.label" |
| | | :value="item.value" |
| | | v-for="item in coalOptions" |
| | | :key="item.id" |
| | | :label="item.coal" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="单位" prop="nickName"> |
| | | <el-input v-model="form.nickName" placeholder="请输入单位" maxlength="30" /> |
| | | <el-form-item label="单位" prop="unit"> |
| | | <el-input v-model="form.unit" placeholder="请输入单位" maxlength="30" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="销售数量" prop="userName"> |
| | | <el-input v-model="form.userName" placeholder="请输入销售数量" maxlength="30" type="number" /> |
| | | <el-form-item label="库存数量" prop="inventoryQuantity"> |
| | | <el-input v-model="form.inventoryQuantity" placeholder="请输入销售数量" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="销售单价" prop="userName"> |
| | | <el-input v-model="form.userName" placeholder="请输入销售单价(含税)" maxlength="30" type="number" /> |
| | | <el-form-item label="单价(含税)" prop="priceIncludingTax"> |
| | | <el-input v-model="form.priceIncludingTax" placeholder="请输入销售单价(含税)" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="销售总价" prop="userName"> |
| | | <el-input v-model="form.userName" placeholder="请输入销售总价(含税)" maxlength="30" type="number" /> |
| | | <el-form-item label="销售数量" prop="saleQuantity"> |
| | | <el-input v-model="form.saleQuantity" placeholder="请输入销售数量" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="热值" prop="userName"> |
| | | <el-input v-model="form.userName" placeholder="请输入热值" maxlength="30" /> |
| | | <el-form-item label="销售单价(含税)" prop="salePrice" @change="mathProfit"> |
| | | <el-input v-model="form.salePrice" placeholder="请输入销售单价(含税)" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="利润" prop="userName"> |
| | | <el-input v-model="form.userName" placeholder="利润" maxlength="30" type="number" /> |
| | | <el-form-item label="销售总价(含税)" prop="totalAmount"> |
| | | <el-input v-model="form.totalAmount" placeholder="请输入销售总价(含税)" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="运费" prop="freight"> |
| | | <el-input v-model="form.freight" placeholder="请输入销售总价(含税)" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="购销煤税率(%)" prop="taxCoal"> |
| | | <el-input v-model="form.taxCoal" placeholder="请输入销售总价(含税)" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="运输税率(%)" prop="taxTrans"> |
| | | <el-input v-model="form.taxTrans" placeholder="请输入销售总价(含税)" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row> |
| | | <el-col :span="12"> |
| | | <el-form-item label="毛利润" prop="grossProfit"> |
| | | <el-input v-model="form.grossProfit" placeholder="毛利润" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="净利润" prop="netProfit"> |
| | | <el-input v-model="form.netProfit" placeholder="净利润" maxlength="30" type="number" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import {ref, reactive} from "vue"; |
| | | import {reactive, ref} from "vue"; |
| | | import {addOrEditSalesRecord, customerList, officialList} from "../../../api/salesOutbound/index.js"; |
| | | import useUserStore from '@/store/modules/user' |
| | | |
| | | const { proxy } = getCurrentInstance() |
| | | const emit = defineEmits() |
| | | |
| | | const userStore = useUserStore() |
| | | const dialogVisitable = ref(false); |
| | | const operationType = ref('add'); |
| | | const customerOptions = ref([]) // 客户下拉框 |
| | | const typeOptions = ref([]) // 煤种下拉框 |
| | | const coalOptions = ref([]) // 煤种下拉框 |
| | | const data = reactive({ |
| | | form: {}, |
| | | form: { |
| | | saleDate: '', |
| | | customerId: '', |
| | | coalId: '', |
| | | unit: '', |
| | | saleQuantity: '', |
| | | salePrice: '', |
| | | totalAmount: '', |
| | | freight: '', |
| | | taxCoal: '', |
| | | taxTrans: '', |
| | | grossProfit: '', |
| | | netProfit: '', |
| | | inventoryQuantity: '', |
| | | priceIncludingTax: '', |
| | | }, |
| | | rules: { |
| | | userName: [{ required: true, message: "登录账号不能为空", trigger: "blur" },], |
| | | nickName: [{ required: true, message: "用户姓名不能为空", trigger: "blur" }], |
| | | roleIds: [{ required: true, message: "角色不能为空", trigger: "change" }], |
| | | deptId: [{ required: true, message: "部门不能为空", trigger: "change" }], |
| | | password: [{ required: true, message: "用户密码不能为空", trigger: "blur" }, { min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" }, { pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符:< > \" ' \\\ |", trigger: "blur" }], |
| | | saleDate: [{ required: true, message: "请选择日期", trigger: "change" },], |
| | | } |
| | | }) |
| | | |
| | | const { form, rules } = toRefs(data) |
| | | |
| | | // 打开弹框 |
| | | const openDialog = (type, row) => { |
| | | console.log('openDialog', type, row) |
| | | const openDialog = async (type, row) => { |
| | | dialogVisitable.value = true |
| | | form.value.saleDate = proxy.getCurrentDate() |
| | | customerList().then((res) => { |
| | | customerOptions.value = res.data |
| | | }) |
| | | officialList().then((res) => { |
| | | coalOptions.value = res.data |
| | | }) |
| | | let res = await userStore.getInfo() |
| | | form.value.registrantId = res.user.userId |
| | | form.value.taxCoal = 13 |
| | | form.value.taxTrans = 9 |
| | | form.value.freight = 20 |
| | | if (type === 'edit') { |
| | | form.value = {...row} |
| | | } |
| | | } |
| | | // 复制煤种相关信息 |
| | | const setInfo = (val) => { |
| | | const index = coalOptions.value.findIndex(item => item.id === val) |
| | | if (index > -1) { |
| | | form.value.inventoryQuantity = coalOptions.value[index].inventoryQuantity |
| | | form.value.priceIncludingTax = coalOptions.value[index].priceIncludingTax |
| | | form.value.unit = coalOptions.value[index].unit |
| | | } |
| | | if (!val) { |
| | | form.value.inventoryQuantity = '' |
| | | form.value.priceIncludingTax = '' |
| | | form.value.unit = '' |
| | | } |
| | | } |
| | | // 计算 |
| | | const mathProfit = () => { |
| | | form.value.totalAmount = form.value.saleQuantity * form.value.salePrice |
| | | // 输入数据 |
| | | const purchaseTons = form.value.inventoryQuantity; // 库存数量 |
| | | const saleTons = form.value.saleQuantity; // 销售数量 |
| | | const purchasePricePerTon = form.value.priceIncludingTax; // 含税单价 |
| | | const transportPricePerTon = form.value.freight; // 运费 |
| | | const salePricePerTon = form.value.salePrice; // 销售单价(元/吨) |
| | | const coalTaxRate = form.value.taxCoal / 100; // 购销煤税率(13%) |
| | | const transportTaxRate = form.value.taxTrans / 100; // 运输税率(9%) |
| | | const surchargeRate = 0.12; // 增值税附加税率(12%) |
| | | const stampDutyRate = 3 / 10000; // 印花税税率(0.03%) |
| | | const waterFundRate = 5 / 10000; // 水利基金费率(0.05%) |
| | | |
| | | // 计算不含税价格及进项/销项税额 |
| | | const A = purchasePricePerTon / (1 + coalTaxRate); // 购煤不含税单价 |
| | | const B = A * coalTaxRate * purchaseTons; // 购煤进项税额 |
| | | const C = transportPricePerTon / (1 + transportTaxRate); // 运费不含税单价 |
| | | const D = C * transportTaxRate * purchaseTons; // 运费进项税额 |
| | | const E = salePricePerTon / (1 + coalTaxRate); // 销售不含税单价 |
| | | const F = E * coalTaxRate * saleTons; // 销项税额 |
| | | |
| | | // 毛利润 = 销售收入 - 成本成本(购煤+运费)的成本部分 |
| | | const G = E * saleTons - A * saleTons - C * saleTons; |
| | | form.value.grossProfit = G.toFixed(2); |
| | | |
| | | // 应缴纳增值税 = 销项税 - 可抵扣进项税(按销售量比例计算) |
| | | const H = F - (A * coalTaxRate * saleTons) - (C * transportTaxRate * saleTons); |
| | | |
| | | // 增值税附加税 |
| | | const K = H * surchargeRate; |
| | | |
| | | // 印花税:购、运、销三方金额合计 × 税率 |
| | | const M = (purchasePricePerTon * saleTons + |
| | | transportPricePerTon * saleTons + |
| | | salePricePerTon * saleTons) * stampDutyRate; |
| | | |
| | | // 水利建设基金:销售收入 × 费率 |
| | | const P = E * saleTons * waterFundRate; |
| | | |
| | | // 净利润 = 毛利润 - 各类税费(附加税、印花税、水利基金) |
| | | form.value.netProfit = (G - K - M - P).toFixed(2); |
| | | } |
| | | // 提交合并表单 |
| | | const submitForm = () => { |
| | | proxy.$refs["userRef"].validate(valid => { |
| | | proxy.$refs["formRef"].validate(valid => { |
| | | if (valid) { |
| | | |
| | | addOrEditSalesRecord(form.value).then(() => { |
| | | cancel() |
| | | proxy.$modal.msgSuccess('提交成功') |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | // 关闭合并表单 |
| | | const cancel = () => { |
| | | proxy.resetForm("userRef") |
| | | proxy.resetForm("formRef") |
| | | dialogVisitable.value = false |
| | | emit('closeDia') |
| | | } |