<template>
  <div class="new-app-container layout-vertical">
    <YMTableSearch :loading="loading" :search-form="searchForm" @onValueChange="onValueChange" @submit="onSubmit"/>
    <YMTable
      ref="table"
      :table-key="1"
      :index="true"
      :selection="false"
      :table-options="tableOptions"
      :edit-form="editForm"
      :edit-config="editConfig"
      :columns="columns"
      :rows-actions="rowsActions"
      :show-summary="false"
      :apis="apis"
      :custom-style="{ height: 'calc(100vh - 150px)' }"
    />
    <!-- 自定义弹窗 -->
    <Dialog ref="dialog">
      <template slot="content"/>
    </Dialog>
  </div>
</template>
<script>
import Dialog from '@/components/Dialog/index.vue'
import { rebatesubmit } from '@/api/data'

export default {
  components: {
    Dialog
  },
  data() {
    return {
      loading: false,
      visibleBasicDrawer: false,
      renderContent: '',
      searchForm: [
        {
          label: '会员ID',
          type: 'input',
          prop: 'member_id',
          clearable: false
        },
        {
          label: '日期',
          type: 'date',
          prop: 'date',
          clearable: false
        },
        {
          label: '会员账号',
          type: 'input',
          prop: 'username',
          clearable: false
        },
{
          label: '会员昵称',
          type: 'input',
          prop: 'first_name',
          clearable: true
        },
      ],
      columns: [
        {
          label: '日期',
          prop: 'date'
        },
          {
          label: '会员ID',
          prop: 'member_id',
          width: 120
        },
        {
          label: '会员昵称',
          popover: true,
          width:140,
          props: ['first_name'],
          options: [
            {
              label: '会员ID',
              value: ['member_id']
            }, {
              label: '会员昵称',
              value: ['member.first_name']
            },
           {
              label: '异常信息',
              vShow: (row) => row?.user_admin_note ? true : false,
              value: ['user_admin_note']
            }
          ]
        },
        {
          label: '投注额',
          prop: 'betting_amount'
        },
        {
          label: '有效投注额',
          prop: 'effective_betting_amount'
        },
        {
          label: '笔笔返',
          prop: 'amount'
        },
        {
          label: '返水比例',
          method: (row) => {
            return (row.rebate_ratio*100)+"%";
          }
        },
        {
          label: '状态',
          prop: 'status',
          method: (row) => {
            return row.status === 0 ? '待结算' : row.status === 1 ? '已结算' : '--'
          }
        },
        {
          label: '返拥时间',
          prop: 'grant_time'
        },
        {
          label: '审核人',
          prop: 'audited_by'
        }
      ],
      rowsActions: [
        {
          key: 'rebate',
          label: '发放佣金',
          vIF: (row) => row.status === 0,
          method: (row) => {
            this.$confirm(`确定发放佣金?`, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              rebatesubmit({
                id: row.id
              })
                .then(() => {
                  this.onSubmit()
                  this.$message({
                    type: 'success',
                    message: '操作成功'
                  })
                })
            })
          }
        }
      ],
      apis: {
        list: {
          url: 'rebate',
          dataParam: 'data.data',
          resultParam: 'data',
          init: false
        },
        add: {
          url: '',
          cover: true,
          coverMethod: (row, node) => {
            return row.year + '、' + node[0].label
          }
        },
        edit: {
          url: '',
          cover: true,
          coverMethod: (row, node) => {
            return row.year + '、' + node[0].label
          }
        }
      },
      tableOptions: {},
      editForm: [],
      editConfig: {
        addTip: '注：备注',
        editTip: '注：备注'
      }
    }
  },
  created() {
  },
  mounted() {
    this.onSubmit()
  },
  methods: {
    handleSubmit(formData) {
      console.log('提交数据:', formData)
      // 调用API提交数据
    },
    handleClickDrawer(row) {

    },
    onValueChange(val) {

    },
    onSubmit(params) {
      this.$refs.table.getList(params)
    }
  }
}
</script>
