<template>
  <a-card :bordered="false" class="LdDetails-page-info">
    <div class="page-header">
      <a @click="goBack">返回列表</a>
      <span>手机号码：<span class="page-header-info">{{ this.page.mobile }}</span></span>
      <span>乐豆余额：<span class="page-header-info">{{ this.page.currentGold }}</span></span>
    </div>
    <div class="LdDetails-searchForm">
      <a-form layout="inline" v-bind="formItemLayout" @keyup.enter.native="refresh">
        <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="refresh">查询</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, customerDetails } 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: '' // 原因
      },
	  info: '',
	  mobile: '', // 手机号
	  userId: '', // 用户ID
	  currentGold: '', // 乐豆余额
	  customerNo: '', // 用户编号
	  page: {}, // 用户信息
      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 => {
		  const searchData = Object.assign(parameter, this.queryParam)
		  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.query.customerNo }, 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]
      }
    },
    // 查详情
    getPageInfo () {
      customerDetails({
        id: this.userId
      }).then(res => {
        if (res.status == 200) {
          this.page = res.data
        }
      })
    },
    // 查询
    refresh () {
      this.getPageInfo()
      this.$refs.table.refresh(true)
    },
    // 重置
    handleReset () {
      this.queryOrderDate = undefined
      this.queryParam.changeType = ''
      this.queryParam.operateType = ''
      this.$refs.table.refresh(true)
    },
    // 返回列表
    goBack () {
      this.$router.push({
        path: `/userInfo/userManageList/list`
      })
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      const userInfo = vm.$route.query
	  if (userInfo) {
		  vm.userId = userInfo.id
		  console.log(vm.userId)
	  	// customerDetails({
	  	// 	id: userInfo.id
	  	// }).then(res => {
	  	// 	if (res.status == 200) {
	  	// 		vm.page = res.data
	  	// 	}
	  	// })
	  }
	  vm.getPageInfo(vm.userId)
    })
  }
}
</script>
<style lang="less" scoped>
  .LdDetails-page-info{
	  .page-header{
		  margin-bottom: 15px;
		  span{
			  margin-left: 20px;
		  }
		  .page-header-info{
			   margin-left:0;
			 font-weight: bold;
		  }
	  }
    .LdDetails-searchForm{
      .ant-form-inline .ant-form-item{
        width: 100%;
      }
      // 搜索框的下间距
      .ant-form-item {
      	margin-bottom: 15px;
      }
      .handle-btn{
        margin-top: 4px;
      }
      .serach-btn{
        margin-right: 10px;
      }
    }
  }
</style>
