Explorar el Código

修改关联规格,显示正在关联的规格

dong025 hace 1 día
padre
commit
a033f1b6a4

+ 17 - 2
app/admin/controller/goods/ImportList.php

@@ -26,14 +26,19 @@ class ImportList extends Backend
     use Actions {
         index as private _index;
         del as private _del;
+    
     }
-
+    private $typeList=null;
+    private $tabValue=null;
+    
     protected function _initialize()
     {
         parent::_initialize();
         $this->model = new ImportListModel();
+        $this->typeList=StockConfig::where('type_id', 'variety_name')->order('sort desc')->column('title', 'id');
+        $this->tabValue=array_keys($this->typeList)[0]?? null;
         // $this->assign('shopList', ShopList::where('status', 1)->column('name', 'id'));
-        $this->assign('typeList',  StockConfig::where('type_id', 'variety_name')->order('sort desc')->column('title', 'id'));
+        $this->assign('typeList',  $this->typeList);
         $this->assign('packingList', StockConfig::where('type_id', 'packing_box')->column('title', 'id'));
     }
     // 获取店铺
@@ -189,6 +194,16 @@ class ImportList extends Backend
 
             $rows = $shopListModel::where('shop_id', $shop_id)->where('status', 1)->find();
             
+            //修改规格
+            $importSku = new ImportSku();
+            $sql_data = $importSku->where(['shop_id' => $row['shop_id'], 'sku_id' => $row['sku_id']])->find();
+            $spec_id=0;
+            if(!empty($sql_data)){
+                $this->tabValue=$sql_data['variety_id'];
+                $spec_id=$sql_data['spec_id'];
+            }
+            $this->assign('tabValue',$this->tabValue.'');
+            $this->assign('spec_id',$spec_id);
             $this->assign('rows', $rows->type_spec ?? '');
             $this->assign('row', $row);
             

+ 36 - 22
app/admin/view/goods/import_list/specs.html

@@ -5,25 +5,11 @@
             </el-tab-pane>
             <el-table :data="tableData" style="width: 100%" border :ref="'multipleTable_' + tabValue" stripe
                 highlight-current-row @select="handleSelectionChange" @select-all="handleAllSelect"
-                @current-change="handleCurrentChange">
+                @current-change="handleCurrentChange" :row-class-name="tableRowClassName">
                 <el-table-column type="index" width="55">
                 </el-table-column>
-                <!-- <el-table-column prop="selected_d" label="店铺关联规格" width="90" height="40">
-                   
-                   <template #default="{row}">
-                        <el-checkbox v-model="row.selected_d" size="large" disabled/>
-                    </template>
-                </el-table-column> -->
                 <el-table-column prop="name" label="规格" align="center">
                 </el-table-column>
-                
-                <!-- <el-table-column prop="packet" label="包装箱" align="center">
-                    <template #default="{row}">
-                        <span>{{options[row.box_id]}}</span>
-                    </template>
-                </el-table-column>
-                <el-table-column prop="price" label="发货价" align="center" ></el-table-column> -->
-
             </el-table>
         </el-tabs>
     </el-card>
@@ -50,13 +36,23 @@
                 nameValue: null,
             },
             options: Yunqi.data.packingList,//品种
-            tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
+            // tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
+            tabValue: Yunqi.data.tabValue,
+
             chooseSpec: [], // 当前分类选中的规格  
             allData: {},
             type: 0, // 1编辑 0新增,
-            shop_allData: []
+            shop_allData: [],
+            spec_id: Yunqi.data.spec_id
         },
         methods: {
+            tableRowClassName({ row, rowIndex }) {
+                // 根据行数据中的selected_d字段判断是否高亮
+                if (row.spec_id_selected) {
+                    return 'current-row';
+                }
+                return '';
+            },
             onSubmit() {
                 if (this.allData == "") return;
                 let arr = Object.values(this.allData).flat(Infinity)
@@ -74,17 +70,31 @@
                     }
                 });
             },
+
             handleAllSelect(e) {
                 this.allData[this.tabValue] = e || []
 
             },
             handleCurrentChange(e) {
+                this.tableData = this.tableData.map((item) => {
+                    if(e.id==item.id){
+                        item.spec_id_selected=true
+                    }else{
+                        item.spec_id_selected=false
+                    }
+                    return item;
+
+                })
                 this.allData[this.tabValue] = e || []
             },
             handleSelectionChange(e) {
-
+                
             },
             handleClick(data, row) {
+                
+                
+
+
                 // 品种切换事件 可以在这里请求规格接口
                 this.tabValue = data.props.name
                 this.tabName = data.props.label
@@ -98,12 +108,13 @@
 
                 //获取规格 ;
                 Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: this.tabValue }, false, false, true).then(res => {
-
                     //编辑数据
                     if (res.length > 0) {
                         for (var key in Object(res)) {
                             let index = this.tableData.findIndex(item => item.id == res[key]['id']);
                             const isExist = this.shop_allData.includes(res[key]['id'])
+                            let spec_id = this.spec_id == res[key]['id'] ? true : false;
+
                             if (index != -1) {
                                 this.tableData.splice(index, 1)
                             } else {
@@ -111,19 +122,21 @@
                                     id: res[key]['id'],
                                     name: res[key]['title'],
                                     type_id: this.tabValue,
-                                    selected_d: isExist
+                                    selected_d: isExist,
+                                    spec_id_selected: spec_id
                                 }
                                 this.tableData.push(item);
 
                             }
 
                         }
-                        
+
                     }
                 });
             }
 
         },
+
         onLoad: function (query) {
             let rows = Yunqi.data.rows;
             if (rows) {
@@ -144,11 +157,12 @@
                 }
                 this.shop_allData = acc;
             }
+            //     this.tableData = [];
             //你只需要保存规格是吧, 是你末尾加了个row
             this.getSpecData()
         },
     }
 </script>
 <style>
-    
+
 </style>