Files
GEAR-OA/gear-ui3/src/views/oms/order/panels/detail.vue
2025-09-22 10:38:50 +08:00

333 lines
11 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" size="small" :disabled="!canEdit"
@click="handleAdd">新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="success" plain icon="Edit" size="small" :disabled="single || !canEdit"
@click="handleUpdate">修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="danger" plain icon="Delete" size="small" :disabled="multiple || !canEdit"
@click="handleDelete">删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="Download" size="small" @click="handleExport">导出</el-button>
</el-col>
<!-- 含税部分 -->
<el-col :span="8">
<span>含税金额</span>
<span style="margin-right: 10px;">{{ orderInfo?.taxAmount }}</span>
<span style="margin-right: 10px;">-</span>
<span style="margin-right: 10px;">{{ actualAmount }}</span>
<span style="margin-right: 10px;">=</span>
<span style="color: red; margin-right: 10px;">{{ amountDifference }}</span>
</el-col>
<!-- 无税部分 -->
<el-col :span="8">
<span>无税金额</span>
<span style="margin-right: 10px;">{{ orderInfo?.noTaxAmount }}</span>
<span style="margin-right: 10px;">-</span>
<span style="margin-right: 10px;">{{ noTaxAmount }}</span>
<span style="margin-right: 10px;">=</span>
<span style="color: red; margin-right: 10px;">{{ noTaxAmountDifference }}</span>
</el-col>
</el-row>
<el-table v-loading="loading" :data="orderDetailList">
<el-table-column label="订单明细ID" align="center" prop="detailId" v-if="true"/>
<el-table-column label="产品" align="center">
<template #default="scope">
<ProductInfo :productId="scope.row.productId">
<template #default="{ product }">
{{ product.productName }}<span v-if="product.productCode">({{ product.productCode }})</span>
</template>
</ProductInfo>
</template>
</el-table-column>
<el-table-column label="BOM" align="center">
<template #default="scope">
<BomInfoMini item-type="product" :item-id="scope.row.productId" />
</template>
</el-table-column>
<el-table-column label="产品数量" align="center" prop="quantity" />
<el-table-column label="单位" align="center" prop="unit" />
<el-table-column label="含税单价" align="center" prop="taxPrice" />
<el-table-column label="无税单价" align="center" prop="noTaxPrice" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" width="200">
<template #default="scope">
<el-button size="small" type="text" icon="Edit"
@click="handleUpdate(scope.row)">修改</el-button>
<el-button size="small" type="text" icon="Delete"
@click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改订单明细对话框 -->
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="产品" prop="productId">
<ProductSelect :can-add="true" v-model="form.productId" placeholder="请选择产品" @change="onProductChange" />
</el-form-item>
<el-form-item label="产品数量" prop="quantity">
<el-input v-model="form.quantity" placeholder="请输入产品数量" />
</el-form-item>
<el-form-item label="单位" prop="unit">
<el-input v-model="form.unit" placeholder="单位" />
</el-form-item>
<el-form-item label="含税单价" prop="taxPrice">
<el-input-number :controls=false controls-position="right" v-model="form.taxPrice" placeholder="请输入含税单价" />
</el-form-item>
<el-form-item label="无税单价" prop="noTaxPrice">
<el-input-number :controls=false controls-position="right" v-model="form.noTaxPrice" placeholder="请输入无税单价"
:min="0" :max="form.taxPrice" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listOrderDetail, getOrderDetail, delOrderDetail, addOrderDetail, updateOrderDetail } from "@/api/oms/orderDetail";
import { getOrder } from "@/api/oms/order";
import ProductSelect from '@/components/ProductSelect';
import { EOrderStatus } from "@/utils/enums";
import ProductInfo from '@/components/Renderer/ProductInfo.vue';
import BomInfoMini from '@/components/Renderer/BomInfoMini.vue';
export default {
name: "OrderDetailPanel",
dicts: ['order_status'],
props: {
orderId: {
type: [String, Number],
required: true
}
},
components: {
ProductSelect,
ProductInfo,
BomInfoMini,
},
data() {
return {
buttonLoading: false,
loading: true,
ids: [],
single: true,
multiple: true,
total: 0,
orderDetailList: [],
orderInfo: null, // 订单信息
title: "",
open: false,
// 订单状态枚举
EOrderStatus,
queryParams: {
pageNum: 1,
pageSize: 100,
orderId: this.orderId,
productId: undefined,
quantity: undefined,
unit: undefined,
},
form: {
orderId: this.orderId
},
rules: {
orderId: [
{ required: true, message: "订单ID不能为空", trigger: "blur" }
],
quantity: [
{ required: true, message: "产品数量不能为空", trigger: "blur" },
{ pattern: /^[1-9]\d*$/, message: "产品数量必须为正整数", trigger: "blur" }
],
unit: [
{ required: true, message: "单位不能为空", trigger: "blur" }
],
},
};
},
computed: {
// 是否可以编辑(订单状态为新建时才能编辑)
canEdit() {
return this.orderInfo && this.orderInfo.orderStatus === EOrderStatus.NEW;
},
actualAmount() {
return this.orderDetailList?.reduce((total, item) => {
return total + (item.taxPrice || 0) * (item.quantity || 0);
}, 0) || 0;
},
amountDifference() {
return ((this.orderInfo?.taxAmount || 0) - this.actualAmount);
},
noTaxAmount() {
return this.orderDetailList?.reduce((total, item) => {
return total + (item.noTaxPrice || 0) * (item.quantity || 0);
}, 0) || 0;
},
noTaxAmountDifference() {
return ((this.orderInfo?.noTaxAmount || 0) - this.noTaxAmount);
}
},
watch: {
orderId(newVal) {
this.queryParams.orderId = newVal;
this.form.orderId = newVal;
this.getOrderInfo();
this.getList();
}
},
created() {
this.getOrderInfo();
this.getList();
},
methods: {
// 获取订单信息
getOrderInfo() {
if (this.orderId) {
getOrder(this.orderId).then(response => {
this.orderInfo = response.data;
}).catch(() => {
this.orderInfo = null;
});
}
},
getList() {
this.loading = true;
listOrderDetail(this.queryParams).then(response => {
this.orderDetailList = response.rows;
this.total = response.total;
this.loading = false;
});
},
cancel() {
this.open = false;
this.reset();
},
reset() {
this.form = {
detailId: undefined,
orderId: this.orderId,
productId: undefined,
quantity: undefined,
taxPrice: undefined,
noTaxPrice: undefined,
unit: undefined,
remark: undefined,
delFlag: undefined,
createTime: undefined,
createBy: undefined,
updateTime: undefined,
updateBy: undefined,
};
this.resetForm && this.resetForm("form");
},
handleSelectionChange(selection) {
this.ids = selection.map(item => item.detailId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
handleAdd() {
if (!this.canEdit) {
this.$modal && this.$modal.msgError("当前订单状态不允许新增明细");
return;
}
this.reset();
this.open = true;
this.title = "添加订单明细";
},
handleUpdate(row) {
if (!this.canEdit) {
this.$modal && this.$modal.msgError("当前订单状态不允许修改明细");
return;
}
this.loading = true;
this.reset();
const detailId = row.detailId || this.ids
getOrderDetail(detailId).then(response => {
this.loading = false;
this.form = response.data;
this.open = true;
this.title = "修改订单明细";
});
},
onProductChange(product) {
console.log(product, '切换产品');
if (product) {
this.form.unit = product.unit;
} else {
this.form.unit = undefined;
}
},
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
this.buttonLoading = true;
if (this.form.detailId != null) {
updateOrderDetail(this.form).then(response => {
this.$modal && this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
}).finally(() => {
this.buttonLoading = false;
});
} else {
addOrderDetail(this.form).then(response => {
this.$modal && this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
}).finally(() => {
this.buttonLoading = false;
});
}
}
});
},
handleDelete(row) {
if (!this.canEdit) {
this.$modal && this.$modal.msgError("当前订单状态不允许删除明细");
return;
}
const detailIds = row.detailId || this.ids;
this.$modal && this.$modal.confirm('是否确认删除订单明细编号为"' + detailIds + '"的数据项?').then(() => {
this.loading = true;
return delOrderDetail(detailIds);
}).then(() => {
this.loading = false;
this.getList();
this.$modal && this.$modal.msgSuccess("删除成功");
}).catch(() => {
}).finally(() => {
this.loading = false;
});
},
handleExport() {
this.download && this.download('oa/orderDetail/export', {
...this.queryParams
}, `orderDetail_${new Date().getTime()}.xlsx`)
},
},
};
</script>
<style scoped>
.el-button--text {
margin: 0 4px;
padding: 0;
}
</style>