<template>
  <div class="detail-box">
    <el-descriptions title="" :column="5" size="medium" border>
      <el-descriptions-item label="类型标识">
        {{ baseInfo.classificationCode }}
      </el-descriptions-item>
      <el-descriptions-item label="物品类型">
        {{ getDictValue('物品类型', baseInfo.assetType) }}
      </el-descriptions-item>
      <el-descriptions-item label="物品编码">
        {{ baseInfo.assetCode }}
      </el-descriptions-item>
      <el-descriptions-item label="物品名称">
        {{ baseInfo.assetName }}
      </el-descriptions-item>
      <el-descriptions-item label="允许拆包">
        {{ baseInfo.isUnpack ? '是' : '否' }}
      </el-descriptions-item>

      <el-descriptions-item
        :label="item.label"
        v-for="(item, index) in uniqueData"
        :key="index"
      >
        <template v-if="item.formatter">{{
          item.formatter(baseInfo)
        }}</template>
        <template v-else>{{ baseInfo[item.prop] }}</template>
      </el-descriptions-item>

      <el-descriptions-item label="分类">
        {{ baseInfo.classificationUrl }}
      </el-descriptions-item>
      <el-descriptions-item label="计量单位">
        {{ baseInfo.unit }}
      </el-descriptions-item>
      <el-descriptions-item label="安全库存">
        {{ baseInfo.safeStock }}
      </el-descriptions-item>
      <el-descriptions-item label="实时库存">
        {{ baseInfo.realInventoryNum }}
      </el-descriptions-item>
      <el-descriptions-item label="锁单数量">
        <!-- {{ baseInfo.assetType }} -->
      </el-descriptions-item>
      <el-descriptions-item label="空闲数量">
        <!-- {{ baseInfo.assetType }} -->
      </el-descriptions-item>
      <!-- <el-descriptions-item label="允许转资产">
        {{ baseInfo.assetType }}
      </el-descriptions-item> -->
      <el-descriptions-item label="包装单位">
        {{ baseInfo.minPackUnit }}
      </el-descriptions-item>
      <!-- <el-descriptions-item label="包装数量">
        {{ baseInfo.outInNum }}{{ baseInfo.minPackUnit }}
      </el-descriptions-item> -->
      <el-descriptions-item label="保质期">
        <template
          v-if="baseInfo.expirationDate || baseInfo.expirationDate === 0"
        >
          {{ baseInfo.expirationDate
          }}{{ dateDict[baseInfo.expirationDateUnit] }}
        </template>
      </el-descriptions-item>
      <el-descriptions-item label="库存累计重量" v-if="baseInfo.assetType == 4">
      </el-descriptions-item>
      <el-descriptions-item
        :label="item.key"
        v-for="(item, index) in selfDefinedParameter"
        :key="index"
      >
        {{ item.value }}
      </el-descriptions-item>
      <el-descriptions-item label="描述" :span="5">
        {{ baseInfo.description }}
      </el-descriptions-item>
    </el-descriptions>
    <!-- 模具、物料 -->
    <template v-if="[6, 3].includes(baseInfo.assetType)">
      <div class="basic-details-title border-none">
        <span class="border-span">匹配产品</span>
      </div>
      <el-descriptions title="" :column="5" size="medium" border>
        <el-descriptions-item
          v-for="(item, index) in productData"
          :key="index"
          :label="item.informationCode"
        >
          {{ item.informationName }}
        </el-descriptions-item>
      </el-descriptions>
    </template>
    <!-- 生产设备、产品 -->
    <template v-if="[1, 4].includes(baseInfo.assetType)">
      <div class="basic-details-title border-none">
        <span class="border-span">匹配模具</span>
      </div>
      <el-descriptions title="" :column="5" size="medium" border>
        <el-descriptions-item
          v-for="(item, index) in mouldData"
          :key="index"
          :label="item.informationCode"
        >
          {{ item.informationName }}
        </el-descriptions-item>
      </el-descriptions>
    </template>
    <!-- 生产设备 -->
    <!-- <template v-if="[1].includes(baseInfo.assetType)"> -->
	<template>
      <!-- <div class="basic-details-title border-none">
        <span class="border-span">匹配备品备件</span>
      </div> -->
	  <HeaderTitle title="匹配备品备件" size="16px"></HeaderTitle>
      <el-descriptions title="" :column="5" size="medium" border>
        <el-descriptions-item
          v-for="(item, index) in partData"
          :key="index"
          :label="item.informationCode"
        >
          {{ item.informationName }}
        </el-descriptions-item>
      </el-descriptions>
    </template>
    <!-- 模具、备品备件 -->
    <!-- <template v-if="[6, 7].includes(baseInfo.assetType)"> -->
	<template>
      <!-- <div class="basic-details-title border-none">
        <span class="border-span">匹配设备</span>
      </div> -->
	  <HeaderTitle title="匹配设备" size="16px"></HeaderTitle>
      <el-descriptions title="" :column="5" size="medium" border>
        <el-descriptions-item
          v-for="(item, index) in facilityData"
          :key="index"
          :label="item.informationCode"
        >
          {{ item.informationName }}
        </el-descriptions-item>
      </el-descriptions>
    </template>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
