<template>
  <div>
    <div class="my-title">查看</div>
    <div style="margin-left: 20px;margin-right: 20px">
      <e-desc title="基本信息" column="3" labelWidth="160px">
        <e-desc-item label="设备名称">{{dataForm.equipmentName}}</e-desc-item>
        <e-desc-item label="设备编号">{{dataForm.codeNumber}}</e-desc-item>
        <e-desc-item label="状态">{{(state = optionsState.find(t => t.value === dataForm.state))? state.label:""}}</e-desc-item>
        <e-desc-item label="报修人">{{dataForm.repairName}}</e-desc-item>
        <e-desc-item label="报修时间">{{dataForm.createTime}}</e-desc-item>
        <e-desc-item label="报修问题说明">{{dataForm.content}}</e-desc-item>
        <e-desc-item label="报修附件" span="3">
          <div v-for="(item, index) in dataForm.attachList" style="display: inline">
            <span v-if="index > 0">,</span>
            <a :key="item.fileName + index" type="primary" href="#" @click="previewFile(item.fileName, item.url)">{{ item.fileName }}</a>
          </div>
        </e-desc-item>
        <e-desc-item label="维修完成时间">{{dataForm.updateTime}}</e-desc-item>
        <e-desc-item label="维修记录说明">{{dataForm.maintenanceRecord}}</e-desc-item>
        <e-desc-item label="维修记录附件" span="3">
          <div v-for="(item, index) in dataForm.attachListRepair" style="display: inline">
            <span v-if="index > 0">,</span>
            <a :key="item.fileName + index" type="primary" href="#" @click="previewFile(item.fileName, item.url)">{{ item.fileName }}</a>
          </div>
        </e-desc-item>
      </e-desc>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="onChose">返回</el-button>
    </span>
    <!-- 文件预览 -->
    <preview-component v-if="previewVisible" ref="preview"/>
  </div>
</template>

<script>
  import EDesc from '../common/e-desc'
  import EDescItem from '../common/e-desc-item'
  import {getRepairDetail} from '@/api/device'
  import {getDate} from '@/utils/date-util'
  import PreviewComponent from '@/views/modules/common/preview-component.vue'
  import {optionsEquipmentRepairState} from '@/utils/enums'
export default {
    name: 'repair-detail',
    components: {
      PreviewComponent,
      EDesc,
      EDescItem
    },
    data () {
      return {
        visible: false,
        id: 0,
        dataForm: {},
        previewVisible: false,
        optionsState: optionsEquipmentRepairState
      }
    },
    methods: {
      getDate,
      onChose () {
        this.$emit('onChose')
      },
      async init (id) {
        this.visible = true
        this.id = id || 0
        this.dataForm = {}
        this.getDetails()
      },
      getDetails () {
        getRepairDetail(this.id).then(({data}) => {
          if (data && data.code === '200') {
            this.dataForm = data.data
          }
        })
      },
      previewFile (fileName, url) {
        this.previewVisible = true
        this.$nextTick(() => {
          this.$refs.preview.init(fileName, url)
        })
      }
    }
  }
</script>

<style scoped>
.my-line{
  border-bottom: 1px solid #c0c4cc;
  margin-bottom: 10px;
}
.title{
  padding: 10px 0 ;
}
</style>
