<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <a-card :bordered="false" v-show="visibleDetail" class="card" :title="modalTitle">
    <div v-show="visible">
      <a-row :gutter="48" slot="extra">
        <a-col :md="48" :sm="48">
          <span class="table-page-search-submitButtons" style="float: right">
            <a-button style="margin-left: 8px" type="default" @click="handleMeasure()">检定记录</a-button>
            <a-button style="margin-left: 8px" type="primary" @click="handleCancel()">返回</a-button>
          </span>
        </a-col>
      </a-row>

      <title-divider title="基本信息" width="90px"></title-divider>
      <detail-list title="" :col="3">
        <detail-list-item term="测量设备编号">{{ model.cardNo }}</detail-list-item>
        <detail-list-item term="设备（新号）">{{ model.no }}</detail-list-item>
        <detail-list-item term="设备名称">{{ model.name }}</detail-list-item>
        <detail-list-item term="规格型号">{{ model.model }}</detail-list-item>
        <detail-list-item term="生产商">{{ model.producerId }}</detail-list-item>
        <detail-list-item term="出厂编号">{{ model.zzh }}</detail-list-item>
        <detail-list-item term="要求准确度等级">{{ model.zz }}</detail-list-item>
        <detail-list-item term="使用部门">{{ model.useDept }}</detail-list-item>
        <detail-list-item term="使用位置">{{ model.cph }}</detail-list-item>
        <detail-list-item term="准确度等级">{{ model.fdjxh }}</detail-list-item>
        <detail-list-item term="检定日期">{{ model.checkDate }}</detail-list-item>
        <detail-list-item term="检定周期">{{ model.checkPeriod }}</detail-list-item>
        <detail-list-item term="检定有效期">{{ model.nextCheckDate }}</detail-list-item>
        <detail-list-item term="检定单位">{{ model.dph }}</detail-list-item>
        <detail-list-item term="检定人">{{ model.zaiz }}</detail-list-item>
        <detail-list-item term="检定结论">{{ BaseTool.Object.getField(measureMap,model.rlType) }}</detail-list-item>
        <detail-list-item term="是否周检查">{{ model.color }}</detail-list-item>
        <detail-list-item term="检定证书编号">{{ model.sbdh }}</detail-list-item>
        <detail-list-item term="预警天数">{{ model.seatNumber }}</detail-list-item>
        <detail-list-item term="是否固定资产">{{ model.isFinancing }}</detail-list-item>
        <detail-list-item term="资产编号">{{ model.financingNo }}</detail-list-item>
        <detail-list-item term="管理状态">{{ BaseTool.Object.getField(statusMap,model.status) }}</detail-list-item>
        <detail-list-item term="检定校准记录">{{ model.zbh }}</detail-list-item>
        <detail-list-item term="备注">{{ model.remark }}</detail-list-item>
      </detail-list>
    </div>
    <detail-sb-bom ref="detailSbBomModal" @ok="handleOk"/>
    <detail-sb-check ref="detailSbCheckModal" @ok="handleOk"/>
    <detail-sb-check-job ref="detailSbCheckJobModal" @ok="handleOk"/>
    <detail-sb-measure ref="detailSbMeasureModal" @ok="handleOk"/>
    <detail-sb-info ref="detailSbInfoModal" @ok="handleOk"/>
    <part-info-list ref="partInfoList" />

  </a-card>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import RepairApplicationFormTable from '@/views/repair/application-form/modules/RepairApplicationFormTable'
import CheckJobTable from '@/views/check/checkjob/modules/CheckJobTable'
import SbStatusLogTable from '@/views/sb/status-log/modules/SbStatusLogTable'
import SbStopLogTable from '@/views/sb/stop-logs/modules/SbStopLogTable'
import { fetchFirmProducer } from '@/api/firm/producer'
import { queryNumCheckStandard } from '@/api/check/checkstandard'
import { queryNumCheckjob, queryTuiCalendarIgnores } from '@/api/check/checkjob'
import { queryNumRepairReason } from '@/api/repair/repair-reason'
import { queryNumPartInfo } from '@/api/part/info'
import { queryNumModelbom } from '@/api/sb/modelbom'
import { queryChildNumSbInfo } from '@/api/sb/info'
import SparePartUsedSelectTable from '@/views/sqarepartmanage/sparepartused/modules/SparePartUsedSelectTable'
import SbRunFillPageTable from '@/views/sb/run-fill/modules/SbRunFillPageTable'
import SbInspectionFillPageTable from '@/views/sb/inspection-fill/modules/SbInspectionFillPageTable'
import DetailSbBom from '@/views/sb/modelbom/modules/DetailSbBom'
import DetailSbCheck from '@/views/check/checkstandard/modules/DetailSbCheck'
import DetailSbCheckJob from '@/views/check/checkjob/modules/DetailSbCheckJob'
import DetailSbMeasure from '@/views/sb/measurelog/modules/DetailSbCheck'
import DetailSbInfo from '@/views/sb/info/modules/DetailSbInfo'
import RepairFeeTable from '@/views/repair/fee/modules/RepairFeeTable'
import PartInfoList from '@/views/part/info/modules/PartInfoList'
const DetailListItem = DetailList.Item

