<template>
  <a-card size="small" :bordered="false" class="accountManagementList-wrap">
    <a-spin :spinning="spinning" tip="Loading...">
      <!-- 搜索条件 -->
      <div ref="tableSearch" class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
          <a-row :gutter="15">
            <a-col :xl="6" :lg="6" :md="12" :sm="24">
              <a-form-item label="货架名称">
                <shelfList @change="shelfChange"></shelfList>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="6" :md="12" :sm="24">
              <a-form-item label="关联客户">
                <custList @change="custChange"></custList>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="4" :md="12" :sm="24">
              <a-form-item label="结算方式">
                <shelfSettType></shelfSettType>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="4" :md="12" :sm="24">
              <a-form-item label="待结金额">
                <div style="display: flex;">
                  <a-input-number/> <span style="margin: 0 10px;">至</span> <a-input-number/>
                </div>
              </a-form-item>
            </a-col>
            <a-col :xl="4" :lg="4" :md="6" :sm="6">
              <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="outboundOrderList-refresh" >查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="outboundOrderList-reset">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-alert type="info" style="margin:10px 0">
        <div slot="message" style="display: flex;align-items: center;padding: 2px 0;">
          共：<strong>{{ }}</strong>条记录；
          待结算金额合计￥<strong>{{ }}</strong>
        </div>
      </a-alert>
      <s-table
        class="sTable fixPagination"
        ref="table"
        :style="{ height: tableHeight+77+'px' }"
        size="small"
        :rowKey="(record) => record.id"
        :columns="columns"
        :data="loadData"
        :scroll="{ y:tableHeight }"
        :defaultLoadData="true"
        bordered>
        <template slot="action" slot-scope="text,record">
          <a-button
            size="small"
            type="link"
            class="button-primary"
            @click="handleUndetail(record)"
            id="shelfMonitoringList-warehousing-btn">待结明细</a-button>
          <a-button
            size="small"
            type="link"
            class="button-primary"
            @click="handleDetail(record)"
            id="shelfMonitoringList-warehousing-btn">结算历史</a-button>
        </template>
      </s-table>
    </a-spin>
  </a-card>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import moment from 'moment'
import { STable } from '@/components'
import shelfList from '@/views/common/shelfList.vue'
import custList from '@/views/common/custList.vue'
import shelfSettType from '@/views/common/shelfSettleType.js'
export default {
  components: { STable, commonMixin, shelfList, custList, shelfSettType },
  data () {
    return {
      spinning: false,
      disabled: false,
      tableHeight: 0,
      showModal: false,
      currentData: null,
      time: [],
      columns: [
        { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
        { title: '交易时间', dataIndex: 'createDate', width: '15%', align: 'center' },
        { title: '调回单号', dataIndex: 'name', width: '30%', align: 'center' },
        { title: '货架名称', dataIndex: '', width: '10%', align: 'center' },
        { title: '状态', dataIndex: '', width: '10%', align: 'center' },
        { title: '调回总量', dataIndex: '', width: '10%', align: 'center' },
        { title: '操作', width: '10%', align: 'center', scopedSlots: { customRender: 'action' } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        const _this = this
        _this.disabled = true
        _this.spinning = true
        return new Promise(function (resolve, reject) {
          const data = {
            list: [{ id: 1, createDate: '2020-08-09' }]
          }
          for (var i = 0; i < data.list.length; i++) {
            data.list[i].no = i + 1
          }
          _this.spinning = false
          _this.disabled = false
          resolve(data)
        })

        // const paramsPage = Object.assign(this.queryParam) //  有分页
        // return reportSalesReturnThjdReportList(paramsPage).then(res => {
        //   let data
        //   if (res.status == 200) {
        //     data = res.data
        //     // this.getCount(paramsPage)
        //     const no = (data.pageNo - 1) * data.pageSize
        //     for (var i = 0; i < data.list.length; i++) {
        //       data.list[i].no = no + i + 1
        //     }
        //     this.disabled = false
        //   }
        //   this.spinning = false
        //   return data
        // })
      }
    }
  },
  methods: {
    // 选择货架
    shelfChange (data) {

    },
    // 禁止选择今天之后的日期
    disabledDate (current) {
      return current && current > moment().endOf('day')
    },
    // 重置
    resetSearchForm () {
      this.time = []
    },
    // 申请提现
    handleTX () {
      this.showModal = true
    },
    // 待结明细
    handleUndetail (row) {
      this.$router.push({ name: 'unSettlementDetail', params: { id: row.id } })
    },
    // 结算历史
    handleDetail (row) {
      this.$router.push({ name: 'settlementDetail', params: { id: row.id } })
    },
    setTableH () {
      const tableSearchH = this.$refs.tableSearch.offsetHeight
      this.tableHeight = window.innerHeight - tableSearchH - 265
    },
    pageInit () {
      const _this = this
      this.$nextTick(() => { // 页面渲染完成后的回调
        _this.setTableH()
      })
    }
  },
  mounted () {
    if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
      this.pageInit()
      this.resetSearchForm()
    }
  },
  watch: {
    advanced (newValue, oldValue) {
      const _this = this
      setTimeout(() => {
        _this.setTableH()
      }, 400)
    },
    '$store.state.app.winHeight' (newValue, oldValue) { //  窗口变更时，需同时更改表格高度
      this.setTableH()
    }
  },
  activated () {
    // 如果是新页签打开，则重置当前页面
    if (this.$store.state.app.isNewTab) {
      this.pageInit()
      this.resetSearchForm()
    }
    // 仅刷新列表，不重置页面
    if (this.$store.state.app.updateList) {
      this.pageInit()
      this.$refs.table.refresh()
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {})
  }
}
</script>

<style lang="less">
  .accountManagementList-wrap{

  }
</style>
