<template>
  <clinic-salesperson-page-layout title="结算记录" :show-back="true">
    <view class="page">
      <view v-if="!list.length" class="empty">暂无结算记录</view>
      <view v-for="item in list" :key="item.id" class="row" @click="openDetail(item.id)">
        <view>
          <text class="no">{{ item.settlement_no }}</text>
          <text class="time">{{ item.created_at_text }}</text>
        </view>
        <text class="amount">¥{{ item.amount }}</text>
      </view>
    </view>
  </clinic-salesperson-page-layout>
</template>

<script>
import ClinicSalespersonPageLayout from '@/subPackages/sub_clinic_salesperson/components/clinic-salesperson-page-layout.vue'
import { getClinicSalespersonSettlementList, getClinicSalespersonSettlementDetail } from '@/api/clinicSalesperson.js'

export default {
  components: { ClinicSalespersonPageLayout },
  data() {
    return { list: [] }
  },
  onLoad() {
    this.loadList()
  },
  methods: {
    async loadList() {
      const wrap = await getClinicSalespersonSettlementList({ page: 1, pageSize: 50 })
      if (wrap && wrap.ok) this.list = wrap.data?.items || []
    },
    async openDetail(id) {
      const wrap = await getClinicSalespersonSettlementDetail(id)
      if (!wrap || !wrap.ok) return
      const d = wrap.data || {}
      uni.showModal({
        title: '结算详情',
        content: `单号：${d.settlement_no}\n金额：¥${d.amount}\n明细：${d.record_count}条`,
        showCancel: false,
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.page { padding: 24rpx; }
.empty { text-align: center; color: #999; padding: 80rpx 0; }
.row { background: #fff; border-radius: 12rpx; padding: 24rpx; margin-bottom: 16rpx; display: flex; justify-content: space-between; align-items: center; }
.no { display: block; font-size: 26rpx; font-weight: 600; }
.time { font-size: 22rpx; color: #999; }
.amount { font-size: 30rpx; color: #4db6a8; font-weight: 600; }
</style>