export default {
  name: 'SbInfoDetail',
  components: {
    DetailList,
    DetailListItem,
    RepairApplicationFormTable,
    CheckJobTable,
    SparePartUsedSelectTable,
    SbRunFillPageTable,
    SbInspectionFillPageTable,
    DetailSbBom,
    DetailSbCheck,
    DetailSbCheckJob,
    PartInfoList,
    DetailSbMeasure,
    DetailSbInfo,
    RepairFeeTable,
    SbStatusLogTable,
    SbStopLogTable
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      paramList: [],
      visible: false,
      visibleDetail: false,
      activeKey: '3',
      isChildMap: {},
      isShowMap: {},
      collapseActiveKey: '1',
      model: {
        'no': null,
        'financingNo': null,
        'financingNoTwo': null,
        'financingNoThird': null,
        'financingNoFour': null,
        'financingNoFive': null,
        'name': null,
        'zz': null,
        'zbh': null,
        'modelId': null,
        'typeId': null,
        'isShow': null,
        'isChild': null,
        'paramList': null,
        'parentId': null,
        'level': null,
        'useType': null,
        'rate': null,
        'month': null,
        'usedMonth': null,
        'initialValue': null,
        'currentValue': null,
        'cutValue': null,
        'producerId': null,
        // 'sourceType': null,
        // 'sourceSbId': null,
        // 'parentId': null,
        'unit': null,
        // 'position': null,
        // 'guigeId': null,
        'useCompanyName': null,
        'useProjectName': null,
        'useDeptName': null,
        'useGroupName': null,
        'useUserName': null,
        'saveDeptName': null,
        'saveUserName': null,
        'repairUserName': null,
        'repairUserNameSecond': null,
        'totalMiles': null,
        'totalHours': null,
        // 'lastBaoyangTime': null,
        // 'lastBaoyangMiles': null,
        // 'lastBaoyangHours': null,
        // 'baoyangTimes': null,
        'buyDate': null,
        'startDate': null,
        // 'nextCheckDate': null,
        // 'guaranteeDate': null,
        // 'workYear': null,
        // 'retirementDate': null,
        // 'depreciationType': null,
        'wbFile': null,
        'useFile': null,
        'checkFile': null,
        'sbImage': null,
        'sbFileList': null,
        'qrCode': null,
        'status': null,
        'remark': null,
        'remark2': null,
        'parentName': null,
        'createdUserName': null,
        'typeName': null,
        'producerName': null,
        'zzh': null,
        'useDept': null,
        'fdjxh': null,
        'fdjh': null,
        'cph': null,
        'positionId': null,
        'positionName': null,
        'dph': null,
        'rlType': null,
        'color': null,
        'seatNumber': null,
        'registerNo': null,
        'characterType': null,
        'usedNo': null,
        'supplier': null,
        'repairUserSecond': null,
        'batchNo': null,
        'workYear': null,
        'retirementDate': null,
        'isFinancing': null,
        'registerDate': null
      },
      numCheckStandard: 0,
      numCheckjob: 0,
      numRepairReason: 0,
      numModelbom: 0,
      numPartInfo: 0,
      numChildSbInfo: 0,
      firmProducerLevelMap: {},
      firmSupplier: {},
      firmProducer: {},
      statusMap: {},
      measureMap: {},
      sourceTypeMap: {}
    }
  },
  created () {
    this.measureMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_MEASURE_RESULT)
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_MEASURE_STATUS)
    this.isFinancingMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_IS_FINANCING)
  },
  computed: {
  },
  methods: {
    inited (viewer) {
      this.$viewer = viewer
    },
    handleViewBom (record) {
      this.visible = false
      const modal = this.$refs.detailSbBomModal
      modal.base(this.model)
    },
    handleViewChildSbInfo () {
      this.visible = false
      const modal = this.$refs.detailSbInfoModal
      modal.base(this.model)
    },
    handleViewCheck (record) {
      this.visible = false
      const modal = this.$refs.detailSbCheckModal
      modal.base(this.model)
    },
    handleViewCheckJob (record) {
      this.visible = false
      const modal = this.$refs.detailSbCheckJobModal
      modal.base(this.model)
    },
    handleMeasure (record) {
      this.visible = false
      const modal = this.$refs.detailSbMeasureModal
      modal.base(this.model)
    },
    base (record) {
      this.visible = true
      this.visibleDetail = true
      this.modalTitle = '详情'
      this.model = record
      this.activeKey = '1'
      this.collapseActiveKey = '0'
      this.paramList = JSON.parse(record.paramList)
      this.fetchNum()
      fetchFirmProducer({ id: this.model.producerId }).then(res => {
        this.firmProducer = res.data
      })
    },
    fetchNum () {
      Promise.all([
        queryNumPartInfo({ sbId: this.model.id }),
        queryNumModelbom({ sbId: this.model.id }),
        queryNumCheckStandard({ sbId: this.model.id }),
        queryNumCheckjob({ sbId: this.model.id }),
        queryNumRepairReason({ sbId: this.model.id })
      ])
        .then((values) => {
          this.numPartInfo = values[0].data
          this.numModelbom = values[1].data
          this.numCheckStandard = values[2].data
          this.numCheckjob = values[3].data
          this.numRepairReason = values[4].data
        })

      // 如果是父设备，则要获取子设备的数量，并点击后可以看到子设备的情况
      queryChildNumSbInfo({ parentId: this.model.id }).then(res => {
        this.numChildSbInfo = res.data
      })
    },
    changeTab (activeKey) {
      this.activeKey = activeKey
      if (this.activeKey === '2' && this.BaseTool.Object.isNotBlank(this.$refs.sparePartUsedSelectTable)) {
        this.$refs.sparePartUsedSelectTable.handleOk()
        return
      }
      if (this.activeKey === '3' && this.BaseTool.Object.isNotBlank(this.$refs.spotJobTable)) {
        this.$refs.spotJobTable.handleOk()
        return
      }
      if (this.activeKey === '4' && this.BaseTool.Object.isNotBlank(this.$refs.repairApplicationFormTable)) {
        this.$refs.repairApplicationFormTable.handleOk()
      }
      if (this.activeKey === '5' && this.BaseTool.Object.isNotBlank(this.$refs.repairFeeTable)) {
        this.$refs.repairFeeTable.handleOk()
      }
      if (this.activeKey === '6' && this.BaseTool.Object.isNotBlank(this.$refs.sbStatusLogTable)) {
        this.$refs.sbStatusLogTable.handleOk()
      }
      if (this.activeKey === '7' && this.BaseTool.Object.isNotBlank(this.$refs.sbStopLogTable)) {
        this.$refs.sbStopLogTable.handleOk()
      }
    },
    getQrcodeSrc: (dom) => {
      console.log(11, 22)
    },
    handleCancel (values) {
      this.visible = false
      this.visibleDetail = false
      this.confirmLoading = false
      this.$emit('ok', values)
    },
    handleOk () {
      this.visible = true
      this.fetchNum()
    },
    partInfoListView () {
      const modal = this.$refs.partInfoList
      modal.base({ sbId: this.model.id }, { sbId: this.model.id })
    },
    checkJobTableWaitDoListView () {
      const modal = this.$refs.checkJobTableWaitDo
      modal.base({ sbId: this.model.id }, { sbId: this.model.id, status: 1 })
    },
    handleTuiCalendar (level) {
      const that = this
      queryTuiCalendarIgnores({ sbId: this.model.id, type: 2, standardLevel: level }).then(res => {
        const a = document.createElement('a')
        a.target = '_blank'
        a.href = '/tui-calendar/checkJobCalendar.html?'
        localStorage.setItem('calendarList', JSON.stringify(res.data.calendarList))
        var scheduleList = res.data.scheduleList
        scheduleList.forEach((item) => {
          item.start = that.BaseTool.Moment(item.start, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
          item.end = that.BaseTool.Moment(item.end, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
        })
        localStorage.setItem('scheduleList', JSON.stringify(scheduleList))
        a.click()
      })
    }
  }
}
</script>
<style scoped>
/* For demo */
.ant-carousel {
  width: 300px;
  height: 300px;
}
.ant-carousel >>> .slick-slide {
  text-align: center;
  height: 300px;
  line-height: 300px;
  overflow: hidden;
}

.ant-carousel >>> .slick-slide h3 {
  color: #fff;
}

.image {
  width: calc(20% - 10px);
  cursor: pointer;
  margin: 5px;
  display: inline-block;
}
</style>
