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

        <el-form-item label="分类名称:">
          <el-input v-model="dataForm.name" style="width: 300px;" placeholder="请输入分类名称"></el-input>
        </el-form-item>
       <!--  <el-form-item label="分类状态:">
          <el-select v-model="dataForm.status"  placeholder="请选择分类状态" size="large" @change="onChangeStatus" 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>
    </el-card>
    <div style="text-align:right; margin-top:20px;margin-bottom: 20px;">
        <el-button type="warning" @click="btnSave">确认保存</el-button>
    </div>
  </div>
</template>

<script>
  import {getSourceDataCategoryInfo,createSourceDataCategory,updateSourceDataCategory} from'@/api/sourceData'
  export default{
    emits:['onClose'],
    props:{
      id:{
        type:Number,
        default:0
      },
    },
    watch:{
      id:{
        handler(v){
            let _this=this;
            if(v==null || v<=0)return;
            this.initCategoryInfo(v);
        },
        immediate: true,
        deep: true
      }
    },
    data(){
      return{
        statusOptions:[
          {
            value:5,
            label:'启用'
          },
          {
            value:6,
            label:"停用"
          },
        ],
        dataForm:{
          code:"",
          name:'',
          intro:'',
          id:0,
        }
      }
    },

    mounted() {
      let _this=this;
     },
    methods:{
      //保存更新
      btnSave(e){
          let _this=this;
          if(_this.dataForm.id>0){
            //更新修改
            updateSourceDataCategory(_this.dataForm).then(res=>{
              if(res.status!=200)return;
              _this.$alert("分类信息更新成功");
              _this.$emit("onClose");
            })
          }else{
            createSourceDataCategory(_this.dataForm).then(res=>{
              if(res.status!=200)return;
              _this.$alert("分类信息创建成功")
              _this.$emit("onClose")
            })
          }
      },
      onChangeStatus(e){
          this.dataForm.status=e;
      },
      initCategoryInfo(e){
        let _this=this;
        getSourceDataCategoryInfo({id:e}).then(res=>{
          if(res.status==200){
              _this.dataForm=res.data
              // _this.dataForm.statusName=_this.statusOptions.filter(o=>o.status==_this.dataForm.status).name;
          }
        })
      }

    }
  }
</script>

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