<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="用户手机号" prop="userPhone">
        <el-input v-model="queryParams.userPhone" placeholder="请输入用户手机号" maxlength="11" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="游戏时间">
        <el-date-picker v-model="daterangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="游戏结果" prop="gameResult">
        <el-select v-model="queryParams.gameResult" placeholder="请选择属性" clearable size="small" style="width: 240px">
          <el-option v-for="(v,i) in gameResultList" :key="i" :label="v.label" :value="v.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="结算订单号" prop="relatedOrderNo">
        <el-input v-model="queryParams.relatedOrderNo" placeholder="请输入关联订单号" maxlength="30" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="奖励订单号" prop="rewardOrderNo">
        <el-input v-model="queryParams.rewardOrderNo" placeholder="请输入奖励订单号" maxlength="30" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column type="index" width="55" label="序号" align="center">
        <template slot-scope="scope">
          <div>
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="流水号" align="center" prop="serialNumber" />
      <el-table-column label="用户手机号" align="center" prop="userPhone">
        <template slot-scope="{row}">
          <div>
            {{row.userPhone||'--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="游戏结果" prop="gameResult" align="center">
        <template slot-scope="{row}">
          <div>
            <div v-for="(v,i) in gameResultList" :key="i" :class="{color_red:row.gameResult==0}" v-if="row.gameResult==v.value">{{v.label}}</div>
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="累计消费金额" align="center" prop="serialNumber" /> -->
      <el-table-column label="结算订单号" prop="relatedOrderNo" align="center">
        <template slot-scope="{row}">
          <div>
            {{row.relatedOrderNo||'--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="奖励订单号" prop="rewardOrderNo" align="center">
        <template slot-scope="{row}">
          <div>
            {{row.rewardOrderNo||'--'}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="游戏类型" align="center" prop="prizeType">
        <template slot-scope="{row}">
          <div v-for="(v,i) in prizeTypeList" :key="i" v-if="row.prizeType==v.value">{{v.label}}</div>
        </template>
      </el-table-column>
      <!-- <el-table-column label="奖励订单号" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="红包金额" align="center" prop="redPacketAmount">
        <template slot-scope="{row}">
          {{row.redPacketAmount||'--'}}
        </template>
      </el-table-column>
      <el-table-column label="转账状态" align="center" prop="transferState">
        <template slot-scope="{row}">
          <div v-for="(v,i) in transferStateList" :key="i" v-if="row.transferState==v.value">{{v.label}}</div>
        </template>
      </el-table-column>
      <el-table-column label="执行时间" align="center" prop="executeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.executeTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

  </div>
</template>

<script>
import { gameRecordPage } from "@/api/game.js";
export default {
  data () {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userPhone: undefined,
        gameResult: undefined,
        relatedOrderNo: undefined,
        rewardOrderNo: undefined,
      },
      daterangeCreateTime: [],
      gameResultList: [
        { label: "赢盘", value: 1 },
        { label: "输盘", value: 0 }
      ],
      transferStateList: [
        { label: "转账已受理", value: 'ACCEPTED' },
        { label: "转账锁定资金中", value: 'PROCESSING' },
        { label: "待用户确认", value: 'WAIT_USER_CONFIRM' },
        { label: "转账中", value: 'TRANSFERING' },
        { label: "转账成功", value: 'SUCCESS' },
        { label: "转账失败", value: 'FAIL' },
        { label: "商户撤销请求受理成功", value: 'CANCELING' },
        { label: "转账撤销完成", value: 'CANCELLED' },
      ],
      prizeTypeList: [
        { label: "订单翻倍", value: 0 },
        { label: "红包奖励", value: 1 },
        { label: "兜底奖励", value: 2 },
      ],
    }
  },
  created () {
    this.getList();
  },
  methods: {
    getList () {
      this.loading = true;
      this.queryParams["startTime"] = undefined;
      this.queryParams["endTime"] = undefined;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams["startTime"] = this.daterangeCreateTime[0];
        this.queryParams["endTime"] = this.daterangeCreateTime[1];
      }
      gameRecordPage(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handlePage () {
      this.queryParams.pageNum = 1;
      this.getPage();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  }
}
</script>

<style lang='scss' scoped>
.color_red {
  color: rgb(245, 108, 108);
}
</style>