<template>
  <div class="data-info">
    <el-card>
      <el-form :model="dataForm" label-width="120px">

        <el-form-item label="品牌名称:">
          <el-input v-model="dataForm.name"></el-input>
        </el-form-item>

        <el-form-item label="品牌状态:">
          <el-select v-model="dataForm.status"  placeholder="请选择分类状态" size="large" style="width:100%;">
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
        </el-form-item>
        <el-form-item label="说明介绍:">
            <el-input type="textarea" v-model="dataForm.intro"></el-input>
        </el-form-item>
      </el-form>
    </el-card>
    <div style="text-align:right; margin-top:20px;">
        <el-button type="warning" @click="btnSave">确认保存</el-button>
    </div>
  </div>
</template>

<script>
  import {createBrand,updateBrand,getBrandInfo} from'@/api/brand'
  export default{
    emits:['onClose'],
    props:{
      id:{
        type:Number,
        default:0
      },
    },
    watch:{
      id:{
        handler(v){
            let _this=this;
            if(v==null || v<=0)return;
            _this.getInfo(v);
        },
        immediate: true,
        deep: true
      }
    },
    data(){
      return{
        activeName:'base',
        currentCategory:[],
        allCategories:[],
        dataForm:{
           id:0,
           name:'',
           intro:'',
           status:5,
        },
        statusOptions:[
         {
           value:'',
           label:"请选择状态"
         },
         {
           value:5,
           label:'启用'
         },
         {
           value:6,
           label:"停用"
         },
        ],
      }
    },

    mounted() {
      let _this=this;
    },
    methods:{
      //保存更新
      btnSave(e){
          let _this=this;
          if(_this.dataForm.id>0){
            updateBrand(_this.dataForm).then(res=>{
              _this.$alert("更新品牌信息成功");
              _this.$emit("onClose");
            })
          }else{
            createBrand(_this.dataForm).then(res=>{
              _this.$alert("品牌信息创建成功")
              _this.$emit("onClose");
            })
          }
      },

      //产品详情
      getInfo(id){
          let _this=this;
          let par={
            id:id,
          };
          getBrandInfo(par).then(res=>{
              if(!res)return;
              if(res.status!=200)return;
              _this.dataForm=res.data;
          })
      },

      onChangeStatus(e){
          this.dataForm.status=e;
      },
      //修改分类信息
      onChangeCategory(e){
         let _this=this;
         _this.dataForm.categoryId=e;
      },

    }
  }
</script>

<style lang="scss">
 @import './dataInfo.scss'
</style>
