<template>
  <view class="vip-components-table__fixed-header">
    
    <!-- 顶部自定义导航 -->
    <tn-nav-bar fixed>固定头部表格</tn-nav-bar>
    
    <view :style="{paddingTop: vuex_custom_bar_height + 'px'}">
      
      <view>
        <tn-table :borderTop="false" :borderLeft="false">
          <tn-tr :fixed="true" :borderTop="true" :top="vuex_custom_bar_height + 'px'">
            <tn-td v-for="(item, index) in header" :key="index" height="48rpx" :bold="true" :span="8" :keys="item.key">{{ item.title }}</tn-td>
          </tn-tr>
          <tn-tr v-for="(item, index) in listData" :key="index" :index="item.id" :margin="index === 0 ? '48rpx 0 0 0' : ''">
            <tn-td v-for="(data, idx) in header" :key="idx" :span="8" :keys="data.key" @click="handleClick($event, item.id)">{{ item[data.key] }}</tn-td>
          </tn-tr>
        </tn-table>
      </view>
      
      <demo-title title="配合scroll-view使用">
        <tn-table>
          <tn-tr left="32rpx" right="30rpx" width="auto">
            <tn-td v-for="(item, index) in header" :key="index" height="48rpx" :bold="true" :span="8" :keys="item.key">{{ item.title }}</tn-td>
          </tn-tr>
          <scroll-view style="height: 400px" scroll-y>
            <tn-tr v-for="(item, index) in listData" :key="index" :index="item.id">
              <tn-td v-for="(data, idx) in header" :key="idx" :span="8" :keys="data.key" @click="handleClick($event, item.id)">{{ item[data.key] }}</tn-td>
            </tn-tr>
          </scroll-view>
          
        </tn-table>
      </demo-title>
      
      <view class="tn-padding-bottom-lg"></view>
      
    </view>
  </view>
</template>

<script>
  import demoTitle from '@/libs/components/demo-title.vue'
  export default {
    name: 'VipComponentsFixedHeaderTable',
    components: { demoTitle },
    data() {
      return {
        header: [
          { title: '日期', key: 'date' },
          { title: '金额', key: 'price' },
          { title: '备注', key: 'note' }
        ],
        listData: [
          { id: 1, date: '20220301', price: '1,000', note: '今天的销售额一般般呀' },
          { id: 2, date: '20220302', price: '1,000,00', note: '今天的销售额还不错嘛' },
          { id: 3, date: '20220303', price: '4000', note: '今天的销售额还行啦' },
          { id: 4, date: '20220301', price: '1,000', note: '今天的销售额一般般呀' },
          { id: 5, date: '20220302', price: '1,000,00', note: '今天的销售额还不错嘛' },
          { id: 6, date: '20220303', price: '4000', note: '今天的销售额还行啦' },
          { id: 7, date: '20220301', price: '1,000', note: '今天的销售额一般般呀' },
          { id: 8, date: '20220302', price: '1,000,00', note: '今天的销售额还不错嘛' },
          { id: 9, date: '20220303', price: '4000', note: '今天的销售额还行啦' },
          { id: 10, date: '20220301', price: '1,000', note: '今天的销售额一般般呀' },
          { id: 11, date: '20220302', price: '1,000,00', note: '今天的销售额还不错嘛' },
          { id: 12, date: '20220303', price: '4000', note: '今天的销售额还行啦' },
          { id: 13, date: '20220301', price: '1,000', note: '今天的销售额一般般呀' },
          { id: 14, date: '20220302', price: '1,000,00', note: '今天的销售额还不错嘛' },
          { id: 15, date: '20220303', price: '4000', note: '今天的销售额还行啦' },
          { id: 16, date: '20220301', price: '1,000', note: '今天的销售额一般般呀' },
          { id: 17, date: '20220302', price: '1,000,00', note: '今天的销售额还不错嘛' },
          { id: 18, date: '20220303', price: '4000', note: '今天的销售额还行啦' },
          { id: 19, date: '20220301', price: '1,000', note: '今天的销售额一般般呀' },
          { id: 20, date: '20220302', price: '1,000,00', note: '今天的销售额还不错嘛' },
          { id: 21, date: '20220303', price: '4000', note: '今天的销售额还行啦' },
          { id: 22, date: '20220301', price: '1,000', note: '今天的销售额一般般呀' },
          { id: 23, date: '20220302', price: '1,000,00', note: '今天的销售额还不错嘛' },
          { id: 24, date: '20220303', price: '4000', note: '今天的销售额还行啦' }
        ]
      }
    },
    methods: {
      // 处理点击事件
      handleClick(e, id) {
        this.$tn.message.toast(`点击了[${e.key}]id为${id}的选项`)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .vip-components-table__fixed-header {
    background-color: $tn-bg-gray-color;
    min-height: 100vh;
  }
</style>
