<template>
  <div>
    <p-card
      style="margin-bottom:20px;"
      :tab-list="infoMain.mainList"
      :active-tab-key="infoMain.checkedKey"
      @tabChange="key => (infoMain.checkedKey = key)"
    >
      <template v-for="subitem of infoMain.mainList">
        <div
          v-show="infoMain.checkedKey === subitem.key"
          :key="subitem.key"
          :style="{ height: infoMain.height || 'auto' }"
          class="box-main"
        >
          <p-grid-form
            :ref="subitem.key"
            :span="6"
            :labelCol="{ span: 5 }"
            :wrapperCol="{ span: 19 }"
            :items="subitem.config"
          />
        </div>
      </template>
    </p-card>
    <p-card
      style="margin-bottom:20px;"
      :tab-list="infoMain.detailList"
      :active-tab-key="infoMain.detailCheckedKey"
      @tabChange="key => (infoMain.detailCheckedKey = key)"
    >
      <template v-for="(subitem, index) of infoMain.detailList">
        <div v-show="infoMain.detailCheckedKey === subitem.key" :key="subitem.key" class="box-main">
          <div v-if="subitem.type == 'table'">
            <p-table
              :columns="subitem.config"
              :data-source.sync="dataSource"
              :rowKey="String(index)"
              :has-row-count="true"
              :scroll="{ x: true }"
            ></p-table>
          </div>
          <div v-if="subitem.type == 'from'">
            <p-grid-form
              :ref="subitem.key"
              :span="6"
              :labelCol="{ span: 5 }"
              :wrapperCol="{ span: 19 }"
              :items="subitem.config"
            />
          </div>
        </div>
      </template>
    </p-card>
  </div>
