<!-- 整件拣货 -待索取  -->
<template>
  <div class="tab0">
    <p-grid-form ref="formTarget" class="mb-10" :span="8" :label-col="{ span: 9 }" :items="items"
                 @submit="handlerSubmit"/>
    <p-table ref='dataSource' :data-source.sync='dataSource'
             :scroll='{x:true}'
             :columns="columns"
             :remote-url='listRemoteUrl'
             :remoteData='listParams'
             :selectedRowKeys.sync='selectedRowKeys'
             bordered dragle row-key='id'/>
  </div>
</template>

<script>
// 商品详情
import {sorter} from '@/views/kzyWMS/utils/sort.js'
import {columns, items} from '../config'
import {getDefaultCargoOwner} from "@/views/kzyWMS/utils/setCargoOwner";
import {listRemoteUrl} from '../api'

export default {
  data() {
    return {
      columns: sorter(columns),
      items: items(this),
      // 列表
      listRemoteUrl,
      listParams: {},
      selectedRowKeys: [],
      dataSource: [],
    }
  },
  mounted() {
    this.setDefaultData()
  },
  methods: {
    // 设置默认数据
    async setDefaultData() {
      // 设置仓库
      const {warehouseId, warehouseCode, warehouseName} = this.$store.getters.warehouse || {}
      this.$nextTick(() => {
        this.$refs.formTarget.form.setFieldsValue({
          branchid: warehouseId,
          branchcode: warehouseCode,
          branchname: warehouseName
        })
      })
      // 设置货主
      const cargoOwner = await getDefaultCargoOwner()
      if (!!cargoOwner) {
        const {companyCode, companyId, companyName} = cargoOwner
        this.$refs.formTarget.form.setFieldsValue({
          consignorid: companyId,
          consignorcode: companyCode,
          consignorname: companyName
        })
        this.$refs.formTarget.form.disableItem('consignorname')
      }
    },
    // 索取 提交
    handlerSubmit(event, form) {
      event.preventDefault();
      form.validateFields((error, values) => {
        if (error) return
        console.log('验证通过: ', values)
        this.listParams = {...values}
      })
    }
  }
}
</script>

<style scoped lang="less">
.tab0 {
  padding-left: 20px;
  padding-right: 20px;
  box-sizing: border-box;
}
</style>
