<template>
  <div class="add">
    <el-button size="mini" type="text"  @click="dialogVisible=true" v-if="type === 'add'" icon="el-icon-plus">新增下级</el-button>
    <el-button size="mini" type="text" @click="editBtn" icon="el-icon-edit"  v-else>编 辑</el-button>
    <el-dialog
      :title="type == 'add' ? '新增营销类别' : '编辑营销类别'"
      :visible.sync="dialogVisible"
      width="500px"
      append-to-body
      :before-close="handleClose">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="demo-ruleForm">
        <el-form-item label="营销类别名" prop="itemclassname">
          <div class="flex-align-center">
            <el-input v-model="ruleForm.itemclassname" size="small" class="inline-16" placeholder="请输入营销类别名">
            </el-input>
            <el-input v-model="ruleForm.num" size="small" style="width:90px" placeholder="排序">
            </el-input>
          </div>
        </el-form-item>
        <el-form-item label="营销类别编号" prop="itemclassnum">
          <el-input v-model="ruleForm.itemclassnum" :disabled="type!='add'" size="small" placeholder="请输入营销类别编号"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <div>
          <el-button @click="dialogVisible = false" size="small">取 消</el-button>
          <el-button type="primary" @click="submit" size="small">确 定</el-button>
        </div>
      </span>
    </el-dialog>
  </div>
  
</template>

<script>
export default {
  name: '',
  data() {
    return {
      currentData:'',
      dialogVisible:false,
      ruleForm: {
        "itemclassnum":'',
        "itemclassname":'',
        // "itemclassfullname":'',
      },
      rules:{
        itemclassname: [
          { required: true, message: '请输入营销类别名', trigger: 'blur' },
        ],
        itemclassnum: [
          { required: true, message: '请输入营销类别编号', trigger: 'blur' },
        ],
        // itemclassfullname: [
        //   { required: true, message: '请输入营销类别全称', trigger: 'blur' },
        // ],
      }
    };
  },
  props:['type','rowData'],
  computed:{
  },
  methods: {
    editBtn() {
      this.dialogVisible = true
      this.ruleForm = Object.assign({},this.ruleForm,this.rowData)
    },
    handleClose() {
      this.dialogVisible = false
    },
    submit() {
      this.$refs.ruleForm.validate(async val => {
        if(val) {
          let res = await this.$api.requested({
            "accesstoken": "bed2f4500c0e799a29ddbbe47a2a04b6",
            "id": "20220922110303",
            "version":1,
            "content": {
                "itemclassid":this.type == 'add' ? 0 : this.rowData.itemclassid,     
                "sa_brandid":this.rowData.sa_brandid,
                "parentid":this.rowData.itemclassid === undefined ? 0 : this.rowData.itemclassid,
                "itemclassnum":this.ruleForm.itemclassnum,
                "itemclassname":this.ruleForm.itemclassname,
                "num":this.ruleForm.num,
                "classtype":"营销"
            }
          })
          this.tool.showMessage(res,() => {
            this.$emit('addSuccess')
            this.$refs.ruleForm.resetFields()
            this.dialogVisible = false
          })
        }
      })
    }
  },
};
</script>

<style scoped>
</style>
