<template>
  <view class="finance-invoice">
    <!-- 头部筛选区 -->
    <view class="filter-card border-shadow">
      <view class="filter-row">
        <view class="filter-item">
          <text class="filter-label">创建时间:</text>
          <view class="date-picker-wrap">
            <text class="calendar-icon">📅</text>
            <text class="date-placeholder">开始日期 - 结束日期</text>
          </view>
        </view>
        <view class="filter-item">
          <text class="filter-label">搜索:</text>
          <view class="search-group">
            <view class="select-trigger">
              <text class="select-txt">请选择</text>
              <text class="arrow-down">▼</text>
            </view>
            <input class="search-input" placeholder="请输入" />
          </view>
        </view>
        <view class="btn-query">
          <text class="btn-txt">查询</text>
        </view>
      </view>
    </view>

    <!-- 状态切换选项卡 -->
    <view class="tab-section">
      <view 
        v-for="(tab, index) in tabs" 
        :key="index"
        class="tab-item"
        :class="{ active: activeTab === index }"
        @click="activeTab = index"
      >
        <text class="tab-title">{{ tab.name }} ({{ tab.count }})</text>
        <view class="active-line" v-if="activeTab === index"></view>
      </view>
    </view>

    <!-- 数据表格 (Flex 模拟) -->
    <view class="table-container border-shadow">
      <view class="table-header">
        <view class="th col-order"><text class="th-txt">订单号</text></view>
        <view class="th col-amount"><text class="th-txt">订单金额</text></view>
        <view class="th col-type"><text class="th-txt">发票类型</text></view>
        <view class="th col-header"><text class="th-txt">发票抬头类型</text></view>
        <view class="th col-time"><text class="th-txt">下单时间</text></view>
        <view class="th col-status-inv"><text class="th-txt">开票状态</text></view>
        <view class="th col-status-order"><text class="th-txt">订单状态</text></view>
        <view class="th col-ops"><text class="th-txt">操作</text></view>
      </view>

      <view class="table-body">
        <view class="table-row" v-for="item in tableData" :key="item.orderNo">
          <view class="td col-order text-left"><text class="td-txt">{{ item.orderNo }}</text></view>
          <view class="td col-amount"><text class="td-txt">¥ {{ item.amount }}</text></view>
          <view class="td col-type"><text class="td-txt">{{ item.invoiceType }}</text></view>
          <view class="td col-header"><text class="td-txt">{{ item.headerType }}</text></view>
          <view class="td col-time"><text class="td-txt">{{ item.time }}</text></view>
          <view class="td col-status-inv"><text class="td-txt red-cell">{{ item.invStatus }}</text></view>
          <view class="td col-status-order"><text class="td-txt">{{ item.orderStatus }}</text></view>
          <view class="td col-ops">
            <view class="ops-box">
              <text class="op-link">操作</text>
              <text class="sep">|</text>
              <text class="op-link">订单信息</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="uts">
import { ref } from 'vue'

const activeTab = ref(0)

const tabs = ref([
  { name: '全部发票', count: 163 },
  { name: '待开发票', count: 105 },
  { name: '已开发票', count: 34 },
  { name: '退款发票', count: 33 }
])

const tableData = ref([
  {
    orderNo: 'cp538981381384962048',
    amount: '999.00',
    invoiceType: '电子普通发票',
    headerType: '个人',
    time: '2026-01-27 07:19:35',
    invStatus: '未开票',
    orderStatus: '未发货'
  },
  {
    orderNo: 'cp523490058603331584',
    amount: '9.00',
    invoiceType: '电子普通发票',
    headerType: '个人',
    time: '2025-12-15 13:22:35',
    invStatus: '未开票',
    orderStatus: '未发货'
  },
  {
    orderNo: 'cp524967077409193984',
    amount: '9.00',
    invoiceType: '电子普通发票',
    headerType: '个人',
    time: '2025-12-19 15:11:44',
    invStatus: '未开票',
    orderStatus: '未发货'
  },
  {
    orderNo: 'cp521126678106210304',
    amount: '11890.00',
    invoiceType: '电子普通发票',
    headerType: '个人',
    time: '2025-12-09 00:51:22',
    invStatus: '未开票',
    orderStatus: '未发货'
  },
  {
    orderNo: 'cp521126166883467264',
    amount: '11800.00',
    invoiceType: '电子普通发票',
    headerType: '个人',
    time: '2025-12-09 00:49:20',
    invStatus: '未开票',
    orderStatus: '未发货'
  },
  {
    orderNo: 'cp517015093888679936',
    amount: '142.00',
    invoiceType: '电子普通发票',
    headerType: '个人',
    time: '2025-11-27 16:33:24',
    invStatus: '未开票',
    orderStatus: '未发货'
  },
  {
    orderNo: 'cp313601579989073920',
    amount: '0.00',
    invoiceType: '电子普通发票',
    headerType: '个人',
    time: '2024-05-15 08:59:56',
    invStatus: '未开票',
    orderStatus: '待评价'
  },
  {
    orderNo: 'cp503871643047690240',
    amount: '999.00',
    invoiceType: '电子普通发票',
    headerType: '个人',
    time: '2025-10-22 10:06:01',
    invStatus: '未开票',
    orderStatus: '未发货'
  }
])
</script>

