<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="80%" class="shopsettlement-dialog">
    <!-- 搜索工作栏 -->
    <!-- <div class="search-one">
      <div style="text-align: right" class="search-input">
        
        <el-button :icon="Operation" @click="showSearchMore" style="margin-left: 0" />
      </div>
    </div>

    <div class="searchMore" v-show="searchMoreShow" style="width: calc(100% - 60px)">
      <el-form
        class="-mb-15px"
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="120px"
      >
         <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="resetQuery">
                <Icon class="mr-5px" icon="ep:refresh" />
                重置
              </el-button>
              <el-button @click="handleQuery" plain type="primary">
                <Icon class="mr-5px" icon="ep:search" />
                搜索
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div> -->
    <ContentWrap class="mt-15px">
      <el-table
        v-loading="loading"
        :data="list"
        :stripe="true"
        :show-overflow-tooltip="true"
        
        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"> ￥{{ (parseFloat(fenToYuan(scope.row.payPrice )) + parseFloat( pointsToPoint(scope.row.payIntegral) + parseFloat( pointsToPoint(scope.row.payConsumptionPoints)) )).toFixed(2)  }} </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>
    <!-- 列表 -->

    <!-- <template #footer>
      <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template> -->
  </Dialog>
</template>
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import { ShopSettlementApi, ShopSettlementVO } from '@/api/system/distri/shopsettlement'
import { Setting, Search, Operation } from '@element-plus/icons-vue'
import { fenToYuan,pointsToPoint,formatTime } from '@/utils'

import * as AfterSaleApi from '@/api/mall/trade/afterSale/index'
import * as TradeOrderApi from '@/api/mall/trade/order'
/** 订单结算信息表，记录店铺的结算信息 表单 */
defineOptions({ name: 'ShopSettlementForm' })

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

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('结算订单明细') // 弹窗的标题
let shopList = ref([])
// 获得所有店铺
const getAllShop = async () => {
  loading.value = true
  const res = await AfterSaleApi.getAllShop()
  shopList.value = res
}
const searchMoreShow = ref(false)
// 打开更多搜索条件
const showSearchMore = () => {
  searchMoreShow.value = !searchMoreShow.value
}
const hideSearchMore = () => {
  searchMoreShow.value = false
}
const loading = ref(true) // 列表的加载中
const list = ref<ShopSettlementVO[]>([]) // 列表的数据
// 列表的总页数
const total = ref(0)
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  shopSettlementId:0,
  createTime: [],
  shopId: undefined,
  
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中
const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (event) => {
  dialogVisible.value = true;
  queryParams.shopSettlementId = event.id;
  getList()
  getAllShop()
}

/** 查询列表 */
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;
	}
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调

// watch(
//   () => queryParams.shopId,
//   () => {
//     getList()
//   }
// )
</script>
<style src="@/styles/SearchIndex.css" lang="scss" scoped></style>
<style scoped>
::v-deep .el-card__body {
  padding: 10px;
}
</style>