<template>
  
  <!-- 搜索 -->
  <div class="search-one">
    <div style="text-align: right;" class="search-input">
      
      <el-button :icon="Operation" @click="showSearchMore" />
    </div>
  </div>
  <div class="searchMore" v-show="searchMoreShow" :style="{ width: (mobile ? '88.7%' : '96%') }">
    <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px">
      <!-- <el-form-item label="平台服务费" prop="ptAdd">
        <el-input v-model="queryParams.ptAdd" placeholder="请输入平台服务费" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="平台收益" prop="ptGrossAdd">
        <el-input v-model="queryParams.ptGrossAdd" placeholder="请输入平台收益" clearable
          @keyup.enter="handleQuery" class="!w-240px" />
      </el-form-item>
      <el-form-item label="平台总收益" prop="ptTotalAdd">
        <el-input v-model="queryParams.ptTotalAdd" placeholder="请输入平台总收益" clearable @keyup.enter="handleQuery"
          class="!w-240px" />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" value-format="YYYY-MM-DD HH:mm:ss" type="daterange"
          start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" class="!w-240px" />
      </el-form-item> -->
      <el-row>
        <el-col>
          <el-form-item>
            <el-button @click="hideSearchMore">
              收起
            </el-button>
            <el-button @click="handleQuery">
              <Icon icon="ep:search" class="mr-5px" /> 搜索
            </el-button>
            <el-button @click="resetQuery">
              <Icon icon="ep:refresh" class="mr-5px" /> 重置
            </el-button>
            
            <!-- <el-button type="primary" plain @click="openForm('create')" v-hasPermi="['distri:pt-profit:create']">
              <Icon icon="ep:plus" class="mr-5px" /> 新增
            </el-button>
            <el-button type="success" plain @click="handleExport" :loading="exportLoading"
              v-hasPermi="['distri:pt-profit:export']">
              <Icon icon="ep:download" class="mr-5px" /> 导出
            </el-button> -->
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
  <!-- 列表 -->
  <ContentWrap  style="margin-top:10px;padding: 10px;" >
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" @row-click="openForm($event)" row-class-name="row">
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="提现总金额" align="center" prop="amountTotal"  >
        <template #default="scope">
          {{ fenToYuan(scope.row.amountTotal) }}
        </template>
      </el-table-column>
      <el-table-column label="到账金额" align="center" prop="amount" >
        <template #default="scope">
          {{ fenToYuan(scope.row.amount) }}
        </template>
      </el-table-column>
      <el-table-column label="消费分" align="center" prop="withdrawConsumption" >
        <template #default="scope">
          {{ pointsToPoint(scope.row.withdrawConsumption) }}
        </template>
      </el-table-column>
      <el-table-column label="笔数" align="center" prop="count" />
      <el-table-column label="状态" align="center" prop="status" >
        <template #default="scope">
          {{ formatStatus(scope.row.status)  }}
        </template>
      </el-table-column>
      
      <!-- <el-table-column
        label="提现开始时间"
        align="center"
        prop="startTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column
        label="提现截止时间"
        align="center"
        prop="endTime"
        :formatter="dateFormatter"
        width="180px"
      /> -->
      <el-table-column
        label="日期"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="300px"
      >
        <template #default="scope">
          {{ formatDate( scope.row.startTime,'YYYY-MM-DD HH:mm') }} - {{ formatDate(scope.row.endTime,'YYYY-MM-DD HH:mm') }}
        
        </template>
      </el-table-column>

      <!-- <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('update', scope.row.id)"
            v-hasPermi="['distri:pt-daily-withdrawal:update']"
          >
            编辑
          </el-button>
          <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['distri:pt-daily-withdrawal:delete']"
          >
            删除
          </el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <PtDailyWithdrawalForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { fenToYuan,pointsToPoint } from '@/utils'
import { dateFormatter, formatDate } from '@/utils/formatTime'
import download from '@/utils/download'
import { PtDailyWithdrawalApi, PtDailyWithdrawalVO } from '@/api/system/distri/ptdailywithdrawal'
import PtDailyWithdrawalForm from './PtDailyWithdrawalForm.vue'
import { Setting, Search, Operation } from '@element-plus/icons-vue'
import { useAppStore } from '@/store/modules/app'
import { format } from 'path'
import { provide } from 'vue'
provide('getPtdailyWithdrawalList', ()=>{
  getList()
});

const appStore = useAppStore()
const mobile = computed(() => appStore.getMobile)
const searchMoreShow = ref(false)
// 打开更多搜索条件
const showSearchMore = () => {
  searchMoreShow.value = !searchMoreShow.value
}
const hideSearchMore = () => {
  searchMoreShow.value = false
}
/** 平台每日提现记录 列表 */
defineOptions({ name: 'PtDailyWithdrawal' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<PtDailyWithdrawalVO[]>([]) // 列表的数据
// 列表的总页数
const total = ref(0)
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  amount: undefined,
  count: undefined,
  status: undefined,
  startTime: [],
  endTime: [],
  createTime: []
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await PtDailyWithdrawalApi.getPtDailyWithdrawalPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (event) => {
  formRef.value.open(event)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await PtDailyWithdrawalApi.deletePtDailyWithdrawal(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await PtDailyWithdrawalApi.exportPtDailyWithdrawal(queryParams)
    download.excel(data, '平台每日提现记录.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}
function formatStatus(status){
  if(!status){
    return '待转账'
  }else if(status === 1){
    return '转账成功'
  }else if(status === 2){
    return '部分转账成功'
  }else{
    return '转账失败'
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>

<style src="@/styles/SearchIndex.css" lang="scss" scoped></style>
<style>
.row {
  cursor: pointer;
}
.ptdailywithdrawal-dialog > .el-dialog__body {
  padding: 10px;
  min-height:500px;
}
</style>
<style scoped>
::v-deep .el-card__body {
  padding: 10px;
}
</style>