<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
<!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
<!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a-->
<!--        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
<!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
<!--      </div>-->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
            <a @click="handletiaoma(record)">条码</a>
          <a-divider type="vertical" />

          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <itdm-sample-inventory-modal ref="modalForm" @ok="modalFormOk"></itdm-sample-inventory-modal>
    <itdm-inventory-barcode-list ref="blist" @ok="modalFormOk"></itdm-inventory-barcode-list>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ItdmSampleInventoryModal from './modules/ItdmSampleInventoryModal'
import ItdmInventoryBarcodeList from './ItdmInventoryBarcodeList'

export default {
  name: 'ItdmSampleInventoryList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ItdmSampleInventoryModal, ItdmInventoryBarcodeList
  },
  data() {
    return {

      description: '样品库存管理页面',
      barcodeShow: false,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '样品名称',
          align: 'center',
          dataIndex: 'sampleName'
        },
        {
          title: '样品规格',
          align: 'center',
          dataIndex: 'sampleSpecifications'
        },
        {
          title: '样品数量',
          align: 'center',
          dataIndex: 'sampleNum'
        },
        {
          title: '生产厂家',
          align: 'center',
          dataIndex: 'sampleManufacturer'
        },
        {
          title: '批次号',
          align: 'center',
          dataIndex: 'batchNumber'
        },
        {
          title: '样品分类',
          align: 'center',
          dataIndex: 'sampleClassifications_dictText'
        },
        {
          title: '样品单位',
          align: 'center',
          dataIndex: 'sampleUnit'
        },
        {
          title: '样品状态',
          align: 'center',
          dataIndex: 'sampleStatus_dictText'
        },

        {
          title: '样品存放位置',
          align: 'center',
          dataIndex: 'samplePosition'
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/inventory/itdmSampleInventory/list',
        delete: '/inventory/itdmSampleInventory/delete',
        deleteBatch: '/inventory/itdmSampleInventory/deleteBatch',
        exportXlsUrl: '/inventory/itdmSampleInventory/exportXls',
        importExcelUrl: 'inventory/itdmSampleInventory/importExcel'

      },
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()

  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {

    handletiaoma(record) {
      this.$refs.blist.init(record.id)

    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'sampleName', text: '样品名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sampleSpecifications', text: '样品规格', dictCode: '' })
      fieldList.push({ type: 'int', value: 'sampleNum', text: '样品数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sampleManufacturer', text: '生产厂家', dictCode: '' })
      fieldList.push({ type: 'string', value: 'batchNumber', text: '批次号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sampleClassifications', text: '样品分类', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sampleUnit', text: '样品单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sampleStatus', text: '样品状态（是否损坏）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'samplePosition', text: '样品存放位置', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'remark', text: '备注', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>