<template>
  <div class="baseInfo">
    <el-form ref="form" :model="dataInfo">
      <el-col :span="4" label-width="80px">
        <el-form-item label="类型:" prop="type">
          {{
            dataInfo.bomType == 1
              ? 'PBOM'
              : dataInfo.bomType == 2
              ? 'MBOM'
              : dataInfo.bomType == 3
              ? 'ABOM'
              : dataInfo.bomType == 4
              ? 'EBOM'
              : ''
          }}
        </el-form-item>
      </el-col>

      <el-row>
        <el-col :span="5" label-width="78px">
          <el-form-item label="BOM编码:" prop="type">
            {{ dataInfo.code }}
          </el-form-item>
        </el-col>
        <el-col :span="5" label-width="78px">
          <el-form-item label="BOM名称:" prop="type">
            {{ dataInfo.name }}
          </el-form-item>
        </el-col>
        <el-col :span="4" label-width="78px">
          <el-form-item label="版本号:" prop="type">
            <span v-if="dataInfo.versions.includes('V')">{{
              dataInfo.versions
            }}</span>
            <span v-else> V{{ dataInfo.versions }}.0</span>
          </el-form-item>
        </el-col>
        <el-col :span="4" label-width="80px">
          <el-form-item label="审批状态:" prop="type">
            <el-select
              size="mini"
              style="width: 120px"
              disabled
              v-model="dataInfo.approvalStatus"
              placeholder="请选择"
            >
              <el-option
                v-for="item in statusOptions"
                :label="item.label"
                :value="item.value"
                :key="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="2" label-width="78px">
          <el-button
            type="text"
            @click="handleEdit"
            v-if="
              dataInfo.approvalStatus != 1 &&
              dataInfo.approvalStatus != 2 &&
              dataInfo.parentId == '0'
            "
          >
            编辑</el-button
          >
        </el-col>
      </el-row>

      <el-button
        type="primary"
        size="medium"
        v-if="dataInfo.parentId != '0' && dataInfo.resourceBomId"
        @click="bomConfig"
        >跳转来源版本</el-button
      >
    </el-form>

    <baseInfoSave
      v-if="baseInfoShow"
      @close="baseClose"
      :categoryObj="dataInfo"
      :isEdit="true"
    ></baseInfoSave>

    <BomDetailsPop ref="bomDrawer"></BomDetailsPop>
  </div>
</template>

<script>
  import baseInfoSave from './baseInfoSave.vue';
  import BomDetailsPop from './detailsPop.vue';
  export default {
    components: {
      baseInfoSave,
      BomDetailsPop
    },
    data() {
      return {
        baseInfoShow: false,
        statusOptions: [
          {
            label: '审批通过',
            value: 2
          },
          {
            label: '审批中',
            value: 1
          },
          {
            label: '草稿',
            value: 0
          },
          {
            label: '审核不通过',
            value: 3
          }
        ]
      };
    },
    props: {
      dataInfo: {
        type: Object,
        default() {
          return {};
        }
      }
    },

    mounted() {
      console.log(this.dataInfo, 'baseClose');
    },

    methods: {
      handleEdit() {
        this.baseInfoShow = true;
      },

      baseClose(formData) {
        if (formData) {
          this.$set(this.dataInfo, 'code', formData.code);
          this.$set(this.dataInfo, 'name', formData.name);
          this.$forceUpdate();
        }
        this.baseInfoShow = false;
      },

      bomConfig() {
        this.$emit('getNewBomData', this.dataInfo);
        // let rowData = {
        //   categoryId: this.dataInfo.categoryId,
        //   categoryName: this.dataInfo.name,
        //   code: this.dataInfo.code,
        //   versions: this.dataInfo.resourceBomVersion,
        //   rootPathIdParent: this.dataInfo.categoryLevelPathIdParent,
        //   isProduct: this.dataInfo,
        //   bomType: Number(this.dataInfo.bomType),
        //   isTemp: this.dataInfo.isTemp
        // }
        // this.$refs.bomDrawer.open(rowData);
        // this.open(rowData);
        // console.log(this.$refs, 'refs');
      }
    }
  };
</script>

<style lang="scss" scoped>
  .baseInfo {
    padding: 2px;
    box-sizing: border-box;
    border: 1px solid #f1f2f2;
  }
  .el-form-item {
    margin-bottom: 2px;
  }
</style>
