<!--
@name: 商品批号查询
@author: 李恒
@time: 2022-05-31 15:25:36
-->
<template>
  <p-card title='商品批号查询'>
    <div slot='extra'>
      <p-button icon='filter' @click='toggleFormTag = !toggleFormTag'>{{ toggleFormTag ? '隐藏' : '显示' }}</p-button>
    </div>
    <p-grid-form v-show="toggleFormTag" ref="formTarget" :span="6" :labelCol="{ span: 6 }" :items="items"
                 @submit="onSubmit"
    />
    <p-table ref='dataSource' :data-source.sync='dataSource'
             :scroll='{x:true}'
             :autoLoad='false'
             :remote-url='listRemoteUrl'
             :remoteBefore="remoteBefore"
             :remoteData='listParams'
             :selectedRowKeys.sync='selectedRowKeys'
             bordered dragle row-key='batchId'>
      <p-table-column data-index='warehouseName' title='仓库名称'/>
      <p-table-column data-index='cargoOwnerCode' title='货主编号'/>
      <p-table-column data-index='cargoOwnerName' title='货主名称'/>
      <p-table-column data-index='itemName' title='商品名称'/>
      <p-table-column data-index='itemCode' title='商品编号'/>
      <p-table-column data-index='uom' title='包装单位'/>
      <p-table-column data-index='conversionRate' title='包装含量'/>
      <p-table-column data-index='specification' title='商品规格'/>
      <p-table-column data-index='batchProductionDate' title='生产日期'/>
      <p-table-column data-index='batchExpiredDate' title='有效期至'/>
      <p-table-column data-index='manufacturerId' title='生产厂家'/>
      <p-table-column data-index='itemHealthListedLicensor' title='上市许可持有人'/>
      <p-table-column data-index='manufacturerLotNum' title='批号'/>
      <p-table-column data-index='itemHealthApprovalNbr' title='批准文号'/>
      <p-table-column data-index='countryOriginId' title='产地'/>
      <p-table-column data-index='sterilizelotno' title='灭菌批号'/>
      <p-table-column data-index='cmpacklotno' title='分装批号'/>
      <p-table-column data-index='itemzjm' title='商品助记码'/>
      <p-table-column data-index='caseBarcode' title='外箱码(最大包装)'/>
      <p-table-column data-index='pieceBarcode' title='条码(最小包装)'/>
    </p-table>
  </p-card>
</template>

<script>
import {listRemoteUrl} from './api'
import {items} from './js/config'
import {getDefaultCargoOwner} from "@/views/kzyWMS/utils/setCargoOwner";

export default {
  data() {
    return {
      toggleFormTag: true,
      items: items(this),
      form: {},
      // 列表参数
      listRemoteUrl,
      listParams: {},
      dataSource: [],
      selectedRowKeys: [],

    }
  },
  mounted() {
    this.setDefaultData()
  },
  methods: {
    // 设置默认数据
    async setDefaultData() {
      // 设置仓库
      const {warehouseId, warehouseCode, warehouseName} = this.$store.getters.warehouse || {}
      this.$refs.formTarget.form.setFieldsValue({
        warehouseId, warehouseCode, warehouseName
      })
      // 设置货主
      const cargoOwner = await getDefaultCargoOwner()
      if (!!cargoOwner) {
        const {companyCode, companyId, companyName} = cargoOwner
        this.$refs.formTarget.form.setFieldsValue({
          cargoOwnerId: companyId,
          cargoOwnerCode: companyCode,
          cargoOwnerName: companyName
        })
      }
    },
    onSubmit(event, form) {
      event.preventDefault()
      form.validateFields((error, values) => {
        if (!!error) return
        this.listParams = values
      })
    },
    remoteBefore(vNode, remoteUrl) {
      remoteUrl.data = {
        num: 'selectItemBatchNumPage',
        pageNum: remoteUrl.data.pageNum,
        pageSize: remoteUrl.data.pageSize,
        params: {...remoteUrl.data}
      }
    }
  }
}
</script>
<style lang='less' scoped>
.search-wrap {
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;

  .separator {
    flex: 0 0 20px;
    text-align: center;
  }

  .search-item {
    flex: 1;
  }
}
</style>