<style scoped lang="scss">
.finance-invoice {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.border-shadow {
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

/* 筛选栏 */
.filter-card {
  padding: 20px 24px;
  margin-bottom: 20px;
}

.filter-row {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.filter-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-right: 30px;
}

.filter-label {
  font-size: 14px;
  color: #333;
  margin-right: 8px;
}

.date-picker-wrap {
  width: 240px;
  height: 32px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 0 10px;
}

.calendar-icon {
  margin-right: 8px;
  font-size: 12px;
}

.date-placeholder {
  font-size: 13px;
  color: #c0c4cc;
}

.search-group {
  display: flex;
  flex-direction: row;
  align-items: center;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  height: 32px;
  overflow: hidden;
}

.select-trigger {
  width: 90px;
  height: 100%;
  border-right: 1px solid #dcdfe6;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background-color: #fff;
}

.select-txt {
  font-size: 13px;
  color: #606266;
}

.arrow-down {
  font-size: 8px;
  color: #c0c4cc;
}

.search-input {
  width: 160px;
  height: 100%;
  padding: 0 12px;
  font-size: 13px;
}

.btn-query {
  background-color: #1890ff;
  border-radius: 4px;
  padding: 0 20px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-txt {
  color: #fff;
  font-size: 14px;
}

/* 选项卡 */
.tab-section {
  display: flex;
  flex-direction: row;
  margin-bottom: 20px;
  border-bottom: 1px solid #e4e7ed;
  padding: 0 10px;
}

.tab-item {
  padding: 12px 20px;
  position: relative;
  cursor: pointer;
}

.tab-title {
  font-size: 14px;
  color: #606266;
  transition: all 0.3s;
}

.tab-item.active .tab-title {
  color: #1890ff;
  font-weight: 600;
}

.active-line {
  position: absolute;
  bottom: 0;
  left: 20px;
  right: 20px;
  height: 2px;
  background-color: #1890ff;
}

/* 表格 */
.table-container {
  display: flex;
  flex-direction: column;
}

.table-header {
  background-color: #f8f9fb;
  display: flex;
  flex-direction: row;
  border-bottom: 1px solid #ebeef5;
}

.th {
  padding: 15px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.th-txt {
  font-size: 14px;
  font-weight: 600;
  color: #909399;
}

.table-row {
  display: flex;
  flex-direction: row;
  border-bottom: 1px solid #ebeef5;
  transition: background-color 0.3s;
}

.td {
  padding: 15px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.td-txt {
  font-size: 13px;
  color: #606266;
}

/* 列宽分配 */
.col-order { width: 220px; justify-content: flex-start; padding-left: 20px; }
.col-amount { width: 120px; }
.col-type { width: 150px; }
.col-header { width: 120px; }
.col-time { width: 180px; }
.col-status-inv { width: 120px; }
.col-status-order { width: 120px; }
.col-ops { flex: 1; min-width: 140px; }

.text-left {
  justify-content: flex-start;
}

.red-cell {
  color: #f56c6c;
}

.ops-box {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.op-link {
  font-size: 13px;
  color: #1890ff;
  cursor: pointer;
}

.sep {
  font-size: 12px;
  color: #ebeef5;
  margin: 0 8px;
}
</style>
