Parcourir la source

药品商品支持多店铺

wangxy il y a 1 jour
Parent
commit
6c403ec1ec
2 fichiers modifiés avec 109 ajouts et 13 suppressions
  1. 36 2
      src/views/his/store/index.vue
  2. 73 11
      src/views/his/storeProduct/index.vue

+ 36 - 2
src/views/his/store/index.vue

@@ -349,6 +349,20 @@
           </el-select>
         </el-form-item>
 
+        <el-form-item label="ERP品牌别名(大包)" prop="erpBrandAliasList">
+          <el-select
+            v-model="form.erpBrandAliasList"
+            multiple
+            filterable
+            allow-create
+            default-first-option
+            placeholder="输入后回车,如:乘济、免费、红德堂、优身、诚质"
+            size="small"
+            style="width: 100%"
+            clearable>
+          </el-select>
+        </el-form-item>
+
           <el-form-item label="登录帐号" prop="account" v-if="title != '修改店铺管理'">
             <el-input v-model="form.account" placeholder="请输入登录帐号" />
           </el-form-item>
@@ -439,7 +453,9 @@ shippingType:[],
       // 表单参数
       form: {
         chainBrand: [],
-        chainBrands: null
+        chainBrands: null,
+        erpBrandAliasList: [],
+        erpBrandAliases: null
       },
       // 表单校验
       rules: {
@@ -621,7 +637,9 @@ shippingType:[],
         fullName:null,
         shopCode: null,
         chainBrand: [],
-        chainBrands: null
+        chainBrands: null,
+        erpBrandAliasList: [],
+        erpBrandAliases: null
       };
       this.resetForm("form");
     },
@@ -670,6 +688,11 @@ shippingType:[],
         } else {
           this.$set(this.form, 'chainBrand', []);
         }
+        if (this.form.erpBrandAliases) {
+          this.$set(this.form, 'erpBrandAliasList', this.form.erpBrandAliases.split(/[,、]/).map(s => s.trim()).filter(Boolean));
+        } else {
+          this.$set(this.form, 'erpBrandAliasList', []);
+        }
         this.handleDeliveryTypeChange(this.form.deliveryType);
 
 
@@ -689,6 +712,17 @@ shippingType:[],
           } else {
             this.form.chainBrands = '';
           }