</template>
<script>
import { itemMain, itemExtend, itemPack, itemPurchase, itemSave, itemHealth } from '../config/itemDetail'
const infoMain = self => {
  return {
    checkedKey: 'itemMain',
    height: '220px',
    mainList: [
      {
        key: 'itemMain',
        tab: '商品属性',
        config: itemMain(self)
      },
      {
        key: 'itemExtend',
        tab: '扩展属性',
        config: itemExtend(self)
      }
    ],
    detailCheckedKey: 'itemHealth',
    detailList: [
      {
        key: 'itemHealth',
        tab: '大健康属性',
        type: 'from',
        config: itemHealth(self)
      },
      {
        key: 'itemPack',
        tab: '包装属性',
        type: 'table',
        config: itemPack(self)
      },
      {
        key: 'itemPurchase',
        tab: '采销属性',
        type: 'from',
        config: itemPurchase(self)
      },
      {
        key: 'itemSave',
        tab: '存储属性',
        type: 'from',
        config: itemSave(self)
      }
    ]
  }
}
export default {
  props: {
    detailData: {
      // 商品详情数据
      type: Object,
      default: {}
    }
  },
  data() {
    return {
      infoMain: infoMain(this),
      dataSource: [],
      datas: {}
    }
  },
  watch: {
    detailData(newVal) {
      console.log(newVal, 'newValnewValnewVal')
      this.dataSource = newVal ? newVal.baseMtlItemUomConversionsList : []
      this.datas = newVal
      this.setformFun()
      localStorage
    }
  },
  created() {},
  methods: {
    setformFun() {
      this.$refs.itemMain[0].form.setFieldsValue({
        // 商品属性
        itemCode: this.datas.itemCode,
        itemName: this.datas.itemName,
        itemShortName: this.datas.itemShortName,
        itemNameEn: this.datas.itemNameEn,
        manufacturerId: this.datas.manufacturerId,
        countryOriginId: this.datas.countryOriginId,
        itemAssistantCode: this.datas.itemAssistantCode,
        specification: this.datas.specification,
        status: this.datas.status,
        isEnable: this.datas.isEnable ? true : false,
        itemDesc: this.datas.itemDesc
      })
      this.$refs.itemExtend[0].form.setFieldsValue({
        // 扩展属性
        cargoOwnerName: this.datas.baseMtlItemProfiles.cargoOwnerName,
        supplierName: this.datas.baseMtlItemProfiles.supplierName,
        brandId: this.datas.baseMtlItemProfiles.brandId,
        seriesId: this.datas.baseMtlItemProfiles.seriesId,
        shelfLifeDays: this.datas.baseMtlItemProfiles.shelfLifeDays,
        attribute21: this.datas.baseMtlItemProfiles.attribute21,
        attribute22: this.datas.baseMtlItemProfiles.attribute22,
        attribute23: this.datas.baseMtlItemProfiles.attribute23,
        attribute24: this.datas.baseMtlItemProfiles.attribute24,
        attribute25: this.datas.baseMtlItemProfiles.attribute25,
        attribute26: this.datas.baseMtlItemProfiles.attribute26,
        attribute27: this.datas.baseMtlItemProfiles.attribute27,
        attribute28: this.datas.baseMtlItemProfiles.attribute28,
        attribute29: this.datas.baseMtlItemProfiles.attribute29,
        attribute30: this.datas.baseMtlItemProfiles.attribute30
      })
      this.$refs.itemPurchase[0].form.setFieldsValue({
        // 采销属性
        piecePurchasePriceTe: this.datas.baseMtlItemOms.piecePurchasePriceTe,
        piecePurchasePriceTi: this.datas.baseMtlItemOms.piecePurchasePriceTi,
        pieceSalePriceTe: this.datas.baseMtlItemOms.pieceSalePriceTe,
        pieceSalePriceTi: this.datas.baseMtlItemOms.pieceSalePriceTi,
        taxRatePurchase: this.datas.baseMtlItemOms.taxRatePurchase,
        taxRateSale: this.datas.baseMtlItemOms.taxRateSale,
        itemSaleAttribute1: this.datas.baseMtlItemOms.itemSaleAttribute1,
        purchaseIsEnable: this.datas.baseMtlItemOms.purchaseIsEnable ? true : false,
        purchaseReturnIsEnable: this.datas.baseMtlItemOms.purchaseReturnIsEnable ? true : false,
        saleIsEnable: this.datas.baseMtlItemOms.saleIsEnable ? true : false,
        saleReturnIsEnable: this.datas.baseMtlItemOms.saleReturnIsEnable ? true : false
      })
      this.$refs.itemSave[0].form.setFieldsValue({
        // 存储属性
        storeTemperature: this.datas.baseMtlItemWms.storeTemperature,
        abcType: this.datas.baseMtlItemWms.abcType,
        storeUnit: this.datas.baseMtlItemWms.storeUnit,
        codeCollectMode: this.datas.baseMtlItemWms.codeCollectMode,
        shelfLifeDays: this.datas.baseMtlItemWms.shelfLifeDays,
        unsaleDay: this.datas.baseMtlItemWms.unsaleDay,
        inStoreDay: this.datas.baseMtlItemWms.inStoreDay,
        outStoreDay: this.datas.baseMtlItemWms.outStoreDay,
        expiryDateTrackLevel: this.datas.baseMtlItemWms.expiryDateTrackLevel,
        qcGroup: this.datas.baseMtlItemWms.qcGroup,
        palletPlacedRule: this.datas.baseMtlItemWms.palletPlacedRule,
        palletStdQuantity: this.datas.baseMtlItemWms.palletStdQuantity,
        stdCaseFactor: this.datas.baseMtlItemWms.stdCaseFactor,
        itemTemperatureHigh: this.datas.baseMtlItemWms.itemTemperatureHigh,
        itemTemperatureLow: this.datas.baseMtlItemWms.itemTemperatureLow,
        isLock: this.datas.baseMtlItemWms.isLock ? true : false,
        isHosted: this.datas.baseMtlItemWms.isHosted ? true : false,
        itemIsRecheck: this.datas.baseMtlItemWms.itemIsRecheck ? true : false,
        itemIsDangerous: this.datas.baseMtlItemWms.itemIsDangerous ? true : false,
        itemIsFragile: this.datas.baseMtlItemWms.itemIsFragile ? true : false,
        itemIsImported: this.datas.baseMtlItemWms.itemIsImported ? true : false,
        itemIsGift: this.datas.baseMtlItemWms.itemIsGift ? true : false,
        itemIsValuable: this.datas.baseMtlItemWms.itemIsValuable ? true : false,
        itemIsWeighed: this.datas.baseMtlItemWms.itemIsWeighed ? true : false,
        itemIsSpecial: this.datas.baseMtlItemWms.itemIsSpecial ? true : false,
        itemIsSpecialSharped: this.datas.baseMtlItemWms.itemIsSpecialSharped ? true : false,
        itemIsBatch: this.datas.baseMtlItemWms.itemIsBatch ? true : false,
        itemIsSeque: this.datas.baseMtlItemWms.itemIsSeque ? true : false,
        itemIsExpire: this.datas.baseMtlItemWms.itemIsExpire ? true : false,
        itemIsLot: this.datas.baseMtlItemWms.itemIsLot ? true : false,
        reacallIsEnable: this.datas.baseMtlItemWms.reacallIsEnable ? true : false,
        itemIsUnpack: this.datas.baseMtlItemWms.itemIsUnpack ? true : false,
        isCaseOrPiece: this.datas.baseMtlItemWms.isCaseOrPiece ? true : false
      })
      this.$refs.itemHealth[0].form.setFieldsValue({
        // 大健康属性
        itemHealthCategory: this.datas.baseMtlItemHealth.itemHealthCategory,
        itemHealthType: this.datas.baseMtlItemHealth.itemHealthType,
        itemHealthUsage: this.datas.baseMtlItemHealth.itemHealthUsage,
        itemHealthApprovalNbr: this.datas.baseMtlItemHealth.itemHealthApprovalNbr,
        itemHealthIndustry: this.datas.baseMtlItemHealth.itemHealthIndustry,
        itemHealthCommonName: this.datas.baseMtlItemHealth.itemHealthCommonName,
        itemHealthBuyer: this.datas.baseMtlItemHealth.itemHealthBuyer,
        itemHealthRegisterNbr: this.datas.baseMtlItemHealth.itemHealthRegisterNbr,
        itemHealthRecordNbr: this.datas.baseMtlItemHealth.itemHealthRecordNbr,
        itemHealthExitemcode: this.datas.baseMtlItemHealth.itemHealthExitemcode,
        itemHealthChecknote: this.datas.baseMtlItemHealth.itemHealthChecknote,
        itemHealthStorenote: this.datas.baseMtlItemHealth.itemHealthStorenote,
        itemHealthCertificateNbr: this.datas.baseMtlItemHealth.itemHealthCertificateNbr,
        itemHealthOtcFlag: this.datas.baseMtlItemHealth.itemHealthOtcFlag,
        maintainCycle: this.datas.baseMtlItemHealth.maintainCycle,
        certificateStartdate: this.datas.baseMtlItemHealth.certificateStartdate,
        certificateEnddate: this.datas.baseMtlItemHealth.certificateEnddate,
        itemHealthRegisterNbrEn: this.datas.baseMtlItemHealth.itemHealthRegisterNbrEn,
        itemHealthListedLicensor: this.datas.baseMtlItemHealth.itemHealthListedLicensor,
        itemHealthProduceLicense: this.datas.baseMtlItemHealth.itemHealthProduceLicense,
        itemHealthTwovoteflag: this.datas.baseMtlItemHealth.itemHealthTwovoteflag ? true : false,
        itemHealthIsPrintedDrug: this.datas.baseMtlItemHealth.itemHealthIsPrintedDrug ? true : false,
        itemHealthIsProtected: this.datas.baseMtlItemHealth.itemHealthIsProtected ? true : false,
        itemHealthIsDouble: this.datas.baseMtlItemHealth.itemHealthIsDouble ? true : false,
        itemHealthErrorproneflag: this.datas.baseMtlItemHealth.itemHealthErrorproneflag ? true : false,
        isBacteria: this.datas.baseMtlItemHealth.isBacteria ? true : false,
        isInstrument: this.datas.baseMtlItemHealth.isInstrument ? true : false,
        itemHealthSuperviseflag: this.datas.baseMtlItemHealth.itemHealthSuperviseflag ? true : false,
        itemHealthAnticrossingflag: this.datas.baseMtlItemHealth.itemHealthAnticrossingflag ? true : false,
        itemHealthFirstopstatus: this.datas.baseMtlItemHealth.itemHealthFirstopstatus ? true : false,
        itemHealthIsNed: this.datas.baseMtlItemHealth.itemHealthIsNed ? true : false,
        itemHealthSubpackflag: this.datas.baseMtlItemHealth.itemHealthSubpackflag ? true : false,
        isDelegate: this.datas.baseMtlItemHealth.isDelegate ? true : false,
        isCheck: this.datas.baseMtlItemHealth.isCheck ? true : false,
        isProtected: this.datas.baseMtlItemHealth.isProtected ? true : false,
        isHerbalSlices: this.datas.baseMtlItemHealth.isHerbalSlices ? true : false,
        isHerbal: this.datas.baseMtlItemHealth.isHerbal ? true : false,
        isPsychotropicDrugsOne: this.datas.baseMtlItemHealth.isPsychotropicDrugsOne ? true : false,
        isPsychotropicDrugsTwo: this.datas.baseMtlItemHealth.isPsychotropicDrugsTwo ? true : false,
        isEfedrina: this.datas.baseMtlItemHealth.isEfedrina ? true : false,
        isToxicDrugs: this.datas.baseMtlItemHealth.isToxicDrugs ? true : false,
        isEasyToxicDrugs: this.datas.baseMtlItemHealth.isEasyToxicDrugs ? true : false,
        isStupefacient: this.datas.baseMtlItemHealth.isStupefacient ? true : false,
        isPreventionMaterial: this.datas.baseMtlItemHealth.isPreventionMaterial ? true : false,
        preventionNum: this.datas.baseMtlItemHealth.preventionNum
      })
    }
  }
}
</script>

<style></style>
