<template>
  <div>
    <div ref="lxHeader">
      <lx-header icon="md-apps" style="margin-bottom: 10px; border: 0px; margin-top: 15px" text="护工工资">
        <div slot="content"></div>
        <slot>
          <div>
            <Input v-model="select.keyword" placeholder="关键字搜索" style="width: 200px; margin-right: 10px"/>
            <Button style="margin-left: 10px" type="primary" @click="select.page = 1,getList">查询</Button>
          </div>
        </slot>
      </lx-header>
    </div>

    <xy-table
      :total="total"
      :list="list"
      :table-item="table">
      <template v-slot:btns>
        <div></div>
      </template>
    </xy-table>

  </div>
</template>

<script>
import {salaryList as getList} from '@/api/worker'
import {parseTime} from "@/utils"

export default {

  data() {
    return {
      select:{
        page:1,
        page_size:10,
        keyword:''
      },
      types:[],

      total:0,
      list:[],
      table:[
        {
          label:'姓名',
          width:140,
          fixed:'left',
          prop:'name'
        },
        {
          label:'明细',
          customFn:(row)=>{
            return (
              <div style={{'display':'flex'}}>
                {
                  row.data.map(item => {
                    return (
                      <div style={{'border':'1px #000 solid'}}>
                        <div style={{'border-bottom':'1px #000 solid'}}>{item.date}</div>
                        <div>{item.money}元</div>
                      </div>
                    )
                  })
                }
              </div>
            )
          }
        },
        {
          label:'合计',
          width: 160,
          align:'right',
          customFn:(row)=>{
            let total = 0;
            row.data.map(item => {
              total += item.money
            })
            return (
              <div>
                {total}
              </div>
            )
          }
        }
      ]
    }
  },
  methods: {

    async getList(){
      const res = await getList(this.select)
      console.log(res)
      this.total = res.length ?? 0
      this.list = res
    },
  },
  mounted() {
    this.getList()
  }
}
</script>

<style scoped lang="scss">
</style>
