<template>
  <el-dialog
    title="批量修改"
    :visible.sync="controlWindows.batch"
    width="30%"
    :before-close="closeWindow"
    @opened="openDrawer"
  >
    <div class="batch">
      <el-form ref="form" :rules="rules" :model="form" label-width="120px">
        <el-form-item>
          <p class="tip">
            已选择 <span>{{ multipleRowList.length }}</span> 条数据
          </p>
        </el-form-item>
        <el-form-item label="状态" prop="enableMark">
          <el-radio-group v-model="form.enableMark">
            <el-radio label="ENABLE">启用</el-radio>
            <el-radio label="DISABLE">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="controlWindows.batch = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import serve from "api/product.js";

export default {
  props: {
    controlWindows: Object,
    multipleRowList: Array,
  },
  data() {
    return {
      list: [],
      form: {},
      rules: {
        enableMark: [
          { required: true, message: "请选择修改状态", trigger: "change" },
        ],
      },
    };
  },
  methods: {
    openDrawer() {
      this.list = JSON.parse(JSON.stringify(this.multipleRowList));
    },
    submit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.list.map((item) => {
            item.enableMark = this.form.enableMark;
          });
          serve.updateBatchEnable(this.list).then((res) => {
            this.$message.success(res.msg);
            this.closeWindow();
          });
        }
      });
    },
    closeWindow() {
      this.list = [];
      this.form = {};
      this.$emit("closeWindow");
      this.$nextTick(() => {
        this.$refs.form.clearValidate();
        this.controlWindows.batch = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.batch {
  .tip {
    span {
      color: orange;
    }
  }
}
</style>
