<template>
  <div class="baseinfo-container">
    <basicInfoVue ref="basicInfoRef" />

    <div class="basic-details-title border-none">
      <span class="border-span">投产信息</span>
    </div>
    <el-descriptions title="" :column="4" size="medium" border>
      <el-descriptions-item>
        <template slot="label"> 固资编码 </template>
        {{ info.fixCode }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 权属部门 </template>
        {{ info.ownershipDeptName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 品牌</template>
        {{ info.brand }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 供应商</template>
        {{ info.supplierName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 供应商电话 </template>
        {{ info.supplierMobile }}
      </el-descriptions-item>
    </el-descriptions>

    <warehouseConfigVue ref="warehouseConfigRef" />
    <productInfoVue ref="productInfoRef" />
    <planVue ref="planRef" />
    <qualityConfig ref="qualityConfigRef" />
    <footerVue ref="footerVueRef" />

    <div class="basic-details-title border-none">
      <span class="border-span">文档信息</span>
    </div>
    <div class="upload-container">
      <div class="img-box">
        <img src="~@/assets/upload-placeholder.svg" alt="" v-if="!imageUrl" />
        <img v-else :src="imageUrl" alt="设备图片" />
      </div>
      <div class="file-list">
        <div
          :class="{ disabled: !item.storePath }"
          @click="openfile(item)"
          v-for="(item, index) in fileList"
          :key="index"
          class="file-box"
        >
          {{ item.t_name }}
        </div>
      </div>
    </div>

    <div class="basic-details-title border-none">
      <span class="border-span">扩展信息</span>
    </div>
    <el-descriptions title="" :column="4" size="medium" border>
      <el-descriptions-item
        v-for="(item, index) in info.extInfoSelf"
        :key="index"
        :span="1"
      >
        <template slot="label"> {{ item.key }} </template>
        <div>{{ item.value }}</div>
      </el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script>
  import { getAssetInfo } from '@/api/ledgerAssets';
  import { getDetails } from '@/api/classifyManage/itemInformation';
  import { getImageUrl } from '@/utils/file.js';
  import { getFile } from '@/api/system/file/index.js';

  import basicInfoVue from '../../components/basicInfo.vue';
  import warehouseConfigVue from '../../components/warehouseConfig.vue';
  import productInfoVue from '../../components/productInfo.vue';
  import planVue from '../../components/plan.vue';
  import qualityConfig from '../../components/qualityConfig.vue';
  import footerVue from '../../components/footer.vue';
  export default {
    components: {
      basicInfoVue,
      warehouseConfigVue,
      productInfoVue,
      planVue,
      qualityConfig,
      footerVue
    },
    props: {
      rowId: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        fileList: [
          { t_name: '使用说明书' },
          { t_name: '生产许可证书' },
          { t_name: '防爆合格证书' },
          { t_name: '检验报告' },
          { t_name: '检验周期说明' },
          { t_name: '图纸资料' },
          { t_name: '产品合格证' }
        ],
        info: {
          baseInfo: {},
          extInfoSelf: []
        },
        // 设备图片
        imageUrl: ''
      };
    },

    created() {
      this.getDetilInfo();
    },
    methods: {
      async getDetilInfo() {
        const res = await getAssetInfo(this.rowId);
        if (res) {
          this.info = res;
          this.$set(this.info, 'baseInfo', res.category.category);
          this.$set(
            this.info,
            'extInfoSelf',
            res.extInfoSelf ? res.extInfoSelf : []
          );
          // 设备图片
          if (typeof res.imageUrl != 'string') {
            this.imageUrl = getImageUrl(res.imageUrl.storePath);
          }
          if (res.attUrl && res.attUrl.length > 0) {
            // 文档信息
            res.attUrl.forEach((item, index) => {
              Object.assign(this.fileList[item.sort - 1], item);
            });
          }

          const rep = await getDetails(res.categoryId);
          console.log('==', rep);
          this.$nextTick(() => {
            this.$refs.basicInfoRef.getDetailInfoAugr(rep.category);
            this.$refs.warehouseConfigRef.getDetailInfoAugr(rep.categoryWms);
            this.$refs.productInfoRef.getDetailInfoAugr(rep.categoryMes);
            this.$refs.planRef.getDetailInfoAugr(rep.categoryAps);
            this.$refs.qualityConfigRef.getDetailInfoAugr(rep.categoryQms);
            this.$refs.footerVueRef.getDetailInfoAugr(rep.category);
          });
        }
      },

      openfile(row) {
        if (row.storePath) {
          getFile({ objectName: row.storePath }, row.name);
        }
      }
    }
  };
</script>

<style lang="scss" scoped>
  ::v-deep.baseinfo-container {
    background-color: #fff;
    padding: 0 20px 20px;
    .content {
      padding: 0 20px;
    }
    .basic-details-title {
      font-size: 16px;
      margin: 15px 0;
    }
    .upload-container {
      display: flex;
      .img-box {
        width: 280px;
        height: 342px;
        border: 1px solid rgba(215, 215, 215, 1);
        display: flex;
        justify-content: center;
        align-items: center;
        img {
          max-width: 100%;
        }
      }
      .file-list {
        margin-left: 50px;
        flex: 1;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        justify-items: baseline;
        align-content: flex-start;
        .file-box {
          width: 30%;
          margin-bottom: 20px;
          height: 57px;
          text-align: center;
          line-height: 55px;
          border: 1px solid #1890ff;
          color: #1890ff;
          cursor: pointer;

          &.disabled {
            cursor: not-allowed;
            border-color: rgba(215, 215, 215, 1);
            color: rgba(215, 215, 215, 1);
          }
        }
      }
    }
  }
</style>
