yuhongqi 12 ore fa
parent
commit
e3cbc72bac

+ 8 - 0
src/api/hisStore/storeProduct.js

@@ -17,6 +17,14 @@ export function batchModify(param) {
   })
 }
 
+export function bulkUpdate(param) {
+  return request({
+    url: '/store/store/storeProduct/bulkUpdate',
+    method: 'post',
+    data: param
+  })
+}
+
 export function batchAudit(param) {
   return request({
     url: '/store/store/storeProduct/batchAudit',

+ 97 - 27
src/views/hisStore/storeProduct/indexZm.vue

@@ -280,6 +280,17 @@
           v-hasPermi="['store:storeProduct:bulkCopy']"
         >批量复制</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          plain
+          icon="el-icon-edit-outline"
+          size="mini"
+          :disabled="multiple"
+          @click="handleBulkUpdate"
+          v-hasPermi="['store:storeProduct:edit']"
+        >批量修改</el-button>
+      </el-col>
 
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
@@ -392,20 +403,36 @@
       @pagination="getList"
     />
 
-    <el-dialog :title="title" :visible.sync="open1" width="580px" append-to-body>
-      <el-form ref="form1" :model="form1" :rules="rules" label-width="80px">
-        <el-form-item label="商品状态" prop="status">
+    <el-dialog title="批量修改商品" :visible.sync="open1" width="580px" append-to-body>
+      <el-form ref="form1" :model="form1" label-width="90px">
+        <el-form-item label="商品状态">
           <el-radio-group v-model="form1.isShow">
-            <el-radio :label="item.dictValue" v-for="item in isShowOptions" >{{item.dictLabel}}</el-radio>
+            <el-radio label="">不修改</el-radio>
+            <el-radio :label="item.dictValue" v-for="item in isShowOptions" :key="item.dictValue">{{ item.dictLabel }}</el-radio>
           </el-radio-group>
         </el-form-item>
-        <el-form-item label="商城展示" prop="isDisplay">
+        <el-form-item label="商城展示">
           <el-radio-group v-model="form1.isDisplay">
-            <el-radio :label="item.dictValue" v-for="item in isDisplayOptions" >{{item.dictLabel}}</el-radio>
+            <el-radio label="">不修改</el-radio>
+            <el-radio :label="item.dictValue" v-for="item in isDisplayOptions" :key="item.dictValue">{{ item.dictLabel }}</el-radio>
           </el-radio-group>
         </el-form-item>
-        <el-form-item label="所属公司" prop="companyId">
-          <el-select style="width: 220px" filterable multiple v-model="form1.companyId" placeholder="请选择公司名" clearable size="small">
+        <el-form-item label="所属公司">
+          <div class="quick-select-row">
+            <el-button type="text" size="mini" @click="handleBulkCompanySelectAll">全选</el-button>
+            <el-button type="text" size="mini" @click="handleBulkCompanyInvert">反选</el-button>
+            <el-button type="text" size="mini" @click="handleBulkCompanyClear">一键清空</el-button>
+            <el-button type="text" size="mini" @click="handleBulkCompanySkip">不修改</el-button>
+          </div>
+          <el-select
+            style="width: 100%"
+            filterable
+            multiple
+            v-model="form1.companyId"
+            placeholder="请选择所属公司,可留空表示清空"
+            clearable
+            size="small"
+          >
             <el-option
               v-for="item in companyOptions"
               :key="item.companyId"
@@ -1142,7 +1169,7 @@ import {
   addOrEdit,
   exportStoreProduct,
   importTemplate,
-  batchModify,bulkCopy
+  bulkCopy,bulkUpdate
 } from "@/api/hisStore/storeProduct";
 import { getAllStoreProductCategory } from "@/api/hisStore/storeProductCategory";
 import { getAllStoreProductRule } from "@/api/hisStore/storeProductRule";
@@ -1221,7 +1248,11 @@ export default {
         attrsVal: ''
       },
       open1: false,
-      form1: {},
+      form1: {
+        isShow: '',
+        isDisplay: '',
+        companyId: null
+      },
       isBtn: false,
       columns: [],
       attrs:[],
@@ -1499,24 +1530,64 @@ export default {
     },
     cancel1(){
       this.open1 = false;
+      this.resetForm1();
+    },
+    resetForm1() {
+      this.form1 = {
+        isShow: '',
+        isDisplay: '',
+        companyId: null
+      };
+    },
+    handleBulkUpdate() {
+      if (!this.ids || this.ids.length === 0) {
+        this.$message.warning("请先选择要修改的商品");
+        return;
+      }
+      this.resetForm1();
+      this.open1 = true;
+    },
+    handleBulkCompanySelectAll() {
+      this.form1.companyId = this.companyOptions.map(item => item.companyId);
+    },
+    handleBulkCompanyInvert() {
+      const current = this.form1.companyId || [];
+      this.form1.companyId = this.companyOptions
+        .map(item => item.companyId)
+        .filter(id => !current.includes(id));
+    },
+    handleBulkCompanyClear() {
+      this.form1.companyId = [];
+    },
+    handleBulkCompanySkip() {
+      this.form1.companyId = null;
     },
     submitForm1(){
-      let param = {}
-      param.productId = this.ids;
-      param.goodsStatus = this.form1.isShow;
-      param.goodsIsShow = this.form1.isDisplay;
-      param.companyIds = this.form1.companyId.join(',');
-      batchModify(param).then(res=>{
-        if(res.code === 200){
-          this.$message.success("批量修改成功");
+      const param = {
+        productId: this.ids
+      };
+      if (this.form1.isShow !== null && this.form1.isShow !== undefined && this.form1.isShow !== '') {
+        param.goodsStatus = Number(this.form1.isShow);
+      }
+      if (this.form1.isDisplay !== null && this.form1.isDisplay !== undefined && this.form1.isDisplay !== '') {
+        param.goodsIsShow = Number(this.form1.isDisplay);
+      }
+      if (this.form1.companyId !== null && this.form1.companyId !== undefined) {
+        param.updateCompanyIds = true;
+        param.companyIds = this.form1.companyId.length > 0 ? this.form1.companyId.join(',') : '';
+      }
+      if (param.goodsStatus == null && param.goodsIsShow == null && !param.updateCompanyIds) {
+        this.$message.warning("请至少修改一项");
+        return;
+      }
+      bulkUpdate(param).then(res => {
+        if (res.code === 200) {
+          this.msgSuccess("批量修改成功");
+          this.open1 = false;
+          this.resetForm1();
           this.getList();
         }
-      }).finally(()=>{
-        this.open1 = false;
-        this.form1.isShow = null;
-        this.form1.isDisplay = null;
-        this.form1.companyId = null;
-      })
+      });
     },
     handleFullScreen(){
       this.isFullscreen = !this.isFullscreen;
@@ -2030,9 +2101,8 @@ export default {
     },
     /** 修改按钮操作 */
     handleUpdate(row) {
-      if(this.ids.length > 1){
-        this.title = "批量修改商品";
-        this.open1 = true;
+      if (this.ids.length > 1) {
+        this.handleBulkUpdate();
         return;
       }
       var that=this;