<template>
  <div>
    <el-dialog
          title="选择商品"
          v-if="selectFormVisible"
          :visible.sync="selectFormVisible"
          :before-close="close"
          width="66%">
          <el-form
            :inline="true"
            :model="formData">
              <el-form-item
                label="货主"
                prop="ownerName">
                <PublicQuery
                title="货主"
                cfgKey="bdWmsCustomer"
                baseUrl="/bd_web/bdweb"
                :valueField.sync="formData.ownerCode"
                :textField.sync="formData.ownerName"
              ></PublicQuery>
              </el-form-item>
              <el-form-item
                label="商品"
                prop="skuName">
                <PublicQuery
                title="商品"
                cfgKey="bdWmsShareSku"
                baseUrl="/bd_web/bdweb"
                :valueField.sync="formData.skuCode"
                :textField.sync="formData.skuName"
                :before="beforeSelectSku"
              ></PublicQuery>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="handleConfirmAdd">查询</el-button>
                <el-button type="primary" @click="handleConfirm">重置</el-button>
              </el-form-item>
          </el-form>
             <el-table
                :data="selectForm"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange">
                <el-table-column
                  type="selection"
                  width="55">
                </el-table-column>
                <el-table-column
                  label="货主编号"
                  prop="cdcmCustomerCode">
                </el-table-column>
                <el-table-column
                  prop="cdcmCustomerName"
                  label="货主名称">
                </el-table-column>
                <el-table-column
                  prop="cdcmMaterialNo"
                  label="商品编号">
                </el-table-column>
                <el-table-column
                  prop="cdcmNameCn"
                  label="商品名称">
                </el-table-column>
              </el-table>
              <el-button type="primary" @click="handleSelectConfirm" style="margin-top: 20px;">确认</el-button>
        </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      formData: {},
      tableData3: [],
      selectionChange: []
    }
  },
  props: {
    selectFormVisible: Boolean,
    selectForm: {
      type: Array,
      default: () => ([])
    },
  },
  mounted () {

  },
  methods: {
    beforeSelectSku () {
      if (this.formData.ownerName) {
        return {
          queryParams: {
            ownerCodeParam: this.formData.ownerCode
          }
        }
      } else {
        return {
          queryParams: {

          }
        }
      }
    },
    close () {
      this.$emit('selectClose')
    },
    handleConfirmAdd () {
      const url = this.$API.warehouseBasic.libraryGoods.queryWareSkuShtml
      const param = { ownerCode: this.formData.ownerCode, skuCode: this.formData.skuCode }
      this.$https.post(url, param).then(res => {
        this.tableData3 = res.data
      })
    },
    handleConfirm () {
      this.formData = {}
    },
    handleSelectConfirm () {
      const url = this.$API.warehouseBasic.libraryGoods.confirmSelectSku
      const param = { selectSkus: JSON.stringify(this.selectionChange) }
      this.$https.post(url, param).then(res => {
        this.$emit('getSelectList')
        this.$emit('selectClose')
      })
    },
    handleSelectionChange (val) {
      this.selectionChange = val
    },
  }
}
</script>

<style>

</style>
