<template>
  <div class="app-container">
    <div class="filter-container">

      <el-date-picker
        v-model="searchTime"
        type="datetimerange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="timestamp"
        :default-value="[new Date((new Date().getTime() - 3600 * 1000 * 24)),new Date()]"
        :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>

      <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
        prop="accountCode"
        width="90"
        label="科目编码">
      </el-table-column>
      <el-table-column
        prop="accountName"
        width="100"
        label="科目名称">
      </el-table-column>
        <el-table-column
          prop="verifyDate"
          width="160"
          label="操作时间">
          <template slot-scope="scope">
            <span v-if="scope.row.verifyDate !=null">{{scope.row.verifyDate | getTime}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作金额"
          width="120"
        prop="inputMoney">
        </el-table-column>
        <el-table-column
          label="期初金额"
          width="120"
          prop="beforeMoney">
        </el-table-column>
        <el-table-column
          width="150"
          label="期末金额">
          <template slot-scope="{row}">
            <el-button type="green" circle size="mini" class="iconfont" v-if="row.borrowFlag==1">&#xe62f;</el-button>
            <el-button type="warning" circle size="mini" class="iconfont" v-else-if="row.borrowFlag==-1">&#xe630;</el-button>
            &nbsp;
            {{row.afterMoney}}
          </template>
        </el-table-column>
      <el-table-column
        width="80"
        align="center"
        label="内部标记">
        <template slot-scope="{row}">
          <span v-if="row.internalFlag==1" style="font-weight: 700">√</span>
<!--          <el-button type="warning" circle size="mini" class="iconfont" v-else></el-button>-->
        </template>
      </el-table-column>
        <el-table-column
          label="操作说明"
          prop="billMemo">
        </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 { getAccountTradeBillList } from '@/api/financial/accountBalance'
export default {
  name: 'TransactionDetails',
  props: {
    isChoose: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      webType: true,
      idAccount: null,
      accountName: null,

      searchTime: [],
      search: {
        beginTime: '',
        endTime: '',
        keyWord: ''
      },
      form: {},
      options: [],

      companyList: [], // 分厂列表
      stockRoomList: [], // 库房列表

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

      listLoading: false,
      tableData: [],
      basePaperName: ''
    }
  },
  created() {
    this.idAccount = this.$route.query.idAccount
    this.accountName = this.$route.query.accountName
    console.log(this.$route.query.searchTime);
    if (this.$route.query.searchTime) {
      this.searchTime = this.$route.query.searchTime.split(',')
    }
    console.log(this.searchTime);
    this.tempRoute = Object.assign({}, this.$route)
    this.setTagsViewTitle()
  },
  mounted() {
    this.getListInfo()
    if (this.$route.query.type === undefined) {
      this.webType = true
    } else {
      this.webType = false
    }
  },
  methods: {
    // 设置标签名称
    setTagsViewTitle() {
      const title = '账表流水'

      // console.log("tempRoute2",this.tempRoute);
      const route = Object.assign({}, this.tempRoute, { title: `${this.accountName}-${title}` })
      // console.log("route",route)
      this.$store.dispatch('tagsView/updateVisitedView', route)
    },
    // 获取列表
    getListInfo() {
      const _that = this
      _that.listLoading = true
      if (_that.searchTime == null || _that.searchTime <= 0 || _that.searchTime[0] == '') {
        _that.search.beginTime = ''
        _that.search.endTime = ''
      } else {
        _that.search.beginTime = _that.searchTime[0]
        _that.search.endTime = _that.searchTime[1]
      }
      var params = {
        'beginTimeLong': _that.search.beginTime,
        'endTimeLong': _that.search.endTime
      }
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var data = {
        'idAccount': _that.idAccount,
        'page': JSON.stringify(page),
        'params': JSON.stringify(params)
      }
      console.log(data);
      getAccountTradeBillList(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.listData.page = 1
      this.getListInfo()
    },
    // 弹窗内选择操作
    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>
