<template>
  <view class="vip-components-table__stripe">
    
    <!-- 顶部自定义导航 -->
    <tn-nav-bar fixed>斑马纹表格</tn-nav-bar>
    
    <view :style="{paddingTop: vuex_custom_bar_height + 'px'}">
      
      <demo-title title="表格样式-1">
        <tn-table borderWidth="0">
          <tn-tr>
            <tn-td v-for="(item, index) in header" :key="index" :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" :backgroundColor="index%2 ? '#FFFFFF' : '#E6E6E6'">
            <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>
      </demo-title>
      
      <demo-title title="表格样式-2">
        <tn-table borderWidth="0">
          <tn-tr>
            <tn-td v-for="(item, index) in header" :key="index" :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" :backgroundColor="index%2 ? 'tn-bg-green--light' : 'tn-bg-red--light'">
            <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>
      </demo-title>
      
      <view class="tn-padding-bottom-lg"></view>
      
    </view>
  </view>
</template>

<script>
  import demoTitle from '@/libs/components/demo-title.vue'
  export default {
    name: 'VipComponentsStripeTable',
    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: '今天的销售额还行啦' }
        ]
      }
    },
    methods: {
      // 处理点击事件
      handleClick(e, id) {
        this.$tn.message.toast(`点击了[${e.key}]id为${id}的选项`)
      }
    }
  }
</script>

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