<template>
  <div>
    <el-button type="primary" size="mini" :disabled="!isEdit()" @click="drawer=true">快速折扣</el-button>
    <el-dialog title="折扣设置" append-to-body :visible.sync="drawer" width="40%">
      <el-form :model="form" :rules="rules" ref="form" label-width="120px" label-position="right" size="mini">
        <el-col :span="24">
          <el-form-item label="折扣:" prop="discountrate">
            <el-input v-model="form.discountrate"  placeholder="请输入折扣"></el-input>
          </el-form-item>
        </el-col>
      </el-form>
      <div class="dialog-footer">
        <el-button size="small" @click="drawer = false" class="normal-btn-width">取 消</el-button>
        <el-button class="normal-btn-width" type="primary" size="small" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: '',
  inject:['isEdit'],
  data() {
    var NumberSize = (rule, value, callback) => {
      if (+value >= 0.1 && +value <= 1) {
        callback()
      } else {
        return callback(new Error('折扣范围(0.1-1)'));
      }
    }
    return {
      drawer:false,
      form:{
        "sa_promotionid": 1,
        "discountrate":0.8
      },
      rules:{
        discountrate:[
          { required: true, message: '请输入折扣', trigger: 'blur'},
          { validator: NumberSize , trigger:'blur'}
        ],
      },
    };
  },
  computed:{
  },
  watch:{
  },
  methods: {
    submit () {
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        this.form.sa_promotionid = this.$route.query.id
        const res = await this.$api.requested({
          "id": "20230102163203",
          "content": this.form
        })
        this.tool.showMessage(res,() => {
          this.$emit('onSuccess')
          this.drawer = false
        })
      })
    }
  },
};
</script>

<style scoped>

</style>
