<template>
  <template-page
    ref="pageRef"
    :getList="getList"
    :exportList="exportList"
    :columnParsing="columnParsing"
    :optionsEvensGroup="optionsEvensGroup"
    :tableAttributes="tableAttributes"
    :tableEvents="tableEvents"
  >
  </template-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import {
  partsOldOutList,
  partsOldOutExport,
  partsOldOutDel,
  partsOldOutImport,
  partsOldOutConfirm
} from '@/api/material-system/center/center-old-parts-shop-out'
import operation_mixin from '@/components/template/operation_mixin.js'
export default {
  components: { TemplatePage },
  mixins: [import_mixin, operation_mixin],
  data() {
    return {
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true,
        selectable: this.selectable
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      recordSelected: []
    }
  },
  computed: {
    optionsEvensGroup() {
      return [
        [
          [
            this.optionsEvensAuth('batchApproval', {
              click: () => {
                this.shenpi()
              }
            })
          ]
        ]
      ]
    }
  },
  methods: {
    // 列表请求函数
    getList(p) {
      this.recordSelected = []
      return partsOldOutList({ ...p, receiveDate: true })
    },
    // 列表导出函数
    exportList: partsOldOutExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    // 批量审批
    shenpi() {
      if (this.recordSelected.length) {
        this.$confirm('此操作将批量审批数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            partsOldOutConfirm(this.recordSelected.map(item => item.id))
              .then(res => {
                this.$refs.pageRef.refreshList()
                this.$message({
                  type: 'success',
                  message: `审批成功!`
                })
                this.recordSelected = []
              })
              .catch(() => {})
          })
          .catch(() => {})
      } else {
        this.$message({
          type: 'info',
          message: '请先勾选需要审批的数据!'
        })
      }
    },
    selectable(row, index) {
      return true
    }
  }
}
</script>

<style lang="scss" scoped></style>
