<!--
 * @Author: Do not edit
 * @Date: 2023-12-29 10:01:55
 * @LastEditTime: 2024-01-30 14:42:15
 * @LastEditors: DY
 * @Description: 报废列表
-->
<template>
  <div class="list">
    <van-row type="flex" justify="space-between">
      <van-col span="5" style="text-align: left">
        <h2>报废管理</h2>
      </van-col>
      <!-- <van-col span="4">
        <img class="homeIcon" @click="goback" src="./../assets/record.png" alt="">
      </van-col> -->
      <van-col span="8" style="text-align: right">
        <img class="homeIcon" @click="toScrap" src="./../assets/record.png" alt="">
        <img class="homeIcon" @click="goback" src="./../assets/home.png" alt="">
      </van-col>
    </van-row>
    <el-table
    :data="tableData"
    border
    :header-cell-style="{ background: 'rgba(210, 220, 242, 1)', color: '#000', height: '33px' }"
    show-header
    style="width: 100%">
      <el-table-column
      type="index" label="序号" width="60" />
      <el-table-column v-for="(item, index) in tableProps" :key="index" :prop="item.prop" :label="item.label" />
    </el-table>
    <el-pagination
      class="pagination"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listQuery.pageNo"
      :page-sizes="[10, 20, 30]"
      :page-size="listQuery.pageSize"
      layout="prev, pager, next"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { scrapLogList } from '@/api/quality'
import { parseTime } from '@/utils/time'

const tableProps = [
  {
    prop: 'scrapTime',
    label: '报废时间'
  },
  {
    prop: 'lineName',
    label: '产线名称'
  },
  {
    prop: 'sectionName',
    label: '工段名称'
  },
  {
    prop: 'workOrderName',
    label: '工单名称'
  },
  {
    prop: 'num',
    label: '报废数量'
  },
  {
    prop: 'detContent',
    label: '报废原因'
  },
  {
    prop: 'sources',
    label: '来源'
  }
]

export default {
  name: 'ScrapList',
  data () {
    return {
      listQuery: {
        pageSize: 10,
        pageNo: 1
      },
      tableProps,
      tableData: [],
      total: 0
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.listQuery.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      this.listQuery.pageNo = val
      this.getList()
      console.log(`当前页: ${val}`)
    },
    getList () {
      scrapLogList(this.listQuery).then(res => {
        if (res.data.code === 0) {
          this.tableData = res.data.data.list.map(item => {
            item.sources = item.source === 1 ? '平板端' : '网页端'
            item.scrapTime = parseTime(item.logTime)
            return item
          })
          this.total = res.data.data.total
        }
      })
    },
    goback () {
      this.$router.push({
        path: 'home'
      })
    },
    toScrap () {
      this.$router.push({
        path: 'scrap'
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.el-table__row--even {
  background-color: #f9fafc; /* 偶数行背景颜色 */
}
.el-table__row--odd {
  background-color: #a76c6c; /* 奇数行背景颜色 */
}
.pagination {
  margin-top: 10px;
  float: right;
}
.list {
  background-image: url('./../assets/quality-bg.png');
  height: 100vh;
  width: 100vw;
  padding: 20px 24px;
  box-sizing: border-box;
}
</style>
