<template>
  <div>
    <div class="mrg-b">
      <!--<drop-filter-->
        <!--:columns="wholeLabels"-->
        <!--:storeKey="storeKey"-->
        <!--:storeLabels="storeLables"-->
        <!--@doFilter="labels => storeLables = labels"-->
      <!--&gt;</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="qcNo">
          <template slot-scope="scope">
            <p class="blue" @click="handleDateil(scope.row)">{{scope.row.qcNo}}</p>
          </template>
        </table-column>
        <table-column label="状态">
          <template slot-scope="scope">
            <p>{{ $utils.keyMatcher(scope.row.status, $keys.stockIn.quality.status).name }}</p>
            <p>{{ $utils.keyMatcher(scope.row.auditStatus, $keys.stockIn.auditStatus).name }}</p>
          </template>
        </table-column>
        <table-column label="单据号" prop="orderNo"></table-column>
        <table-column label="单据类型">
          <template
            slot-scope="scope"
          >{{ $utils.keyMatcher(scope.row.orderType, $keys.stockIn.orderType).name }}</template>
        </table-column>
        <table-column label="质检阶段">
          <template
            slot-scope="scope"
          >{{ $utils.keyMatcher(scope.row.qcPhase, $keys.stockIn.qcPhase).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="orderTime"></table-column>
        <table-column label="预计质检时间">
          <template slot-scope="scope">
            <p>从：{{scope.row.fmEtq}}</p>
            <p>到：{{scope.row.toEtq}}</p>
          </template>
        </table-column>
        <table-column label="操作" width="100" fixed="right">
          <template slot-scope="scope">
            <el-tooltip content="编辑" placement="top">
              <el-button
                size="mini"
                type="primary"
                icon="el-icon-edit"
                plain
                circle
                @click="handleEdit(scope.$index, scope.row)"
                v-auth="50100020127"
              ></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button
                size="mini"
                type="danger"
                icon="el-icon-delete"
                plain
                circle
                @click="handleDelete(scope.$index, scope.row)"
                v-auth="50100020128"
              ></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 EditForm from './add-form'
export default {
  components: {
    EditForm
  },
  data () {
    return {

      editVisible: false,
      model: {
        type: ''
      },
      headData: {},
      ListData: [],
      infoData: {},
      storeKey: 'quailty',
    }
  },
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    total: Number,
    currentPage: Number,
    pageSize: Number,
  },
  methods: {

    // 点击表格行
    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)
    },
    // 编辑
    handleEdit (index, row) {
      const headUrl = this.$API.stockIn.Quality.getHeader
      const listUrl = this.$API.stockIn.Quality.queryDetail
      const infoUrl = this.$API.stockIn.Quality.getUserName
      const param = { 'qcNo': row.qcNo, 'page.currentPage': 1, 'page.limitCount': 10 }

      this.$https.all([this.getData(headUrl, param), this.getData(listUrl, param)]).then(res => {
        this.headData = res[0]
        this.listData = res[1].rows
        const infoparam = { creator: res[0].creator, modifier: res[0].modifier }
        this.$https.post(infoUrl, infoparam).then(res => {
          this.infoData = res.data
          this.$emit('handleOpenEditForm', 'edit', this.headData, this.listData, this.infoData)
        })
      })
    },
    handleDateil (row) {
      const headUrl = this.$API.stockIn.Quality.getHeader
      const listUrl = this.$API.stockIn.Quality.queryDetail
      const infoUrl = this.$API.stockIn.Quality.getUserName
      const param = { 'qcNo': row.qcNo, 'page.currentPage': 1, 'page.limitCount': 10 }

      this.$https.all([this.getData(headUrl, param), this.getData(listUrl, param)]).then(res => {
        this.headData = res[0]
        this.listData = res[1].rows
        const infoparam = { creator: res[0].creator, modifier: res[0].modifier }
        this.$https.post(infoUrl, infoparam).then(res => {
          this.infoData = res.data
          this.$emit('handleDateil', 'dateil', this.headData, this.listData, this.infoData)
        })
      })
    },

    // 删除当前行数据
    handleDelete (index, row) {
      const url = this.$API.stockIn.Quality.remove
      const param = {
        qcNos: row.qcNo
      }
      this.$confirm('是否删除此条数据？', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          if (res.success) {
            this.$emit('getList')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

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

  }
}
</script>
<style lang="scss" scoped>
.mrg-b {
  margin-bottom: 20px;
}
.mrg-l {
  margin-left: 10px;
}
.blue {
  cursor: pointer;
  color: #0682ea;
}
</style>
