<template>
  <a-card :bordered="false" class="shopOrder-table-page-search-wrapper">
    <div class="shopOrder-searchForm">
      <a-form layout="inline" v-bind="formItemLayout" @keyup.enter.native="$refs.table.refresh(true)">
        <a-row :gutter="48">
          <a-col :span="6">
            <a-form-item label="下单时间" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
              <a-range-picker
                id="LdDetails-queryOrderDate"
                :disabledDate="disabledDate"
                v-model="queryOrderDate"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']" />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="类型" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
              <v-select
                v-model="queryParam.changeType"
                ref="changeType"
                id="LdDetails-status"
                code="GOLD_CHANGE_TYPE"
                placeholder="请选择订单状态"
                allowClear></v-select>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="原因" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
              <v-select
                v-model="queryParam.operateType"
                ref="operateType"
                id="LdDetails-status"
                code="GOLD_OPERATE_TYPE_ALL"
                placeholder="请选择"
                allowClear></v-select>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-button class="handle-btn serach-btn" id="LdDetails-btn-serach" type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button class="handle-btn" type="" id="LdDetails-btn-reset" @click="handleReset">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <s-table
      ref="table"
      size="default"
      :rowKey="(record) => record.id"
      :columns="columns"
      :data="loadData"
      bordered>
    </s-table>
  </a-card>
</template>

<script>
import { STable, VSelect } from '@/components'
import { customerGoldLogDetail } from '@/api/userInfo.js'
import moment from 'moment'
export default {
  name: 'ShopOrder',
  components: { STable, VSelect },
  data () {
    return {
      formItemLayout: {
        labelCol: { span: 7 },
        wrapperCol: { span: 17 }
      },
	  queryOrderDate: undefined,
      // 查询参数
      queryParam: {
        beginDate: null, // 开始时间
        endDate: null, // 结束时间
        changeType: '', // 类型
        operateType: '' // 原因
      },
      loading: false, // 导出loading
      // 表头
      columns: [
        { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
        { title: '下单时间', dataIndex: 'createDate', width: 200, align: 'center' },
        { title: '类型', dataIndex: 'changeTypeDictValue', width: 200, align: 'center' },
        { title: '原因', dataIndex: 'operateTypeDictValue', width: 200, align: 'center' },
        { title: '乐豆变动', dataIndex: 'changeNum', width: 200, align: 'center' },
        { title: '详情',
          dataIndex: 'remarks',
          width: 200,
          align: 'center',
          customRender: (text) => {
            return text || '--'
          } }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
		  console.log(this.customerNo)
		  const searchData = Object.assign(parameter, this.queryParam)
		  console.log(this.queryOrderDate, 'this.queryOrderDate')
		  if (this.queryOrderDate && this.queryOrderDate.length) {
		    searchData.beginDate = moment(this.queryOrderDate[0]).format('YYYY-MM-DD')
		    searchData.endDate = moment(this.queryOrderDate[1]).format('YYYY-MM-DD')
		  } else {
		    searchData.beginDate = ''
		    searchData.endDate = ''
		  }
		  return customerGoldLogDetail(Object.assign(parameter, { customerNo: this.$route.params.id }, searchData)).then(res => {
		    if (res.status == 200) {
		      const no = (res.data.pageNo - 1) * res.data.pageSize
		      for (let i = 0; i < res.data.list.length; i++) {
		        const _item = res.data.list[i]
		        _item.no = no + i + 1
		      }
		      return res.data
		    }
		  })
      }
    }
  },
  methods: {
    moment,
    // 不可选日期
    disabledDate (date, dateStrings) {
      return date && date.valueOf() > Date.now()
    },
    // 创建时间change
    onChange (dates, dateStrings) {
      if ((dates, dateStrings)) {
        this.queryParam.beginDate = dateStrings[0]
        this.queryParam.endDate = dateStrings[1]
      }
    },
    // 重置
    handleReset () {
      this.queryOrderDate = undefined
      this.queryParam.changeType = ''
      this.queryParam.operateType = ''
      this.$refs.table.refresh(true)
    }
  }
}
</script>
<style lang="less" scoped>
  .shopOrder-table-page-search-wrapper{
    .shopOrder-searchForm{
      .ant-form-inline .ant-form-item{
        width: 100%;
      }
      // 搜索框的下间距
      .ant-form-item {
      	margin-bottom: 10px;
      }
      .handle-btn{
        margin-top: 4px;
      }
      .serach-btn{
        margin-right: 10px;
      }
    }
    .export-btn{
      background-color: #ff9900;
      border-color: #ff9900;
      color: #fff;
    }
    .export-btn.ant-btn:focus:not(.ant-btn-primary):not(.ant-btn-danger), .export-btn.ant-btn:hover:not(.ant-btn-primary):not(.ant-btn-danger){
      color: #fff;
      border-color: #ff9900;
    }
    .blue {
    	color: #1890FF;
    }
    .green {
    	color: #16b50e;
    }
    .red {
    	color: red;
    }
  }
</style>
