<template>
  <div v-loading="loading" class="addCarBrand">
    <div class="head-title">
      <span @click="CommonJump('directorCarBrandList')" class="blue point">车辆管理</span> / 编辑车辆管理
    </div>
    <div class="content">
      <el-form :model="addMsg" :rules="rules" ref="addMsg" label-width="150px" style="width:50%">

        <el-form-item label="车辆名称" prop="Name" class="is-required">
          <el-input v-model="addMsg.Name" placeholder="请输入车辆名称" />
        </el-form-item>

        <el-form-item label="LOGO" class="is-required">
          <el-button @click="openChangeDig(1)" size="small">选择文件</el-button>
          <div class="app-gallery-item" style="position: relative;width: 100px;margin-top: 10px;">
            <img v-if="!addMsg.BrandLogo || addMsg.BrandLogo==''"
                 src="../../assets/img/default.png" style="width:80px;height:80px" alt="">
            <img v-else style="width:80px;height:80px" :src="addMsg.BrandLogo"
                 alt="">
          </div>
        </el-form-item>

      </el-form>
    </div>
    <div style="margin-top:20px">
      <el-button size="small" type="primary" @click="Save('addMsg')">保存</el-button>
    </div>

    <!-- 选择文件 -->
    <el-dialog title="选择文件" :visible.sync="changeState" width="1240px">
      <ChooseImg  @SelectId="SelectId"></ChooseImg>
    </el-dialog>
  </div>

</template>
<script>
  import ChooseImg from "@/components/global/ChooseImg.vue";

  export default {
    components: {
      ChooseImg,
    },
    data() {
      return {
        addMsg: {
          ID: 0,
          BrandLogo:'',
          Name:'',
        },
        Picindex:0,
        rules: {

          Name: [{
            required: true,
            message: '请输入品牌名称',
            trigger: 'blur'
          }],
        },

        loading: false,
        changeState:false,
        imgType:0,
      };
    },
    created() {

      if(this.$route.query.ID){
        this.getData(this.$route.query.ID)
      }

    },
    methods: {

      SelectId(msg){
        if(this.imgType==1){
          let url  = this.getIconLink(msg.url)
          this.addMsg.BrandLogo = url
        }
        this.changeState = false;
      },

      openChangeDig(num) {

        this.changeState = true;
        this.imgType=num;
      },
      Save(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.addMsg.BrandLogo==''){
              this.Error('请上传品牌Logo')
              return false
            }



            this.apipost("/api/GuideCar/AddOrUpdateGuideCarBrand", this.addMsg, res => {
              if (res.data.resultCode == 1) {
                this.CommonJump('directorCarBrandList');
                this.Success(res.data.message);
              } else {
                this.Error(res.data.message);
              }
            })
          } else {
            return false;
          }
        });
      },


      getData(ID) {
        this.loading = true;
        this.apipost("/api/GuideCar/GetGuideCarBrandModel", {
          ID: ID
        }, res => {
          this.loading = false;
          this.addMsg = res.data.data;

        })
      },


    },
    mounted() {
    }
  };
</script>
<style>
  .app-add-cat .el-checkbox-group {
    font-size: 14px !important;
  }

  .app-add-cat .el-checkbox {
    margin-right: 0;
  }

  .app-add-cat .el-dialog__body {
    padding: 10px 20px !important;
  }

  .app-add-cat .tag-box .tag-item {
    margin-right: 5px;
  }

  .app-add-cat .tag-box {
    margin: 20px 0;
  }

  .app-add-cat .app-goods-cat-list .active {
    background: #FAFAFA;
  }

  .app-add-cat .app-goods-cat-list .cat-item {
    cursor: pointer;
    padding: 5px 10px;
  }

  .app-add-cat .app-goods-cat-list {
    border: 1px solid #E8EAEE;
    border-radius: 5px;
    margin-top: -5px;
    padding: 10px 0;
    overflow: scroll;
    height: 400px;
  }



  .addCarBrand .blue {
    color: #409EFF;

  }

  .addCarBrand .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
  }
  .addCarBrand .gez_list{
    /*width: 650px;*/
    margin-bottom: 12px;
    padding: 20px;
    border: 1px solid #EBEEF5;
    background-color: #FFF;
    color: #303133;

  }
  .addCarBrand .quyu{
    background-color: #f4f4f5;
    color: #909399;
    padding: 10px;
    line-height: 30px;
    height: 30px;
    font-size: 12px;
    border-radius: 4px;
    white-space: nowrap;
    margin: 5px;
  }


</style>
