| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862 |
- <template>
- <div class="account-detail-table">
- <el-form ref="detailForm" :model="{ flatList }">
- <ele-pro-table
- ref="detailTable"
- row-key="id"
- :needPage="false"
- :columns="columns"
- max-height="500px"
- :datasource="flatList"
- :cache-key="cacheKeyUrl"
- :selection.sync="selection"
- class="time-form"
- >
- <template v-slot:toolbar>
- <div class="detail-toolbar">
- <setAllValue :disabled="!selection.length" inputType="number" title="税率" valueKey="taxRate" @success="confirmBatchSet" />
- <setAllValue :disabled="!selection.length" inputType="number" title="单价" valueKey="singlePrice" @success="confirmBatchSet" />
- <setAllValue :disabled="!selection.length" inputType="number" title="折让比例" valueKey="discountRatio" @success="confirmBatchSet" />
- <!-- <el-button
- v-if="!isView"
- type="primary"
- size="small"
- @click="batchSetTaxRate"
- >批量设置税率</el-button
- >
- <el-button
- v-if="!isView"
- type="primary"
- size="small"
- @click="batchSetPrice"
- >批量设置单价</el-button
- >
- <el-button
- v-if="!isView"
- type="primary"
- size="small"
- @click="batchSetDiscount"
- >批量设置折让比例</el-button
- > -->
- <!-- <div class="summary-info">
- <span
- >本次总对账金额:<b>{{ totalStatementAmount }}</b> 元</span
- >
- <span
- >本次总对账数量:<b>{{ totalStatementCount }}</b></span
- >
- </div> -->
- </div>
- </template>
- <template v-slot:statementCount="scope">
- <el-form-item
- :prop="'flatList.' + scope.$index + '.statementCount'"
- :rules="{
- validator: (rule, value, cb) =>
- validateStatementCount(rule, value, cb, scope.row),
- trigger: 'change'
- }"
- >
- <el-input
- v-model="scope.row.statementCount"
- type="number"
- :disabled="isView || queryDimension == 1"
- @input="handleCountChange(scope.row, scope.$index)"
- />
- </el-form-item>
- </template>
- <template v-slot:technologyRouteName="scope">
- <el-input
- v-model="scope.row.technologyRouteName"
- placeholder="请选择"
- :disabled="isView"
- @click.native="openVersion(scope.$index)"
- />
- </template>
- <template v-slot:singlePrice="scope">
- <el-form-item
- :prop="'flatList.' + scope.$index + '.singlePrice'"
- :rules="{
- required: true,
- message: '请输入单价',
- trigger: 'change'
- }"
- >
- <el-input
- v-model="scope.row.singlePrice"
- type="number"
- :disabled="isView"
- @input="handlePriceChange(scope.row, scope.$index)"
- />
- <!-- <div v-if="isPriceInvalid(scope.row)" class="price-warning">
- 单价无效,请核对商品价格
- </div> -->
- </el-form-item>
- </template>
- <template v-slot:taxRate="scope">
- <el-form-item
- :prop="'flatList.' + scope.$index + '.taxRate'"
- :rules="{
- required: isTaxRate == 1,
- message: '请输入税率',
- trigger: 'change'
- }"
- >
- <el-input
- v-model="scope.row.taxRate"
- type="number"
- :disabled="isView"
- @input="handleTaxChange(scope.row, scope.$index)"
- />
- </el-form-item>
- </template>
- <template v-slot:discountRatio="scope">
- <el-form-item
- :prop="'flatList.' + scope.$index + '.discountRatio'"
- :rules="{
- required: true,
- message: '请输入折让比例',
- trigger: 'change'
- }"
- >
- <el-input
- v-model="scope.row.discountRatio"
- type="number"
- :min="0"
- :max="100"
- :disabled="isView"
- @input="handleDiscountChange(scope.row, scope.$index)"
- />
- </el-form-item>
- </template>
- <template v-slot:statementAmount="scope">
- <span>{{ scope.row.statementAmount }}</span>
- </template>
- <template v-slot:headerRequired="{ column }">
- <span class="is-required">{{ column.label }}</span>
- </template>
- <template v-slot:action="scope">
- <el-link
- v-if="!isView && queryDimension == 2"
- type="danger"
- :underline="false"
- icon="el-icon-delete"
- @click="removeRow(scope.$index)"
- >删除</el-link
- >
- <span v-else>--</span>
- </template>
- </ele-pro-table>
- </el-form>
- <!-- 批量设置弹窗 -->
- <el-dialog
- :visible.sync="batchDialogVisible"
- title="批量设置"
- width="400px"
- append-to-body
- >
- <el-form label-width="100px">
- <el-form-item :label="batchLabel">
- <el-input v-model="batchValue" type="number" />
- </el-form-item>
- </el-form>
- <div slot="footer">
- <el-button @click="batchDialogVisible = false">取消</el-button>
- <el-button
- type="primary"
- @click="confirmBatchSet({ key: batchType, value: batchValue })"
- >确定</el-button
- >
- </div>
- </el-dialog>
- <!-- 工艺路线选择弹窗 -->
- <ProductionVersion
- ref="versionRefs"
- @changeProduct="changeProduct"
- ></ProductionVersion>
- </div>
- </template>
- <script>
- import { parameterGetByCode } from '@/api/main/index.js';
- import { pricingWayList } from '@/enum/dict.js';
- import ProductionVersion from '@/components/ProductionVersion2/index.vue';
- import setAllValue from '@/BIZComponents/setAllValue.vue'; //批量修改
- import { getGoodsById } from '@/api/goodsManage/index';
- export default {
- name: 'accountDetailTable',
- components: {
- ProductionVersion,
- setAllValue
- },
- props: {
- datasource: {
- type: Array,
- default: () => []
- },
- dialogType: {
- type: String,
- default: 'add'
- },
- queryDimension: {
- type: Number,
- default: 1
- }
- },
- data() {
- return {
- cacheKeyUrl: 'eom-202608171423-account-detail-table',
- isTaxRate: 0,
- flatList: [],
- selection: [],
- totalStatementAmount: 0,
- totalStatementCount: 0,
- batchDialogVisible: false,
- batchType: '',
- batchValue: '',
- batchLabel: '',
- columnsVersion: 1,
- };
- },
- computed: {
- isView() {
- return this.dialogType === 'view';
- },
- columns() {
- let columnsVersion = this.columnsVersion;
- return [
- {
- width: 45,
- type: 'selection',
- columnKey: 'selection',
- align: 'center',
- fixed: 'left'
- },
- {
- width: 60,
- label: '序号',
- type: 'index',
- columnKey: 'index',
- align: 'center',
- fixed: 'left'
- },
-
- {
- minWidth: 140,
- prop: 'orderNo',
- label: this.queryDimension == 3 ? '采购订单编码' : '销售订单编码',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- minWidth: 140,
- prop: 'statementSubOrderNo',
- label: this.queryDimension == 3 ? '收货单编码' : this.queryDimension == 1 ? '发货单编码' : '调拨单编码',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- minWidth: 120,
- prop: 'productOperateTime',
- label: this.queryDimension == 3 ? '收货日期' : this.queryDimension == 1 ? '发货日期' : '调拨单日期',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- minWidth: 120,
- prop: 'productCode',
- label: '产品编码',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- minWidth: 140,
- prop: 'productName',
- label: '产品名称',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- minWidth: 120,
- prop: 'batchNo',
- label: '批次号',
- align: 'center',
- showOverflowTooltip: true
- },
-
- {
- minWidth: 110,
- prop: 'historicalStatementCount',
- label: '已对账数量',
- align: 'center'
- },
- {
- minWidth: 140,
- headerSlot: 'headerRequired',
- prop: 'statementCount',
- label: '本次对账数量',
- align: 'center',
- slot: 'statementCount'
- },
- {
- minWidth: 120,
- headerSlot: 'headerRequired',
- prop: 'statementAmount',
- label: '本次对账金额',
- align: 'center',
- slot: 'statementAmount'
- },
- {
- minWidth: 120,
- prop: 'totalCount',
- label: this.queryDimension == 3 ? '收货数量' : this.queryDimension == 1 ? '发货数量' : '调拨数量',
- align: 'center',
- },
-
- {
- minWidth: 140,
- prop: 'technologyRouteName',
- label: '工艺路线',
- align: 'center',
- slot: 'technologyRouteName',
- showOverflowTooltip: true
- },
- {
- minWidth: 120,
- prop: 'singlePrice',
- label: '单价',
- align: 'center',
- slot: 'singlePrice'
- },
- {
- minWidth: 100,
- prop: 'taxRate',
- label: '税率',
- align: 'center',
- slot: 'taxRate'
- },
- {
- minWidth: 100,
- prop: 'noTaxSinglePrice',
- label: '不含税单价',
- align: 'center',
- },
- {
- minWidth: 100,
- prop: 'totalPrice',
- label: '合计',
- align: 'center',
- },
- {
- minWidth: 120,
- headerSlot: 'headerRequired',
- prop: 'discountRatio',
- label: '折让比例',
- align: 'center',
- slot: 'discountRatio'
- },
- {
- minWidth: 120,
- prop: 'discountSinglePrice',
- label: '折让单价',
- align: 'center',
- },
- {
- minWidth: 120,
- prop: 'discountTotalPrice',
- label: '折让合计',
- align: 'center',
- },
- {
- minWidth: 100,
- prop: 'specification',
- label: '规格',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- minWidth: 100,
- prop: 'modelType',
- label: '型号',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- minWidth: 80,
- prop: 'color',
- label: '颜色',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- minWidth: 120,
- prop: 'outInCount',
- label: '出库数量',
- align: 'center',
- },
- {
- minWidth: 120,
- prop: 'measuringUnit',
- label: '计量单位',
- align: 'center',
- },
- {
- minWidth: 120,
- prop: 'sendTotalWeight',
- label: '出库重量',
- align: 'center',
- },
- {
- minWidth: 120,
- prop: 'weightUnit',
- label: '重量单位',
- align: 'center',
- },
- {
- minWidth: 120,
- prop: 'pricingWay',
- label: '计价方式',
- align: 'center',
- formatter: (row, column) => {
- return pricingWayList.find((item) => item.id == row.pricingWay)
- ?.name;
- }
- },
- ]
- }
- },
- watch: {
- datasource: {
- handler(newVal, oldVal) {
- this.$nextTick(() => {
- // 直接基于原始 productList 扁平行初始化派生字段(单价/税率/折让比例默认值及本次对账金额)
- const list = (newVal || []).map((item) => this.buildRow(item, item.orderNo || '', false));
- this.flatList = list;
- console.log(this.flatList)
- this.calcTotals();
- });
- },
- immediate: true
- },
- queryDimension() {
- // this.buildFlatList();
- this.calcTotals();
- }
- },
- created() {
- parameterGetByCode({ code: 'eom_saleOrder_order-taxRate' }).then(
- (res) => {
- this.isTaxRate = res.value;
- }
- );
- },
- methods: {
- buildRow(item, orderNo, isReturn) {
- const outboundCount = +item.totalCount || 0;
- // 退货单数量为负
- const count = isReturn ? -Math.abs(outboundCount) : outboundCount;
- const statemented = +item.statementedCount || 0;
- // 发货单:本次对账数量=出库数量(不可改);调拨单:默认=出库数量(可改)
- let statementCount = item.statementCount;
- if (
- statementCount === undefined ||
- statementCount === null ||
- statementCount === ''
- ) {
- statementCount = count;
- }
- const singlePrice = +item.singlePrice;
- const discountRatio =
- item.discountRatio === undefined ||
- item.discountRatio === null ||
- item.discountRatio === ''
- ? 100
- : +item.discountRatio;
- // 税率非必填,可空值:undefined/null/空字符串 均保持空,不默认 0
- const taxRate =
- item.taxRate === undefined ||
- item.taxRate === null ||
- item.taxRate === ''
- ? ''
- : +item.taxRate;
- const amount =
- Math.round(
- statementCount * singlePrice * (discountRatio / 100) * 100
- ) / 100;
- const noTaxSinglePrice =
- singlePrice && taxRate
- ? +((singlePrice / (1 + taxRate / 100)).toFixed(4))
- : '';
- const totalPrice = Math.round(statementCount * singlePrice * 100) / 100;
- const discountSinglePrice =
- Math.round(singlePrice * (discountRatio / 100) * 100) / 100;
- const discountTotalPrice =
- Math.round(totalPrice * (discountRatio / 100) * 100) / 100;
- // 直接修改原 item,保证编辑同步回 datasource
- // this.$set(item, 'id', item.id || Math.random().toString(36).slice(2));
- this.$set(item, 'saleOrderNo', orderNo);
- this.$set(
- item,
- 'statementSubOrderNo',
- item.statementSubOrderNo || item.subOrderNo || ''
- );
- this.$set(
- item,
- 'productOperateTime',
- item.productOperateTime || item.deliveryDate || ''
- );
- this.$set(item, 'outboundCount', count);
- this.$set(item, 'statementedCount', statemented);
- this.$set(item, 'statementCount', statementCount);
- this.$set(item, 'singlePrice', singlePrice);
- this.$set(item, 'taxRate', taxRate);
- this.$set(item, 'discountRatio', discountRatio);
- this.$set(item, 'statementAmount', amount);
- this.$set(item, 'noTaxSinglePrice', noTaxSinglePrice);
- this.$set(item, 'totalPrice', totalPrice);
- this.$set(item, 'discountSinglePrice', discountSinglePrice);
- this.$set(item, 'discountTotalPrice', discountTotalPrice);
- this.$set(item, 'isReturn', isReturn);
- this.$set(item, 'processRouteName', item.processRouteName || '');
- return item;
- },
- initDefaultValues() {
- this.datasource.forEach((item) => {
- if (item.singlePrice === undefined)
- this.$set(item, 'singlePrice', '');
- if (item.taxRate === undefined) this.$set(item, 'taxRate', '');
- if (item.discountRatio === undefined)
- this.$set(item, 'discountRatio', 100);
- });
- },
- buildFlatList() {
- const list = [];
- // this.datasource.forEach((order) => {
- // const orderNo = order.orderNo || '';
- // (order.deliveryProducts || []).forEach((item) => {
- // list.push(this.buildRow(item, orderNo, false));
- // });
- // (order.returnProducts || []).forEach((item) => {
- // list.push(this.buildRow(item, orderNo, true));
- // });
- // });
- // this.flatList = list;
- },
- calcTotals() {
- const amount =
- this.flatList.reduce(
- (pre, cur) => pre + Math.round((+cur.statementAmount || 0) * 100),
- 0
- ) / 100;
- const count = this.flatList.reduce(
- (pre, cur) => pre + (+cur.statementCount || 0),
- 0
- );
- this.totalStatementAmount = amount;
- this.totalStatementCount = count;
- this.$emit('totalChange', amount);
- this.$emit('countChange', count);
- // 按销售订单编码(saleOrderNo)汇总本次对账金额,供应收信息同步
- this.emitStatementAmountChange();
- },
- // 按销售订单编码汇总本次对账金额并抛出
- emitStatementAmountChange() {
- const summaryMap = {};
- this.flatList.forEach((row) => {
- const key = row.saleOrderNo;
- if (!key) return;
- summaryMap[key] =
- Math.round(
- ((summaryMap[key] || 0) + (+row.statementAmount || 0)) * 100
- ) / 100;
- });
- this.$emit('statementAmountChange', summaryMap);
- },
- // 重算某一行金额(参考 inventoryTable.vue 价格计算链)
- calcRow(row) {
- const count = +row.statementCount;
- const price = +row.singlePrice;
- // 折让比例未填写时按 100(不打折)计,避免金额被算成 0
- const ratio = row.discountRatio === '' ||
- row.discountRatio === null ||
- row.discountRatio === undefined ||
- isNaN(+row.discountRatio)
- ? 100
- : +row.discountRatio;
- const taxRate = +row.taxRate;
- // 本次对账金额
- const amount = Math.round(count * price * (ratio / 100) * 100) / 100;
- this.$set(row, 'statementAmount', amount);
- // 不含税单价 = 单价 / (1 + 税率/100) (与 inventoryTable.getNotaxSinglePrice 一致)
- if (price && taxRate) {
- this.$set(
- row,
- 'noTaxSinglePrice',
- +((price / (1 + taxRate / 100)).toFixed(4))
- );
- } else {
- this.$set(row, 'noTaxSinglePrice', '');
- }
- // 合计 = 对账数量 * 单价
- this.$set(row, 'totalPrice', Math.round(count * price * 100) / 100);
- // 折让单价 = 单价 * 折让比例/100
- this.$set(
- row,
- 'discountSinglePrice',
- Math.round(price * (ratio / 100) * 100) / 100
- );
- // 折让合计 = 合计 * 折让比例/100
- this.$set(
- row,
- 'discountTotalPrice',
- Math.round(row.totalPrice * (ratio / 100) * 100) / 100
- );
- },
- handleCountChange(row, index) {
- this.calcRow(row);
- this.calcTotals();
- this.emitChange();
- },
- handlePriceChange(row, index) {
- this.calcRow(row);
- this.calcTotals();
- this.emitChange();
- },
- handleTaxChange(row, index) {
- // 税率变化需重算不含税单价、合计及折让相关字段
- this.calcRow(row);
- this.calcTotals();
- this.emitChange();
- },
- handleDiscountChange(row, index) {
- this.calcRow(row);
- this.calcTotals();
- this.emitChange();
- },
- emitChange() {
- // 表格实际编辑的是 flatList,直接以其为新数据源回写父组件
- this.$emit('update:datasource', [...this.flatList]);
- },
- // 单价校验:单价缺失或为 0 视为无效(需结合商品价目表有效期进一步校验)
- isPriceInvalid(row) {
- const price = +row.singlePrice || 0;
- return price <= 0;
- },
- validateStatementCount(rule, value, callback, row) {
- const val = +value || 0;
- const max = Math.abs(row.outboundCount || 0);
- if (Math.abs(val) > max) {
- callback(new Error('不能超出库数量'));
- }
- // else if (this.queryDimension == 1 && val != row.outboundCount) {
- // callback(new Error('按发货单查询时不可修改'));
- // }
- else {
- callback();
- }
- },
- // 批量设置
- batchSetTaxRate() {
- this.batchType = 'taxRate';
- this.batchLabel = '税率';
- this.batchValue = '';
- this.batchDialogVisible = true;
- },
- batchSetPrice() {
- this.batchType = 'singlePrice';
- this.batchLabel = '单价';
- this.batchValue = '';
- this.batchDialogVisible = true;
- },
- batchSetDiscount() {
- this.batchType = 'discountRatio';
- this.batchLabel = '折让比例';
- this.batchValue = '';
- this.batchDialogVisible = true;
- },
- // 批量设置:只作用于选中的行(selection)
- confirmBatchSet({ key, value }) {
- if (!this.selection.length) {
- this.$message.warning('请先勾选需要批量设置的行');
- this.batchDialogVisible = false;
- return;
- }
- this.selection.forEach((item) => {
- this.$set(item, key, +value);
- this.calcRow(item);
- });
- this.calcTotals();
- this.batchDialogVisible = false;
- this.emitChange();
- },
- removeRow(index) {
- // 调拨单模式下允许删除行,基于扁平行数组操作,保持数据格式一致
- if (index < 0 || index >= this.flatList.length) return;
- const list = [...this.flatList];
- list.splice(index, 1);
- this.flatList = list;
- this.calcTotals();
- this.emitChange();
- },
- getValidForm() {
- return new Promise((resolve, reject) => {
- this.$refs.detailForm.validate((valid, invalidFields) => {
- if (valid) resolve(true);
- else {
- this.$message.warning(this.buildValidateTip(invalidFields));
- reject(false);
- }
- });
- });
- },
- // 获取勾选的行数据(供父组件提交时使用)
- getSelection() {
- return this.selection;
- },
- // 校验勾选行的必填字段
- validateSelection() {
- return new Promise((resolve, reject) => {
- if (!this.selection.length) {
- this.$message.warning('请先勾选需要提交的对账明细');
- reject(false);
- return;
- }
- const fieldLabelMap = {
- statementCount: '本次对账数量',
- singlePrice: '单价',
- taxRate: '税率',
- discountRatio: '折让比例'
- };
- const tips = [];
- this.selection.forEach((row) => {
- // 本次对账数量必填
- if (row.statementCount === '' || row.statementCount == null) {
- tips.push(`「${fieldLabelMap.statementCount}」未填写`);
- }
- // 单价必填
- if (row.singlePrice === '' || row.singlePrice == null) {
- tips.push(`「${fieldLabelMap.singlePrice}」未填写`);
- }
- // 折让比例必填
- if (row.discountRatio === '' || row.discountRatio == null) {
- tips.push(`「${fieldLabelMap.discountRatio}」未填写`);
- }
- // 税率(isTaxRate == 1 时必填)
- if (this.isTaxRate == 1 && (row.taxRate === '' || row.taxRate == null)) {
- tips.push(`「${fieldLabelMap.taxRate}」未填写`);
- }
- });
- if (tips.length) {
- this.$message.warning('勾选的对账明细存在未填写项:' + tips.join('、'));
- reject(false);
- } else {
- resolve(true);
- }
- });
- },
- // 根据校验失败字段生成具体提示
- buildValidateTip(invalidFields) {
- const fieldLabelMap = {
- statementCount: '本次对账数量',
- singlePrice: '单价',
- taxRate: '税率',
- discountRatio: '折让比例'
- };
- const tips = [];
- Object.keys(invalidFields || {}).forEach((path) => {
- // path 形如 flatList.0.singlePrice
- const match = path.match(/flatList\.(\d+)\.(.+)/);
- if (match) {
- const rowIndex = +match[1] + 1;
- const field = match[2];
- const label = fieldLabelMap[field] || field;
- const msg =
- (invalidFields[path] && invalidFields[path][0] && invalidFields[path][0].message) ||
- '';
- tips.push(`第${rowIndex}行「${label}」${msg || '未填写'}`);
- } else {
- tips.push(path);
- }
- });
- return tips.length ? tips.join(';') : '对账明细未填写完整';
- },
- // 打开工艺路线选择弹窗(参考 inventoryTable.openVersion)
- openVersion(index) {
- this.$refs.versionRefs.open(index);
- },
- // 工艺路线选择回调(参考 inventoryTable.changeProduct)
- async changeProduct(data, index) {
- const row = this.flatList[index];
- if (!row) return;
- // 先回填工艺路线信息
- this.$set(row, 'technologyRouteName', data.name);
- this.$set(row, 'technologyRouteId', data.id);
- // 根据工艺路线带出默认单价
- if (row.goodsId) {
- await this.setDefaultPrice(row, data.id);
- }
- // 单价变化后重算金额与汇总
- this.calcRow(row);
- this.calcTotals();
- this.emitChange();
- },
- // 根据商品 + 工艺路线匹配默认单价(有效期内)
- async setDefaultPrice(row, technologyRouteId) {
- try {
- const goodsInfo = await getGoodsById(row.goodsId);
- const priceList = goodsInfo?.goodsPriceList || [];
- // 命中当前工艺路线,且为默认价、在有效期内的价目
- const defaultItem = priceList.find((item) => {
- if (item.technologyRouteId != technologyRouteId) return false;
- if (item.isDefault != 1) return false;
- const expiry = new Date(item.priceExpiryDate);
- return !isNaN(expiry.getTime()) && expiry >= new Date();
- });
- if (defaultItem) {
- this.$set(row, 'singlePrice', defaultItem.singlePrice);
- }
- } catch (e) {
- console.error('获取商品价目失败:', e);
- }
- }
- }
- };
- </script>
- <style scoped lang="scss">
- .account-detail-table {
- .detail-toolbar {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- margin-bottom: 10px;
- .summary-info {
- span {
- margin-left: 20px;
- b {
- color: #f56c6c;
- }
- }
- }
- }
- .time-form .el-form-item {
- margin-bottom: 0 !important;
- }
- .price-warning {
- color: #f56c6c;
- font-size: 12px;
- line-height: 1.4;
- margin-top: 2px;
- }
- }
- </style>
|