<template>
  <div class="add">
    <i style="font-weight:bold" class="el-icon-plus" @click="dialogVisible=true" v-if="type=='add'"></i>
    <i class="el-icon-edit" @click="editBtn" v-else></i>
    <el-dialog
      :title="type == 'add' ? '新增营销类别' : '编辑营销类别'"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="demo-ruleForm">
        <el-form-item label="营销类别名" prop="itemclassname">
          <el-input v-model="ruleForm.itemclassname" size="small" placeholder="请输入营销类别名"></el-input>
        </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-item label="营销类别全称" prop="itemclassfullname">
          <el-input v-model="ruleForm.itemclassfullname" 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:{
  },
  watch:{
    currentData: {
      handler(val) {
        this.ruleForm.itemclassnum = val.itemclassnum
        this.ruleForm.itemclassname = val.itemclassname
        // this.ruleForm.itemclassfullname = val.itemclassfullname
      }
    }
  },
  methods: {
    editBtn() {
      this.dialogVisible=true
      this.currentData = 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,
                // "itemclassfullname":this.ruleForm.itemclassfullname,
                "classtype":"营销"
            }
          })
          this.tool.showMessage(res,() => {
            this.$emit('addSuccess')
            this.$refs.ruleForm.resetFields()
            this.dialogVisible = false
          })
        }
      })
    }
  },
};
</script>

<style scoped>
  .dialog-footer {
    display: flex;
    justify-content: space-evenly;
  }
  /deep/.el-dialog__body {
    padding-top: 10px !important;
    padding-bottom: 0 !important;
  }
  /deep/.dialog-footer {
    margin-top: 10px !important;
  }
  /deep/.el-select {
    width: 100% !important;
  }
</style>
