From ef50aee330d6d6b99d52bfff257b9b5dfc72fc1c Mon Sep 17 00:00:00 2001
From: lixiaomin <gdc@1357>
Date: Tue, 7 Mar 2023 11:52:34 +0800
Subject: [PATCH] 修改商品查看规格状态

---
 src/api/system/shop.js                       |  11 ++++++-----
 src/views/shop/shop/components/commodity.vue | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------
 2 files changed, 119 insertions(+), 54 deletions(-)

diff --git a/src/api/system/shop.js b/src/api/system/shop.js
index d61b994..664ce5f 100644
--- a/src/api/system/shop.js
+++ b/src/api/system/shop.js
@@ -175,18 +175,19 @@ export function checkMachine(id) {
   });
 }
 
-// 获取规格选项状态
-export function getSpecState(shopId,goodsId) {
+// 获取规格选项
+export function getSpecSku(shopId,goodsId) {
   return request({
-    url: "/system/shop/getShopGoodsSpecs?shopId=" + shopId+"&goodsId="+goodsId,
+    //url: "/system/shop/getShopGoodsSpecs?shopId=" + shopId+"&goodsId="+goodsId,
+    url: "/system/shop/selectSkuByShopGoods?shopId=" + shopId+"&goodsId="+goodsId,
     method: "get",
   });
 }
 
 // 修改规格选项状态
-export function updateSpecState(shopId,goodsId,ruleId,state) {
+export function updateSpecState(ids,state) {
   return request({
-    url: "/system/shop/updateShopGoodsSpecState?shopId=" + shopId+"&goodsId="+goodsId+"&ruleId="+ruleId+"&state="+state,
+    url: "/system/shop/updateShopGoodsSkuState?ids="+ids+"&state="+state,
     method: "get",
   });
 }
diff --git a/src/views/shop/shop/components/commodity.vue b/src/views/shop/shop/components/commodity.vue
index a048eed..44d1530 100644
--- a/src/views/shop/shop/components/commodity.vue
+++ b/src/views/shop/shop/components/commodity.vue
@@ -97,37 +97,48 @@
         layout="total, sizes, prev, pager, next,jumper"
         :total="totalNum">
     </el-pagination>
-    <el-dialog title="查看规格" :visible.sync="viewSpecDialog" width="1000px" append-to-body>
-      <div style="margin-bottom: 10px;">
+    <el-dialog title="查看规格" :visible.sync="viewSpecDialog" width="800px" append-to-body>
+      <div style="margin-bottom: 10px;" >
         <el-row>
-          <el-col :span='2'>商品名称</el-col>
-          <el-col :span='22'>{{goodsName}}</el-col>
+          <div>
+            <el-col :span='2'>商品名称</el-col>
+            <el-col :span='4'>{{goodsName}}</el-col>
+          </div>
+          <div style="display: flex;justify-content:space-between">
+            <div></div>
+            <div></div>
+            <div>
+              <!-- <el-button size="small" type="primary">全选</el-button> -->
+              <el-button size="small" type="success" @click="changeMoreState('1')">上架</el-button>
+              <el-button size="small" type="danger" @click="changeMoreState('2')">下架</el-button>
+            </div>
+          </div>
         </el-row>
       </div>
-      <div style="display:flex;flex-direction:row;flex-wrap:wrap;width:1000px;margin-bottom: 10px;">
-        <div style="width:480px;" v-for="(item,index) in specList" :key="index">
-          <el-row style="margin-bottom: 10px;">
-            <el-col :span='4'>规格组名</el-col>
-            <el-col :span='20'>{{item.name}}</el-col>
-          </el-row>
-          <el-row>
-            <el-col :span='4'> 选项值</el-col>
-            <el-col :span='20'> 
-              <el-table  :data="item.specRules">
-                <el-table-column label="选项名称" prop="name"/>                
-                <el-table-column label="售罄" >
-                  <template slot-scope="scope">
-                    <div @click="changeState(scope.row)"  ><el-switch v-model="scope.row.state"/> </div>
-                    <span v-if="scope.row.state == false">售罄</span>
-                    <span v-if="scope.row.state == true">在售</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </el-col>
-          </el-row>            
-        </div>
-      </div>
-      <div class="dialog-footer" style="text-align: center">       
+      <el-table :data="specNameList" style="width: 100%" @selection-change="specNameStateChange" ref="multipleTable">
+        <el-table-column          
+          type="selection"
+          width="55">
+        </el-table-column>
+        <el-table-column label="商品规格">
+          
+            <template slot-scope="scope">
+              <div style="white-space: pre-wrap;">
+              {{scope.row.strName}}
+              </div>
+            </template>
+          
+        </el-table-column>
+        <el-table-column label="状态" >
+          <template slot-scope="scope">
+            <div @click="changeOneState(scope.row)"  ><el-switch v-model="scope.row.state"/> </div>
+            <span v-if="scope.row.state == false">下架</span>
+            <span v-if="scope.row.state == true">上架</span>
+          </template>
+        </el-table-column>
+         
+      </el-table>
+      <div class="dialog-footer" style="text-align: center;margin-top: 10px;">       
         <el-button @click="cancel" type="primary">关闭</el-button>
 		  </div>
     </el-dialog>
@@ -135,7 +146,7 @@
 </template>
 
 <script>
-import { getCategoryGoods, addGoods ,offGoods,turnList,getSpecState,updateSpecState} from "@/api/system/shop";
+import { getCategoryGoods, addGoods ,offGoods,turnList,getSpecSku,updateSpecState} from "@/api/system/shop";
 import SelectGoods from '@/components/SelectGoods';
 import AddRecommend from './addRecommend.vue'
 import Preferential from './preferential.vue';
@@ -164,48 +175,102 @@ export default {
       outIds: '',
       total: null,
       goodsList:[],
-      viewSpecDialog:false,
-      specList:[],
-      specState:true,
+      viewSpecDialog:false,      
       goodsId:null,
-      goodsName:""
+      goodsName:"",
+      specNameList:[],
+      ids:"",
 		}    
 	},
 	mounted() {
 		//this.getList()
 	},
 	methods: {
+    //新增接口1
     cancel(){
       this.viewSpecDialog=false;
     },
-    changeState(row){     
+    specNameStateChange(val) {
+      this.ids="";
+      for(let i=0;i<val.length;i++){
+        this.ids +=val[i].id+","
+      }
+      this.ids=this.ids.substring(0,this.ids.length-1)      
+    },
+    //新增接口2
+    changeOneState(row){        
       let tag=2;      
       if(row.state){
         tag=1;
       }
-      updateSpecState(this.shopId,this.goodsId,row.id,tag).then((response) => {
-        if(response.code=="200"){
-          this.$modal.msgSuccess("修改状态成功!");
+      this.updateSpecState(row.id,tag);      
+    },
+    //新增接口3
+    changeMoreState(tag){
+      this.updateSpecState(this.ids,tag);      
+    },
+    updateSpecState(ids,tag){
+      updateSpecState(ids,tag).then((response) => {
+        if(response.code=="200"){          
+          let idsList=ids.split(",");
+          for(let i=0;i<idsList.length;i++){
+            let selectedId=idsList[i]
+            for(let j=0;j<this.specNameList.length;j++){
+              if(this.specNameList[j].id==selectedId){
+                this.specNameList[j].state=(tag == 1?true:false)
+              }
+            }
+          }
+          if(tag==1){
+            this.$modal.msgSuccess("上架成功!");
+          }else{
+            this.$modal.msgSuccess("下架成功!");
+          } 
+          this.$refs.multipleTable.clearSelection();
+        }else{
+          if(tag==1){
+            this.$message.error("上架失败!");
+          }else{
+            this.$message.error("下架失败!");
+          }
         }
-      })      
+      })
     },
+    //新增接口3
     clickView(row){
+      this.specNameList=[];
       this.viewSpecDialog=true;  
       this.goodsId=row.id; 
       this.goodsName=row.name;
-      getSpecState(this.shopId,row.id).then((response) => {
+      let specList=JSON.parse(row.spec);      
+      getSpecSku(this.shopId,row.id).then((response) => {
         if(response.code=="200"){
-        for(let i=0;i<response.data.length;i++){
-            let itemI = response.data[i];
-            for(let j=0;j<itemI.specRules.length;j++){
-               let itemJ= itemI.specRules[j];
-               itemJ.state = (itemJ.state == 1?true:false);
+          let list=response.data;
+          for(let i=0;i<list.length;i++){
+            let ruleList=JSON.parse(list[i].ruleList);
+            let strName = '';
+            for(let j=0;j<ruleList.length;j++){             
+              ruleList[j].specName=this.findSpecNameById(specList,ruleList[j].specId); 
+              strName +=ruleList[j].specName+":"+ruleList[j].name+"\n"; 
             }
-          }
-          this.specList=response.data 
-        }
+            list[i].state=(list[i].state == 1?true:false)
+            this.specNameList.push({"id":list[i].id,"strName":strName,"state":list[i].state})                               
+          }      
+        }        
       });      
     },
+    //根据id找name
+    findSpecNameById(specList,p_specId){      
+      let specName = '';
+      for(let i=0;i<specList.length;i++){
+          let specId = specList[i].id;
+          if(specId == p_specId){
+              specName = specList[i].name;
+              break;
+          }
+      }
+      return specName;
+    },
     turnClick(row,tag){
       turnList({"shopId":this.shopId,"goodsId": row.id,"pointer":tag}).then((response) => {
         if(response.code=="200"){
@@ -264,8 +329,7 @@ export default {
     handleSelectionChange(selection) {
       this.outIds = selection.map((item) => item.id);
     },
-    soldOutGoos(){
-      console.log("this.outIds",this.outIds)
+    soldOutGoos(){      
       if(this.outIds.length==0){
         this.$message.error('请选择所需下架的商品!');
         return;
--
libgit2 0.26.0