<template>
  <div>
    <el-dialog
      title="添加盲豆奖品"
      :visible.sync="dialogVisible"
      :before-close="close"
      width="500px"
    >
      <el-form
        :model="coinForm"
        :rules="coinRules"
        ref="coinForm"
        label-width="100px"
      >
        <el-form-item label="盲豆数量" prop="quantity">
          <el-input
            v-model="coinForm.quantity"
            size="small"
            placeholder="请输入盲豆数量"
            style="width: 200px"
          />
        </el-form-item>
      </el-form>
      <div class="dialog-btn">
        <el-button size="small" @click="close"> 取 消 </el-button>
        <div class="ge"></div>
        <el-button type="primary" size="small" @click="confirmCoin">
          确 认
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { publicFileGetUrl } from "@/api/common";
export default {
  name: "CoinAdd",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      coinForm: { quantity: "" },
      coinRules: {
        quantity: [
          { required: true, message: "请输入数量", trigger: "blur" },
          {
            pattern: /^([1-9]\d*)$/,
            message: "请输入合法的数字",
            trigger: ["blur", "change"],
          },
        ],
      },
    };
  },
  methods: {
    // 确认输入盲豆
    confirmCoin() {
      let coin = {
        prizeType: "coin",
        // quantity: 1,
        title: `盲豆 x${this.coinForm.quantity}`,
        picUrl: publicFileGetUrl + "md.jpeg",
        value: this.coinForm.quantity,
        sortWeight: 100
      };
      this.$refs["coinForm"].validate((valid) => {
        if (valid) {
          this.$emit("confirmCoin", coin);
        } else {
          return false;
        }
      });
    },
    close() {
      this.$emit("close");
    },
  },
};
</script>
<style lang="scss" scoped>
.dialog-btn {
  display: flex;
  align-content: center;
  justify-content: flex-end;
  padding: 40px 0 0;
  .ge {
    width: 40px;
  }
}
</style>
