<template>
  <div>
    <el-button size="mini" type="primary" @click="onshow">{{data.isonsale === 0?'上 架':'下 架'}}</el-button>
    <el-dialog
        title="提示"
        :visible.sync="upVisible"
        width="25%"
        append-to-body
    >
      <span>确定上架该商品组吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="upVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="shelvesUp" size="small">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
        title="提示"
        :visible.sync="downVisible"
        width="25%"
        append-to-body
    >
      <span>确定下架该商品组吗</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="downVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="shelvesDown" size="small">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "shelves",
  props:["data"],
  data(){
    return {
      upVisible:false,
      downVisible:false
    }
  },
  methods:{
    onshow(){
      console.log("输出数据")
      console.log(this.data)
      if (this.data.isonsale === 0){
        this.openUp()
      }else {
        this.openDown()
      }
    },
    openUp() {
      this.$confirm('确定上架该商品组吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal:false,
        type: 'warning'
      }).then(() => {
       this.shelvesUp()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消上架'
        });
      });
    },
    openDown() {
      this.$confirm('确定下架该商品组吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal:false,
        type: 'warning'
      }).then(() => {
        this.shelvesDown()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消下架'
        });
      });
    },
    async shelvesUp(){
      const res = await this.$api.requested({
        "id": "20220923143603",
        "content": {
          "sa_itemgroupids":[this.data.sa_itemgroupid]

        }
      })
      this.tool.showMessage(res,()=>{
        this.upVisible = false
        this.$emit("upSuccess")
      })

    },
    async shelvesDown(){
      const res = await this.$api.requested({
        "id": "20220923143703",
        "content": {
          "sa_itemgroupids":[this.data.sa_itemgroupid]

        }
      })
      this.tool.showMessage(res,()=>{
        this.downVisible = false
        this.$emit("upSuccess")
      })
    }
  },
  mounted() {

  }
}
</script>

<style scoped>

</style>