<template>
  <div class="page">
    <div class="ele-body">
      <a-card :bordered="false">
        <!-- 表格 -->
        <ele-pro-table
          ref="tableRef"
          row-key="withdrawCode"
          :columns="columns"
          :datasource="datasource"
          v-model:selection="selection"
          tool-class="ele-toolbar-form"
          :scroll="{ x: 1200 }"
          class="sys-org-table"
          :striped="true"
        >
          <template #toolbar>
            <search
              @search="reload"
              :selection="selection"
              @advanced="openAdvanced"
            />
          </template>
          <template #bodyCell="{ column, record }">
            <template v-if="column.key === 'action' && record.applyStatus == 10">
              <a-space>
                <a-popconfirm
                  title="确定通过支付宝线上打款？"
                  @confirm="auditOffline(record)">
                  <a class="ele-text-success">通过</a>
                </a-popconfirm>
                <a-divider type="vertical" />
                <!-- <a-popconfirm
                  title="确定通过支付宝打款？"
                  @confirm="auditAlipay(record)">
                  <a class="ele-text-primary">支付宝</a>
                </a-popconfirm> -->
                <a class="ele-text-danger" @click="openFail(record)">拒绝</a>
                <!-- <div class="pointer cannotselect margin-top-l margin-left-l btn-blue-full" @click="auditFail(record)">拒绝</div>
                <input-box :caption="caption" :show="showInput" :value="inputValue" @close="showInput=false" @confirm="inputBoxYes" @cancel="showInput=false">
                          </input-box> -->
                <fail v-model:visible="showFail" :data="current" @done="reload"/>
              </a-space>
            </template>
            <template v-if="column.key === 'withdrawCode'">
              {{ record.withdrawCode}}
            </template>
            <template v-if="column.key === 'nickname'">
              {{ record.nickname}}
            </template>
            <template v-if="column.key === 'cardTypeDis'">
              {{ record.cardTypeDis }}
            </template>
            <template v-if="column.key === 'alipayName'">
              {{ record.alipayName }}
            </template>
            <template v-if="column.key === 'alipayAccount'">
              {{ record.alipayAccount }}
            </template>
            <template v-if="column.key === 'payTypeDis'">
              {{ record.payTypeDis }}
            </template>
            <template v-if="column.key === 'money'">
                <span class="ele-text-warning price-edit">
                  ￥{{ record.money }}
                </span>
            </template>
            <template v-if="column.key === 'applyStatusDis'">
              {{ record.applyStatusDis }}
            </template>
            <template v-if="column.key === 'comments'">
              {{ record.comments }}
            </template>
            <template v-if="column.key === 'rejectReason'">
              {{ record.rejectReason }}
            </template>
            <template v-if="column.key === 'createTime'">
              {{ record.createTime }}
            </template>
            <template v-if="column.key === 'updateTime'">
              <span v-if="record.applyStatus ===20">{{ record.updateTime }}</span>
              <span v-else>-</span>
            </template>
          </template>

        </ele-pro-table>
      </a-card>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { createVNode,ref } from 'vue';
  import { message, Modal } from 'ant-design-vue/es';
  import {
    PlusOutlined,
    DeleteOutlined,
    ExclamationCircleOutlined
  } from '@ant-design/icons-vue';
  import type { EleProTable } from 'ele-admin-pro';
  import type {
    DatasourceFunction,
    ColumnItem
  } from 'ele-admin-pro/es/ele-pro-table/types';
  import { messageLoading,toDateString } from 'ele-admin-pro';
  import Search from './search.vue';
  import type { Withdraw, WithdrawParam, AuditRejectParam } from '@/api/withdraw/model';
  import { withdrawPage, pass, reject } from '@/api/withdraw';
  import Fail from './fail.vue';

  // 当前用户信息
  // const userStore = useUserStore();
  // const loginUser = computed(() => userStore.info ?? {});
  // const orderType = localStorage.getItem('orderType');
  defineProps<{
    activeKey?: boolean;
    data?: any;
  }>();

  // 表格实例
  const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);

  /* 获取字典数据 */
  // const orderSource = getDictionaryOptions('equipmentCategory');

  // 表格列配置
  const columns = ref<ColumnItem[]>([
    {
      key: 'index',
      width: 20,
      align: 'center',
      fixed: 'left',
      hideInSetting: true,
      hideInTable: true,
      customRender: ({ index }) => index + (tableRef.value?.tableIndex ?? 0)
    },
    {
      title: '操作',
      key: 'action',
      width: 200,
      align: 'center',
      fixed: 'left',
      hideInSetting: true
    },
    {
      title: '编号',
      dataIndex: 'withdrawCode',
      key: 'withdrawCode',
      sorter: true
    },
    {
      title: '提现用户',
      dataIndex: 'nickname',
      key: 'nickname'
    },
    {
      title: '手机号',
      dataIndex: 'userPhone',
      key: 'userPhone'
    },
    {
      title: '收入卡类型',
      dataIndex: 'cardTypeDis',
      key: 'cardTypeDis'
    },
    {
      title: '支付宝名',
      dataIndex: 'alipayName',
      key: 'alipayName'
    },
    {
      title: '支付宝账号',
      dataIndex: 'alipayAccount',
      key: 'alipayAccount'
    },
    {
      title: '打款方式',
      dataIndex: 'payTypeDis',
      key: 'payTypeDis'
    },
    {
      title: '申请金额',
      key: 'money',
      dataIndex: 'money',
      ellipsis: true
    },
    {
      title: '状态',
      dataIndex: 'applyStatusDis',
      key: 'applyStatusDis'
    },
    {
      title: '备注',
      dataIndex: 'comments',
      key: 'comments'
    },
    {
      title: '拒绝理由',
      dataIndex: 'rejectReason',
      key: 'rejectReason'
    },
    {
      title: '申请时间',
      dataIndex: 'createTime',
      key: 'createTime',
      sorter: true/* ,
      customRender: ({ text }) => toDateString(text) */
    },
    {
      title: '审核时间',
      dataIndex: 'updateTime',
      key: 'updateTime',
      sorter: true/* ,
      customRender: ({ text }) => toDateString(text) */
    },
  ]);

  // 表格选中数据
  const selection = ref<Withdraw[]>([]);

  // 是否显示高级搜索
  const showAdvancedSearch = ref(false);
  const showFail = ref(false);

  const current = ref<AuditRejectParam | null>(null);

  // 表格数据源
  const datasource: DatasourceFunction = ({
    page,
    limit,
    where,
    orders,
    filters
  }) => {
    // 搜索条件
    if (filters.scene) {
      where.scene = filters.scene;
    }
    where.tenantId = localStorage.getItem('tenantId');
    return withdrawPage({
      ...where,
      ...orders,
      page,
      limit
    });
  };

  /* 搜索 */
  const reload = (where?: WithdrawParam) => {
    selection.value = [];
    tableRef?.value?.reload({ where: where });
  };

  /* 打开高级搜索 */
  const openAdvanced = () => {
    showAdvancedSearch.value = !showAdvancedSearch.value;
  };

  const auditOffline = (param) => {
    pass({
    	id: param.id,
    	payType: 20
    }).then(result => {
      message.success(result)
      reload()
    }).catch(err => {
    	message.error(err)
    })
  }

  /* const auditAlipay = (param) => {

  } */

  /* 打开编辑弹窗 */
  const openFail = (row?: AuditRejectParam) => {
    current.value = row ?? null;
    showFail.value = true;
  };

</script>

<script lang="ts">
  export default {
    name: 'WithdrawIndex'

  };
</script>

<style lang="less" scoped>
  p {
    line-height: 0.8;
  }
  // .sys-org-table :deep(.ant-table-body) {
  //   overflow: auto !important;
  //   overflow: overlay !important;
  // }

  // .sys-org-table :deep(.ant-table-pagination.ant-pagination) {
  //   padding: 0 4px;
  //   margin-bottom: 0;
  // }
  .price-edit {
    padding-right: 5px;
    align-items: center;
  }
  .comments {
    max-width: 200px;
  }
</style>
