<template>
  <div class="baseinfo-container">
    <basicInfoVue ref="basicInfoVueRef" />
    <!-- <el-descriptions title="" :column="4" size="medium" border>
      <el-descriptions-item>
        <template slot="label"> 分类 </template>
        {{ categoryObj.categoryLevelName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 编码 </template>
        {{ categoryObj.code }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 名称 </template>
        {{ categoryObj.name }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 牌号</template>
        {{ categoryObj.brandNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 型号 </template>
        {{ categoryObj.modelType }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 规格 </template>
        {{ categoryObj.specification }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 计量单位 </template>
        {{ categoryObj.measuringUnit }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 重量单位 </template>
        {{ categoryObj.weightUnit }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 包装单位 </template>
        {{ categoryObj.packingUnit }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 体积 </template>
        {{ categoryObj.volume }}{{ '/' + categoryObj.volumeUnit }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 毛重 </template>
        {{ categoryObj.roughWeight }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">净重 </template>
        {{ categoryObj.netWeight }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">所属部门 </template>
        {{ depInfo.groupName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">负责人 </template>
        {{ depInfo.name }}
      </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>
        {{
          categoryMold.shrinkEffictive
            ? categoryMold.shrinkEffictive + '%'
            : null
        }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 芯杆数量 </template>
        {{ categoryMold.coreBarNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 模孔数量</template>
        {{ categoryMold.dieHoleNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 上冲头数量</template>
        {{ categoryMold.upperPunchNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 下冲头数量</template>
        {{ categoryMold.downPunchNum }}
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label"> 最大冲压次数</template>
        {{ categoryMold.maxCyTimes }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 大模体型号 </template>
        {{ categoryMold.maxMoldType }}
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label"> 芯棒直径 </template>
        {{ categoryMold.mandrelDiameter }}
      </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.fixCode }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 冲压次数</template>
        <!-- {{ info.processName }} -->
      </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-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>

    <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>
        {{ dictType[categoryWms.isWarn] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">允许拆包</template>
        {{ dictType[categoryWms.isUnpack] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">安全库存</template>
        {{ categoryWms.secureInventory }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">最小库存</template>
        {{ categoryWms.minInventory }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label"> 最大库存</template>
        {{ categoryWms.maxInventory }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">盘点模式</template>
        {{ dictPd[categoryWms.inventoryMode] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">质保预警参考</template>
        <!-- <DictSelection
                dictName="质保预警参考"
                clearable
                v-model="categoryWms.warrantyWarnRefer"
              >
              </DictSelection> -->
        {{ categoryWms.warrantyWarnRefer }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">保质期</template>
        {{ categoryWms.warrantyPeriod ? categoryWms.warrantyPeriod + '/' : null
        }}{{ categoryWms.warrantyPeriodUnit }}
      </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>
        {{ dictType[categoryMes.isCompleteSet] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">消耗波动</template>
        {{ categoryMes.consumWave ? categoryMes.consumWave + '%' : null }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">变动损耗率</template>
        {{
          categoryMes.changeLossRate ? categoryMes.changeLossRate + '%' : null
        }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">固定损耗数</template>
        {{ categoryMes.fixLossNum }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">排程类型</template>
        {{ categoryMes.apsType }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">允许改型</template>
        {{ dictType[categoryMes.isModify] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">允许返工返修</template>
        {{ dictType[categoryMes.isRework] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">是否返回料</template>
        {{ dictType[categoryMes.isRematerial] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">是否副产品</template>
        {{ dictType[categoryMes.isByProduct] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">是否废品</template>
        {{ dictType[categoryMes.isWaste] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">是否不良品</template>
        {{ dictType[categoryMes.isDefective] }}
      </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>
        {{ categoryAps.fixLeadTime }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">变动提前期</template>
        {{ categoryAps.changeLeadTime }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">检验提前期</template>
        {{ categoryAps.checkLeadTime }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">累计提前期</template>
        {{ categoryAps.cumLeadTime }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">提前期单位</template>
        {{ categoryAps.unit }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">订货间隔期</template>
        {{
          categoryAps.orderIntervalTime
            ? categoryAps.orderIntervalTime + '/'
            : null
        }}{{ categoryAps.orderIntervalUnit }}
      </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>
        {{ dictType[categoryQms.isComeCheck] }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">检验方案</template>
        {{ categoryQms.checkFormula }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">采购组织</template>
        {{ cgInfo.groupName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">采购员</template>
        {{ cgInfo.name }}
      </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>
        {{ categoryObj.fileName }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">备注</template>
        {{ categoryObj.remark }}
      </el-descriptions-item>
    </el-descriptions>

    <div class="basic-details-title border-none">
      <span class="border-span">关联信息</span>
    </div>
    <linkMsg
      ref="linkMsgRef"
      :id="categoryObj.id"
      :categoryLevelId="categoryObj.categoryLevelId"
      :categoryLevelGroupId="categoryObj.categoryLevelGroupId"
    />

    <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';
  import { getDetailInfo } from '@/api/material/list';
  import { getUserPage } from '@/api/system/organization';
  import { sysDict } from '@/utils/sys';
  import linkMsg from '../../equipment/components/link-msg.vue';
  import basicInfoVue from '../../components/basicInfo.vue';
  export default {
    props: {
      rowId: {
        type: String,
        default: ''
      }
    },
    components: { linkMsg, basicInfoVue },
    data() {
      return {
        categoryMold: {},
        cgInfo: {},
        categoryQms: {},
        categoryAps: {},
        categoryMes: {},
        categoryWms: {},
        dictType: {
          1: '是',
          0: '否'
        },
        dictPd: {
          1: '逐个盘点',
          2: '批量盘点'
        },
        categoryObj: {},
        fileList: [
          { t_name: '使用说明书' },
          { t_name: '生产许可证书' },
          { t_name: '防爆合格证书' },
          { t_name: '检验报告' },
          { t_name: '检验周期说明' },
          { t_name: '图纸资料' },
          { t_name: '产品合格证' }
        ],
        info: {
          baseInfo: {},
          extInfoSelf: [],
          extraInfo: {}
        },
        // 设备图片
        imageUrl: '',
        sourceType: null,
        depList: [],
        depInfo: {}
      };
    },
    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.length > 0 && 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);
            });
          }
          this.searchMoudol(data.category.category.id);
        }
      },
      async searchMoudol(id) {
        const res = await getDetailInfo(id);
        console.log(res);
        this.categoryObj = {
          ...res.category,
          // deptId:
          fileName: res.category.remarkAttach
            ? res.category.remarkAttach.map((item) => item.name).join(', ')
            : ''
        };
        this.$nextTick(() => {
          this.$refs.basicInfoVueRef.getDetailInfoAugr(this.categoryObj);
        });
        await this.searchDeptNodeClick(res.category.deptLeaderId);
        for (const key in this.depList) {
          if (this.depList[key].id == res.category.deptId) {
            this.depInfo = this.depList[key];
            break;
          }
        }
        for (const key in this.depList) {
          if (this.depList[key].id == res.categoryQms.checkPerson) {
            console.log('++', this.depList[key]);
            this.cgInfo = this.depList[key];
            break;
          }
        }

        this.categoryWms = {
          ...res.categoryWms,
          warrantyPeriodUnit: await sysDict(
            '保质期单位',
            res.categoryWms.warrantyPeriodUnit
          ),
          warrantyWarnRefer: await sysDict(
            '质保预警参考',
            res.categoryWms.warrantyWarnRefer
          )
        };
        this.categoryMes = {
          ...res.categoryMes,
          apsType: await sysDict('排程类型', res.categoryMes.apsType)
        };
        this.categoryAps = {
          ...res.categoryAps,
          orderIntervalUnit: await sysDict(
            '提前期单位',
            res.categoryAps.orderIntervalUnit
          ),
          unit: await sysDict('提前期单位', res.categoryAps.unit)
        };
        this.categoryQms = {
          ...res.categoryQms,
          checkFormula: await sysDict('检验方案', res.categoryQms.checkFormula)
        };
        this.categoryMold = { ...res.categoryMold };
      },
      // 选择所属部门
      async searchDeptNodeClick(id, ids) {
        // 根据部门获取人员
        const res = await getUserPage({
          pageNum: 1,
          size: -1,
          executeGroupId: id ? id : ''
        });
        this.depList = res.list;
      },

      // 打开详情弹窗
      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>
