<template>
  <a-modal
    :title="modalTitle"
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
    <title-divider title="明细列表" width="90px"></title-divider>
    <a-table
      bordered
      :data-source="data"
      :columns="columns"
      :scroll="{x: 1000, y: BaseTool.Constant.scrollY}"
      tableLayout="auto"
      rowKey="id"
    >
      <span slot="action" slot-scope="record">
        <template>
          <a @click="handleView(record)">查看</a>
        </template>
      </span>
      <span slot="status" slot-scope="text">
        <badge
          :text="BaseTool.Object.getField(statusMap,text)"
          :status="DictCache.COLOR.REPAIR_APPLICATION_FORM_STATUS[text]" />
      </span>
    </a-table>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
    </template>
    <detail :check-type="2" ref="detailModal"/>
  </a-modal>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
import Detail from '@/views/check/checkjob/modules/Detail'
import { fetchCheckJob } from '@/api/check/checkjob'

const DetailListItem = DetailList.Item

export default {
  name: 'DetailRepairReport',
  components: {
    DetailList,
    DetailListItem,
    Detail
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      // 下拉框map
      typeMap: {},
      statusMap: {},
      model: {},
      // 查询参数
      queryParam: {
        filter: this.filter,
        searchType: this.searchType
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          checked: true,
          width: '70px',
          customRender: (text, record, index) => {
            return `${index + 1}`
          }
        },
        {
          title: '出库单号',
          dataIndex: 'outNo',
          checked: true,
          width: '150px'
        },
        {
          title: '备件规格',
          dataIndex: 'ggxh',
          checked: true,
          width: '200px'
        },
        {
          title: '原厂编号',
          dataIndex: 'initNo',
          checked: true,
          width: '150px'
        },
        {
          title: '备件名称',
          dataIndex: 'spareId',
          width: '100px',
          checked: true,
          customRender: (text, record, index) => {
            return record.spareName
          }
        },
        {
          title: '出库数量',
          dataIndex: 'num',
          checked: true,
          width: '200px'
        },
        {
          title: '出库单价',
          dataIndex: 'price',
          checked: true,
          width: '150px',
          customRender: (text, record, index) => {
            return this.BaseTool.Amount.formatter(text)
          }
        },
        {
          title: '出库总价',
          dataIndex: 'totalPrice',
          checked: true,
          width: '150px',
          customRender: (text, record, index) => {
            return this.BaseTool.Amount.formatter(text)
          }
        },
        {
          title: '出库日期',
          dataIndex: 'createdTime',
          checked: true,
          width: '200px'
        }
      ],
      // 下拉框map
      levelMap: {},
      standardLevelMap: {},
      sbStatusMap: {},
      periodTypeMap: {},
      data: []
    }
  },
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_JOB_STATUS)
    this.sbStatusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
    this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
    this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_LEVEL)
    this.standardLevelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_LEVEL)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = record.outDetailList
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    },
    handleView (record) {
      fetchCheckJob({ id: record.id }).then(res => {
        const modal = this.$refs.detailModal
        modal.base(res.data)
      })
    }
  }
}
</script>
