<template>
  <el-card class="cards">
    <div slot="header">
      <span class="card-title">
        已备内容
      </span>
    </div>

    <!-- 列表 -->
    <el-table
      ref="multipleTable"
      v-loading="loading"
      :data="list"
      border
      show-summary
      :summary-method="getSummaries"
    >
      <el-table-column
        label="批号"
        align="center"
        prop="wmsLabelMasterId"
        show-overflow-tooltip
      />
      <el-table-column
        label="数量"
        align="center"
        prop="batchQty"
        show-overflow-tooltip
      />
      <el-table-column
        label="拆批标志"
        align="center"
        prop="splitFlag"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.YES_NO" :value="scope.row.splitFlag" />
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
import { getPreparationLogsPage } from '@/api/wms/inLibrary/productionPreparation'

export default {
  name: 'ProductionPreparation',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用料清单（投料单）列表
      list: [],
      // 是否显示弹出层
      open: false,
      currentRows: [],
      // 发料支援表列表
      resourceList: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        materialNo: null,
        materialName: null,
        masterId: null,
        wmsSyntheticalSendDetailId: null
      }
    }
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      getPreparationLogsPage(this.queryParams).then(response => {
        this.list = response.data.list
        this.total = response.data.total
      }).finally(() => {
        this.loading = false
      })
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        orderType: undefined,
        erpId: undefined,
        erpOrderNo: undefined,
        erpOrderTime: undefined,
        status: undefined,
        workErpId: undefined,
        workOrderNo: undefined,
        workDetailErpId: undefined,
        productCode: undefined,
        productUnit: undefined,
        productName: undefined,
        productModel: undefined,
        productAmount: undefined,
        departmentNo: undefined,
        remark: undefined,
        erpMdtime: undefined,
        erpMark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 总计
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总计'
          return
        }

        const values = data.map(item => Number(item[column.property]))
        if (column.property === 'batchQty') {
          sums[index] = values.reduce((acc, cur) => {
            const value = Number(cur)
            if (!isNaN(value)) {
              return acc + cur
            } else {
              return acc
            }
          }, 0)
          sums[index]
        }
      })
      return sums
    }
  }
}
</script>
<style scoped>
.cards {
  height: 100%;
}
</style>