+          if (this.form.erpBrandAliasList && Array.isArray(this.form.erpBrandAliasList)) {
+            const aliasSet = [];
+            this.form.erpBrandAliasList.forEach(item => {
+              String(item || '').split(/[,、]/).map(s => s.trim()).filter(Boolean).forEach(a => {
+                if (!aliasSet.includes(a)) aliasSet.push(a);
+              });
+            });
+            this.form.erpBrandAliases = aliasSet.join(',');
+          } else {
+            this.form.erpBrandAliases = '';
+          }
           if (this.form.storeId != null) {
             updateStore(this.form).then(response => {
               this.msgSuccess("修改成功");

+ 73 - 11
src/views/his/storeProduct/index.vue

@@ -137,7 +137,7 @@
          </template>
       </el-table-column>
       <el-table-column label="商品名称" align="center" prop="productName" show-overflow-tooltip  width="150px"/>
-     <el-table-column label="店铺" align="center" prop="storeName" width="150px"/>
+     <el-table-column label="店铺" align="center" prop="storeName" show-overflow-tooltip min-width="150px"/>
       <el-table-column label="分类" align="center" prop="cateName" />
       <el-table-column label="商品价格" align="center" prop="price" />
       <el-table-column label="市场价" align="center" prop="otPrice" />
@@ -250,15 +250,24 @@
               </el-form-item>
             </el-col>
            <el-col :span="12">
-             <el-form-item label="所属店铺" prop="storeId">
-               <el-select v-model="form.storeId" placeholder="状态" clearable size="small">
-                       <el-option
-                         v-for="dict in storeOPtions"
-                         :key="dict.dictValue"
-                         :label="dict.dictLabel"
-                         :value="dict.dictValue"
-                       />
-                     </el-select>
+             <el-form-item label="所属店铺" prop="storeIdList">
+               <el-select
+                 v-model="form.storeIdList"
+                 placeholder="请选择所属店铺"
+                 clearable
+                 filterable
+                 multiple
+                 collapse-tags
+                 size="small"
+                 style="width: 100%"
+               >
+                 <el-option
+                   v-for="dict in storeOPtions"
+                   :key="dict.dictValue"
+                   :label="dict.dictLabel"
+                   :value="dict.dictValue"
+                 />
+               </el-select>
              </el-form-item>
            </el-col>
          </el-row>
@@ -1096,9 +1105,55 @@ export default {
     },
     getstoreList() {
       listStore().then(response => {
-        this.storeOPtions = response.rows;
+        this.storeOPtions = (response.rows || []).map(item => ({
+          ...item,
+          dictValue: item.dictValue != null ? Number(item.dictValue) : item.dictValue
+        }));
       });
     },
+    /** storeId 单店 / brandStoreIds 大品牌归属 → 表单多选回显 */
+    resolveStoreIdList(product) {
+      if (!product) {
+        return [];
+      }
+      // 大品牌归属优先:即使只有一个店,也按 brandStoreIds 回显,不能当成 storeId
+      if (product.brandStoreIds) {
+        return String(product.brandStoreIds)
+          .split(',')
+          .map(id => id && String(id).trim())
+          .filter(Boolean)
+          .map(id => Number(id))
+          .filter(id => !Number.isNaN(id));
+      }
+      if (product.storeId != null && product.storeId !== '') {
+        return [Number(product.storeId)];
+      }
+      return [];
+    },
+    /**
+     * 多选店铺写回:
+     * - 来自大品牌归属(brandStoreIds)的,始终写回 brandStoreIds(哪怕只选 1 个店)
+     * - 来自单店 storeId 的,单选写 storeId;改成多选则升为 brandStoreIds
+     * - 新建:1 个店 → storeId;多个 → brandStoreIds
+     */
+    applyStoreIdListToForm() {
+      const ids = Array.isArray(this.form.storeIdList)
+        ? this.form.storeIdList.map(id => Number(id)).filter(id => !Number.isNaN(id))
+        : [];
+      const fromBrand = !!this.form.storeAttrFromBrand;
+      if (ids.length === 0) {
+        this.form.storeId = null;
+        this.form.brandStoreIds = null;
+        return;
+      }
+      if (fromBrand || ids.length > 1) {
+        this.form.storeId = null;
+        this.form.brandStoreIds = ids.join(',');
+        return;
+      }
+      this.form.storeId = ids[0];
+      this.form.brandStoreIds = null;
+    },
     handleAvatarSuccess(res, file) {
         if(res.code==200){
           this.form.imgUrl=res.url;
@@ -1129,6 +1184,9 @@ export default {
       this.form = {
         productId: null,
         storeId: null,
+        brandStoreIds: null,
+        storeIdList: [],
+        storeAttrFromBrand: false,
         doctorBrokerage:null,
         imgUrl: null,
         images: null,
@@ -1228,6 +1286,9 @@ export default {
         this.form = response.data;
         this.open = true;
         this.title = "修改商品";
+        const fromBrand = !!this.form.brandStoreIds;
+        this.$set(this.form, 'storeAttrFromBrand', fromBrand);
+        this.$set(this.form, 'storeIdList', this.resolveStoreIdList(this.form));
         this.form.isShow = String(this.form.isShow)
         this.form.isHot = String(this.form.isHot)
         this.form.isBenefit = String(this.form.isBenefit)
@@ -1333,6 +1394,7 @@ export default {
             return this.$message.warning('请点击生成规格!');
           }
 
+          this.applyStoreIdListToForm();
           addOrEdit(this.form).then(response => {
             if (response.code === 200) {
               this.msgSuccess("操作成功");