// import { getDetails as getMatchData } from '@/api/stockManagement/itemInformation'
export default {
  data () {
    return {
      productData: [],
      mouldData: [],
      partData: [],
      bomData: [],
      facilityData: [],
      dateDict: {
        minute: '分钟',
        hour: '小时',
        day: '天',
        month: '月',
        year: '年'
      }
    }
  },
  props: {
    baseInfo: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    ...mapGetters(['getDictValue']),
    selfDefinedParameter () {
			[]
      // return JSON.parse(this.baseInfo.selfDefinedParameter) || []
    },
    uniqueData () {
      switch (+this.baseInfo.assetType) {
        case 3: //物料
          return [{ label: '牌号', prop: 'brandNum' }]
        case 8: //耗材
          return [
            { label: '型号', prop: 'modelType' },
            { label: '规格', prop: 'specification' }
          ]
        case 4: //产品
          return [
            { label: '牌号', prop: 'brandNum' },
            { label: '型号', prop: 'modelType' },
            {
              label: '标准单重',
              prop: 'modelType',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return `${extendField.unqualifiedRate || '-'}KG`
              }
            },
            {
              label: '不良品率',
              prop: 'modelType',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return `${extendField.unqualifiedRate || '-'}%`
              }
            }
          ]
        case 5: //'周转车'
          return [
            { label: '规格', prop: 'specification' },
            {
              label: '材质',
              prop: 'texture',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return extendField.texture
              }
            },
            {
              label: '长宽高',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return `${extendField.length || '-'}/${
                  extendField.width || '-'
                }/${extendField.high || '-'}`
              }
            }
          ]
        case 2: //'舟皿'
          return [
            { label: '规格', prop: 'specification' },
            { label: '型号', prop: 'modelType' },
            {
              label: '角度',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)

                return { notA: '非A', A: 'A' }[extendField.angle]
              }
            },
            {
              label: '长宽高',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return `${extendField.length || '-'}*${
                  extendField.width || '-'
                }*${extendField.high || '-'}`
              }
            }
          ]
        case 1: //'设备'
          return [
            { label: '型号', prop: 'modelType' },
            { label: '规格', prop: 'specification' }
          ]
        case 6: //'模具'
          return [
            { label: '牌号', prop: 'brandNum' },
            { label: '型号', prop: 'modelType' },
            {
              label: '大模体型号',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return extendField.dieBodyModel
              }
            },
            {
              label: '最大冲压次数',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return extendField.maximumStampingTimes
              }
            },
            {
              label: '收缩系数',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return extendField.shrinkageCoefficient
              }
            },
            {
              label: '芯杆数量',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return extendField.mandrelNum
              }
            },
            {
              label: '模孔数量',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return extendField.dieHoleNum
              }
            },
            {
              label: '上冲头数量',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return extendField.upperPunchNum
              }
            },
            {
              label: '下冲头数量',
              prop: '',
              formatter (row) {
                if (!row?.extendField) return ''
                const extendField = JSON.parse(row.extendField)
                return extendField.lowerPunchNum
              }
            }
          ]
        case 7: //'备品备件'
          return [
            { label: '规格', prop: 'specification' },
            { label: '型号', prop: 'modelType' }
          ]
      }

      return []
    }
  },
  created () {
    // this.requestDict('物品类型')
    // this._getMatchData()
  },
  methods: {
    ...mapActions('dict', ['requestDict']),
    async _getMatchData () {
      const res = await getMatchData({ id: this.baseInfo.materialId })
      if (res?.success) {
        for (const key in res.data.informationRelationMap) {
          this.matchList(key, res.data.informationRelationMap)
        }
      }
    },
    matchList (key, data) {
      switch (key) {
        case 'w01': {
          this.facilityData = data[key]
          break
        }
        case 'w04': {
          this.mouldData = data[key]
          break
        }
        case 'w05': {
          this.partData = data[key]
          break
        }
        case 'w07': {
          this.productData = data[key]
          break
        }
        default:
          break
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-box{
	margin: 0 auto;
	.el-descriptions{
		margin: 20px 0;
	}
}
</style>
