<template>
  <div>
    <el-drawer :with-header="false" :size="1000" :visible.sync="drawer" :direction="direction" :before-close="handleClose">
      <div v-loading="loading">
        <!--顶部内容-->
        <div class="head">
          <div class="text">
            <div class="title">
              <span class="bold" v-if="isAdd">添加供应商</span>
              <span class="bold" v-else-if="isEdit">编辑供应商</span>
              <span class="bold" v-else>查看供应商信息</span>
            </div>
          </div>
        </div>
        <!--具体内容-->
        <supplierEditForm ref="editForm" :supplierId="supplierId" :isAdd="isAdd" :supplierData="supplierData" @success="editSuccess" v-if="isEdit || isAdd"></supplierEditForm>
        <supplierInfo ref="supplierInfo" :supplierData="supplierData" v-else-if="!isEdit && !isAdd"></supplierInfo>
      </div>
      <div class="footer">
        <el-button size="small" @click="handleClose">取消</el-button>
        <el-button type="primary" size="small" @click="submitInfo">提交</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import supplierInfo from './supplierInfo';
import supplierEditForm from './supplierEditForm';
import {getSupplierInfo} from "@/api/supplier";
export default {
  props: {
    drawer: {
      type: Boolean,
      default: false,
    },
  },
  components: { supplierInfo, supplierEditForm },
  data() {
    return {
      loading: true,
      supplierId: '',
      isEdit: false,
      isAdd: false,
      direction: 'rtl',
      activeName: 'detail',
      supplierData: {},
      orderImg: require('@/assets/images/store_icon.png'),
    };
  },
  filters: {},
  methods: {
    // 关闭弹框
    handleClose() {
      if(this.isEdit || this.isAdd) {
        this.$refs.editForm.resetData();
        this.$refs.editForm.activeName = 'detail';
      }else{
        this.$refs.supplierInfo.activeName = 'detail';
      }
      this.$emit('closeDrawer');
    },
    // 提交编辑信息
    submitInfo(){
      this.$refs.editForm.submitInfo();
    },
    // 信息初始化
    initData(){
      this.supplierData = {
        is_trader:0
      }
      this.isEdit = false;
      this.isAdd = true;
      this.loading = false;
    },
    // 获取供应商信息
    getInfo(id) {
      this.supplierId = id
      this.isAdd = false;
      getSupplierInfo(id).then((res) => {
        this.loading = false;
        this.drawer = true;
        this.supplierData = res.data;
      }).catch((res) => {
        this.$message.error(res.message);
      });
    },
    // 编辑成功回调
    editSuccess(){
      if(this.isAdd){
        this.handleClose();
      }else{
        this.isEdit = false;
      }
      this.$emit('getList')
    },
  },
};
</script>

<style lang="scss" scoped>
.head {
  padding: 20px 20px 10px;
  .full {
    display: flex;
    align-items: center;
    .order_icon {
      width: 60px;
      height: 60px;
    }
    .text {
      align-self: center;
      flex: 1;
      min-width: 0;
      padding-left: 12px;
      font-size: 13px;
      color: #606266;
      .title {
        margin-bottom: 10px;
        font-weight: 500;
        font-size: 16px;
        line-height: 16px;
        color: #282828;
      }
    }
  }
  .bold{
    font-weight: bold;
  }
  .list {
    display: flex;
    margin-top: 20px;
    overflow: hidden;
    list-style: none;
    padding: 0;
    .item {
      flex: none;
      width: 200px;
      font-size: 14px;
      line-height: 14px;
      color: rgba(0, 0, 0, 0.85);
      .title {
        margin-bottom: 12px;
        font-size: 13px;
        line-height: 13px;
        color: #666666;
      }
    }
  }
}
.el-tabs--border-card {
  box-shadow: none;
  border-bottom: none;
}
.section {
  padding: 20px 0 5px;
  border-bottom: 1px dashed #eeeeee;
  .title {
    padding-left: 10px;
    border-left: 3px solid #437FFD;
    font-size: 15px;
    line-height: 15px;
    color: #303133;
  }
  .list {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
  }
  .item {
    flex: 0 0 calc(100% / 2);
    display: flex;
    margin-top: 16px;
    font-size: 13px;
    color: #606266;

    &:nth-child(2n + 1) {
      padding-right: 20px;
      padding-left: 20px;
    }
    &:nth-child(2n) {
     padding-right: 20px;
    }
  }
  .value {
    flex: 1;
    image {
      display: inline-block;
      width: 40px;
      height: 40px;
      margin: 0 12px 12px 0;
      vertical-align: middle;
    }
  }
}
.tab {
  display: flex;
  align-items: center;
  .el-image {
    width: 36px;
    height: 36px;
    margin-right: 10px;
  }
}
/deep/.el-drawer__body {
  overflow: auto;
}
.gary {
  color: #aaa;
}
.footer{
  width: 100%;
  text-align: center;
  position: absolute;
  bottom: 17px;
  padding-top: 17px;
  border-top: 1px dashed #eeeeee;
}
</style>
