<template>
  <div>
    <data-table :menuFlag="false" :handleFlag.sync="handleFlag" :loadPage="loadPage"
                :queryParas="queryParas" :sourceData.sync="formTableData.sourceData" :border="true" :stripe="true"
                :loadCount.sync="loadCount" :columns="columns" :operateBtnLayout="operateBtnLayout"
                operatWidth="0px">
    </data-table>
  </div>
</template>
<script>
import BasePage from '@/pages/basePage'
import * as format from '@/filters/index'
import mixin from '@/pages/mixin'
import { DataTable, upDownLayout } from 'newepoch-components'
import tracemgrApi from '@/api/tracemgrApi'
export default {
  extends: new BasePage(),
  name: 'supplierFactoringCommissionerHistoryList',
  mixins: [mixin],
  components: {
    upDownLayout,
    format,
    DataTable
  },
  mounted () {
    this.handleFilter()
  },
  props: {
    creditorId: {
      type: String
    }
  },
  data: function () {
    return {
      isManager: false,
      styles: '',
      buttonDisable: false,
      needComplete: true,
      currentTotal: 0,
      loadPage: 'getUserList',
      loadCount: 0,
      operateBtnLayout: '',
      formTableData: {
        sourceData: []
      },
      showOperation: true,
      handleFlag: true,
      creditorName: '',
      addTime: 0,
      queryParas: {
        pageIndex: 1,
        pageSize: 10,
        id: this.creditorId
      },
      columns: [
        {
          prop: 'creditor',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.supplier,
          showOverflowTooltip: true
        },
        {
          prop: 'operateBefore',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.factoringCommissioner,
          showOverflowTooltip: true
        },
        {
          prop: 'modifyTime',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.responsibleTime,
          showOverflowTooltip: true,
          format: function (row) {
            let start = ''
            if (row.lastTime) {
              let date = new Date(row.lastTime)
              let y = date.getFullYear()
              let MM = date.getMonth() + 1
              MM = MM < 10 ? ('0' + MM) : MM
              let d = date.getDate()
              d = d < 10 ? ('0' + d) : d
              start = y + '-' + MM + '-' + d
            } else {
              let date = new Date(row.addTime)
              let y = date.getFullYear()
              let MM = date.getMonth() + 1
              MM = MM < 10 ? ('0' + MM) : MM
              let d = date.getDate()
              d = d < 10 ? ('0' + d) : d
              start = y + '-' + MM + '-' + d
            }
            if (row.operateAfter === 'listUserStart') {
              return start  + ' - 至今'
            } else {
              let date2 = new Date(row.modifyTime)
              let y2 = date2.getFullYear()
              let MM2 = date2.getMonth() + 1
              MM2 = MM2 < 10 ? ('0' + MM2) : MM2
              let d2 = date2.getDate()
              d2 = d2 < 10 ? ('0' + d2) : d2
              let end = y2 + '-' + MM2 + '-' + d2
              return start + ' - ' + end
            }
          }
        }
      ]
    }
  },
  computed: {
  },
  watch: {
  },
  methods: {
    searchData (val, creditorName, addTime) {
      this.queryParas.id = val
      this.creditorName = creditorName
      this.addTime = addTime
      console.log(this.addTime)
      console.log(this.queryParas)
      this.isLoading = true
      return tracemgrApi['supplierDistributionApiList'].getUserList(this.queryParas).then(res => {
        // this.$set(res.data, 'creditor', this.creditorName)
        res.data.forEach(el => {
          el.creditor = this.creditorName
          this.$set(el, 'addTime', this.addTime)
        })
        console.log(res.data)
        this.formTableData.sourceData = res.data
        this.isLoading = false
      }, res => {
        this.isLoading = false
      })
      // this.val = []
    }
  }
}
</script>
