<template>
<div class="list">
  <!--<drop-filter :columns="wholeLabels" :storeKey="storeKey" :storeLabels="storeLables" @doFilter="labels => storeLables = labels"></drop-filter>-->
  <el-table
    ref="table"
    stripe
    border
    :max-height="tableMaxHeight"
    :data="list"
    :filteredLabels="storeLables"
    @selection-change="selectionChange"
    @row-click="toCheck"
  >
    <table-column type="selection" fixed align="center"></table-column>
    <table-column label="盘点单号" prop="countNo">
      <template slot-scope="scope">
        <span class="detail-no" @click.stop="toDetail(scope.row.countNo)">{{scope.row.countNo}}</span>
      </template>
    </table-column>
    <table-column label="状态" prop="status">
      <template slot-scope="scope">
        {{ $utils.keyMatcher(scope.row.status, $keys.inventory.count.status).name }}
      </template>
    </table-column>
    <table-column label="类型" prop="countType">
      <template slot-scope="scope">
        {{ $utils.keyMatcher(scope.row.countType, $keys.inventory.count.countType).name }}
      </template>
    </table-column>
    <table-column label="盘点范围" prop="countRange">
      <template slot-scope="scope">
        {{ $utils.keyMatcher(scope.row.countRange, $keys.inventory.count.countRange).name }}
      </template>
    </table-column>
    <table-column label="静态/动态盘点" prop="countMethod">
      <template slot-scope="scope">
        {{ $utils.keyMatcher(scope.row.countMethod, $keys.inventory.count.countMethod).name }}
      </template>
    </table-column>
    <table-column label="明盘/盲盘" prop="countMode">
      <template slot-scope="scope">
        {{ $utils.keyMatcher(scope.row.countMode, $keys.inventory.count.countMode).name }}
      </template>
    </table-column>
    <table-column label="货主" prop="ownerName" ></table-column>
    <table-column label="商品" prop="skuName" ></table-column>
    <table-column label="操作" width="150" fixed="right">
      <template slot-scope="scope">
        <el-badge style="margin-right: 20px;" :value="scope.row.fileNumber">
          <el-button
            title="查看附件"
            size="mini"
            type="primary"
            icon="el-icon-tickets"
            plain
            circle
            @click.stop="toFile(scope.row)"
          ></el-button>
        </el-badge>
        <el-button
          v-auth="50300010119"
          title="编辑"
          size="mini"
          type="primary"
          icon="el-icon-edit"
          plain
          circle
          @click.stop="toEdit(scope.row)"
        ></el-button>
        <el-button
          v-auth="50300010120"
          title="删除"
          size="mini"
          type="danger"
          icon="el-icon-delete"
          plain
          circle
          @click.stop="toDelete(scope.row)"
        ></el-button>
      </template>
    </table-column>
  </el-table>
  <el-pagination
    class="pagination"
    @size-change="sizeChange"
    @current-change="currentChange"
    :current-page="currentNo"
    :page-sizes="[10, 20, 30, 40, 50]"
    :page-size="pageSize"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total"
  ></el-pagination>
</div>
</template>

<script>
export default {
  props: ['list', 'total', 'currentNo', 'pageSize'],
  created () {
  },
  mounted () {
  },

  data () {
    return {
      storeKey: 'count',
    }
  },
  methods: {
    // 点击表格行
    toCheck (row) {
      this.$refs.table.toggleRowSelection(row)
    },
    // 页码变化
    currentChange (currentNo) {
      //      this.currentNo = currentNo
      const query = { 'page.currentPage': currentNo, 'page.limitCount': this.pageSize }
      this.$emit('getList', query)
    },
    // 每页条数变化
    sizeChange (pageSize) {
      //      this.pageSize = pageSize
      const query = { 'page.limitCount': pageSize, 'page.currentPage': this.currentNo }
      this.$emit('getList', query)
    },
    // 编辑
    toEdit (row) {
      const forbiddenStatus = ['80', '90', '99']
      if (forbiddenStatus.includes(row.status)) {
        this.$message.warning('该状态下不能编辑哦~')
      } else {
        this.$emit('toCreator', row.countNo, 'edit')
      }
    },
    // 删除
    toDelete (row) {
      this.$confirm(`确定要删除吗 ?`)
        .then(() => {
          const url = this.$API.inventory.count.delete
          const param = {
            countNos: row.countNo,
          }
          this.$https.post(url, param)
            .then(data => {
              this.$emit('getList')
            })
        })
        .catch(e => console.log(e))
    },
    // 勾选变化
    selectionChange (selection) {
      const selectedIds = selection.map(item => item.countNo).join(',')
      this.$emit('selectionChange', selectedIds)
    },
    // 前往详情
    toDetail (countNo) {
      this.$emit('toCreator', countNo)
    },
    // 附件管理
    toFile (row) {
      const config = {
        orderNo: row.countNo, // 组件需要的当前选择的业务单号
      }
      this.$upload(config)
    },
  },
}
</script>

<style lang="scss" scoped>
.pagination {
  margin-top: 20px;
}
.detail-no {
  color: #0682ea;
  &:hover {
    cursor: pointer;
  }
}
</style>
