<template>
  <div class="button-group" v-if="buttonlist || LightList">
    <el-dropdown
      v-if="LightList"
      trigger="click"
      @command="changeLight"
    >
      <el-button
        size="small"
        plain
        v-loading="LightList.loading"
        element-loading-spinner="el-icon-loading"
      >
        {{ command }}<i class="el-icon-arrow-down el-icon--right" />
      </el-button>
      <el-dropdown-menu slot="dropdown" class="dropdown-menu">
        <el-scrollbar wrap-class="scrollbar-wrap">
          <el-dropdown-item
            v-for="item in LightList.light"
            :key="item.command"
            :command="item.command"
            >{{ item.label }}</el-dropdown-item
          >
        </el-scrollbar>
      </el-dropdown-menu>
    </el-dropdown>
    <el-button
      plain
      size="small"
      v-loading="item.loading"
      element-loading-spinner="el-icon-loading"
      @click="selectButton(item)"
      v-show="item.show"
      v-for="item in buttonlist"
      :key="item.value"
      >{{ item.label }}</el-button
    >
  </div>
</template>

<script>
export default {
  props: ["buttonlist", "LightList"],
  components: {},
  data() {
    return {
      command: "批量亮灯",
    };
  },
  methods: {
    selectButton(item) {
      if (item.loading) return;
      switch (item.value) {
        case 1:
          this.$emit("BatchOffShelf"); //批量下架
          break;
        case 2:
          this.$emit("BatchChange"); //批量改价
          break;
        case 3:
          this.$emit("BatchPublish"); //批量发布
          break;
        case 4:
          this.$emit("BatchRedlight", 4); //批量亮红灯
          break;
        case 5:
          this.$emit("BatchDelete"); //批量删除
          break;
        case 6:
          this.$emit("SyncOrder"); //同步订单
          break;
        case 7:
          this.$emit("BatchRepublish"); //批量翻库
          break;
        case 8:
          this.$emit("BatchAudited"); //批量审核
          break;
        case 9:
          this.$emit("PrintPICK"); //打印拣货单
          break;
        case 10:
          this.$emit("ScanDelivery"); //扫码发货
          break;
        default:
          break;
      }
    },
    changeLight(e) {
      if (this.LightList.loading) return;
      this.LightList.light.forEach((item) => {
        if (e === item.command) {
          this.command = item.label;
        }
      });
      this.$emit("changeLight", e);
    },
  },
};
</script>

<style scoped lang='scss'>
.button-group {
  margin-left: 18px;
}
::v-deep .el-button {
  margin-left: 0px !important;
  margin-right: 10px;
}
::v-deep .el-loading-spinner {
  top: 90%;
}
::v-deep .el-icon-loading {
  font-size: 18px;
}
</style>