<template>
  <div class="app-container">
    <div class="filter-container" style="margin-bottom: 0">
      <el-select data-type="normal" filterable v-model="search.timeRange" v-loadmore="loadMore" style="width: 200px" @change="searchData()">
        <el-option v-for="(item,index) in lineOptions" :key="index" :label="item.periodName" :value="item.beginTime+','+item.endTime+','+item.periodDateRange"></el-option>
      </el-select>
<!--      <el-date-picker-->
<!--        v-model="searchTime"-->
<!--        type="datetimerange"-->
<!--        range-separator="-"-->
<!--        start-placeholder="开始日期"-->
<!--        end-placeholder="结束日期"-->
<!--        value-format="yyyy-MM-dd HH:mm:ss"-->
<!--        :default-time="['18:30:00', '18:29:59']">-->
<!--      </el-date-picker>-->
<!--        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="searchData">-->
<!--          搜索-->
<!--        </el-button>-->
      {{timeShow}}
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="getListInfo" />
        </el-tooltip>
      </div>
    </div>
    <el-table
      :data="tableData"
      v-loading="listLoading"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      :size="!webType ? 'mini':''"
      border
      default-expand-all>
      <el-table-column
        align="center"
        label="科目名称">
              <el-table-column
                prop="accountCode"
                label="科目编码">
                <template slot-scope="{row}">
                  <el-link type="primary" @click="$router.push({path:'/financial/transactionDetails/'+row.idAccount ,query:{idAccount:row.idAccount,accountName:row.accountName,searchTime:search.beginTime+','+search.endTime}})">{{row.accountCode}}</el-link>
                </template>
              </el-table-column>
      <el-table-column
        prop="accountName"
        label="科目名称">
      </el-table-column>
        <el-table-column
          prop="beforeMoney"
          label="前日余额">
        </el-table-column>
      </el-table-column>
      <el-table-column
        align="center"
        label="借">
        <el-table-column
          prop="borrowOutMoney"
          label="借">
        </el-table-column>
      <el-table-column
        prop="borrowInMoney"
        label="内部转入">
      </el-table-column>
      <el-table-column
        prop="borrowMonthMoney"
        label="本月累计">
      </el-table-column>
      </el-table-column>
      <el-table-column
        align="center"
        label="贷">
        <el-table-column
          prop="lendOutMoney"
          label="贷">
        </el-table-column>
        <el-table-column
          prop="lendInMoney"
          label="内部转出">
        </el-table-column>
        <el-table-column
          prop="lendMonthMoney"
          label="本月累计">
        </el-table-column>
      </el-table-column>
      <el-table-column
        align="center"
        prop="afterMoney"
        label="当日余额">
      </el-table-column>
      <el-table-column
        align="center"
        prop="realMoney"
        label="实时余额">
      </el-table-column>
    </el-table>
<!--    <pagination v-show="listData.total>0" :total="listData.total" :page.sync="listData.page" :limit.sync="listData.pageSize" @pagination="getListInfo" />-->
  </div>
</template>

<script>
import { getAccountClosedData, getAccountPeriodList } from '@/api/financial/accountClosedData'
export default {
  name: 'AccountBalance',
  props: {
    isChoose: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      webType: true,
      form: {},
      timeShow:'',
      search: {
        timeRange: '',
        beginTime: '',
        endTime: '',
        keyWord: ''
      },
      options: [],

      listData: {
        total: 0,
        page: 1,
        pageSize: 10
      },

      listLoading: false,
      tableData: [],
      basePaperName: '',

      lineOptions: [],
      canmore: true,

      optionListData: {
        total: 0,
        page: 1,
        pageSize: 10
      }
    }
  },
  mounted() {
    this.getListInfo()
    this.getPeriodList()
    if (this.$route.query.type === undefined) {
      this.webType = true
    } else {
      this.webType = false
    }
  },
  methods: {
    // 获取列表
    getListInfo() {
      const _that = this
      _that.listLoading = true
      if(_that.search.timeRange){
        var times = _that.search.timeRange.split(',')
        _that.search.beginTime = times[0]
        _that.search.endTime = times[1]
      }
      var params = {
        'beginTimeLong': _that.search.beginTime,
        'endTimeLong': _that.search.endTime
      }
      // var page = {
      //   pageIndex: _that.listData.page,
      //   pageSize: _that.listData.pageSize
      // }
      var data = {
        'params': JSON.stringify(params)
        // 'page': JSON.stringify(page)
      }
      console.log(data)
      // return
      getAccountClosedData(data).then(response => {
        console.log(response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data
        // _that.listData.total = response.total
        // console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },
    // 刷新变革
    tableRefresh() {
      this.getListInfo()
    },
    // 搜索
    searchData() {
      this.timeShow = this.search.timeRange.split(',')[2]
      this.listData.page = 1
      this.getListInfo()
    },
    getPeriodList() {
      const _that = this
      if (!_that.canmore) {
        return
      }
      var page = {
        pageIndex: _that.optionListData.page,
        pageSize: _that.optionListData.pageSize
      }
      var data = {
        'page': JSON.stringify(page)
      }
      // return
      getAccountPeriodList(data).then(response => {
        console.log(response)
        const data = response.data
        _that.optionListData.total = response.pages

        if (_that.optionListData.page < _that.optionListData.total) {
          _that.lineOptions = _that.lineOptions.concat(data)
        } else if (_that.optionListData.page = _that.optionListData.total) {
          _that.canmore = false
          _that.lineOptions = _that.lineOptions.concat(data)
        } else {
          _that.canmore = false
        }
        console.log(_that.optionListData.page)
        console.log(_that.canmore)
        // //  组合表单数据
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    loadMore() {
      if (this.canmore) {
        this.optionListData.page++
        this.getPeriodList()
      }
    },
    // 弹窗内选择操作
    chooseThis(row) {
      // console.log('点击选择');
      this.$emit('choosePaper', row)
    },
    ERPChoose(row) {
      // this.$message.error(row)
      dyERP.sendJson(JSON.stringify(row))
    }
  }
}
</script>

<style lang="scss" scoped>
  .filter-container {
    margin-bottom: 15px;
  }
</style>
