<template>
  <a-modal
    :title="modalTitle"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    class="ant-modal2"
    @cancel="handleCancel"
  >
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
            </a-col>
            <a-col :md="8 || 24" :sm="24">
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div class="table-operator">
      </div>
      <a-table
        rowKey="id"
        :columns="columns"
        :data-source="data"
        :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: type }"
        tableLayout="auto"
      >
      </a-table>
    </a-card>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
      <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
    </template>
  </a-modal>
</template>

<script>
import { STable, Ellipsis } from '@/components'

export default {
  name: 'SparePartInfoSelectModalForAdjust',
  components: {
    STable,
    Ellipsis
  },
  props: {
    type: {
      type: String,
      default: 'radio'
    },
    selectedRowKey: {
      type: Array,
      default: () => {
        return []
      }
    },
    selectedRow: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      data: [],
      selectedRows: [],
      selectedRowKeys: [],
      // 表头
      columns: [
        {
          title: '备件编码',
          dataIndex: 'no'
        },
        {
          title: '原厂编号',
          dataIndex: 'initNo'
        },
        {
          title: '备件名称',
          dataIndex: 'name'
        },
        {
          title: '规格型号',
          dataIndex: 'ggxh'
        },
        {
          title: '备件价值',
          dataIndex: 'initialValue',
          customRender: (text, record, index) => {
            return this.BaseTool.Amount.formatter(text)
          }
        },
        {
          title: '计量单位',
          dataIndex: 'unit'
        }
      ]
    }
  },
  created () {
    // 下拉框map
    this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_PART_INFO_LEVEL)
    this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  },
  methods: {
    handleOk () {
      this.$refs.table.refresh()
    },
    base (data) {
      this.visible = true
      this.modalTitle = '请设置主备件'
      this.data = data
      console.log(this.data instanceof Array)
      console.log(1111111111)
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
    },
    onSelectChange (selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    handleSelect () {
      if (this.selectedRowKeys.length === 0) {
        this.$message.warn('请选择主备件')
      } else {
        this.confirmLoading = true
        this.$emit('selected', this.selectedRowKeys)
        this.confirmLoading = false
        this.visible = false
      }
    },
  }
}
</script>
