<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="asnNo">
                  <template slot-scope="scope">
                    <p class="blue" @click="handelDetailForm(scope.row.asnNo)">{{scope.row.asnNo}}</p>
                  </template>
                </table-column>
                <table-column
                label="状态">
                  <template slot-scope="scope">
                    <p>{{ $utils.keyMatcher(scope.row.status, $keys.stockIn.status).name }}</p>
                    <p>{{ $utils.keyMatcher(scope.row.auditStatus, $keys.stockIn.auditStatus).name }}</p>
                    <p>{{ $utils.keyMatcher(scope.row.holdStatus, $keys.stockIn.holdStatus).name }}</p>
                  </template>
                </table-column>
                <table-column
                label="数量">
                    <template slot-scope="scope">
                        <p>预收：{{scope.row.qtyPlanEa}}</p>
                        <p>已收：{{scope.row.qtyRcvEa}}</p>
                        <p>未收：{{scope.row.qtyWatEa}}</p>
                    </template>
                </table-column>
                <table-column
                label="重量" :render-header="renderWeightHeader">
                    <template slot-scope="scope">
                        <p>预收：{{scope.column.unit === 'KG' ? (+scope.row.planWeight * 1000).toFixed($consts.numFix.KG) : (+scope.row.planWeight).toFixed($consts.numFix.TON)}}</p>
                        <p>已收：{{scope.column.unit === 'KG' ? (+scope.row.rcvWeight * 1000).toFixed($consts.numFix.KG) : (+scope.row.rcvWeight).toFixed($consts.numFix.TON)}}</p>
                        <p>未收：{{scope.column.unit === 'KG' ? (+scope.row.watWeight * 1000).toFixed($consts.numFix.KG) : (+scope.row.watWeight).toFixed($consts.numFix.TON)}}</p>
                    </template>
                </table-column>
                <table-column
                label="类型">
                <template slot-scope="scope">
                    {{ $utils.keyMatcher(scope.row.asnType, $keys.stockIn.asnType).name }}
                </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="供应商"
                prop="supplierName">
                </table-column>
                <table-column
                label="物流单号"
                prop="logisticNo">
                </table-column>
                <table-column
                label="订单时间"
                prop="orderTime">
                </table-column>
                <table-column
                label="操作"
                width="100"
                fixed="right">
                    <template slot-scope="scope">
                      <el-tooltip content="收货" placement="top">
                        <el-button v-auth="50100030107" size="mini" plain
                          type="primary" icon="el-icon-info" circle @click.stop="handelDetailForm(scope.row.asnNo)"></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>
export default {
  data () {
    return {
      // currentPage: 1,
      // pageSize: 10,
      storeKey: 'collectGoods',
    }
  },
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    total: Number,
    currentPage: Number,
    pageSize: Number
  },
  methods: {

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

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

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

    // checkbox勾选,存储id
    handleSelectChange (selection) {
      const selectedIds = selection.map(item => item.asnNo).join(',')
      this.$emit('handleSelectChange', selectedIds, selection)
    },

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

    // 打开详情
    async handelDetailForm (id) {
      const headUrl = this.$API.stockIn.collectGoods.queryRcv
      const goodsUrl = this.$API.stockIn.collectGoods.queryAsnRcvDetails
      const infoUrl = this.$API.stockIn.collectGoods.getUserName
      // const carUrl = this.$API.stockIn.preReceiving.getDetailCar
      const param = { asnNo: id, 'page.currentPage': 1, 'page.limitCount': 10 }

      const head = await this.getData(headUrl, param)
      const goods = await this.getData(goodsUrl, param)
      // const car = await this.getData(carUrl, param)
      const info = await this.getData(infoUrl, { creator: head.rows[0].creator, modifier: head.rows[0].modifier })
      const headData = { ...head.rows[0], ...info.data }
      const goodsData = goods.rows
      // const carData = car.rows
      this.$emit('handelDetailForm', 'edit', headData, goodsData, id)
    },
  },
}
</script>
<style lang="scss" scoped>
    .mrg-b{
        margin-bottom: 20px;
    }
    .mrg-l{
        margin-left:10px;
    }
    .blue{
      cursor: pointer;
      color:#0682ea
    }
</style>
