<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width='80%'  class="dailybill-dialog">
    
    <!-- 搜索工作栏 -->
    <!-- <el-form
      class="mb-15px text-right"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="120px"
    >
    
      <el-form-item label="订单所属日期" prop="orderCalcTime">
        <el-date-picker
          v-model="queryParams.orderCalcTime"
          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-form-item>
    </el-form> -->
  

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true" @row-click="openDetail($event)"  row-class-name="row">
      <el-table-column label="订单号" align="center" prop="no" />
      <!-- <el-table-column label="商品名" align="center" prop="no" /> -->
      <el-table-column label="金额" align="center" prop="no" >
        <template #default="scope"> 
          ￥{{fenToYuan(scope.row.payPrice) }}
        </template>
      </el-table-column>
      <el-table-column label="确收金额" align="center" >
        <template #default="scope"> 
          ￥{{fenToYuan(scope.row.payPrice - scope.row.refundPrice) }}
        </template>
      </el-table-column>
      <el-table-column label="退款金额" align="center" prop="refundPrice" >
        <template #default="scope"> 
          ￥{{fenToYuan(scope.row.refundPrice) }}
        </template>
      </el-table-column>
     
      <el-table-column label="佣金抵扣" align="center" prop="payIntegral" >
        <template #default="scope"> 
          {{pointsToPoint(scope.row.payIntegral || 0) }}
        </template>
      </el-table-column>
      <el-table-column label="消费分抵扣" align="center" prop="payConsumptionPoints" >
        <template #default="scope"> 
          {{pointsToPoint(scope.row.payConsumptionPoints || 0) }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="确收佣金" align="center" prop="receivedIntegral" >
        <template #default="scope"> 
          {{pointsToPoint(scope.row.receivedIntegral) }}
        </template>
      </el-table-column>
      <el-table-column label="退款佣金" align="center" prop="refundIntegral" >
        <template #default="scope"> 
          {{pointsToPoint(scope.row.refundIntegral) }}
        </template>
      </el-table-column> -->

      <el-table-column label="下单时间" align="center" prop="createTime" >
        <template #default="scope"> 
          {{formatTime(scope.row.createTime,'yyyy-MM-dd HH:mm:ss')}}
        </template>
      </el-table-column>
      
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
  <OrderIndex ref="formRef" @success="getList" />
  </Dialog>
</template>
<script setup lang="ts">
// import { DailyBillApi, DailyBillVO } from '@/api/system/distri/dailybill'
import { fenToYuan,pointsToPoint,formatTime } from '@/utils'
import OrderIndex from "@/views/mall/trade/order/components/OrderIndex.vue"
import * as TradeOrderApi from '@/api/mall/trade/order'
import { useAppStore } from '@/store/modules/app'
const { currentRoute, push } = useRouter() // 路由跳转
const appStore = useAppStore()
const mobile = computed(() => appStore.getMobile)
const loading = ref(true) // 列表的加载中
const total = ref(0)
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  orderCalcTime: undefined,
  payStatus:1,
  shopId:undefined,
  merchantId:undefined,
  
})
/** 每日账单 表单 */
defineOptions({ name: 'DailyBillForm' })

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

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('明细项') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formType = ref('') // 表单的类型：create - 新增；update - 修改


const list = ref([])
/** 打开弹窗 */
const open = async (event) => {
  dialogVisible.value = true;
  queryParams.orderCalcTime = event.orderCalcTime;
  queryParams.merchantId = event.merchantId;
  queryParams.shopId = event.shopId;
  getList();
}


defineExpose({ open }) // 提供 open 方法，用于打开弹窗

const formRef = ref()
const openDetail = (row) => {

	// console.log("当前是不是移动端", mobile.value)
	const id = row.id
	// console.log("当前订单的id是", id)
	if (mobile.value) {
		push({ name: 'TradeOrderMobileDetail', params: { id } })
	} else {
		formRef.value.open('view', row, row.no)
	}
}


/** 查询列表 */
const getList = async () => {
	loading.value = true;
  console.log(unref(queryParams));
	try {
		const data = await TradeOrderApi.getOrderPage(unref(queryParams));
		list.value = data.list;
    
		total.value = data.total;
	} finally {
		loading.value = false;
	}
}
</script>
<style>
.dailybill-dialog{
  min-height: 600px;
}

</style>
