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

        <el-form-item label="供应商编码:">
          <el-input v-model="dataForm.code"></el-input>
        </el-form-item>
        <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 {createSupplier,updateSupplier,getSupplierInfo} from'@/api/supplier'
  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',
        dataForm:{
           id:0,
           code:'',
           name:'',
           intro:'',
           status:'',
        },
        statusOptions:[
          {
            value:'',
            label:"请选择状态"
          },
          {
            value:5,
            label:'启用'
          },
          {
            value:6,
            label:"停用"
          },
        ],
      }
    },

    mounted() {
    },
    methods:{
      //保存更新
      btnSave(e){
          let _this=this;

          if(_this.dataForm.id>0){
            updateSupplier(_this.dataForm).then(res=>{
              _this.$alert("供应商信息更新成功");

              _this.$emit("onClose");
            })
          }else{
            createSupplier(_this.dataForm).then(res=>{
              _this.$alert("创建供应商信息成功");
              _this.$emit("onClose");
            })
          }

      },

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



    }
  }
</script>

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