<template>
  <!-- <ContentWrap>

    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="毛利 = 成本 * 0.38... (推广费用)" prop="grossProfitPerc">
        <el-input
          v-model="queryParams.grossProfitPerc"
          placeholder="请输入毛利 = 成本 * 0.38... (推广费用)"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="推广-用户额度 百分比" prop="grossProfitUserQuotaPerc">
        <el-input
          v-model="queryParams.grossProfitUserQuotaPerc"
          placeholder="请输入推广-用户额度 百分比"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="推广-推荐人额度 百分比" prop="grossProfitAncestorQuotaPerc">
        <el-input
          v-model="queryParams.grossProfitAncestorQuotaPerc"
          placeholder="请输入推广-推荐人额度 百分比"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="推广-合赢奖额度(浮动) 百分比" prop="grossProfitBonusQuotaPerc">
        <el-input
          v-model="queryParams.grossProfitBonusQuotaPerc"
          placeholder="请输入推广-合赢奖额度(浮动) 百分比"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="推广-平台分成额度(浮动) 百分比" prop="grossProfitPlatformQuotaPerc">
        <el-input
          v-model="queryParams.grossProfitPlatformQuotaPerc"
          placeholder="请输入推广-平台分成额度(浮动) 百分比"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="分成百分比" prop="divideIntoPerc">
        <el-input
          v-model="queryParams.divideIntoPerc"
          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-form-item>
        <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:order-percentage:create']"
        >
          <Icon icon="ep:plus" class="mr-5px" /> 新增
        </el-button>
        <el-button
          type="success"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['distri:order-percentage:export']"
        >
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap> -->

  <!-- 列表 -->
  <h3 class="m-y-1">佣金</h3>
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">

      <el-table-column label="毛利" align="center" prop="grossProfitPerc" >
        <template #default="scope">
          <span>{{ scope.row.grossProfitPerc*100 }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="用户自得" align="center" prop="grossProfitUserQuotaPerc" >
        <template #default="scope">
          <span>{{ scope.row.grossProfitUserQuotaPerc*100  }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="直推奖" align="center" prop="grossProfitAncestorQuotaPerc" >
        <template #default="scope">
          <span>{{ scope.row.grossProfitAncestorQuotaPerc*100}}%</span>
        </template>
      </el-table-column>
      <el-table-column label="合赢奖" align="center" prop="grossProfitBonusQuotaPerc" >
        <template #default="scope">
          <span>{{ scope.row.grossProfitBonusQuotaPerc*100 }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="平台服务费" align="center" prop="grossProfitPlatformQuotaPerc" >
        <template #default="scope">
          <span>{{ scope.row.grossProfitPlatformQuotaPerc*100 }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="分成百分比" align="center" prop="divideIntoPerc">
        <template #default="scope">
          <span>{{ scope.row.divideIntoPerc*100 }}%</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('update1', scope.row.id)"
            v-hasPermi="['distri:order-percentage:update']"
          >
            编辑
          </el-button>
          <!-- <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['distri:order-percentage:delete']"
          >
            删除
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
  </ContentWrap>
  <h3 class="m-y-1">公众提现</h3>
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">

      <el-table-column label="提现比例" align="center" prop="withdrawCommission" >
        <template #default="scope">
          <span>{{ scope.row.withdrawCommission*100 }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="消费分比例" align="center" prop="withdrawConsumption" >
        <template #default="scope">
          <span>{{ scope.row.withdrawConsumption*100  }}%</span>
        </template>
      </el-table-column>
      

      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('withdraw', scope.row.id)"
            v-hasPermi="['distri:order-percentage:update']"
          >
            编辑
          </el-button>
          <!-- <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['distri:order-percentage:delete']"
          >
            删除
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
  </ContentWrap>
  <h3 class="m-y-1">身价</h3>
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="购物自得" align="center" prop="orderUserSocialStatus" >
        <template #default="scope">
          <span>{{ scope.row.orderUserSocialStatus }}</span>
        </template>
      </el-table-column>
      <el-table-column label="购物推荐人获得" align="center" prop="orderAncestorSocialStatus" >
        <template #default="scope">
          <span>{{ scope.row.orderAncestorSocialStatus  }}</span>
        </template>
      </el-table-column>
      <el-table-column label="注册默认身价" align="center" prop="registerSocialStatus" >
        <template #default="scope">
          <span>{{ scope.row.registerSocialStatus}}</span>
        </template>
      </el-table-column>
      <el-table-column label="推荐注册身价" align="center" prop="registerAncestorSocialStatus" >
        <template #default="scope">
          <span>{{ scope.row.registerAncestorSocialStatus}}</span>
        </template>
      </el-table-column>
      <el-table-column label="收藏获得" align="center" prop="collectSocialStatus" >
        <template #default="scope">
          <span>{{ scope.row.collectSocialStatus }}</span>
        </template>
      </el-table-column>
      <el-table-column label="签到获得" align="center" prop="signInSocialStatus" />
      <el-table-column label="签到可获得的最大身价值" align="center" prop="signInSocialStatusMax" />
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('update2', scope.row.id)"
            v-hasPermi="['distri:order-percentage:update']"
          >
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </ContentWrap>
  <h3 class="m-y-1">消费分</h3>
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="充值倍率" align="center" prop="consumptionMagnification" >
        <template #default="scope">
          <span>{{ scope.row.consumptionMagnification*100 }}%</span>
        </template>

      </el-table-column>
      <el-table-column label="触发倍率的最低金额" align="center" prop="triggerMagnificationPoints" >
        <template #default="scope">
          <span>{{ scope.row.triggerMagnificationPoints }}</span>
        </template>

      </el-table-column>
      <!-- <el-table-column label="首次最低充值金额" align="center" prop="firstTopUpConsumption" >
        <template #default="scope">
          <span>{{ scope.row.firstTopUpConsumption  }}</span>
        </template>
      </el-table-column>
      <el-table-column label="后续单次最低充值金额" align="center" prop="followUpConsumption" >
        <template #default="scope">
          <span>{{ scope.row.followUpConsumption}}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="用户单次最低充值金额" align="center" prop="userTopUpConsumptionPoints" >
        <template #default="scope">
          <span>{{ scope.row.userTopUpConsumptionPoints}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm('consumption', scope.row.id)"
            v-hasPermi="['distri:order-percentage:update']"
          >
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </ContentWrap>
  <!-- 表单弹窗：添加/修改 -->
  <OrderPercentageForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { OrderPercentageApi, OrderPercentageVO } from '@/api/system/distri/orderpercentage'
import OrderPercentageForm from './OrderPercentageForm.vue'

/** 佣金相关计算浮动百分比设置 列表 */
defineOptions({ name: 'OrderPercentage' })

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

const loading = ref(true) // 列表的加载中
const list = ref<OrderPercentageVO[]>([]) // 列表的数据
// 列表的总页数
const total = ref(0)
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  grossProfitPerc: undefined,
  grossProfitUserQuotaPerc: undefined,
  grossProfitAncestorQuotaPerc: undefined,
  grossProfitBonusQuotaPerc: undefined,
  grossProfitPlatformQuotaPerc: undefined,
  divideIntoPerc: undefined,
  createTime: []
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await OrderPercentageApi.getOrderPercentagePage(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 = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

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

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await OrderPercentageApi.exportOrderPercentage(queryParams)
    download.excel(data, '佣金相关计算浮动百分比设置.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

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