<template>
  <div>
    <Card style="width:100%">
      <div class="config_meta">
        <p class="fl">待完成委托 {{total}} </p>
        <div class="fr">
          <Tooltip content="刷新" placement="left-start">
            <Icon @click="_page" type="ios-refresh" size="30" color="#2d8cf0" style="cursor:pointer;"></Icon>
          </Tooltip>
<!--          <Tooltip content="查看更多" placement="left-start" style="margin-left: 5px">-->
<!--            <Icon @click="_detail" type="ios-more" size="30" color="#2d8cf0" style="cursor:pointer;"></Icon>-->
<!--          </Tooltip>-->
        </div>
        <div class="clear"></div>
      </div>
      <div style="width: 100%;">
        <PTVXETableHeight ref="pageTable" :table-height="300" :loading="true"
                    :get-page="getPage" hide-checkbox="true">
          <vxe-table-column
            v-for="item in pageColumns"
            :key="item.key"
            :field="item.key"
            :title="item.title"
            :min-width="item.width?item.width:200"
            :fixed="item.fixed?item.fixed:undefined" sortable>
            <template slot-scope="scope">
              <span v-if="item.date">{{scope.row[item.key]?$dateformat(scope.row[item.key],'yyyy-mm-dd'):''}}</span>
              <span v-else-if="item.status">{{scope.row[item.key].display}}</span>
              <span v-else>{{scope.row[item.key]}}</span>
            </template>
          </vxe-table-column>
        </PTVXETableHeight>
      </div>
    </Card>
    <!--未完成委托列表-->
  </div>
</template>

<script>
import { soilStatistics } from '../../api'

export default {
  components: {},
  data() {
    return {
      tableData: { records: [] },
      getPage: {},
      pageColumns: [
        { title: '委托单位', key: 'client' },
        { title: '委托编号', key: 'entrustCode', width: 180 },
        { title: '状态', key: 'progress', width: 110, status: true },
        { title: '委托日期', key: 'entrustDate', date: true }
      ],
      tableHeight: '280',
      total: ''
    }
  },
  mounted() {
    // this._request()
    this._page()
  },
  methods: {
    _detail() {
      this.$refs.unfinishedDetail._open()
    },
    _page: async function() {
      const result = await soilStatistics.pageWaitEnd()
      if (result) {
        console.log(result)
        this.getPage = result
      }
    },
    _request() {
      this.$refs.pageTable._hideLoading()
      this.$store
        .dispatch('FoodContract/unfinishedContract', { page: 1, rows: 7 })
        .then(() => {
          const tableData = this.$store.state.FoodContract.page.records
          const total = this.$store.state.FoodContract.page.total

          if (total === 0) {
            this.total = ''
          } else {
            this.total = '（共 ' + total + ' 条）'
          }
          let num = 0
          if (tableData.length < 7) {
            num = tableData.length
          } else {
            num = 7
          }
          for (let i = 0; i < num; i++) {
            this.tableData.records.push(tableData[i])
          }
        })
    }
  }
}
</script>
