<template>
  <div class="goodsAllocationSet-page">
    <a-spin :spinning="spinning" tip="Loading...">
      <a-page-header :ghost="false" :backIcon="false" class="goodsAllocationSet-baseInfo" >
        <template slot="subTitle">
          <a href="javascript:;" @click="handleBack"><a-icon type="left"></a-icon> 返回列表</a>
          <span style="margin: 0 15px;color: #666;">{{ this.$route.params.shelfName||'--' }}</span>
        </template>
      </a-page-header>
      <a-card :bordered="false" size="small" class="goodsAllocationSet-baseInfo">
        <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="结算时间">
                  <a-range-picker v-model="time" allowClear :disabledDate="disabledDate" format="YYYY-MM-DD" @change="dateChange"/>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="6" :md="12" :sm="24">
                <a-form-item label="支付方式">
                  <v-select code="PAY_WAY" v-model="queryParam.payWay" allowClear placeholder="请选择支付方式"></v-select>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="6" :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" >
            结算资金可通过账户管理-提现管理功能提出至银行卡
          </div>
        </a-alert>
        <s-table
          class="sTable fixPagination"
          ref="table"
          size="small"
          rowKey="id"
          :columns="columns"
          :data="loadData"
          :defaultLoadData="false"
          bordered>
          <template slot="action" slot-scope="text, record">
            <a-button
              size="small"
              type="link"
              class="button-primary"
              @click="handleDetail(record)"
              id="shelfMonitoringList-warehousing-btn">查看详情</a-button>
          </template>
        </s-table>
      </a-card>
      <!-- 导入货位模板 -->
      <detailModal :openModal="openModal" @close="openModal=false" :settleData="settleData"></detailModal>
    </a-spin>
  </div>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { STable, VSelect } from '@/components'
import detailModal from './detailModal.vue'
import moment from 'moment'
import { querySettleBillPage } from '@/api/merchant'
import { toThousands } from '@/libs/tools.js'
export default {
  mixins: [commonMixin],
  components: { STable, VSelect, detailModal },
  data () {
    return {
      spinning: false,
      disabled: false,
      isEdit: false, // 货位号是否为编辑
      openModal: false, // 货位模板弹窗初始状态
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 16 }
      },
      time: [],
      queryParam: {
        beginDate: '',
        endDate: '',
        payWay: undefined
      },
      settleData: null,
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', width: '12.5%', align: 'center' },
        { title: '结算时间', dataIndex: 'payDate', width: '25%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '结算金额', dataIndex: 'settleAmount', width: '25%', align: 'right', customRender: function (text) { return toThousands(text, 2) || '--' } },
        { title: '支付方式', dataIndex: 'payWayDictValue', width: '25%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '操作', width: '12.5%', align: 'left', scopedSlots: { customRender: 'action' } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.spinning = true
        const paramsPage = Object.assign(parameter, this.queryParam)
        paramsPage.shelfSn = this.$route.params.shelfSn
        paramsPage.payState = 'FINISH'
        return querySettleBillPage(paramsPage).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            const no = (data.pageNo - 1) * data.pageSize
            for (let i = 0; i < data.list.length; i++) {
              const _item = data.list[i]
              _item.no = no + i + 1
            }
          }
          this.spinning = false
          return data
        })
      }
    }
  },
  methods: {
    handleBack () {
      this.$router.push({ path: '/numsGoodsShelves/settlementManagement/list' })
    },
    dateChange (date) {
	  this.queryParam.beginDate = moment(date[0]).format('YYYY-MM-DD')
	  this.queryParam.endDate = moment(date[1]).format('YYYY-MM-DD')
    },
    disabledDate (current) {
	  return current && current > moment().endOf('day')
    },
    // 重置
    resetSearchForm () {
      this.time = []
      this.queryParam = {
        beginDate: '',
        endDate: '',
        payWay: undefined
      }
      this.$refs.table.refresh(true)
    },
    // 查看详情
    handleDetail (row) {
      this.settleData = row
      this.openModal = true
    }
  },
  mounted () {
    if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
      // this.getPageInfo()
      this.resetSearchForm()
    }
  },
  activated () {
    // 如果是新页签打开或者进入新的子页（例：存在列表第2条数据编辑页页签时再打开第4条数据的编辑页），则重置当前页面
    if (this.$store.state.app.isNewTab || !this.$store.state.app.isNewSubTab) {
      // this.getPageInfo()
      this.resetSearchForm()
    }
  }
}
</script>

<style lang="less">
  .goodsAllocationSet-page{
    position: relative;
    height: 100%;
    padding-bottom: 51px;
    box-sizing: border-box;
    .goodsAllocationSet-baseInfo{
      margin-bottom: 10px;
    }
    .bzj-collapse{
      margin-top: 10px;
      .ant-collapse-content-box{
        padding: 10px !important;
      }
    }

  }
</style>
