<template>
  <div class="baseinfo-container">
    <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.code }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 名称 </template>
        {{ info.name }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 牌号</template>
        {{ info.baseInfo.brandNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 型号 </template>
        {{ info.baseInfo.modelType }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 大模体型号 </template>
        {{ info.extraInfo.dieBodyModel }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 芯杆数量 </template>
        {{ info.extraInfo.mandrelNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 模孔数量</template>
        {{ info.extraInfo.dieHoleNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 收缩系数</template>
        {{ info.extraInfo.shrinkageCoefficient }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 下冲头数量 </template>
        {{ info.extraInfo.lowerPunchNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 上冲头数量 </template>
        {{ info.extraInfo.upperPunchNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 最大冲压次数</template>
        {{ info.extraInfo.maximumStampingTimes }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label" :span="2"> 分类 </template>
        {{ info.baseInfo.categoryLevelPath }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 采购日期 </template>
        <!-- {{info.warehouseDetail.procurementTime}} -->
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 过保日期 </template>
        <!-- {{info.warehouseDetail.expirationTime}} -->
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 计量单位</template>
        {{ info.baseInfo.measuringUnit }}
      </el-descriptions-item>
    </el-descriptions>

    <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.warehouseDetail.createTime}} -->
      </el-descriptions-item>
      <el-descriptions-item :span="2">
        <template slot="label">
          {{ sourceType == 1 ? '入库单号' : '出库单号' }}
        </template>
        <!-- <el-link style="color: #70B603" @click="jumpDetails">{{info.warehouseDetail.bizNum}}</el-link> -->
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 所属工序</template>
        {{ info.processName }}
      </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>
    <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>

    <!--    <DetailsDialog
      ref="detailsDialogRef"
    /> -->
  </div>
</template>

<script>
  import { getImageUrl } from '@/utils/file.js';
  import { getFile } from '@/api/system/file/index.js';
  import { getAssetInfo } from '@/api/ledgerAssets';
  import { getDetails } from '@/api/classifyManage/itemInformation';
  export default {
    props: {
      rowId: {
        type: String,
        default: ''
      }
    },
    // components: { DetailsDialog },
    data() {
      return {
        fileList: [
          { t_name: '使用说明书' },
          { t_name: '生产许可证书' },
          { t_name: '防爆合格证书' },
          { t_name: '检验报告' },
          { t_name: '检验周期说明' },
          { t_name: '图纸资料' },
          { t_name: '产品合格证' }
        ],
        info: {
          baseInfo: {},
          extInfoSelf: [],
          extraInfo: {}
        },
        // 设备图片
        imageUrl: '',
        sourceType: null
      };
    },
    created() {
      this.getDetilInfo();
    },
    methods: {
      async getDetilInfo() {
        const data = await getAssetInfo(this.rowId);
        if (data) {
          this.info = data;
          this.$set(this.info, 'baseInfo', data.category.category);
          this.$set(this.info, 'extraInfo', data.category.categoryMold);
          this.sourceType = data.positionList[0].type;
          // 设备图片
          if (typeof data.imageUrl != 'string') {
            this.imageUrl = getImageUrl(data.imageUrl.storePath);
          }
          if (data.attUrl && data.attUrl.length > 0) {
            // 文档信息
            data.attUrl.forEach((item, index) => {
              Object.assign(this.fileList[item.sort - 1], item);
            });
          }
        }
      },

      // 打开详情弹窗
      jumpDetails() {
        if (!this.info.warehouseDetail) {
          return;
        }
        this.$refs.detailsDialogRef.init(
          this.info.warehouseDetail,
          this.sourceType
        );
      },

      openfile(row) {
        if (row.accessUrl) {
          fileSystemDownload(row);
        }
      }
    }
  };
</script>

<style lang="scss" scoped>
  .baseinfo-container {
    background-color: #fff;
    padding: 0px 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>
