Explorar o código

feat: 添加批量设置数量与单价功能,仅在开发环境可用

xieyong hai 1 día
pai
achega
531c65d904

+ 51 - 1
src/BIZComponents/inventoryTable.vue

@@ -84,6 +84,11 @@
                 valueKey="taxRate"
                 @success="setAllTaxRateChange"
               />
+              <setAllCountPrice
+                :disabled="tableBusy || !selection.length"
+                :show-price="quoteType !== 2"
+                @success="setAllCountPriceChange"
+              />
             </div>
             <div class="pricebox">
               <span class="amount" v-if="showSummary"
@@ -1084,6 +1089,8 @@
   import { copyObj } from '@/utils/util';
   import selectStockLedgerDialog from '@/BIZComponents/selectStockLedger/selectStockLedgerDialog.vue'; //库存台账
   import setAllValue from '@/BIZComponents/setAllValue.vue'; //批量修改
+  import setAllCountPrice from '@/BIZComponents/setAllCountPrice.vue'; //批量修改数量与单价
+  import { IS_DEV } from '@/config/setting'; //是否开发环境
 
   import tabMixins from '@/mixins/tableColumnsMixin';
   import commodityPriceListDialog from '@/views/commodityManagement/commodityPriceList/components/commodityPriceListDialog.vue';
@@ -1107,7 +1114,8 @@
       timeDialog,
       selectStockLedgerDialog,
       commodityPriceListDialog,
-      setAllValue
+      setAllValue,
+      setAllCountPrice
     },
     props: {
       pageName: {
@@ -2450,6 +2458,48 @@
           this.setDeliveryDays(this.form.datasource[i], i, 'guaranteePeriod');
         });
       },
+      // 批量设置数量与单价:只作用于勾选的行,仅开发环境可用
+      setAllCountPriceChange({ count, singlePrice }) {
+        if (!IS_DEV || this.tableBusy) return;
+        const indexS = this.getSelectedIndexes();
+        if (!indexS.length) {
+          this.$message.warning('请先勾选需要设置的行');
+          return;
+        }
+        indexS.forEach((i) => {
+          const row = this.form.datasource[i];
+          if (!row) return;
+          if (count !== undefined && count !== null) {
+            this.$set(row, this.countObj.countKey, count);
+          }
+          if (singlePrice !== undefined && singlePrice !== null) {
+            this.$set(row, 'singlePrice', singlePrice);
+          }
+        });
+        if (this.quoteType === 2) {
+          // 生产加工类型:合计按含税小计 × 数量计算,不走普通计价逻辑
+          indexS.forEach((i) => {
+            const row = this.form.datasource[i];
+            if (row) {
+              this.calculateIncludingTaxPrice(row, i);
+            }
+          });
+        } else {
+          // 只重算勾选的行:计量数量、总重、合计、折让等,未勾选的行保持原样
+          this.recalculateTableOnce(indexS);
+        }
+      },
+      // 勾选行在数据源中的下标:按 row-key 匹配,不依赖 key 与下标一一对应
+      getSelectedIndexes() {
+        const keys = new Set(this.selection.map((item) => item.key));
+        const indexS = [];
+        this.form.datasource.forEach((row, index) => {
+          if (keys.has(row.key)) {
+            indexS.push(index);
+          }
+        });
+        return indexS;
+      },
       //获取折让单价
       getDiscountSinglePrice(row) {
         let num =

+ 129 - 0
src/BIZComponents/setAllCountPrice.vue

@@ -0,0 +1,129 @@
+<template>
+  <el-button
+    v-if="isDevEnv"
+    size="small"
+    type="primary"
+    class="ele-btn-icon"
+    style="margin-left: 5px"
+    :disabled="disabled"
+    @click="open"
+    >批量设置数量与单价
+
+    <ele-modal
+      custom-class="ele-dialog-form long-dialog-form"
+      :centered="true"
+      :visible.sync="show"
+      :close-on-click-modal="false"
+      title="批量设置数量与单价"
+      width="500px"
+      :maxable="true"
+      :resizable="true"
+      :append-to-body="true"
+    >
+      <el-form ref="form" :model="form" label-width="90px">
+        <el-form-item :label="countTitle">
+          <el-input
+            v-model="form.count"
+            type="number"
+            :min="0"
+            placeholder="不填写则不修改"
+          />
+        </el-form-item>
+        <el-form-item v-if="showPrice" :label="priceTitle">
+          <el-input
+            v-model="form.singlePrice"
+            type="number"
+            :min="0"
+            placeholder="不填写则不修改"
+          >
+            <template slot="append">元</template>
+          </el-input>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="footer">
+        <el-button type="primary" @click="confirm">确认</el-button>
+        <el-button @click="show = false">返回</el-button>
+      </div>
+    </ele-modal>
+  </el-button>
+</template>
+<script>
+  import { IS_DEV } from '@/config/setting';
+
+  export default {
+    props: {
+      disabled: {
+        default: true,
+        type: Boolean
+      },
+      // 生产加工类型没有单价列,此时只设置数量
+      showPrice: {
+        default: true,
+        type: Boolean
+      },
+      countTitle: {
+        default: '数量',
+        type: String
+      },
+      priceTitle: {
+        default: '单价',
+        type: String
+      }
+    },
+    data() {
+      return {
+        show: false,
+        form: {
+          count: '',
+          singlePrice: ''
+        }
+      };
+    },
+    computed: {
+      // 该批量设置只在开发环境提供
+      isDevEnv() {
+        return IS_DEV;
+      }
+    },
+    methods: {
+      open() {
+        this.form.count = '';
+        this.form.singlePrice = '';
+        this.show = true;
+      },
+      confirm() {
+        const countText = (this.form.count ?? '').toString().trim();
+        const priceText = (this.form.singlePrice ?? '').toString().trim();
+        if (!countText && (!this.showPrice || !priceText)) {
+          this.$message.error(
+            '请填写' + this.countTitle + '或' + this.priceTitle
+          );
+          return;
+        }
+        const count = countText ? Number(countText) : undefined;
+        const singlePrice =
+          this.showPrice && priceText ? Number(priceText) : undefined;
+        if (count !== undefined && (isNaN(count) || count < 0)) {
+          this.$message.error('请输入正确的' + this.countTitle);
+          return;
+        }
+        if (
+          singlePrice !== undefined &&
+          (isNaN(singlePrice) || singlePrice < 0)
+        ) {
+          this.$message.error('请输入正确的' + this.priceTitle);
+          return;
+        }
+        this.$emit('success', { count, singlePrice });
+        this.cancel();
+      },
+      cancel() {
+        this.form.count = '';
+        this.form.singlePrice = '';
+        this.show = false;
+      }
+    }
+  };
+</script>
+
+<style scoped lang="scss"></style>

+ 4 - 0
src/config/setting.js

@@ -4,6 +4,10 @@ export const API_BASE_URL = process.env.VUE_APP_API_BASE_URL;
 // 项目名称
 export const PROJECT_NAME = process.env.VUE_APP_NAME;
 
+// 是否开发环境:只在 npm run serve 下为 true,
+// 生产(npm run build)和预发布(npm run build:preview)都是 false
+export const IS_DEV = process.env.NODE_ENV === 'development';
+
 // 不显示侧栏的路由
 export const HIDE_SIDEBARS = [];