<template>
  <a-card :bordered="false" v-show="visible" class="card" :title="modalTitle">
    <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: 16px"  v-if="model.status === DictCache.VALUE.CHECK_JOB_STATUS.NOT_EXECUTE" type="default" @click="handleExecute()">接收</a-button>
            <a-button style="margin-left: 16px"  v-if="model.status === DictCache.VALUE.CHECK_JOB_STATUS.EXECUTING" type="default" @click="handleFinish()">完成</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="2">
      <detail-list-item term="标准名称">{{ modelStandard.name }}</detail-list-item>
      <detail-list-item term="编码">{{ modelStandard.no }}</detail-list-item>
      <detail-list-item term="检查类型">{{ BaseTool.Object.getField(typeMap,modelStandard.type) }}</detail-list-item>
      <detail-list-item term="计划周期">{{ modelStandard.period }}{{ BaseTool.Object.getField(periodTypeMap,modelStandard.periodType) }}</detail-list-item>
      <detail-list-item term="标准工时">{{ modelStandard.standardHours }}</detail-list-item>
      <detail-list-item term="动作类型">{{ BaseTool.Object.getField(actionTypeMap,modelStandard.actionType) }}</detail-list-item>
      <detail-list-item term="部位">{{ modelStandard.partName }}</detail-list-item>
      <!--      <detail-list-item term="更新人">{{ model.updateUserName }}</detail-list-item>
            <detail-list-item term="创建时间">{{ model.updateTime }}</detail-list-item>
            <detail-list-item term="更新时间">{{ model.updateTime }}</detail-list-item>-->
    </detail-list>
    <detail-list title="" :col="1">
      <detail-list-item term="要求">{{ modelStandard.requirement }}</detail-list-item>
      <detail-list-item term="备注">{{ modelStandard.remark }}</detail-list-item>
    </detail-list>
    <title-divider title="标准图片" width="90px"></title-divider>
    <detail-list title="" :col="6">
      <detail-list-item v-for="item in modelStandard.checkImgList" term="">
        <img :src="BaseTool.Constant.FILE_URL + item.url" width="200px" height="200px"/>
      </detail-list-item>
    </detail-list>
    <title-divider title="标准文件" width="90px"></title-divider>
    <detail-list title="" :col="8">
      <detail-list-item term="">
        <a-upload
          :multiple="true"
          :fileList="BaseTool.UPLOAD.transImg(modelStandard.checkFileList)"
        >
        </a-upload>
      </detail-list-item>
    </detail-list>
    <title-divider title="任务信息" width="90px"></title-divider>
    <detail-list title="" :col="3">
      <detail-list-item term="实际工时">{{ model.realHours }}</detail-list-item>
      <detail-list-item term="执行日期">{{ model.startTime }}</detail-list-item>
      <detail-list-item term="截至日期">{{ model.endTime }}</detail-list-item>
      <detail-list-item term="实际开始时间">{{ model.actualStartTime }}</detail-list-item>
      <detail-list-item term="实际结束时间">{{ model.actualEndTime }}</detail-list-item>
      <!--<detail-list-item term="是否停机"><badge :status="DictCache.COLOR.YES_NO[model.sbStatus]" :text="sbStatusMap[model.sbStatus]" /></detail-list-item>-->
      <detail-list-item term="任务状态"><badge :status="DictCache.COLOR.CHECK_JOB_STATUS[model.status]" :text="statusMap[model.status]" /></detail-list-item>
    </detail-list>
    <detail-list title="" :col="1">
      <detail-list-item term="检查结果">{{ model.feedback }}</detail-list-item>
    </detail-list>
    <base-form :check-type="checkType" ref="baseModal" @ok="handleOk"/>
  </a-card>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import { fetchCheckStandard } from '@/api/check/checkstandard'
import { executeJob, fetchCheckJob } from '@/api/check/checkjob'
import BaseForm from '@/views/check/checkjob/modules/BaseForm'
const DetailListItem = DetailList.Item

export default {
  name: 'CheckJobDetail',
  components: {
    DetailList,
    DetailListItem,
    BaseForm
  },
  props: {
    /**
     * 检查类型： 1-任务 2-巡检
     */
    checkType: {
      type: Number,
      default: 1
    }
  },
  data () {
    return {
      names: ['任务', '巡检'],
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      statusMap: {},
      sbStatusMap: {},
      periodTypeMap: {},
      actionTypeMap: {},
      typeMap: {},
      enableMap: {},
      modelStandard: {},
      model: {
        'planId': null,
        'startTime': null,
        'endTime': null,
        'actualStartTime': null,
        'actualEndTime': null,
        'checkedNum': null,
        'abnormalNum': null,
        'checkNum': null,
        'status': null,
        'sbStatus': null,
        'createdUserId': null,
        'updateUserId': null,
        'updateUserName': null,
        'updateTime': null
      }
    }
  },
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_JOB_STATUS)
    this.sbStatusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_STANDARD_TYPE)
    this.enableMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
    this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
    this.actionTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_ACTION_TYPE)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      fetchCheckStandard({ id: record.standardId }).then(res => {
        this.modelStandard = res.data
      })
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
      this.$emit('ok')
    },
    handleFinish () {
      fetchCheckJob({ id: this.model.id }).then(res => {
        const modal = this.$refs.baseModal
        modal.base(res.data)
      })
    },
    handleExecute () {
      executeJob({ id: this.model.id }).then(res => {
        this.$message.info('接收成功')
        this.handleOk()
      })
    },
    handleOk () {
      fetchCheckJob({ id: this.model.id }).then(res => {
        this.model = res.data
      })
    }
  }
}
</script>
