<template>
  <div>
    <m-search class="mb-3" :items="searchItems" v-model="searchValues" @search="onSearch"></m-search>
    <m-table
      v-loading="loading"
      :items="items"
      :headers="headers"
      :page-size="pageInfo.size"
      :page-current="pageInfo.current"
      :total="total"
      @page-change="onPageChange"
    >
      <!-- <template #card-tools>
        <m-button type="orange" icon="el-icon-plus" @click="onAdd">新增</m-button>
      </template> -->
      <template #actions="{ row }">
        <m-button type="primary" text @click="onEdit(row)">分润认领</m-button>
        <!-- <m-button type="danger" text @click="onDelete(row)">删除</m-button> -->
      </template>
    </m-table>
  </div>
</template>

<script>
import { getCustomerProfitSharingClaim } from '@/api/salary'
export default {
  name: 'salaryClaimCommonTable',
  props: {
    type: {
      type: String,
      default: '0'
    }
  },
  data () {
    return {
      searchItems: [
        {
          label: '客户编号',
          prop: 'customerId',
          type: 'input',
          options: {
            placeholder: '请输入客户编号'
          }
        },
        {
          label: '科目名称',
          prop: 'subjectName',
          type: 'input',
          options: {
            placeholder: '请输入科目名称'
          }
        }
      ],
      searchValues: {
        subjectName: null,
        customerId: null
      },
      headers: [
        { label: '客户编号', prop: 'customerId' },
        { label: '一级科目编码/名称', prop: 'oneLevelSubject' },
        { label: '二级科目编码/名称', prop: 'twoLevelSubject' },
        { label: '金额', prop: 'amount' },
        { label: '统一认证号1', prop: 'unifiedCertificationNumber1' },
        { label: '统一认证号2', prop: 'unifiedCertificationNumber2' },
        { label: '数据日期', prop: 'dataDate' },
        { label: '管户层级标识', prop: 'customerLevelIdentifier' },
        { label: '客户类别标识', prop: 'customerCategoryIdentifier' },
        { label: '员工分润比例', prop: 'employeeProfitSharingRatio' },
        { label: '操作', prop: 'actions', fixed: 'right' }
      ],
      items: [],
      total: 0,
      pageInfo: {
        current: 1,
        size: 10
      },
      loading: false
    }
  },
  methods: {
    async onInit () {
      this.loading = true
      try {
        const { data } = await getCustomerProfitSharingClaim({
          ...this.pageInfo,
          level: this.type,
          ...this.searchValues
        })
        this.items = data.records
        this.total = data.total
      } catch (error) {
        this.$message.error(error)
      } finally {
        this.loading = false
      }
    },
    onAdd () {
      this.$refs.templateRefs.open()
    },
    onEdit (item) {
      this.$refs.templateRefs.open(item)
    },
    onDelete (row) {
      this.$confirm('确定删除吗？', '提示')
        .then(async () => {
          try {
            // await ApiName({ id: row.id })
            this.$message.success('删除成功')
            this.onInit()
          } catch (error) {
            this.$message.error(error)
          }
        })
        .catch(_ => {})
    },
    onSearch () {
      this.pageInfo.current = 1
      this.onInit()
    },
    onPageChange (index) {
      this.pageInfo.current = index
      this.onInit()
    }
  }
}
</script>

<style lang="scss" scoped>
  /* 自定义样式 */
</style>
