<template>
  <basic-container>

    <avue-form ref="form" v-model="form" :option="option" @reset-change="emptytChange" @submit="submit">
      <template slot-scope="scope" slot="menuForm">
        <el-button @click="create">生成红包</el-button>
      </template>
    </avue-form>
  </basic-container>
</template>

<script>
import {getOne, add,create} from "@/api/redpacket/setting";
import {mapGetters} from "vuex";

var DIC = {
  TYPE: [{
    label: '拼手气红包',
    value: 0
  }, {
    label: '普通红包',
    value: 1
  }]
}
export default {
  data() {
    return {
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        lazy: true,
        tip: false,
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        dialogWidth: "60%",
        tree: true,
        border: true,
        index: true,
        selection: true,
        viewBtn: true,
        menuWidth: 300,
        dialogClickModal: false,
        column: [
          {
            label: "标题",
            prop: "title",
            span: 24,
            suffixIcon: 'el-icon-tickets',
            prefixIcon: 'el-icon-tickets',
            rules: [{
              required: true,
              message: "请输入标题",
              trigger: "blur"
            }],

          },
          {
            label: "类型",
            prop: "type",
            span: 24,
            type: "radio",
            dicData: DIC.TYPE,
            mock: {
              type: 'dic'
            }
          },
          {
            label: "金额",
            prop: "totalAmount",
            rules: [{
              required: false,
              message: "请输入金额",
              trigger: "blur"
            }]
          },
          {
            label: "个数",
            prop: "num",
            rules: [{
              required: true,
              message: "请输入红包个数",
              trigger: "blur"
            }]
          },
          {
            label: "最小金额",
            prop: "minAmount",
            rules: [{
              required: true,
              message: "请输入最小金额",
              trigger: "blur"
            }]
          },
          {
            label: "最大金额",
            prop: "maxAmount",
            rules: [{
              required: true,
              message: "请输入最大金额",
              trigger: "blur"
            }]
          },
          {
            label: "随机红包比例",
            prop: "proportion",
            rules: [{
              required: true,
              message: "请输入随机红包比例,默认为1,即100%",
              trigger: "blur"
            }]
          },
          {
            label: "加速(专属)红包比例",
            prop: "belongProportion",
            rules: [{
              required: true,
              message: "请输入加速(专属)红包比例,默认为1,即100%",
              trigger: "blur"
            }]
          },
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.category_add, false),
        viewBtn: this.vaildData(this.permission.category_view, false),
        delBtn: this.vaildData(this.permission.category_delete, false),
        editBtn: this.vaildData(this.permission.category_edit, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      getOne().then(res => {
        this.form = res.data.data
        console.log(this.form)
      })
    },
    submit(form,done) {
      add(this.form).then(res=>{
        if (res.data.code===200){
          this.$message.success("设置成功!")
          done()

        }
      })
    },
    create(){
      create().then(res=>{
        if (res.data.code===200){
          this.$message.success("生成成功!")
        }
      })
    }
  }
};
</script>

<style>
</style>
