<template>
  <div class="outboundManage">
    <div class="head-title">
      出库管理
      <el-button style="float:right" size="small" @click="outapplyfor" type="primary">出库申请
      </el-button>
    </div>
    <div class="content">
      <el-table :data="tableData" v-loading="loading" border style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" style="text-align:center;">
        </el-table-column>
        <el-table-column prop="OrderNo" label="订单号" width="220">
        </el-table-column>
        <el-table-column prop="GoodsName" label="商品名称">
        </el-table-column>
        <el-table-column prop="Specification" label="商品规格">
        </el-table-column>
        <el-table-column prop="Number" label="购买数量" width="150px">
        </el-table-column>
      </el-table>
      <el-pagination style="text-align:right" background @current-change="handleCurrentChange" :page-size="msg.pageSize" :current-page.sync="msg.pageIndex"
        layout="prev, pager, next" :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        loading: false,

       tableData:[],
       total: 0,
       outobj:{
           ID:0,
           WarehouseOutGoodsList:[],
       },
       msg:{
           pageIndex: 1,
          pageSize: 15,
          SupplierId:0
          
       },
       ERPEmpId:0
      }
    },
    created() {
      let currentUser = this.getLocalStorage()
      this.ERPEmpId =  currentUser.ERPEmpId
    },
    mounted() {
      this.getList();
    },
    methods: {
 
      getList() {
      
        this.loading = true;
        this.assetsApipost("/api/WarehouseOut/GetNoOutOrderGoodsList", this.msg, res => {
          this.loading = false;
          if (res.data.resultCode == 1) {
            // this.tableData = res.data.data;
             this.total = res.data.data.count;
            this.tableData = res.data.data.pageData;
          }else{
            this.Error(res.data.message);
          }
        })
      },
      handleCurrentChange(val) {
        this.msg.pageIndex = val;
        this.getList();
      },
      
      handleSelectionChange(val) {
        var selectRow = JSON.parse(JSON.stringify(val));
        let array= [];
        selectRow.forEach(x => {
            let obj = {}
            obj.OrderGoodsId = x.Id;
            array.push(obj)
        });
        this.outobj.WarehouseOutGoodsList = array;

      },
      outapplyfor(){
        let that = this
        if(that.ERPEmpId==0){
          that.Error('您还未授权，暂不能出库');
        }else{


           if (that.outobj.WarehouseOutGoodsList.length == 0) {
            that.Info('请选择商品');
            return
         } 
           that.$confirm('是否申请出库?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            that.loading = true;
          that.assetsApipost("/api/WarehouseOut/SetWarehouseOutApply", that.outobj, res => {
            that.loading = false;
            if (res.data.resultCode == 1) {
              that.Success(res.data.message);
              that.outobj.WarehouseOutGoodsList = []
              that.getList();
            }else{
              that.Error(res.data.message);
            }
          })
        }).catch(() => {

        });
         
        }
         


      }
   

    }
  };

</script>
<style>
  .outboundManage .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }

</style>
