<template>
  <p-modal
    :title="title"
    :visible="logVisible"
    width="80%"
    :enlargeable="true"
    :maskClosable="false"
    :destroyOnClose="true"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="logVisible = false"
  >
    <p-table
      dragle
      ref="table"
      autoWidth
      rowSelectFixed
      :rowSelectType="2"
      :remoteUrl="remoteUrl"
      :remoteBefore="remoteBefore"
      :columns="columns"
      bordered
      :selectedRowKeys.sync="selectedRowKeys"
      row-key="billno"
    >
    </p-table>
  </p-modal>
</template>
<script>
import { detailColumns } from '../js/config'
import { sourceTrans } from '../api/index'
import { upcloud_base_wh_operate } from "@/config/serviceSettings";

export default {
  data() {
    return {
      columns: detailColumns,
      logVisible: false,
      remoteUrl: {
        url: upcloud_base_wh_operate+'/stock-change/v1/source-heads',
        method: 'get'
      },
      warehouseId: '',
      remoteData: {},
      selectedRowKeys: [], // 选中集合
      confirmLoading: false
    }
  },
  components: {},
  props: {
    // currentData: {
    //   type: Object,
    //   default: {}
    // },
    title: {
      type: String,
      default: '提取'
    },
    wareId: {
      type: String,
      default: ''
    }
  },
  watch: {
    logVisible(newVal) {
      this.logVisible = newVal
    },
    wareId(newVal) {
      this.warehouseId = newVal
    }
  },
  created() {},
  mounted() {
    let warehouse = this.$store.state.user.warehouse
    this.warehouseId = warehouse.warehouseId
  },
  methods: {
    remoteBefore(res, remoteParams) {
      remoteParams.params = {
        ...remoteParams.params,
        warehouseId: this.warehouseId
      }
      return remoteParams
    },
    handleCancel() {
      // 取消
      this.logVisible = false
    },
    handleOk() {
      // 确定
      if (this.selectedRowKeys && this.selectedRowKeys.length < 1) {
        this.$message.warn('请选择提取单据')
        return
      }
      console.log('确定')
      this.confirmLoading = true
      let params = {
        billnos: this.selectedRowKeys
      }
      sourceTrans(params).then(res => {
        this.confirmLoading = false
        if (res.success) {
          this.$message.success('保存成功！')
          this.logVisible = false
          this.$emit('successSource', true)
        } else {
          this.$exception(res)
        }
      })
    },
    selectChange(data) {
      // 勾选框
      // this.
      this.checkData = data
    }
  }
}
</script>
