<template>
    <div>
        <div class="mrg-b">
          <!--<drop-filter :columns="wholeLabels" :storeKey="storeKey"  :storeLabels="storeLables" @doFilter="labels => storeLables = labels"></drop-filter>-->
            <el-table
                ref="table"
                stripe
                border
                :max-height="tableMaxHeight"
                :data="tableData"
                :filteredLabels="storeLables"
                @selection-change='handleSelectChange'
                @row-click="toCheck">
                <table-column
                type="selection"
                fixed
                align="center">
                </table-column>
                <table-column
                label="出库单号"
                prop="soNo">
                  <template slot-scope="scope">
                    <span class="blue" @click.stop="handleOpenDetail(scope.row.soNo)">{{scope.row.soNo}}</span>
                  </template>
                </table-column>
                <table-column
                    label="类型">
                    <template slot-scope="scope">
                       {{ $utils.keyMatcher(scope.row.soType, $keys.stockOut.soType).name }}
                    </template>
                </table-column>
                <table-column
                label="状态">
                <template slot-scope="scope">
                    <p>{{ $utils.keyMatcher(scope.row.status, $keys.stockOut.status).name }}</p>
                    <p>{{ $utils.keyMatcher(scope.row.interceptStatus, $keys.stockOut.interceptStatus).name }}</p>
                </template>
                </table-column>
                <table-column
                label="货主">
                    <template slot-scope="scope">
                        <p>{{scope.row.ownerCode}}</p>
                        <p>{{scope.row.ownerName}}</p>
                    </template>
                </table-column>
                <table-column
                label="供应商">
                    <template slot-scope="scope">
                        <p>{{scope.row.supplierCodes}}</p>
                        <p>{{scope.row.supplierName}}</p>
                    </template>
                </table-column>
                <table-column
                label="收货人"
                prop="consigneeName">
                </table-column>
                <table-column
                label="订单时间"
                prop="orderTime">
                </table-column>
                <table-column
                label="数量">
                    <template slot-scope="scope">
                        <p>订货数：{{scope.row.qtySoEa}} &nbsp;&nbsp; 已分配：{{scope.row.qtyAllocEa}}</p>
                        <p>已拣货：{{scope.row.qtyPkEa}} &nbsp;&nbsp; 已发货：{{scope.row.qtyShipEa}}</p>
                    </template>
                </table-column>
                <table-column
                label="重量" :render-header="renderWeightHeader">
                    <template slot-scope="scope">
                        <p>订货：{{scope.column.unit === 'KG' ? (+scope.row.soWeight * 1000).toFixed($consts.numFix.KG) : (+scope.row.soWeight).toFixed($consts.numFix.TON)}}</p>
                        <p>已发：{{scope.column.unit === 'KG' ? (+scope.row.shipWeight * 1000).toFixed($consts.numFix.KG) : (+scope.row.shipWeight).toFixed($consts.numFix.TON)}}</p>
                    </template>
                </table-column>
                <table-column
                label="订单波次单号"
                prop="waveNo">
                </table-column>
                <table-column
                    label="预计发货时间">
                    <template slot-scope="scope">
                        <p>{{scope.row.fmEta}}</p>
                        <p>{{scope.row.toEta}}</p>
                    </template>
                </table-column>
                <table-column
                label="操作"
                width="100"
                fixed="right">
                <template slot-scope="scope">
                  <el-tooltip content="查看附件" placement="top">
                    <el-badge style="margin-right: 20px;" :value="scope.row.fileNumber">
                      <el-button
                        size="mini"
                        type="primary"
                        icon="el-icon-tickets"
                        plain
                        circle
                        @click.stop="toFile(scope.row)"
                      ></el-button>
                    </el-badge>
                  </el-tooltip>
                  <el-tooltip content="发货确认" placement="top">
                    <el-button v-auth="50200100311" size="mini" plain
                         type="primary" icon="el-icon-info" circle @click="doDelivery(scope.row)"></el-button></el-tooltip>
                </template>
                </table-column>
            </el-table>
        </div>
        <div>
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { createNamespacedHelpers } from 'vuex'
const { mapState } = createNamespacedHelpers('framework')
export default {
  data () {
    return {

      storeKey: 'deliverGoods'
    }
  },
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    total: Number,
    currentPage: Number,
    pageSize: Number,
  },
  methods: {
    // 发货确认
    doDelivery (data) {
      const url = this.$API.stockOut.deliverGoods.getShipMent
      const query = { 'page.currentPage': this.currentPage }
      const param = { soNos: data.soNo, allocateInWh: '' }
      this.$confirm(`是否执行发货确认操作？`, `发货确认`, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$message(res.messagesAsString)
          this.$emit('getList', query)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: `已取消`
        })
      })
    },

    // 点击表格行
    toCheck (row) {
      this.$refs.table.toggleRowSelection(row)
    },

    // 当前页码
    handleCurrentChange (currentPage) {
      const query = { 'page.limitCount': this.pageSize, 'page.currentPage': currentPage }
      this.$emit('getList', query)
    },

    // 每页显示条数
    handleSizeChange (pageSize) {
      const query = { 'page.limitCount': pageSize, 'page.currentPage': this.currentPage }
      this.$emit('getList', query)
    },

    getData (url, param) {
      return this.$https.post(url, param)
    },

    // 打开详情
    handleOpenDetail (id) {
      const headUrl = this.$API.stockOut.deliverGoods.getDetailHead
      const goodsUrl = this.$API.stockOut.deliverGoods.getDetailgoods
      const listUrl = this.$API.stockOut.deliverGoods.getDetailList
      // const carUrl = this.$API.stockOut.sendOrder.carList
      const param = { soNo: id, 'page.currentPage': 1, 'page.limitCount': 10 }
      this.$https.all([this.getData(headUrl, param), this.getData(goodsUrl, param), this.getData(listUrl, param)]).then(res => {
        const headData = res[0]
        const goodsData = res[1].rows
        const listData = res[2].rows
        // const carData = res[3].rows
        this.$emit('handleOpenDetail', 'edit', headData, goodsData, listData)
      })
    },

    // checkbox勾选,存储id
    handleSelectChange (selection) {
      const selectedIds = selection.map(item => item.soNo).join(',')
      this.$emit('handleSelectChange', selectedIds)
    },
    // 附件管理
    toFile (row) {
      const config = {
        orderNo: row.soNo, // 组件需要的当前选择的业务单号
      }
      this.$upload(config)
    },
  }
}
</script>
<style lang="scss" scoped>
    .mrg-b{
        margin-bottom: 20px;
    }
    .mrg-l{
        margin-left:10px;
    }
    .blue{
      cursor: pointer;
      color:#0682ea
    }
</style>
